Skip to content

Commit b3f9e1f

Browse files
committed
add tests to Example project
1 parent 675e1be commit b3f9e1f

9 files changed

+450
-6
lines changed

Examples/Package.resolved

+64-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"originHash" : "7df801fbf92ae86259dad3815ef4d283ea3c6fe70a47cd2aae1434ea589a6eb7",
2+
"originHash" : "59596559cd9569246f17d99534bd1fdbb00707301c4028b46ce969519d1e794c",
33
"pins" : [
44
{
55
"identity" : "async-http-client",
@@ -10,6 +10,15 @@
1010
"version" : "1.22.1"
1111
}
1212
},
13+
{
14+
"identity" : "combine-schedulers",
15+
"kind" : "remoteSourceControl",
16+
"location" : "https://github.com/pointfreeco/combine-schedulers",
17+
"state" : {
18+
"revision" : "9fa31f4403da54855f1e2aeaeff478f4f0e40b13",
19+
"version" : "1.0.2"
20+
}
21+
},
1322
{
1423
"identity" : "hummingbird",
1524
"kind" : "remoteSourceControl",
@@ -55,6 +64,15 @@
5564
"version" : "1.2.0"
5665
}
5766
},
67+
{
68+
"identity" : "swift-clocks",
69+
"kind" : "remoteSourceControl",
70+
"location" : "https://github.com/pointfreeco/swift-clocks",
71+
"state" : {
72+
"revision" : "b9b24b69e2adda099a1fa381cda1eeec272d5b53",
73+
"version" : "1.0.5"
74+
}
75+
},
5876
{
5977
"identity" : "swift-collections",
6078
"kind" : "remoteSourceControl",
@@ -64,6 +82,24 @@
6482
"version" : "1.1.3"
6583
}
6684
},
85+
{
86+
"identity" : "swift-concurrency-extras",
87+
"kind" : "remoteSourceControl",
88+
"location" : "https://github.com/pointfreeco/swift-concurrency-extras",
89+
"state" : {
90+
"revision" : "bb5059bde9022d69ac516803f4f227d8ac967f71",
91+
"version" : "1.1.0"
92+
}
93+
},
94+
{
95+
"identity" : "swift-dependencies",
96+
"kind" : "remoteSourceControl",
97+
"location" : "https://github.com/pointfreeco/swift-dependencies.git",
98+
"state" : {
99+
"revision" : "fd1fb25b68fdb9756cd61d23dbd9e2614b340085",
100+
"version" : "1.4.0"
101+
}
102+
},
67103
{
68104
"identity" : "swift-distributed-tracing",
69105
"kind" : "remoteSourceControl",
@@ -172,6 +208,24 @@
172208
"version" : "2.6.1"
173209
}
174210
},
211+
{
212+
"identity" : "swift-snapshot-testing",
213+
"kind" : "remoteSourceControl",
214+
"location" : "https://github.com/pointfreeco/swift-snapshot-testing",
215+
"state" : {
216+
"revision" : "7b0bbbae90c41f848f90ac7b4df6c4f50068256d",
217+
"version" : "1.17.5"
218+
}
219+
},
220+
{
221+
"identity" : "swift-syntax",
222+
"kind" : "remoteSourceControl",
223+
"location" : "https://github.com/swiftlang/swift-syntax",
224+
"state" : {
225+
"revision" : "cb53fa1bd3219b0b23ded7dfdd3b2baff266fd25",
226+
"version" : "600.0.0"
227+
}
228+
},
175229
{
176230
"identity" : "swift-system",
177231
"kind" : "remoteSourceControl",
@@ -180,6 +234,15 @@
180234
"revision" : "d2ba781702a1d8285419c15ee62fd734a9437ff5",
181235
"version" : "1.3.2"
182236
}
237+
},
238+
{
239+
"identity" : "xctest-dynamic-overlay",
240+
"kind" : "remoteSourceControl",
241+
"location" : "https://github.com/pointfreeco/xctest-dynamic-overlay",
242+
"state" : {
243+
"revision" : "bc2a151366f2cd0e347274544933bc2acb00c9fe",
244+
"version" : "1.4.0"
245+
}
183246
}
184247
],
185248
"version" : 3

Examples/Package.swift

+15-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ let package = Package(
1212
dependencies: [
1313
.package(url: "https://github.com/hummingbird-project/hummingbird.git", from: "2.0.0"),
1414
.package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.3.0"),
15+
.package(url: "https://github.com/pointfreeco/swift-snapshot-testing.git", from: "1.12.0"),
16+
.package(url: "https://github.com/pointfreeco/swift-dependencies.git", from: "1.4.0"),
1517
.package(name: "swift-http-types-htmx", path: "../"),
1618
],
1719
targets: [
@@ -21,8 +23,20 @@ let package = Package(
2123
.product(name: "ArgumentParser", package: "swift-argument-parser"),
2224
.product(name: "Hummingbird", package: "hummingbird"),
2325
.product(name: "HTTPTypesHtmx", package: "swift-http-types-htmx"),
26+
.product(name: "Dependencies", package: "swift-dependencies"),
2427
],
2528
path: "Sources/App"
26-
)
29+
),
30+
.testTarget(
31+
name: "AppTests",
32+
dependencies: [
33+
"App",
34+
.product(name: "HummingbirdTesting", package: "hummingbird"),
35+
.product(name: "SnapshotTesting", package: "swift-snapshot-testing"),
36+
.product(name: "InlineSnapshotTesting", package: "swift-snapshot-testing"),
37+
.product(name: "Dependencies", package: "swift-dependencies"),
38+
],
39+
path: "Tests/AppTests"
40+
),
2741
]
2842
)

Examples/README.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@ This project provides examples of `swift-htmx` usage
44

55
## Getting Started
66

7-
Start the server by running `swift run App` in the project root
7+
Start the server by running `swift run App` in the project root or run the project on Xcode
8+
9+
## Examples
810

911
- (HX-Location)[Sources/App/HtmxExamples/HXLocationHandlers.swift] - Do a client side redirect via `HX-Location`
1012
- (HX-Reswap)[Sources/App/HtmxExamples/HXReswapHandlers.swift] - Swap an element via `HX-Reswap`
1113
- (HX-Trigger)[Sources/App/HtmxExamples/HXTriggerHandlers.swift] - Trigger a client-side event via `HX-Trigger`
14+
15+
The (AppTests.swift)[Tests/AppTests/AppTests.swif] contains a tests for all the request handlers, demonstrating mocked htmx requests and its how the response looks like in an HTTP Response
16+

Examples/Sources/App/HtmxExamples/HXReswapHandlers.swift

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import Dependencies
12
import Foundation
23
import HTTPTypesHtmx
34
import Hummingbird
@@ -11,7 +12,8 @@ extension Route {
1112
}
1213

1314
@Sendable func hxReswapHandler(_ req: Request) -> Response {
14-
let timestamp = String(Date.now.timeIntervalSince1970)
15+
@Dependency(\.date) var date
16+
let timestamp = String(date().timeIntervalSince1970)
1517
let inputId = "timestamp"
1618
let inputSelector = "#timestamp"
1719
let input = """

Examples/Sources/App/HtmxExamples/Support/Hummingbird+Html.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ extension Response {
1212
]
1313
headers.append(contentsOf: extraHeaders)
1414
return .init(
15-
status: .accepted,
15+
status: .ok,
1616
headers: headers,
1717
body: .init(byteBuffer: .init(string: htmlString))
1818
)

0 commit comments

Comments
 (0)