Skip to content

Commit a4ea02e

Browse files
Add unit tests to UIKitCaseStudies (#1002)
1 parent 85050a2 commit a4ea02e

File tree

1 file changed

+51
-1
lines changed

1 file changed

+51
-1
lines changed
Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,56 @@
1+
import ComposableArchitecture
12
import XCTest
23

34
@testable import UIKitCaseStudies
45

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+
}
656
}

0 commit comments

Comments
 (0)