Merge branch 'setup' into template
This commit is contained in:
@@ -0,0 +1,105 @@
|
||||
import Testing
|
||||
|
||||
@testable import Infrastructure
|
||||
|
||||
@Suite(
|
||||
"Analytics.Event type",
|
||||
.tags(.type)
|
||||
)
|
||||
struct AnalyticsEventTests {
|
||||
|
||||
// MARK: Computed tests
|
||||
|
||||
@Test
|
||||
func `renders the event name alone when it carries no properties`() {
|
||||
let event = Analytics.Event(name: "instagram")
|
||||
|
||||
#expect(event.attributes.count == 1)
|
||||
#expect(event.attributes[0] == Analytics.Attribute(
|
||||
"data-umami-event",
|
||||
value: "instagram"
|
||||
))
|
||||
}
|
||||
|
||||
@Test
|
||||
func `renders each property as an attribute suffixed by its key`() {
|
||||
let event = Analytics.Event(
|
||||
name: "playlist",
|
||||
properties: ["set": "avc-xi"]
|
||||
)
|
||||
|
||||
#expect(event.attributes.count == 2)
|
||||
#expect(event.attributes[1] == Analytics.Attribute(
|
||||
"data-umami-event-set",
|
||||
value: "avc-xi"
|
||||
))
|
||||
}
|
||||
|
||||
@Test
|
||||
func `renders the name first, then the properties in the order given`() {
|
||||
let event = Analytics.Event(
|
||||
name: "interview",
|
||||
properties: [
|
||||
"placement": "credit",
|
||||
"locale": "en",
|
||||
]
|
||||
)
|
||||
|
||||
// The order is the rendered attribute order, which a dictionary would leave to churn between builds.
|
||||
#expect(event.attributes.map(\.name) == [
|
||||
"data-umami-event",
|
||||
"data-umami-event-placement",
|
||||
"data-umami-event-locale",
|
||||
])
|
||||
#expect(event.attributes.map(\.value) == ["interview", "credit", "en"])
|
||||
}
|
||||
|
||||
// MARK: Equatable tests
|
||||
|
||||
@Test
|
||||
func `matches an event rendering the same attributes`() {
|
||||
let event = Analytics.Event(
|
||||
name: "playlist",
|
||||
properties: ["set": "avc-xi"]
|
||||
)
|
||||
|
||||
#expect(event == Analytics.Event(
|
||||
name: "playlist",
|
||||
properties: ["set": "avc-xi"]
|
||||
))
|
||||
}
|
||||
|
||||
@Test(arguments: [
|
||||
Analytics.Event(
|
||||
name: "playlist",
|
||||
properties: ["set": "avc-ix"]
|
||||
),
|
||||
Analytics.Event(
|
||||
name: "playlist",
|
||||
properties: ["show": "avc-xi"]
|
||||
),
|
||||
Analytics.Event(
|
||||
name: "apple_music",
|
||||
properties: ["set": "avc-xi"]
|
||||
),
|
||||
Analytics.Event(name: "playlist"),
|
||||
Analytics.Event(
|
||||
name: "playlist",
|
||||
properties: [
|
||||
"set": "avc-xi",
|
||||
"placement": "strip",
|
||||
]
|
||||
),
|
||||
])
|
||||
func `differs from an event rendering anything else`(
|
||||
from other: Analytics.Event
|
||||
) {
|
||||
let event = Analytics.Event(
|
||||
name: "playlist",
|
||||
properties: ["set": "avc-xi"]
|
||||
)
|
||||
|
||||
#expect(event != other)
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user