@@ -100,6 +100,73 @@ final class JetpackConnectionErrorViewModelTests: XCTestCase {
100100 // Then
101101 XCTAssertTrue ( navigationController. topViewController is AuthenticatedWebViewController )
102102 }
103+
104+ func test_error_view_is_tracked( ) {
105+ // Given
106+ let analyticsProvider = MockAnalyticsProvider ( )
107+ let analytics = WooAnalytics ( analyticsProvider: analyticsProvider)
108+ let viewModel = JetpackConnectionErrorViewModel ( siteURL: siteURL,
109+ credentials: credentials,
110+ analytics: analytics,
111+ onJetpackSetupCompletion: { _ in } )
112+
113+ // When
114+ viewModel. viewDidLoad ( nil )
115+
116+ // Then
117+ XCTAssertNotNil ( analyticsProvider. receivedEvents. first ( where: { $0 == " login_jetpack_connection_error_shown " } ) )
118+ }
119+
120+ func test_primary_button_tap_is_tracked( ) {
121+ // Given
122+ let analyticsProvider = MockAnalyticsProvider ( )
123+ let analytics = WooAnalytics ( analyticsProvider: analyticsProvider)
124+ let viewModel = JetpackConnectionErrorViewModel ( siteURL: siteURL,
125+ credentials: credentials,
126+ analytics: analytics,
127+ onJetpackSetupCompletion: { _ in } )
128+
129+ // When
130+ viewModel. didTapPrimaryButton ( in: nil )
131+
132+ // Then
133+ XCTAssertNotNil ( analyticsProvider. receivedEvents. first ( where: { $0 == " login_jetpack_connect_button_tapped " } ) )
134+ }
135+
136+ func test_failure_to_fetch_connection_url_is_tracked( ) throws {
137+ // Given
138+ let stores = MockStoresManager ( sessionManager: . makeForTesting( ) )
139+ var completed = false
140+ stores. whenReceivingAction ( ofType: JetpackConnectionAction . self) { action in
141+ switch action {
142+ case . fetchJetpackConnectionURL( let completion) :
143+ let error = NSError ( domain: " Test " , code: 123 )
144+ completion ( . failure( error) )
145+ completed = true
146+ default :
147+ break
148+ }
149+ }
150+
151+ let analyticsProvider = MockAnalyticsProvider ( )
152+ let analytics = WooAnalytics ( analyticsProvider: analyticsProvider)
153+
154+ // When
155+ _ = JetpackConnectionErrorViewModel ( siteURL: siteURL,
156+ credentials: credentials,
157+ stores: stores,
158+ analytics: analytics,
159+ onJetpackSetupCompletion: { _ in } )
160+ waitUntil {
161+ completed == true
162+ }
163+
164+ // Then
165+ let indexOfEvent = try XCTUnwrap ( analyticsProvider. receivedEvents. firstIndex ( where: { $0 == " login_jetpack_connection_url_fetch_failed " } ) )
166+ let properties = try XCTUnwrap ( analyticsProvider. receivedProperties [ indexOfEvent] )
167+ XCTAssertEqual ( properties [ " error_code " ] as? String , " 123 " )
168+ XCTAssertEqual ( properties [ " error_domain " ] as? String , " Test " )
169+ }
103170}
104171
105172private extension JetpackConnectionErrorViewModelTests {
0 commit comments