From 6d9927337b0049c342a2c97b0d44493f647cad80 Mon Sep 17 00:00:00 2001 From: Michel Anderson Lutz Teixeira Date: Wed, 27 Nov 2024 22:26:07 -0300 Subject: [PATCH 1/2] New Tags Span and Button --- README.md | 2 +- Sources/WingedSwift/HTML/Commons/Button.swift | 15 +++++++++ Sources/WingedSwift/HTML/Commons/Span.swift | 14 ++++++++ Sources/WingedSwift/WingedSwift.swift | 2 +- Tests/WingedSwiftTests/HTMLTagTests.swift | 33 +++++++++++++++++++ 5 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 Sources/WingedSwift/HTML/Commons/Button.swift create mode 100644 Sources/WingedSwift/HTML/Commons/Span.swift diff --git a/README.md b/README.md index 3e6ddd8..13882d4 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ To add WingedSwift to your project, add the following line to your `Package.swif ```swift dependencies: [ - .package(url: "https://github.com/micheltlutz/Winged-Swift.git", from: "1.1.0") + .package(url: "https://github.com/micheltlutz/Winged-Swift.git", from: "1.2.2") ] ``` diff --git a/Sources/WingedSwift/HTML/Commons/Button.swift b/Sources/WingedSwift/HTML/Commons/Button.swift new file mode 100644 index 0000000..ec50d62 --- /dev/null +++ b/Sources/WingedSwift/HTML/Commons/Button.swift @@ -0,0 +1,15 @@ +import Foundation + +/// Represents a + """ + XCTAssertEqual(document.render(), expected) + } + + func testHTMLButtonChildren() { + let document = html { + Button(attributes: [Attribute(key: "class", value: "button-class")], children: [ + Span(attributes: [Attribute(key: "class", value: "icon-bar")]) + ]) + } + + let expected = """ + + """ + XCTAssertEqual(document.render(), expected) + } } From 183cf597894031a4e460f7891106007b55c6e8be Mon Sep 17 00:00:00 2001 From: Michel Anderson Lutz Teixeira Date: Wed, 27 Nov 2024 22:46:34 -0300 Subject: [PATCH 2/2] add HTMLBuilderTests --- Tests/WingedSwiftTests/HTMLBuilderTests.swift | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 Tests/WingedSwiftTests/HTMLBuilderTests.swift diff --git a/Tests/WingedSwiftTests/HTMLBuilderTests.swift b/Tests/WingedSwiftTests/HTMLBuilderTests.swift new file mode 100644 index 0000000..7e33e8e --- /dev/null +++ b/Tests/WingedSwiftTests/HTMLBuilderTests.swift @@ -0,0 +1,60 @@ +import XCTest +@testable import WingedSwift + +final class HTMLBuilderTests: XCTestCase { + func testHTMLBuilderCreatesRootHTMLTag() { + // Given + let expectedTagName = "html" + + // When + let document = html { + HTMLTag("body") + HTMLTag("head") + } + + // Then + XCTAssertEqual(document.name, expectedTagName, "Root tag should be 'html'") + XCTAssertEqual(document.children.count, 2, "Root tag should have two children.") + XCTAssertEqual(document.children[0].name, "body", "First child should be 'body'") + XCTAssertEqual(document.children[1].name, "head", "Second child should be 'head'") + } + + func testHTMLBuilderHandlesOptional() { + // Given + let optionalComponent: HTMLTag? = HTMLTag("optional") + + // When + let document = html { + HTMLBuilder.buildOptional(optionalComponent) + } + + // Then + XCTAssertEqual(document.name, "html", "Root tag should be 'html'") + XCTAssertEqual(document.children.count, 1, "Root tag should have one child.") + XCTAssertEqual(document.children[0].name, "optional", "Child tag should be 'optional'") + } + + func testHTMLBuilderHandlesEitherFirst() { + // When + let document = html { + HTMLBuilder.buildEither(first: HTMLTag("first")) + } + + // Then + XCTAssertEqual(document.name, "html", "Root tag should be 'html'") + XCTAssertEqual(document.children.count, 1, "Root tag should have one child.") + XCTAssertEqual(document.children[0].name, "first", "Child tag should be 'first'") + } + + func testHTMLBuilderHandlesEitherSecond() { + // When + let document = html { + HTMLBuilder.buildEither(second: HTMLTag("second")) + } + + // Then + XCTAssertEqual(document.name, "html", "Root tag should be 'html'") + XCTAssertEqual(document.children.count, 1, "Root tag should have one child.") + XCTAssertEqual(document.children[0].name, "second", "Child tag should be 'second'") + } +}