Skip to content

Commit 03219c8

Browse files
committed
More fixed functionality tests, this time for HStack, VStack, List, and more.
1 parent 47ef71a commit 03219c8

File tree

7 files changed

+247
-0
lines changed

7 files changed

+247
-0
lines changed

Tests/IgniteTesting/Elements/HStack.swift

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,33 @@ class HStackTests: IgniteTestSuite {
4545
</div>
4646
""")
4747
}
48+
49+
@Test("HStack with bottom alignment uses align-self-end")
50+
func bottomAlignment() async throws {
51+
let element = HStack(alignment: .bottom) {
52+
ControlLabel("Item")
53+
}
54+
let output = element.markupString()
55+
#expect(output.contains("align-self-end"))
56+
}
57+
58+
@Test("HStack with semantic spacing uses gap class")
59+
func semanticSpacing() async throws {
60+
let element = HStack(spacing: .large) {
61+
ControlLabel("Item")
62+
}
63+
let output = element.markupString()
64+
#expect(output.contains("gap-4"))
65+
}
66+
67+
@Test("HStack with spacing none omits gap class")
68+
func spacingNone() async throws {
69+
let element = HStack(spacing: .none) {
70+
ControlLabel("Item")
71+
}
72+
let output = element.markupString()
73+
#expect(output.contains("hstack"))
74+
#expect(!output.contains("gap-"))
75+
#expect(!output.contains("gap:"))
76+
}
4877
}

Tests/IgniteTesting/Elements/Item.swift

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,44 @@ struct ItemTests {
4141
</div></div></div>
4242
""")
4343
}
44+
45+
@Test("Item with startsOpen true renders without collapsed class and with show class")
46+
func startsOpenTrue() async throws {
47+
let accordionID = "accordion\(UUID().uuidString.truncatedHash)"
48+
let element = Item("Open item", startsOpen: true) {
49+
Text("Visible content")
50+
}
51+
.assigned(to: accordionID, openMode: .individual)
52+
53+
let output = element.markupString()
54+
#expect(output.contains("accordion-button "))
55+
#expect(!output.contains("accordion-button collapsed"))
56+
#expect(output.contains("aria-expanded=\"true\""))
57+
#expect(output.contains("collapse show"))
58+
}
59+
60+
@Test("Item with contentBackground adds background style")
61+
func contentBackgroundColor() async throws {
62+
let accordionID = "accordion\(UUID().uuidString.truncatedHash)"
63+
let element = Item("Colored item") {
64+
Text("Content")
65+
}
66+
.contentBackground(.red)
67+
.assigned(to: accordionID, openMode: .individual)
68+
69+
let output = element.markupString()
70+
#expect(output.contains("background:"))
71+
}
72+
73+
@Test("Item with openMode all omits data-bs-parent with accordion ID")
74+
func openModeAll() async throws {
75+
let accordionID = "accordion\(UUID().uuidString.truncatedHash)"
76+
let element = Item("All mode") {
77+
Text("Content")
78+
}
79+
.assigned(to: accordionID, openMode: .all)
80+
81+
let output = element.markupString()
82+
#expect(!output.contains("data-bs-parent=\"#\(accordionID)\""))
83+
}
4484
}

