|
| 1 | +import ComposableArchitecture |
1 | 2 | import XCTest |
2 | 3 |
|
3 | 4 | @testable import UIKitCaseStudies |
4 | 5 |
|
5 | | -class UIKitCaseStudiesTests: XCTestCase { |
| 6 | +final class UIKitCaseStudiesTests: XCTestCase { |
| 7 | + func testCountDown() { |
| 8 | + let store = TestStore( |
| 9 | + initialState: CounterState(), |
| 10 | + reducer: counterReducer, |
| 11 | + environment: CounterEnvironment() |
| 12 | + ) |
| 13 | + |
| 14 | + store.send(.incrementButtonTapped) { |
| 15 | + $0.count = 1 |
| 16 | + } |
| 17 | + store.send(.decrementButtonTapped) { |
| 18 | + $0.count = 0 |
| 19 | + } |
| 20 | + } |
| 21 | + |
| 22 | + func testCountDownList() { |
| 23 | + let firstState = CounterState() |
| 24 | + let secondState = CounterState() |
| 25 | + let thirdState = CounterState() |
| 26 | + |
| 27 | + let store = TestStore( |
| 28 | + initialState: CounterListState( |
| 29 | + counters: [firstState, secondState, thirdState] |
| 30 | + ), |
| 31 | + reducer: counterListReducer, |
| 32 | + environment: CounterListEnvironment() |
| 33 | + ) |
| 34 | + |
| 35 | + store.send(.counter(id: firstState.id, action: .incrementButtonTapped)) { |
| 36 | + $0.counters[id: firstState.id]?.count = 1 |
| 37 | + } |
| 38 | + store.send(.counter(id: firstState.id, action: .decrementButtonTapped)) { |
| 39 | + $0.counters[id: firstState.id]?.count = 0 |
| 40 | + } |
| 41 | + |
| 42 | + store.send(.counter(id: secondState.id, action: .incrementButtonTapped)) { |
| 43 | + $0.counters[id: secondState.id]?.count = 1 |
| 44 | + } |
| 45 | + store.send(.counter(id: secondState.id, action: .decrementButtonTapped)) { |
| 46 | + $0.counters[id: secondState.id]?.count = 0 |
| 47 | + } |
| 48 | + |
| 49 | + store.send(.counter(id: thirdState.id, action: .incrementButtonTapped)) { |
| 50 | + $0.counters[id: thirdState.id]?.count = 1 |
| 51 | + } |
| 52 | + store.send(.counter(id: thirdState.id, action: .decrementButtonTapped)) { |
| 53 | + $0.counters[id: thirdState.id]?.count = 0 |
| 54 | + } |
| 55 | + } |
6 | 56 | } |
0 commit comments