Implemented the "tagging()" method for the the AnalyticsEvent+Tagging extension in the Infrastructure package.
This commit is contained in:
+49
@@ -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)
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user