Skip to content

Commit c278e04

Browse files
committed
Add unit tests
1 parent cee711f commit c278e04

File tree

2 files changed

+62
-5
lines changed

2 files changed

+62
-5
lines changed

Package.swift

+1
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@ let package = Package(
1515
.target(
1616
name: "SplitView",
1717
dependencies: []),
18+
.testTarget(name: "SplitViewTests", dependencies: ["SplitView"]),
1819
]
1920
)
+61-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,67 @@
11
import XCTest
2+
import SwiftUI
23
@testable import SplitView
34

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+
422
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)
1065
}
1166
}
67+

0 commit comments

Comments
 (0)