Skip to content

Commit

Permalink
0097 fix tests (#59)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
mayoff and Rob Mayoff authored Apr 8, 2020
1 parent d6a45cc commit 0506da9
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@ 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)
vc.view.frame = UIScreen.main.bounds

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")
Expand All @@ -32,27 +32,27 @@ 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()
}
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:
Expand All @@ -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
Expand All @@ -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]
),
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
</BuildableReference>
</TestableReference>
<TestableReference
skipped = "YES">
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "DCF0C5A22326032B008B45A0"
Expand All @@ -49,7 +49,7 @@
</BuildableReference>
</TestableReference>
<TestableReference
skipped = "YES">
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "DCF0C5C523260348008B45A0"
Expand All @@ -59,7 +59,7 @@
</BuildableReference>
</TestableReference>
<TestableReference
skipped = "YES">
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "DCF0C5E72326035C008B45A0"
Expand All @@ -69,7 +69,7 @@
</BuildableReference>
</TestableReference>
<TestableReference
skipped = "YES">
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "DCF0C6092326036F008B45A0"
Expand All @@ -79,7 +79,7 @@
</BuildableReference>
</TestableReference>
<TestableReference
skipped = "YES">
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "CA79FC2C239C23310096D881"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ class PrimeTimeTests: XCTestCase {
offlineNthPrime: { _ in .sync { 17 } }
),
steps:
Step(.send, .counterView(.counter(.nthPrimeButtonTapped))) {
$0.isNthPrimeButtonDisabled = true
Step(.send, .counterView(.counter(.requestNthPrime))) {
$0.isNthPrimeRequestInFlight = true
},
Step(.receive, .counterView(.counter(.nthPrimeResponse(n: 4, prime: 17)))) {
$0.isNthPrimeButtonDisabled = false
$0.isNthPrimeRequestInFlight = false
$0.alertNthPrime = PrimeAlert(n: 4, prime: 17)
},
Step(.send, .favoritePrimes(.loadButtonTapped)),
Expand Down

0 comments on commit 0506da9

Please sign in to comment.