This commit contains the latest updates from the generic Website template, which move the toolchain to Swift 6.4, gate analytics and structured data behind traits, and rework page routing: - Updated the Swift toolchain for all the package dependencies and the Website service to version 6.4. (345b305) - Adapted all the existing middlewares in the Infrastructure package to Swift 6.4. (26008df) - Moved test resource teardown in the Persistence and the Website library into defer blocks. (27984a9) - Gated analytics behind a trait and reworked structured data in the Infrastructure package. (c7d4769) - Enabled the Analytics trait in the Website service. (f6a6bbd) - Reworked page routing in the Website service. (d1cb2c1) - Gated the structured data features in the Infrastructure package behind a trait. (f0a8791) - Enabled the StructuredData trait of the Infrastructure package in the Website service. (bbfdeb3) - Fixed the asset pin and a build warning in the Dockerfile of the Website service. (6ed0f9b) The root README change in 345b305 was left out, as this project no longer carries that file. From d1cb2c1, the RootController rework was left out, as the prototype serves a session-aware landing page and routes its other pages through their own controllers; the view-event reporter was appended to the prototype's shared script instead. The prototype code was adapted to the stricter Swift 6.4 settings: `String(format:)` was swapped for safe formatting, the NoIndex middleware takes a `@concurrent` next handler, and the tests flagged by warnings-as-errors were tightened. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
69 lines
1.8 KiB
Swift
69 lines
1.8 KiB
Swift
#if Analytics
|
|
import Elementary
|
|
import Testing
|
|
|
|
@testable import Infrastructure
|
|
|
|
@Suite(
|
|
"MarkupContent+Reporting extension",
|
|
.tags(.extension)
|
|
)
|
|
struct MarkupContentReportingTests {
|
|
|
|
// MARK: Methods tests
|
|
|
|
@Test
|
|
func `renders the same markup as applying the event's tagging`() {
|
|
let event = Analytics.Event(
|
|
name: "playlist",
|
|
properties: ["set": "avc-xi"]
|
|
)
|
|
|
|
let reported = a(.href("/")) { "Listen" }
|
|
.reporting(event)
|
|
.render()
|
|
let tagged = a(.href("/")) { "Listen" }
|
|
.attributes(contentsOf: event.tagging())
|
|
.render()
|
|
|
|
#expect(reported == tagged)
|
|
#expect(reported == #"<a href="/" data-umami-event="playlist" data-umami-event-set="avc-xi">Listen</a>"#)
|
|
}
|
|
|
|
@Test
|
|
func `keeps the attributes chained before it`() {
|
|
let rendered = a(.href("https://example.com")) { "Listen" }
|
|
.attributes(.target(.blank), when: true)
|
|
.reporting(.init(name: "playlist"))
|
|
.render()
|
|
|
|
#expect(rendered == #"<a href="https://example.com" target="_blank" data-umami-event="playlist">Listen</a>"#)
|
|
}
|
|
|
|
@Test
|
|
func `tags a view under its own prefix`() {
|
|
let rendered = h2 { "KLM" }
|
|
.reporting(
|
|
.init(
|
|
name: "case_view",
|
|
properties: ["case": "klm"]
|
|
),
|
|
on: .view
|
|
)
|
|
.render()
|
|
|
|
#expect(rendered == #"<h2 data-view-event="case_view" data-view-event-case="klm">KLM</h2>"#)
|
|
}
|
|
|
|
@Test
|
|
func `reports from an SVG tag`() {
|
|
let rendered = SVG.path {}
|
|
.reporting(.init(name: "logo"))
|
|
.render()
|
|
|
|
#expect(rendered.contains(#"data-umami-event="logo""#))
|
|
}
|
|
|
|
}
|
|
#endif
|