@@ -4,14 +4,14 @@ import XCTest
44
55@MainActor
66final class RootReducerTests : XCTestCase {
7- func testSearchButtonTapped( ) async {
8- let store = makeStore (
9- repositoryClient: RepositoryClient (
10- fetchRepositories: { _ in [ . stub] }
11- )
12- )
7+ func testTextChanged( ) async {
8+ let store = RootView ( ) . testStore ( viewState: . init( searchText: " text " ) ) {
9+ $0. repositoryClient. fetchRepositories = { _ in [ . stub] }
10+ $0. continuousClock = ImmediateClock ( )
11+ }
1312
14- await store. send ( . onSearchButtonTapped) {
13+ await store. send ( . textChanged)
14+ await store. receive ( . queryChangeDebounced) {
1515 $0. isLoading = true
1616 }
1717 await store. receive ( . fetchRepositoriesResponse( . success( [ . stub] ) ) ) {
@@ -20,15 +20,15 @@ final class RootReducerTests: XCTestCase {
2020 }
2121 }
2222
23- func testSearchButtonTappedWithFailure ( ) async {
23+ func testTextChangedWithFailure ( ) async {
2424 let error = CancellationError ( )
25- let store = makeStore (
26- repositoryClient: RepositoryClient (
27- fetchRepositories: { _ in throw error }
28- )
29- )
25+ let store = RootView ( ) . testStore ( viewState: . init( searchText: " text " ) ) {
26+ $0. repositoryClient. fetchRepositories = { _ in throw error }
27+ $0. continuousClock = ImmediateClock ( )
28+ }
3029
31- await store. send ( . onSearchButtonTapped) {
30+ await store. send ( . textChanged)
31+ await store. receive ( . queryChangeDebounced) {
3232 $0. isLoading = true
3333 }
3434 await store. receive ( . fetchRepositoriesResponse( . failure( error) ) ) {
@@ -48,19 +48,12 @@ final class RootReducerTests: XCTestCase {
4848 }
4949 }
5050
51- func testTextChanged ( ) async {
51+ func testEmptyTextChanged ( ) async {
5252 let store = RootView ( ) . testStore ( viewState: . init( repositories: [ . stub] ) )
53- await store. send ( . onTextChanged( " test " ) )
54- await store. send ( . onTextChanged( " " ) ) {
53+ await store. send ( . textChanged) {
5554 $0. repositories = [ ]
5655 }
5756 }
58-
59- func makeStore( repositoryClient: RepositoryClient ) -> TestStore < RootReducer > {
60- RootView ( ) . testStore ( viewState: . init( ) ) {
61- $0. repositoryClient = repositoryClient
62- }
63- }
6457}
6558
6659extension Repository {
0 commit comments