Tests/IgniteTesting/Elements/Label.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,26 @@ class LabelTests: IgniteTestSuite {
2626
</span>
2727
""")
2828
}
29+
30+
@Test("Label with system image uses Bootstrap icon")
31+
func systemImageLabel() async throws {
32+
let element = Label("Settings", systemImage: "gear")
33+
let output = element.markupString()
34+
#expect(output.contains("bi-gear"))
35+
#expect(output.contains("Settings"))
36+
#expect(output.contains("inline-flex"))
37+
}
38+
39+
@Test("Label with builder initializer renders custom content")
40+
func builderLabel() async throws {
41+
let element = Label {
42+
Span("Custom Title")
43+
} icon: {
44+
Span("Icon")
45+
}
46+
let output = element.markupString()
47+
#expect(output.contains("Custom Title"))
48+
#expect(output.contains("Icon"))
49+
#expect(output.contains("inline-flex"))
50+
}
2951
}

Tests/IgniteTesting/Elements/List.swift

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,74 @@ class ListTests: IgniteTestSuite {
3232

3333
#expect(output == "<ul><li>Veni</li><li>Vidi</li><li>Vici</li></ul>")
3434
}
35+
36+
@Test("Ordered list uses ol tag")
37+
func orderedList() async throws {
38+
let list = List {
39+
"First"
40+
"Second"
41+
}.listMarkerStyle(.ordered)
42+
let output = list.markupString()
43+
#expect(output.hasPrefix("<ol"))
44+
#expect(output.hasSuffix("</ol>"))
45+
#expect(output.contains("First"))
46+
}
47+
48+
@Test("Group list style adds list-group class")
49+
func groupListStyle() async throws {
50+
let list = List {
51+
"Item"
52+
}.listStyle(.group)
53+
let output = list.markupString()
54+
#expect(output.contains("list-group"))
55+
#expect(output.contains("list-group-item"))
56+
}
57+
58+
@Test("Plain list style adds list-group-flush class")
59+
func plainListStyle() async throws {
60+
let list = List {
61+
"Item"
62+
}.listStyle(.plain)
63+
let output = list.markupString()
64+
#expect(output.contains("list-group-flush"))
65+
}
66+
67+
@Test("Horizontal group list style adds list-group-horizontal class")
68+
func horizontalGroupListStyle() async throws {
69+
let list = List {
70+
"Item"
71+
}.listStyle(.horizontalGroup)
72+
let output = list.markupString()
73+
#expect(output.contains("list-group-horizontal"))
74+
}
75+
76+
@Test("Custom marker style converts symbol to CSS unicode")
77+
func customMarkerStyle() async throws {
78+
let list = List {
79+
"Starred"
80+
}.listMarkerStyle(.custom(""))
81+
let output = list.markupString()
82+
#expect(output.contains("list-style-type"))
83+
}
84+
85+
@Test("Sequence initializer renders items from collection")
86+
func sequenceInitializer() async throws {
87+
let names = ["Alice", "Bob"]
88+
let list = List(names) { name in
89+
Text(name)
90+
}
91+
let output = list.markupString()
92+
#expect(output.contains("Alice"))
93+
#expect(output.contains("Bob"))
94+
}
95+
96+
@Test("Ordered list with specific marker style applies style")
97+
func orderedListWithRomanMarker() async throws {
98+
let list = List {
99+
"Item"
100+
}.listMarkerStyle(.ordered(.upperRoman))
101+
let output = list.markupString()
102+
#expect(output.hasPrefix("<ol"))
103+
#expect(output.contains("list-style-type: upper-roman"))
104+
}
35105
}

Tests/IgniteTesting/Elements/ListItem.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,25 @@ class ListItemTests: IgniteTestSuite {
2323

2424
#expect(output == "<li>Standalone List Item</li>")
2525
}
26+
27+
@Test("ListItem with role adds role class")
28+
func roleModifier() async throws {
29+
let element = ListItem {
30+
"Important item"
31+
}.role(.danger)
32+
let output = element.markupString()
33+
#expect(output.contains("list-group-item-danger"))
34+
}
35+
36+
@Test("ListItem with HTML content renders nested elements")
37+
func htmlContent() async throws {
38+
let element = ListItem {
39+
Text("Bold item")
40+
Text("Second line")
41+
}
42+
let output = element.markupString()
43+
#expect(output.contains("<p>Bold item</p>"))
44+
#expect(output.contains("<p>Second line</p>"))
45+
#expect(output.hasPrefix("<li>"))
46+
}
2647
}

Tests/IgniteTesting/Elements/Spacer.swift

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,33 @@ class SpacerTests: IgniteTestSuite {
2121

2222
#expect(output == "<div class=\"mt-auto\"></div>")
2323
}
24+
25+
@Test("Spacer with exact pixel size produces frame height")
26+
func exactPixelSize() async throws {
27+
let element = Spacer(size: 50)
28+
let output = element.markupString()
29+
#expect(output.contains("height: 50px"))
30+
}
31+
32+
@Test("Spacer with semantic size produces margin")
33+
func semanticSize() async throws {
34+
let element = Spacer(size: .large)
35+
let output = element.markupString()
36+
#expect(output.contains("mt-4"))
37+
}
38+
39+
@Test("Spacer with horizontal axis uses ms-auto instead of mt-auto")
40+
func horizontalAxis() async throws {
41+
let element = Spacer().axis(.horizontal)
42+
let output = element.markupString()
43+
#expect(output.contains("ms-auto"))
44+
#expect(!output.contains("mt-auto"))
45+
}
46+
47+
@Test("Spacer with exact size and horizontal axis produces frame width")
48+
func exactPixelHorizontal() async throws {
49+
let element = Spacer(size: 30).axis(.horizontal)
50+
let output = element.markupString()
51+
#expect(output.contains("width: 30px"))
52+
}
2453
}

Tests/IgniteTesting/Elements/VStack.swift

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,40 @@ class VStackTests: IgniteTestSuite {
4545
</div>
4646
""")
4747
}
48+
49+
@Test("VStack with leading alignment uses align-self-start")
50+
func leadingAlignment() async throws {
51+
let element = VStack(alignment: .leading) {
52+
ControlLabel("Item")
53+
}
54+
let output = element.markupString()
55+
#expect(output.contains("align-self-start"))
56+
}
57+
58+
@Test("VStack with trailing alignment uses align-self-end")
59+
func trailingAlignment() async throws {
60+
let element = VStack(alignment: .trailing) {
61+
ControlLabel("Item")
62+
}
63+
let output = element.markupString()
64+
#expect(output.contains("align-self-end"))
65+
}
66+
67+
@Test("VStack with semantic spacing uses gap class")
68+
func semanticSpacing() async throws {
69+
let element = VStack(spacing: .large) {
70+
ControlLabel("Item")
71+
}
72+
let output = element.markupString()
73+
#expect(output.contains("gap-4"))
74+
}
75+
76+
@Test("VStack with nil spacing preserves implicit margins by omitting mb-0")
77+
func nilSpacingPreservesMargins() async throws {
78+
let element = VStack(spacing: nil) {
79+
ControlLabel("Item")
80+
}
81+
let output = element.markupString()
82+
#expect(!output.contains("mb-0"))
83+
}
4884
}

0 commit comments

Comments
 (0)