11import XCTest
22import Yosemite
33import WordPressAuthenticator
4+ import WordPressUI
45@testable import WooCommerce
56
67final class WrongAccountErrorViewModelTests : XCTestCase {
@@ -163,7 +164,7 @@ final class WrongAccountErrorViewModelTests: XCTestCase {
163164 XCTAssertTrue ( navigationController. topViewController is AuthenticatedWebViewController )
164165 }
165166
166- func test_fetchSiteInfo_is_triggered_if_credentials_are_not_present( ) throws {
167+ func test_fetchSiteInfo_is_triggered_if_credentials_are_not_present( ) {
167168 // Given
168169
169170 let viewModel = WrongAccountErrorViewModel ( siteURL: Expectations . url,
@@ -247,7 +248,7 @@ final class WrongAccountErrorViewModelTests: XCTestCase {
247248 XCTAssertEqual ( properties [ " is_selfhosted_site " ] as? Bool , false )
248249 }
249250
250- func test_primary_button_tap_is_tracked( ) throws {
251+ func test_primary_button_tap_is_tracked( ) {
251252 // Given
252253 let analyticsProvider = MockAnalyticsProvider ( )
253254 let analytics = WooAnalytics ( analyticsProvider: analyticsProvider)
@@ -266,21 +267,49 @@ final class WrongAccountErrorViewModelTests: XCTestCase {
266267 XCTAssertNotNil ( analyticsProvider. receivedEvents. first ( where: { $0 == " login_jetpack_connect_button_tapped " } ) )
267268 }
268269
269- func test_primary_button_tap_triggers_site_credential_login_if_credentials_are_not_present ( ) throws {
270+ func test_primary_button_tap_triggers_site_credential_login_if_credentials_are_not_present_and_fetched_site_info_returns_self_hosted_site ( ) {
270271 // Given
272+ let siteInfo = WordPressComSiteInfo ( remote: [ " isWordPressDotCom " : false ] )
273+ MockAuthenticator . setMockSiteInfo ( siteInfo)
271274 let viewModel = WrongAccountErrorViewModel ( siteURL: Expectations . url,
272275 showsConnectedStores: false ,
273276 siteCredentials: nil ,
274277 authenticatorType: MockAuthenticator . self,
275278 onJetpackSetupCompletion: { _, _ in } )
279+ let viewController = UIViewController ( )
276280
277281 // When
278- viewModel. didTapPrimaryButton ( in: UIViewController ( ) )
282+ viewModel. viewDidLoad ( viewController)
283+ viewModel. didTapPrimaryButton ( in: viewController)
279284
280285 // Then
281286 XCTAssertTrue ( MockAuthenticator . siteCredentialLoginTriggered)
282287 }
283288
289+ func test_primary_button_tap_presents_fancy_alert_if_credentials_are_not_present_and_fetched_site_info_returns_wpcom_site( ) {
290+ // Given
291+ let siteInfo = WordPressComSiteInfo ( remote: [ " isWordPressDotCom " : true ] )
292+ MockAuthenticator . setMockSiteInfo ( siteInfo)
293+ let viewModel = WrongAccountErrorViewModel ( siteURL: Expectations . url,
294+ showsConnectedStores: false ,
295+ siteCredentials: nil ,
296+ authenticatorType: MockAuthenticator . self,
297+ onJetpackSetupCompletion: { _, _ in } )
298+ let viewController = ULAccountMismatchViewController ( viewModel: viewModel)
299+
300+ // When
301+ viewModel. viewDidLoad ( viewController)
302+ viewModel. didTapPrimaryButton ( in: viewController)
303+
304+ // Then
305+ XCTAssertFalse ( MockAuthenticator . siteCredentialLoginTriggered)
306+
307+ waitUntil { // waiting for a bit since the presentation involves animation
308+ viewController. presentedViewController != nil
309+ }
310+ XCTAssertTrue ( viewController. presentedViewController is FancyAlertViewController )
311+ }
312+
284313 func test_failure_to_fetch_connection_url_is_tracked( ) throws {
285314 // Given
286315 let stores = MockStoresManager ( sessionManager: . makeForTesting( ) )
@@ -325,9 +354,9 @@ private extension WrongAccountErrorViewModelTests {
325354 static let url = " https://woocommerce.com "
326355 static let image = UIImage . productErrorImage
327356
328- static let primaryButtonTitle = NSLocalizedString ( " Connect Jetpack " ,
329- comment: " Action button to handle Jetpack connection . "
330- + " Presented when logging in with a self-hosted site that does not match the account entered " )
357+ static let primaryButtonTitle = NSLocalizedString ( " Connect to the site " ,
358+ comment: " Action button to handle connecting the logged-in account to a given site . "
359+ + " Presented when logging in with a store address that does not match the account entered " )
331360
332361 static let secondaryButtonTitle = NSLocalizedString ( " See Connected Stores " ,
333362 comment: " Action button linking to a list of connected stores. "
0 commit comments