Skip to content

Commit 306e2a1

Browse files
committed
Some more tests. I feel like these commit messages are getting repetitive, so: what's red and smells like blue paint? Red paint.
1 parent cc5c34d commit 306e2a1

File tree

7 files changed

+203
-22
lines changed

7 files changed

+203
-22
lines changed

Tests/IgniteTesting/Elements/Body.swift

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@ import Testing
1313
/// Tests for the `title` element.
1414
@Suite("Body Tests")
1515
@MainActor class BodyTests: IgniteTestSuite {
16-
static let sites: [any Site] = [TestSite(), TestSubsite()]
17-
18-
@Test("Simple Body Test", arguments: await Self.sites)
19-
func simpleBody(for site: any Site) async throws {
16+
@Test("Simple Body Test")
17+
func simpleBody() async throws {
2018
let element = Body()
2119
let output = element.markupString()
2220
let path = publishingContext.path(for: URL(string: "/js")!)
@@ -28,4 +26,27 @@ import Testing
2826
</body>
2927
""")
3028
}
29+
30+
@Test("Body with content renders content inside body tags")
31+
func bodyWithContent() async throws {
32+
let element = Body { Text("Hello") }
33+
let output = element.markupString()
34+
#expect(output.contains("<body"))
35+
#expect(output.contains("Hello"))
36+
#expect(output.contains("</body>"))
37+
}
38+
39+
@Test("Body without container omits container class")
40+
func bodyIgnorePageGutters() async throws {
41+
let element = Body().ignorePageGutters()
42+
let output = element.markupString()
43+
#expect(!output.contains("container"))
44+
}
45+
46+
@Test("Body with data attribute renders data attribute")
47+
func bodyDataAttribute() async throws {
48+
let element = Body().data("theme", "dark")
49+
let output = element.markupString()
50+
#expect(output.contains("data-theme=\"dark\""))
51+
}
3152
}

Tests/IgniteTesting/Elements/CodeBlock.swift

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,35 @@ class CodeBlockTests: IgniteTestSuite {
3434
let test = CodeBlockTest(name: "Swift")</code></pre>
3535
""")
3636
}
37+
38+
@Test("Code block with language adds language class to code element")
39+
func codeBlockWithLanguage() {
40+
let element = CodeBlock(.swift) { "let x = 1" }
41+
let output = element.markupString()
42+
#expect(output.contains("class=\"language-swift\""))
43+
#expect(output.contains("let x = 1"))
44+
}
45+
46+
@Test("Code block without language omits language class")
47+
func codeBlockWithoutLanguage() {
48+
let element = CodeBlock { "echo hello" }
49+
let output = element.markupString()
50+
#expect(!output.contains("language-"))
51+
}
52+
53+
@Test("Code block with highlighted lines adds data-line attribute")
54+
func highlightedLines() {
55+
let element = CodeBlock(.swift) { "line1\nline2\nline3" }
56+
.highlightedLines(1, 3)
57+
let output = element.markupString()
58+
#expect(output.contains("data-line=\"1,3\""))
59+
}
60+
61+
@Test("Code block with highlighted ranges adds data-line attribute with range")
62+
func highlightedRanges() {
63+
let element = CodeBlock(.swift) { "a\nb\nc\nd" }
64+
.highlightedRanges(1...3)
65+
let output = element.markupString()
66+
#expect(output.contains("data-line=\"1-3\""))
67+
}
3768
}

