@@ -311,6 +311,53 @@ final class ItemListViewModelTests: XCTestCase {
311311 XCTAssertEqual ( receivedItems. last? . productID, lastItem. productID)
312312 }
313313
314+ func test_populatePointOfSaleItems_when_no_items_are_loaded_then_statePublisher_emits_expected_empty_state( ) async throws {
315+ // Given
316+ XCTAssertEqual ( sut. state, . loading, " Initial state " )
317+
318+ let itemProvider = MockPOSItemProvider ( )
319+ itemProvider. shouldReturnZeroItems = true
320+ let sut = ItemListViewModel ( itemProvider: itemProvider)
321+ let expectation = XCTestExpectation ( description: " Publisher should emit state changes " )
322+
323+ var receivedStates : [ ItemListViewModel . ItemListState ] = [ ]
324+ sut. statePublisher
325+ . removeDuplicates ( )
326+ . sink { state in
327+ receivedStates. append ( state)
328+ expectation. fulfill ( )
329+ }
330+ . store ( in: & cancellables)
331+
332+ // When
333+ await sut. populatePointOfSaleItems ( )
334+
335+ // Then
336+ XCTAssertEqual ( receivedStates, [ . loading, . empty] )
337+ }
338+
339+ func test_populatePointOfSaleItems_when_items_are_loaded_then_statePublisher_emits_expected_loaded_state( ) async throws {
340+ // Given
341+ XCTAssertEqual ( sut. state, . loading, " Initial state " )
342+ let expectation = XCTestExpectation ( description: " Publisher should emit state changes " )
343+ let items = Self . makeItems ( )
344+
345+ var receivedStates : [ ItemListViewModel . ItemListState ] = [ ]
346+ sut. statePublisher
347+ . removeDuplicates ( )
348+ . sink { state in
349+ receivedStates. append ( state)
350+ expectation. fulfill ( )
351+ }
352+ . store ( in: & cancellables)
353+
354+ // When
355+ await sut. populatePointOfSaleItems ( )
356+
357+ // Then
358+ XCTAssertEqual ( receivedStates, [ . loading, . loaded( items) ] )
359+ }
360+
314361 func test_simpleProductsInfoButtonTapped_when_tapped_then_showSimpleProductsModal_toggled( ) {
315362 XCTAssertFalse ( sut. showSimpleProductsModal)
316363
0 commit comments