@@ -169,29 +169,33 @@ class AddProductToOrderViewModelTests: XCTestCase {
169169 XCTAssertEqual ( viewModel. productRows. count, 1 )
170170 }
171171
172- func test_searching_products_returns_expected_results ( ) {
172+ func test_searching_products_filters_product_list_as_expected ( ) {
173173 // Given
174+ let hoodie = Product . fake ( ) . copy ( siteID: sampleSiteID, productID: 1 , name: " Hoodie " , purchasable: true )
175+ let shirt = Product . fake ( ) . copy ( siteID: sampleSiteID, productID: 2 , name: " T-shirt " , purchasable: true )
176+ insert ( [ hoodie, shirt] )
177+
174178 let viewModel = AddProductToOrderViewModel ( siteID: sampleSiteID, storageManager: storageManager, stores: stores)
175179 let expectation = expectation ( description: " Completed product search " )
176- let product = Product . fake ( ) . copy ( siteID: sampleSiteID, purchasable: true )
177- insert ( [ product. copy ( name: " T-shirt " ) , product. copy ( name: " Hoodie " ) ] )
178180 stores. whenReceivingAction ( ofType: ProductAction . self) { action in
179181 switch action {
180182 case let . searchProducts( _, _, _, _, _, onCompletion) :
181- self . insert ( product . copy ( name : " T- shirt" ) , withSearchTerm: " shirt " )
183+ self . insert ( shirt, withSearchTerm: " shirt " )
182184 onCompletion ( . success( ( ) ) )
183185 expectation. fulfill ( )
184186 default :
185187 XCTFail ( " Unsupported Action " )
186188 }
187189 }
188190
191+ XCTAssertEqual ( viewModel. productRows. count, 2 , " Full product list is not loaded before search " )
192+
189193 // When
190194 viewModel. searchTerm = " shirt "
191195 waitForExpectations ( timeout: Constants . expectationTimeout, handler: nil )
192196
193197 // Then
194- XCTAssertEqual ( viewModel. productRows. count, 1 )
198+ XCTAssertEqual ( viewModel. productRows. count, 1 , " Product list is not filtered after search " )
195199 XCTAssertEqual ( viewModel. productRows [ 0 ] . name, " T-shirt " )
196200 }
197201
0 commit comments