Tests/IgniteTesting/Elements/Embed.swift

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,35 @@ class EmbedTests: IgniteTestSuite {
2626
gyroscope; picture-in-picture; web-share"></iframe></div>
2727
""")
2828
}
29+
30+
@Test("Vimeo embed uses correct URL format")
31+
func vimeoEmbed() async throws {
32+
let element = Embed(vimeoID: 123456, title: "Vimeo Test")
33+
let output = element.markupString()
34+
#expect(output.contains("src=\"https://player.vimeo.com/video/123456\""))
35+
#expect(output.contains("title=\"Vimeo Test\""))
36+
}
37+
38+
@Test("Spotify embed uses correct URL format with content type and theme")
39+
func spotifyEmbed() async throws {
40+
let element = Embed(spotifyID: "abc123", title: "My Track", type: .track, theme: 1)
41+
let output = element.markupString()
42+
#expect(output.contains("src=\"https://open.spotify.com/embed/track/abc123?utm_source=generator&theme=1\""))
43+
#expect(output.contains("title=\"My Track\""))
44+
}
45+
46+
@Test("Spotify playlist type uses playlist in URL")
47+
func spotifyPlaylistEmbed() async throws {
48+
let element = Embed(spotifyID: "pl123", title: "My Playlist", type: .playlist)
49+
let output = element.markupString()
50+
#expect(output.contains("/embed/playlist/pl123"))
51+
}
52+
53+
@Test("Generic URL embed renders provided URL")
54+
func genericURLEmbed() async throws {
55+
let element = Embed(title: "Custom", url: "https://example.com/widget")
56+
let output = element.markupString()
57+
#expect(output.contains("src=\"https://example.com/widget\""))
58+
#expect(output.contains("title=\"Custom\""))
59+
}
2960
}

Tests/IgniteTesting/Elements/SubscribeForm.swift

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,37 @@ class SubscribeFormTests: IgniteTestSuite {
4343
<script charset="utf-8" src="https://cdn.sendfox.com/js/form.js"></script>
4444
""")
4545
}
46+
47+
@Test("Mailchimp form uses correct endpoint and form ID")
48+
func mailchimpForm() async throws {
49+
let element = SubscribeForm(.mailchimp(username: "user", uValue: "abc", listID: "123"))
50+
let output = element.markupString()
51+
#expect(output.contains("action=\"https://user.us1.list-manage.com/subscribe/post?u=abc&id=123\""))
52+
#expect(output.contains("id=\"mc-embedded-subscribe-form\""))
53+
#expect(output.contains("name=\"mc-embedded-subscribe-form\""))
54+
}
55+
56+
@Test("Kit form uses correct endpoint and email field name")
57+
func kitForm() async throws {
58+
let element = SubscribeForm(.kit("myToken"))
59+
let output = element.markupString()
60+
#expect(output.contains("action=\"https://app.convertkit.com/forms/myToken/subscriptions\""))
61+
#expect(output.contains("name=\"email_address\""))
62+
}
63+
64+
@Test("Buttondown form uses correct endpoint and form class")
65+
func buttondownForm() async throws {
66+
let element = SubscribeForm(.buttondown("myuser"))
67+
let output = element.markupString()
68+
#expect(output.contains("action=\"https://buttondown.com/api/emails/embed-subscribe/myuser\""))
69+
#expect(output.contains("embeddable-buttondown-form"))
70+
}
71+
72+
@Test("Custom subscribe button label renders correctly")
73+
func customButtonLabel() async throws {
74+
let element = SubscribeForm(.sendFox(listID: "x", formID: "y"))
75+
.subscribeButtonLabel("Join Now")
76+
let output = element.markupString()
77+
#expect(output.contains(">Join Now</button>"))
78+
}
4679
}

