Skip to content

Commit

Permalink
Fixing logic and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Ken Ackerson committed Feb 22, 2023
1 parent 96dc68d commit d203239
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Example/Photos/PhotoListViewStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ final class PhotoListViewStore: ViewStore {
let showsPhotosCountPublisher = self.showsPhotosCountPublisher.prepend(ViewState.initial.showsPhotoCount)
let photoPublisher = provider.providePhotos().prepend([])
let searchTextUIPublisher = self.searchTextPublisher.prepend(ViewState.initial.searchText)
let searchTextPublisher = searchTextUIPublisher.debounce(for: .seconds(1), scheduler: scheduler)
let searchTextPublisher = searchTextUIPublisher.throttle(for: 1, scheduler: scheduler, latest: true)

photoPublisher
.combineLatest(showsPhotosCountPublisher, searchTextPublisher, searchTextUIPublisher)
Expand All @@ -74,7 +74,7 @@ final class PhotoListViewStore: ViewStore {
let navigationTitle = showsPhotosCount ? LocalizedStringKey("Photos \(filteredPhotos.count)") : ViewState.defaultNavigationTitle
return ViewState(status: .content(filteredPhotos), showsPhotoCount: showsPhotosCount, navigationTitle: navigationTitle, searchText: searchTextUI)
case let .failure(error):
return ViewState(status: .error(error), showsPhotoCount: false, navigationTitle: ViewState.defaultNavigationTitle, searchText: searchText)
return ViewState(status: .error(error), showsPhotoCount: false, navigationTitle: ViewState.defaultNavigationTitle, searchText: searchTextUI)
}
}
.receive(on: scheduler)
Expand Down
5 changes: 1 addition & 4 deletions ExampleTests/ViewStoreTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,10 @@ final class ViewStoreTests: XCTestCase {

func testSearchProperlyFiltersAndSearchTextIsCorrect() {
let mock = MockItemProvider(photosCount: 3)
let scheduler = MainQueueScheduler(type: .test)

let vs = PhotoListViewStore(provider: mock, scheduler: scheduler)
let vs = PhotoListViewStore(provider: mock, scheduler: MainQueueScheduler(type: .synchronous))
vs.send(.search("2"))

scheduler.advance(by: 1)

XCTAssertEqual(vs.viewState.searchText, "2")
}
}

0 comments on commit d203239

Please sign in to comment.