Skip to content

Commit

Permalink
Merge pull request #449 from rauhja/main
Browse files Browse the repository at this point in the history
Added a test for margin and linespacing modifier
  • Loading branch information
JPToroDev authored Feb 11, 2025
2 parents e3f2807 + 693344f commit fb5661c
Show file tree
Hide file tree
Showing 2 changed files with 141 additions and 4 deletions.
43 changes: 41 additions & 2 deletions Tests/IgniteTesting/Modifiers/LineSpacing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,47 @@ import Testing
@Suite("LineSpacing Tests")
@MainActor
struct LineSpacingTests {
@Test("ExampleTest")
func example() async throws {
@Test("LineSpacing with custom line height", arguments: [
(value: 2.5, expected: "2.5"),
(value: 0.0, expected: "0"),
(value: -2.0, expected: "-2")
])
func textWithCustomLineSpacing(testCase: (value: Double, expected: String)) async throws {
let element = Text("Hello, world!").lineSpacing(testCase.value)
let output = element.render()

#expect(output == "<p style=\"line-height: \(testCase.expected)\">Hello, world!</p>")
}

@Test("LineSpacing with xSmall preset line height")
func xSmallPresetLineSpacing() async throws {
let element = Text("Hello, world!").lineSpacing(.xSmall)
let output = element.render()

#expect(output == "<p class=\"lh-1\">Hello, world!</p>")
}

@Test("LineSpacing with small preset line height")
func smallPresetLineSpacing() async throws {
let element = Text("Hello, world!").lineSpacing(.small)
let output = element.render()

#expect(output == "<p class=\"lh-sm\">Hello, world!</p>")
}

@Test("LineSpacing with small preset line height")
func standardPresetLineSpacing() async throws {
let element = Text("Hello, world!").lineSpacing(.standard)
let output = element.render()

#expect(output == "<p class=\"lh-base\">Hello, world!</p>")
}

@Test("LineSpacing with small preset line height")
func largePresetLineSpacing() async throws {
let element = Text("Hello, world!").lineSpacing(.large)
let output = element.render()

#expect(output == "<p class=\"lh-lg\">Hello, world!</p>")
}
}
102 changes: 100 additions & 2 deletions Tests/IgniteTesting/Modifiers/Margin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,106 @@ import Testing
@Suite("Margin Tests")
@MainActor
struct MarginTests {
@Test("ExampleTest")
func example() async throws {
@Test("Default margin applies 20px to all edges")
func defaultMargin() async throws {
let element = Text("Hello, world!").margin()
let output = element.render()

#expect(output == "<p style=\"margin: 20px\">Hello, world!</p>")
}

@Test("Margin modifier with custom pixel value", arguments: [
(value: 40, expected: "40px"),
(value: 0, expected: "0px"),
(value: -40, expected: "-40px")
])
func customPixelMargin(testCase: (value: Int, expected: String)) async throws {
let element = Text("Hello, world!").margin(testCase.value)
let output = element.render()

#expect(output == "<p style=\"margin: \(testCase.expected)\">Hello, world!</p>")
}

@Test("Margin modifier with amount value")
func amountUnitMargin() async throws {
let element = Text("Hello, world!").margin(.small)
let output = element.render()

#expect(output == "<p class=\"m-2\">Hello, world!</p>")
}

@Test("Margin modifier with length unit", arguments: [
(value: LengthUnit.rem(2.5), expected: "2.5rem"),
(value: LengthUnit.em(3), expected: "3.0em"),
(value: LengthUnit.percent(25%), expected: "25.0%"),
(value: LengthUnit.vw(10%), expected: "10.0vw"),
(value: LengthUnit.vh(30%), expected: "30.0vh")
])
func lengthUnitMargin(testCase: (value: LengthUnit, expected: String)) async throws {
let element = Text("Hello, world!").margin(testCase.value)
let output = element.render()

#expect(output == "<p style=\"margin: \(testCase.expected)\">Hello, world!</p>")
}

@Test("Margin with negative length values", arguments: [
(value: LengthUnit.rem(-2.5), expected: "-2.5rem"),
(value: LengthUnit.em(-3), expected: "-3.0em"),
(value: LengthUnit.percent(-25%), expected: "-25.0%"),
(value: LengthUnit.vw(-10%), expected: "-10.0vw"),
(value: LengthUnit.vh(-30%), expected: "-30.0vh")
])
func negativeMargin(testCase: (value: LengthUnit, expected: String)) {
let element = Text("Hello, world!").margin(testCase.value)
let output = element.render()

#expect(output == "<p style=\"margin: \(testCase.expected)\">Hello, world!</p>")
}

@Test("Margin modifier with custom length unit")
func customLengthUnitMargin() async throws {
let element = Text("Hello, world!").margin(.custom("min(60vh, 300px)"))
let output = element.render()

#expect(output == "<p style=\"margin: min(60vh, 300px)\">Hello, world!</p>")
}

@Test("Margin on selected sides with default pixels", arguments: [
(value: (Edge.top), expected: "margin-top: 20px"),
(value: (Edge.bottom), expected: "margin-bottom: 20px"),
(value: (Edge.leading), expected: "margin-left: 20px"),
(value: (Edge.trailing), expected: "margin-right: 20px"),
(value: (Edge.vertical), expected: "margin-bottom: 20px; margin-top: 20px"),
(value: (Edge.horizontal), expected: "margin-left: 20px; margin-right: 20px")
])
func selectedEdgeMargin(testCase: (value: Edge, expected: String)) {
let element = Text("Hello, world!").margin(testCase.value)
let output = element.render()

#expect(output == "<p style=\"\(testCase.expected)\">Hello, world!</p>")
}

@Test("Margin with custom pixel value and multiple edges")
func customValueAndEdgeMargin() {
let element = Text("Hello, world!").margin(.top, 25).margin(.leading, 10)
let output = element.render()

#expect(output == "<p style=\"margin-left: 10px; margin-top: 25px\">Hello, world!</p>")
}

@Test("Margin on selected side with specified unit")
func selectedEdgeMarginWithUnit() {
let element = Text("Hello, world!").margin(.top, .rem(1.125))
let output = element.render()

#expect(output == "<p style=\"margin-top: 1.125rem\">Hello, world!</p>")
}

@Test("Margin on selected side with specified amount")
func selectedEdgeMarginWithAmount() {
let element = Text("Hello, world!").margin(.top, .medium)
let output = element.render()

#expect(output == "<p class=\"mt-3\">Hello, world!</p>")
}
}

0 comments on commit fb5661c

Please sign in to comment.