From 0506da94f9db74ce19fa965f44e57258a2aa3c1c Mon Sep 17 00:00:00 2001 From: Rob Mayoff Date: Wed, 8 Apr 2020 12:53:12 -0500 Subject: [PATCH] 0097 fix tests (#59) * add all tests to PrimeTime app scheme This change lets you run all tests (for all modules) using Product > Test with the PrimeTime scheme selected. * fix tests for ViewStore refactoring This commit updates CounterTests and PrimeTimeTests to work with CounterFeatureState and the corresponding changes to actions. * update CounterTests snapshots This commit updates the snapshot taken while the nth prime request is in flight. Originally, the + and - buttons were still enabled while the request is in flight. Then the app was changed to disable them while the request is in flight, which changes their appearance. This snapshot shows the buttons with the disabled appearance. Co-authored-by: Rob Mayoff --- .../PrimeTime/CounterTests/CounterTests.swift | 40 +++++++++--------- .../CounterTests/testSnapshots.4.png | Bin 88389 -> 88414 bytes .../xcshareddata/xcschemes/PrimeTime.xcscheme | 10 ++--- .../PrimeTimeTests/PrimeTimeTests.swift | 6 +-- 4 files changed, 28 insertions(+), 28 deletions(-) diff --git a/0097-adaptive-state-management-pt4/PrimeTime/CounterTests/CounterTests.swift b/0097-adaptive-state-management-pt4/PrimeTime/CounterTests/CounterTests.swift index 9851481b..827ba6b9 100644 --- a/0097-adaptive-state-management-pt4/PrimeTime/CounterTests/CounterTests.swift +++ b/0097-adaptive-state-management-pt4/PrimeTime/CounterTests/CounterTests.swift @@ -8,7 +8,7 @@ import XCTest class CounterTests: XCTestCase { func testSnapshots() { - let store = Store(initialValue: CounterViewState(), reducer: counterViewReducer, environment: { _ in .sync { 17 } }) + let store = Store(initialValue: CounterFeatureState(), reducer: counterViewReducer, environment: { _ in .sync { 17 } }) let view = CounterView(store: store) let vc = UIHostingController(rootView: view) @@ -16,13 +16,13 @@ class CounterTests: XCTestCase { assertSnapshot(matching: vc, as: .windowedImage) - store.send(.counter(.incrTapped)) + view.viewStore.send(.incrTapped) assertSnapshot(matching: vc, as: .windowedImage) - store.send(.counter(.incrTapped)) + view.viewStore.send(.incrTapped) assertSnapshot(matching: vc, as: .windowedImage) - store.send(.counter(.nthPrimeButtonTapped)) + view.viewStore.send(.nthPrimeButtonTapped) assertSnapshot(matching: vc, as: .windowedImage) var expectation = self.expectation(description: "wait") @@ -32,7 +32,7 @@ class CounterTests: XCTestCase { self.wait(for: [expectation], timeout: 0.5) assertSnapshot(matching: vc, as: .windowedImage) - store.send(.counter(.alertDismissButtonTapped)) + view.viewStore.send(.alertDismissButtonTapped) expectation = self.expectation(description: "wait") DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { expectation.fulfill() @@ -40,19 +40,19 @@ class CounterTests: XCTestCase { self.wait(for: [expectation], timeout: 0.5) assertSnapshot(matching: vc, as: .windowedImage) - store.send(.counter(.isPrimeButtonTapped)) + view.viewStore.send(.isPrimeButtonTapped) assertSnapshot(matching: vc, as: .windowedImage) - store.send(.primeModal(.saveFavoritePrimeTapped)) + store.view.send(.primeModal(.saveFavoritePrimeTapped)) assertSnapshot(matching: vc, as: .windowedImage) - store.send(.counter(.primeModalDismissed)) + view.viewStore.send(.primeModalDismissed) assertSnapshot(matching: vc, as: .windowedImage) } func testIncrDecrButtonTapped() { assert( - initialValue: CounterViewState(count: 2), + initialValue: CounterFeatureState(count: 2), reducer: counterViewReducer, environment: { _ in .sync { 17 } }, steps: @@ -64,20 +64,20 @@ class CounterTests: XCTestCase { func testNthPrimeButtonHappyFlow() { assert( - initialValue: CounterViewState( + initialValue: CounterFeatureState( alertNthPrime: nil, count: 7, - isNthPrimeButtonDisabled: false + isNthPrimeRequestInFlight: false ), reducer: counterViewReducer, environment: { _ in .sync { 17 } }, steps: - Step(.send, .counter(.nthPrimeButtonTapped)) { - $0.isNthPrimeButtonDisabled = true + Step(.send, .counter(CounterAction.requestNthPrime)) { + $0.isNthPrimeRequestInFlight = true }, Step(.receive, .counter(.nthPrimeResponse(n: 7, prime: 17))) { $0.alertNthPrime = PrimeAlert(n: $0.count, prime: 17) - $0.isNthPrimeButtonDisabled = false + $0.isNthPrimeRequestInFlight = false }, Step(.send, .counter(.alertDismissButtonTapped)) { $0.alertNthPrime = nil @@ -87,26 +87,26 @@ class CounterTests: XCTestCase { func testNthPrimeButtonUnhappyFlow() { assert( - initialValue: CounterViewState( + initialValue: CounterFeatureState( alertNthPrime: nil, count: 7, - isNthPrimeButtonDisabled: false + isNthPrimeRequestInFlight: false ), reducer: counterViewReducer, environment: { _ in .sync { nil } }, steps: - Step(.send, .counter(.nthPrimeButtonTapped)) { - $0.isNthPrimeButtonDisabled = true + Step(.send, .counter(.requestNthPrime)) { + $0.isNthPrimeRequestInFlight = true }, Step(.receive, .counter(.nthPrimeResponse(n: 7, prime: nil))) { - $0.isNthPrimeButtonDisabled = false + $0.isNthPrimeRequestInFlight = false } ) } func testPrimeModal() { assert( - initialValue: CounterViewState( + initialValue: CounterFeatureState( count: 1, favoritePrimes: [3, 5] ), diff --git a/0097-adaptive-state-management-pt4/PrimeTime/CounterTests/__Snapshots__/CounterTests/testSnapshots.4.png b/0097-adaptive-state-management-pt4/PrimeTime/CounterTests/__Snapshots__/CounterTests/testSnapshots.4.png index ed1a854e14770bb692aea0b8d4cc7d735cdd0743..2cffd1715b186265f1ca27633668e1d514b2a48d 100644 GIT binary patch delta 5338 zcmeHKdpOkV+Kz~_M7zUOj@2qjg;mITqF5!P2svA8im7Q3avC$gBwDSC-6G1FLQD=h z%)}6_R+Lr_Wt_&$h#1CUG7i(sFtgt=WAFX_^Zox_*XO!iml?nJd7tNg?&p5)-`gsA zdX@Y?S@KT{MhcT(u;zv%QNp8hvxl{^s_*1ho@K_jrU~^tfuA1t}ie zb0YPGwtvyYw(vjOetJ<-<>&uY!>4QOPs9JzRaM&P*0=q`y1hf5kK{IVrzOZfH16I_ zvbG}orR@&Ed$*fbgw1gA9V7cp4lx%6!W{O9pxuZ&(a4pPyG2}6u&Me2GGkM9r3-%x zwEg^09WzHS*@};f{*nM&r!g8OE2pTc4ZpD_?(#oW2a49yFRzz;oZZq_7ZzB@DkZde z1ZKM;Oh;2W<&lj9^=p4^y43UBqoP3zH{W&X{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piCVYE+LHvpDpkgRi zJ%ISD>vXLrb&GFc#6-AjcdO`x8)c?;(z`O~!Qz%b?Ez%kOQm*$1xpX;L5*tgDIe>; zi!e@#H;IpGup1L$7}r8M$*~l^Yfq=B%xZDNO5MbUWMpJSqK{TS%S(fjdnqe-FFSSg UctXos@VCt2Lq`r4?f1F(KOQKbzyJUM diff --git a/0097-adaptive-state-management-pt4/PrimeTime/PrimeTime.xcodeproj/xcshareddata/xcschemes/PrimeTime.xcscheme b/0097-adaptive-state-management-pt4/PrimeTime/PrimeTime.xcodeproj/xcshareddata/xcschemes/PrimeTime.xcscheme index d64f316c..c8018bd7 100644 --- a/0097-adaptive-state-management-pt4/PrimeTime/PrimeTime.xcodeproj/xcshareddata/xcschemes/PrimeTime.xcscheme +++ b/0097-adaptive-state-management-pt4/PrimeTime/PrimeTime.xcodeproj/xcshareddata/xcschemes/PrimeTime.xcscheme @@ -39,7 +39,7 @@ + skipped = "NO"> + skipped = "NO"> + skipped = "NO"> + skipped = "NO"> + skipped = "NO">