Tests/IgniteTesting/Elements/Table.swift

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,67 @@ class TableTests: IgniteTestSuite {
1818
let output = element.markupString()
1919
#expect(output == "<table class=\"table\"><tbody></tbody></table>")
2020
}
21+
22+
@Test("Table with header renders thead")
23+
func tableWithHeader() async throws {
24+
let element = Table {
25+
Row {
26+
Column { "A" }
27+
Column { "B" }
28+
}
29+
} header: {
30+
"Name"
31+
"Value"
32+
}
33+
let output = element.markupString()
34+
#expect(output.contains("<thead><tr><th>Name</th><th>Value</th></tr></thead>"))
35+
}
36+
37+
@Test("Table with rows renders content inside tbody")
38+
func tableWithRows() async throws {
39+
let element = Table {
40+
Row {
41+
Column { "Cell1" }
42+
}
43+
}
44+
let output = element.markupString()
45+
#expect(output.contains("<tbody>"))
46+
#expect(output.contains("Cell1"))
47+
}
48+
49+
@Test("Striped rows style adds table-striped class")
50+
func stripedRowsStyle() async throws {
51+
let element = Table { }.tableStyle(.stripedRows)
52+
let output = element.markupString()
53+
#expect(output.contains("table-striped"))
54+
#expect(!output.contains("table-striped-columns"))
55+
}
56+
57+
@Test("Striped columns style adds table-striped-columns class")
58+
func stripedColumnsStyle() async throws {
59+
let element = Table { }.tableStyle(.stripedColumns)
60+
let output = element.markupString()
61+
#expect(output.contains("table-striped-columns"))
62+
}
63+
64+
@Test("Plain style adds no striping class")
65+
func plainStyle() async throws {
66+
let element = Table { }.tableStyle(.plain)
67+
let output = element.markupString()
68+
#expect(!output.contains("table-striped"))
69+
}
70+
71+
@Test("Table border adds table-bordered class")
72+
func tableBorder() async throws {
73+
let element = Table { }.tableBorder(true)
74+
let output = element.markupString()
75+
#expect(output.contains("table-bordered"))
76+
}
77+
78+
@Test("Accessibility label adds caption element")
79+
func accessibilityLabel() async throws {
80+
let element = Table { }.accessibilityLabel("Test caption")
81+
let output = element.markupString()
82+
#expect(output.contains("<caption>Test caption</caption>"))
83+
}
2184
}

Tests/IgniteTesting/Framework/Transition.swift

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -78,30 +78,14 @@ struct TransitionTests {
7878
#expect(item.final == "blur(10.0px)")
7979
}
8080

81-
@Test("flip right contains rotateY(360deg) with correct duration and timing")
82-
func flipRight() async throws {
81+
@Test("flip sets duration to 0.5 and timing to easeInOut")
82+
func flipDurationAndTiming() async throws {
8383
let transition = Transition.flip(.right)
8484
let item = transition.data[0]
85-
#expect(item.property == .transform)
86-
#expect(item.final.contains("rotateY(360deg)"))
8785
#expect(item.duration == 0.5)
8886
#expect(item.timing == .easeInOut)
8987
}
9088

91-
@Test("flip left contains rotateY(-360deg)")
92-
func flipLeft() async throws {
93-
let transition = Transition.flip(.left)
94-
let item = transition.data[0]
95-
#expect(item.final.contains("rotateY(-360deg)"))
96-
}
97-
98-
@Test("flip up contains rotateX(-360deg)")
99-
func flipUp() async throws {
100-
let transition = Transition.flip(.up)
101-
let item = transition.data[0]
102-
#expect(item.final.contains("rotateX(-360deg)"))
103-
}
104-
10589
@Test("speed() halves the last data item's duration")
10690
func speedModifier() async throws {
10791
let transition = Transition.fadeIn.speed(2.0)

Tests/IgniteTesting/Modifiers/MediaQuery.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,4 +126,22 @@ class MediaQueryTests: IgniteTestSuite {
126126
let light = ThemeQuery(DefaultLightTheme.self)
127127
#expect(dark != light)
128128
}
129+
130+
// MARK: - Hashable
131+
132+
@Test("Equal theme queries hash equally")
133+
func themeQueryHashable() async throws {
134+
let a = ThemeQuery(DefaultDarkTheme.self)
135+
let b = ThemeQuery(DefaultDarkTheme.self)
136+
#expect(a.hashValue == b.hashValue)
137+
}
138+
139+
// MARK: - BreakpointQuery init from Breakpoint
140+
141+
@Test("init from Breakpoint maps correctly")
142+
func breakpointQueryInitFromBreakpoint() async throws {
143+
let query = BreakpointQuery(.medium)
144+
#expect(query != nil)
145+
#expect(query?.condition == "min-width: 768px")
146+
}
129147
}

0 commit comments

Comments
 (0)