Skip to content

Commit 9b575b2

Browse files
committed
Add paywall view event test
1 parent 240e94f commit 9b575b2

File tree

6 files changed

+52
-5
lines changed

6 files changed

+52
-5
lines changed

Modules/Logging/Sources/Event.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
public struct Event: Sendable {
55
let name: Name
66
let info: [String: String]
7-
var value: String { String(name.value) }
7+
public var value: String { String(name.value) }
88

99
public init(name: Name, info: [String: String]) {
1010
self.name = name

Modules/Paywall/Sources/PaywallView.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ import FactoryKit
77

88
import BarcDesignSystem
99
import BarcLogging
10+
import BarcTestHelpersInterface
1011

1112
public struct PaywallView: View {
1213
@Environment(\.horizontalSizeClass) private var horizontalSizeClass
1314
@Injected(\.logger) private var logger
1415

1516
public init() {}
1617

18+
let inspection = Inspection<Self>()
1719
public var body: some View {
1820
GeometryReader { proxy in
1921
VStack(spacing: 0) {
@@ -55,6 +57,7 @@ public struct PaywallView: View {
5557
Event(name: "Barc.PaywallView.viewed", info: [:])
5658
)
5759
}
60+
.onReceive(inspection.notice) { self.inspection.visit(self, $0) }
5861
}
5962

6063
private static let breakWidth = Double(640)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Created by Geoff Pado on 5/18/25.
2+
// Copyright © 2025 Cocoatype, LLC. All rights reserved.
3+
4+
import ViewInspector
5+
6+
import BarcTestHelpersInterface
7+
8+
extension Inspection: @retroactive InspectionEmissary, @unchecked Sendable {}

Modules/Paywall/Tests/PaywallTests.swift

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Created by Geoff Pado on 9/9/24.
2+
// Copyright © 2024 Cocoatype, LLC. All rights reserved.
3+
4+
import Testing
5+
import ViewInspector
6+
7+
import FactoryKit
8+
import FactoryTesting
9+
10+
import BarcLogging
11+
import BarcLoggingDoubles
12+
import BarcTestHelpers
13+
14+
@testable import BarcPaywall
15+
16+
@MainActor @Suite(.container)
17+
struct PaywallViewTests {
18+
@available(iOS 18.0, *)
19+
@Test("Sends event on appear")
20+
func onAppearEvent() async throws {
21+
let logger = SpyLogger()
22+
Container.shared.logger.register { logger }
23+
let paywall = PaywallView()
24+
25+
ViewHosting.host(view: paywall)
26+
defer { ViewHosting.expel() }
27+
28+
try await paywall.inspection.inspect { inspectedPaywall in
29+
#expect(logger.loggedEvents.count == 1)
30+
let event = try #require(logger.loggedEvents.first)
31+
#expect(event.value == "Barc.PaywallView.viewed")
32+
}
33+
}
34+
}

Tuist/ProjectDescriptionHelpers/Targets/Modules/Paywall.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,19 @@ public enum Paywall {
99
.target(ErrorHandling.target),
1010
.target(Logging.target),
1111
.target(Purchasing.target),
12+
.target(TestHelpers.interfaceTarget),
1213
.external(name: "FactoryKit"),
1314
]
1415
)
1516

1617
public static let testTarget = Target.moduleTestTarget(
1718
name: "Paywall",
1819
dependencies: [
20+
.target(Logging.target),
21+
.target(Logging.doublesTarget),
22+
.external(name: "FactoryKit"),
23+
.external(name: "FactoryTesting"),
24+
.external(name: "ViewInspector"),
1925
]
2026
)
2127
}

0 commit comments

Comments
 (0)