@@ -6,18 +6,14 @@ import TestKit
66final class CountrySelectorViewModelTests : XCTestCase {
77
88 let sampleSiteID : Int64 = 123
9- let testingStorage = MockStorageManager ( )
109
1110 override func setUp ( ) {
1211 super. setUp ( )
13-
14- testingStorage. reset ( )
15- testingStorage. insertSampleCountries ( readOnlyCountries: Self . sampleCountries)
1612 }
1713
1814 func test_filter_countries_return_expected_results( ) {
1915 // Given
20- let viewModel = CountrySelectorViewModel ( siteID: sampleSiteID, storageManager : testingStorage )
16+ let viewModel = CountrySelectorViewModel ( siteID: sampleSiteID, countries : Self . sampleCountries )
2117
2218 // When
2319 viewModel. searchTerm = " Co "
@@ -42,7 +38,7 @@ final class CountrySelectorViewModelTests: XCTestCase {
4238
4339 func test_filter_countries_with_uppercase_letters_return_expected_results( ) {
4440 // Given
45- let viewModel = CountrySelectorViewModel ( siteID: sampleSiteID, storageManager : testingStorage )
41+ let viewModel = CountrySelectorViewModel ( siteID: sampleSiteID, countries : Self . sampleCountries )
4642
4743 // When
4844 viewModel. searchTerm = " CO "
@@ -67,7 +63,7 @@ final class CountrySelectorViewModelTests: XCTestCase {
6763
6864 func test_cleaning_search_terms_return_all_countries( ) {
6965 // Given
70- let viewModel = CountrySelectorViewModel ( siteID: sampleSiteID, storageManager : testingStorage )
66+ let viewModel = CountrySelectorViewModel ( siteID: sampleSiteID, countries : Self . sampleCountries )
7167 let totalNumberOfCountries = viewModel. command. data. count
7268
7369 // When
@@ -78,28 +74,6 @@ final class CountrySelectorViewModelTests: XCTestCase {
7874 // Then
7975 XCTAssertEqual ( viewModel. command. data. count, totalNumberOfCountries)
8076 }
81-
82- func test_starting_view_model_without_stored_countries_fetches_them_remotely( ) {
83- // Given
84- testingStorage. reset ( )
85- let testingStores = MockStoresManager ( sessionManager: . testingInstance)
86-
87-
88- // When
89- let countriesFetched : Bool = waitFor { promise in
90- testingStores. whenReceivingAction ( ofType: DataAction . self) { action in
91- switch action {
92- case . synchronizeCountries:
93- promise ( true )
94- }
95- }
96-
97- _ = CountrySelectorViewModel ( siteID: self . sampleSiteID, storageManager: self . testingStorage, stores: testingStores)
98- }
99-
100- // Then
101- XCTAssertTrue ( countriesFetched)
102- }
10377}
10478
10579// MARK: Helpers
@@ -108,6 +82,8 @@ private extension CountrySelectorViewModelTests {
10882 return Locale . isoRegionCodes. map { regionCode in
10983 let name = Locale . current. localizedString ( forRegionCode: regionCode) ?? " "
11084 return Country ( code: regionCode, name: name, states: [ ] )
85+ } . sorted { a, b in
86+ a. name <= b. name
11187 }
11288 } ( )
11389}
0 commit comments