Skip to content

Commit 52f6813

Browse files
committed
Add a test case for StoreCreationCountryQuestionViewModel.
1 parent 6aa63cb commit 52f6813

File tree

1 file changed

+24
-10
lines changed

1 file changed

+24
-10
lines changed

WooCommerce/WooCommerceTests/Authentication/Store Creation/Profiler/StoreCreationCountryQuestionViewModelTests.swift

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ final class StoreCreationCountryQuestionViewModelTests: XCTestCase {
88

99
func test_topHeader_is_set_to_store_name() throws {
1010
// Given
11-
let viewModel = StoreCreationCountryQuestionViewModel(storeName: "store 🌟") { _ in }
11+
let viewModel = StoreCreationCountryQuestionViewModel(storeName: "store 🌟") { _ in } onSupport: {}
1212

1313
// Then
1414
XCTAssertEqual(viewModel.topHeader, "store 🌟")
1515
}
1616

1717
func test_currentCountryCode_and_initial_selectedCountryCode_are_set_by_locale() throws {
1818
// Given
19-
let viewModel = StoreCreationCountryQuestionViewModel(storeName: "store", currentLocale: .init(identifier: "fr_FR")) { _ in }
19+
let viewModel = StoreCreationCountryQuestionViewModel(storeName: "store", currentLocale: .init(identifier: "fr_FR")) { _ in } onSupport: {}
2020

2121
// Then
2222
XCTAssertEqual(viewModel.currentCountryCode, .FR)
@@ -25,7 +25,7 @@ final class StoreCreationCountryQuestionViewModelTests: XCTestCase {
2525

2626
func test_currentCountryCode_and_initial_selectedCountryCode_are_nil_with_an_invalid_locale() throws {
2727
// Given
28-
let viewModel = StoreCreationCountryQuestionViewModel(storeName: "store", currentLocale: .init(identifier: "zzzz")) { _ in }
28+
let viewModel = StoreCreationCountryQuestionViewModel(storeName: "store", currentLocale: .init(identifier: "zzzz")) { _ in } onSupport: {}
2929

3030
// Then
3131
XCTAssertNil(viewModel.currentCountryCode)
@@ -34,15 +34,15 @@ final class StoreCreationCountryQuestionViewModelTests: XCTestCase {
3434

3535
func test_countryCodes_include_all_countries_with_an_invalid_locale() throws {
3636
// Given
37-
let viewModel = StoreCreationCountryQuestionViewModel(storeName: "store", currentLocale: .init(identifier: "zzzz")) { _ in }
37+
let viewModel = StoreCreationCountryQuestionViewModel(storeName: "store", currentLocale: .init(identifier: "zzzz")) { _ in } onSupport: {}
3838

3939
// Then
4040
XCTAssertEqual(viewModel.countryCodes, SiteAddress.CountryCode.allCases.sorted(by: { $0.readableCountry < $1.readableCountry }))
4141
}
4242

4343
func test_countryCodes_do_not_include_currentCountryCode_from_locale() throws {
4444
// Given
45-
let viewModel = StoreCreationCountryQuestionViewModel(storeName: "store", currentLocale: .init(identifier: "fr_FR")) { _ in }
45+
let viewModel = StoreCreationCountryQuestionViewModel(storeName: "store", currentLocale: .init(identifier: "fr_FR")) { _ in } onSupport: {}
4646

4747
// Then
4848
XCTAssertFalse(viewModel.countryCodes.contains(.FR))
@@ -51,7 +51,7 @@ final class StoreCreationCountryQuestionViewModelTests: XCTestCase {
5151

5252
func test_selecting_a_country_updates_selectedCountryCode() throws {
5353
// Given
54-
let viewModel = StoreCreationCountryQuestionViewModel(storeName: "store") { _ in }
54+
let viewModel = StoreCreationCountryQuestionViewModel(storeName: "store") { _ in } onSupport: {}
5555

5656
// When
5757
viewModel.selectCountry(.FJ)
@@ -62,7 +62,7 @@ final class StoreCreationCountryQuestionViewModelTests: XCTestCase {
6262

6363
func test_selecting_a_country_sets_isContinueButtonEnabled_to_true_with_an_invalid_locale() throws {
6464
// Given
65-
let viewModel = StoreCreationCountryQuestionViewModel(storeName: "store", currentLocale: .init(identifier: "zzzz")) { _ in }
65+
let viewModel = StoreCreationCountryQuestionViewModel(storeName: "store", currentLocale: .init(identifier: "zzzz")) { _ in } onSupport: {}
6666
var isContinueButtonEnabledValues = [Bool]()
6767
viewModel.isContinueButtonEnabled.removeDuplicates().sink { isEnabled in
6868
isContinueButtonEnabledValues.append(isEnabled)
@@ -79,7 +79,7 @@ final class StoreCreationCountryQuestionViewModelTests: XCTestCase {
7979

8080
func test_isContinueButtonEnabled_stays_true_with_a_valid_locale() throws {
8181
// Given
82-
let viewModel = StoreCreationCountryQuestionViewModel(storeName: "store", currentLocale: .init(identifier: "fr_FR")) { _ in }
82+
let viewModel = StoreCreationCountryQuestionViewModel(storeName: "store", currentLocale: .init(identifier: "fr_FR")) { _ in } onSupport: {}
8383
var isContinueButtonEnabledValues = [Bool]()
8484
viewModel.isContinueButtonEnabled.removeDuplicates().sink { isEnabled in
8585
isContinueButtonEnabledValues.append(isEnabled)
@@ -102,7 +102,7 @@ final class StoreCreationCountryQuestionViewModelTests: XCTestCase {
102102
// Then
103103
XCTAssertEqual(countryCode, .JP)
104104
promise(())
105-
}
105+
} onSupport: {}
106106

107107
// When
108108
viewModel.selectCountry(.JP)
@@ -118,10 +118,24 @@ final class StoreCreationCountryQuestionViewModelTests: XCTestCase {
118118
currentLocale: .init(identifier: "zzzz")) { countryCode in
119119
// Then
120120
XCTFail("Should not be invoked without selecting a country.")
121-
}
121+
} onSupport: {}
122122
// When
123123
Task { @MainActor in
124124
await viewModel.continueButtonTapped()
125125
}
126126
}
127+
128+
func test_supportButtonTapped_invokes_onSupport() throws {
129+
waitFor { promise in
130+
// Given
131+
let viewModel = StoreCreationCountryQuestionViewModel(storeName: "store",
132+
currentLocale: .init(identifier: "")) { _ in } onSupport: {
133+
// Then
134+
promise(())
135+
}
136+
137+
// When
138+
viewModel.supportButtonTapped()
139+
}
140+
}
127141
}

0 commit comments

Comments
 (0)