Skip to content

Commit 7486c3f

Browse files
committed
Another delivery of tests for your reading pleasure.
1 parent ca33769 commit 7486c3f

File tree

6 files changed

+122
-0
lines changed

6 files changed

+122
-0
lines changed

Tests/IgniteTesting/Elements/Group.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,24 @@ class GroupTests: IgniteTestSuite {
5454
onclick="alert('Bottom Button Tapped')">Bottom Button</button>
5555
""")
5656
}
57+
58+
@Test("Class modifier propagates to all children")
59+
func classPropagatesToChildren() async throws {
60+
let element = Group {
61+
Text("First")
62+
Text("Second")
63+
}.class("highlight")
64+
let output = element.markupString()
65+
66+
#expect(output.contains("<p class=\"highlight\">First</p>"))
67+
#expect(output.contains("<p class=\"highlight\">Second</p>"))
68+
}
69+
70+
@Test("Empty Group produces empty output")
71+
func emptyGroup() async throws {
72+
let element = Group {}
73+
let output = element.markupString()
74+
75+
#expect(output == "")
76+
}
5777
}

Tests/IgniteTesting/Elements/Time.swift

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,36 @@ import Testing
4444

4545
#expect(output == "<time datetime=\"2024-05-22T20:00:30Z\">\(timeText)</time>")
4646
}
47+
48+
@Test("Time with dateTime but no visible content")
49+
func dateTimeOnly() async throws {
50+
guard
51+
let customTimeInterval = DateComponents(
52+
calendar: .current,
53+
timeZone: .gmt,
54+
year: 2024,
55+
month: 5,
56+
day: 22,
57+
hour: 20,
58+
minute: 0,
59+
second: 30
60+
).date?.timeIntervalSince1970
61+
else {
62+
Issue.record("Failed to create test data!")
63+
return
64+
}
65+
let dateTime = Date(timeIntervalSince1970: customTimeInterval)
66+
let element = Time(dateTime: dateTime)
67+
let output = element.markupString()
68+
69+
#expect(output == "<time datetime=\"2024-05-22T20:00:30Z\"></time>")
70+
}
71+
72+
@Test("Time with no content and no date renders empty time element")
73+
func noContentNoDate() async throws {
74+
let element = Time()
75+
let output = element.markupString()
76+
77+
#expect(output == "<time></time>")
78+
}
4779
}

Tests/IgniteTesting/Modifiers/AnimationModifier.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,23 @@ class AnimationModifierTests: IgniteTestSuite {
4949
Issue.record("Failed to create regular expression: \(error)")
5050
}
5151
}
52+
53+
@Test("Click trigger produces onclick handler")
54+
func clickTrigger() async throws {
55+
let element = Text("Click me").animation(Animation.bounce, on: .click)
56+
let output = element.markupString()
57+
58+
#expect(output.contains("igniteToggleClickAnimation(this)"))
59+
#expect(output.contains("onclick"))
60+
}
61+
62+
@Test("Appear trigger produces animation class without hover suffix")
63+
func appearTrigger() async throws {
64+
let element = Text("Appear").animation(Animation.bounce, on: .appear)
65+
let output = element.markupString()
66+
67+
#expect(output.contains("animation-"))
68+
#expect(!output.contains("-hover"))
69+
#expect(!output.contains("onclick"))
70+
}
5271
}

Tests/IgniteTesting/Modifiers/BackgroundImage.swift

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,29 @@ struct BackgroundImageTests {
5353
</p>
5454
""")
5555
}
56+
57+
@Test("Background image with repeats true produces background-repeat repeat")
58+
func repeatsTrue() async throws {
59+
let element = Text {
60+
"Hello World!"
61+
}.background(image: "assets/pattern.png", contentMode: .original, repeats: true)
62+
let output = element.markupString()
63+
64+
#expect(output.contains("background-repeat: repeat"))
65+
#expect(!output.contains("no-repeat"))
66+
}
67+
68+
@Test("Background position with percent values and non-center alignment")
69+
func percentRelativePosition() async throws {
70+
let position = BackgroundPosition.position(
71+
vertical: .percent(10), relativeTo: .top,
72+
horizontal: .percent(20), relativeTo: .leading
73+
)
74+
let element = Text {
75+
"Hello World!"
76+
}.background(image: "assets/image.png", contentMode: .fill, position: position)
77+
let output = element.markupString()
78+
79+
#expect(output.contains("background-position: calc(0% + 20%) calc(0% + 10%)"))
80+
}
5681
}

Tests/IgniteTesting/Modifiers/BadgeModifier.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,5 @@ class BadgeModifierTests: IgniteTestSuite {
4242
</li>
4343
""")
4444
}
45+
4546
}

Tests/IgniteTesting/Modifiers/Border.swift

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,29 @@ class BorderModifierTests: IgniteTestSuite {
3030
#expect(!output.contains("border-left"))
3131
#expect(!output.contains("border-right"))
3232
}
33+
34+
@Test("Border with default width and style uses 1px solid")
35+
func borderDefaultParams() async throws {
36+
let element = Text("Hello").border(.red)
37+
let output = element.markupString()
38+
#expect(output.contains("border: 1.0px solid rgb(255 0 0 / 100%)"))
39+
}
40+
41+
@Test("Border with single leading edge produces only border-left")
42+
func borderLeadingEdge() async throws {
43+
let element = Text("Hello").border(.red, width: 2.0, style: .dashed, edges: .leading)
44+
let output = element.markupString()
45+
#expect(output.contains("border-left: 2.0px dashed rgb(255 0 0 / 100%)"))
46+
#expect(!output.contains("border-right"))
47+
#expect(!output.contains("border-top"))
48+
#expect(!output.contains("border-bottom"))
49+
}
50+
51+
@Test("Border on InlineElement applies border style")
52+
func borderOnInlineElement() async throws {
53+
let element = Span("Hello").border(.green)
54+
let output = element.markupString()
55+
#expect(output.contains("border: 1.0px solid"))
56+
#expect(output.contains("<span"))
57+
}
3358
}

0 commit comments

Comments
 (0)