|
1 | 1 | import XCTest
|
| 2 | +import SwiftUI |
2 | 3 | @testable import SplitView
|
3 | 4 |
|
| 5 | +struct ContentView: View { |
| 6 | + let hide = SideHolder() |
| 7 | + var body: some View { |
| 8 | + VStack(spacing: 0) { |
| 9 | + Button("Toggle Hide") { |
| 10 | + withAnimation { |
| 11 | + hide.toggle() // Toggle between hiding nothing and hiding secondary |
| 12 | + } |
| 13 | + } |
| 14 | + HSplit(left: { Color.red }, right: { Color.green }) |
| 15 | + .hide(hide) |
| 16 | + .constraints(minPFraction: 0.2, minSFraction: 0.2) |
| 17 | + .splitter { Splitter.invisible() } |
| 18 | + } |
| 19 | + } |
| 20 | +} |
| 21 | + |
4 | 22 | final class SplitViewTests: XCTestCase {
|
5 |
| - func testExample() throws { |
6 |
| - // This is an example of a functional test case. |
7 |
| - // Use XCTAssert and related functions to verify your tests produce the correct |
8 |
| - // results. |
9 |
| - XCTAssertEqual(SplitView().text, "Hello, World!") |
| 23 | + func testSplitViewHideSecondary() { |
| 24 | + let view = ContentView() |
| 25 | + let hide = view.hide |
| 26 | + |
| 27 | + // Initial state: Both primary (red) and secondary (green) views are visible. |
| 28 | + XCTAssertNil(hide.side) |
| 29 | + |
| 30 | + // Toggle hide to hide the secondary (green) view. |
| 31 | + withAnimation { |
| 32 | + hide.toggle() |
| 33 | + } |
| 34 | + XCTAssertEqual(hide.side, .secondary) |
| 35 | + |
| 36 | + // Toggle hide again to unhide the secondary (green) view. |
| 37 | + withAnimation { |
| 38 | + hide.toggle() |
| 39 | + } |
| 40 | + XCTAssertNil(hide.side) |
| 41 | + } |
| 42 | + |
| 43 | + func testSplitViewHidPrimary() { |
| 44 | + let view = ContentView() |
| 45 | + let hide = view.hide |
| 46 | + |
| 47 | + // Initial state: Both primary (red) and secondary (green) views are visible. |
| 48 | + XCTAssertNil(hide.side) |
| 49 | + |
| 50 | + // Set the previous value to .primary (to simulate the initial old value) |
| 51 | + hide.side = .primary |
| 52 | + XCTAssertEqual(hide.side, .primary) |
| 53 | + |
| 54 | + // Toggle to unhide the primary side (red view). |
| 55 | + hide.toggle() |
| 56 | + XCTAssertNil(hide.side) |
| 57 | + |
| 58 | + // Toggle to hide the primary side again (red view). |
| 59 | + hide.toggle() |
| 60 | + XCTAssertEqual(hide.side, .primary) |
| 61 | + |
| 62 | + // Toggle to unhide the primary side again (red view). |
| 63 | + hide.toggle() |
| 64 | + XCTAssertNil(hide.side) |
10 | 65 | }
|
11 | 66 | }
|
| 67 | + |
0 commit comments