Implemented the "tagging()" method for the the AnalyticsEvent+Tagging extension in the Infrastructure package.

This commit is contained in:
2026-08-30 09:15:59 +02:00
parent cf58b97de1
commit 8bf6e86ffb
4 changed files with 76 additions and 3 deletions
@@ -0,0 +1,49 @@
import Elementary
import Testing
@testable import Infrastructure
@Suite(
"Analytics.Event+Tagging extension",
.tags(.extension)
)
struct AnalyticsEventTaggingTests {
// MARK: Methods tests
@Test
func `applies the event name to the tag`() {
let markup = a(.href("/")) { "Listen" }
.attributes(contentsOf: Analytics.Event(name: "instagram").tagging())
#expect(markup.render().contains(#"data-umami-event="instagram""#))
}
@Test
func `applies every event attribute to the tag`() {
let event = Analytics.Event(
name: "playlist",
properties: ["set": "avc-xi"]
)
let markup = button {}
.attributes(contentsOf: event.tagging())
let rendered = markup.render()
#expect(rendered.contains(#"data-umami-event="playlist""#))
#expect(rendered.contains(#"data-umami-event-set="avc-xi""#))
}
@Test
func `returns one attribute per event attribute`() {
let event = Analytics.Event(
name: "playlist",
properties: ["set": "avc-xi"]
)
let attributes: [HTMLAttribute<HTMLTag.a>] = event.tagging()
#expect(attributes.count == event.attributes.count)
}
}