Skip to content

Commit c1cefae

Browse files
committed
Add replay tests
1 parent d1b8dc4 commit c1cefae

File tree

3 files changed

+47
-5
lines changed

3 files changed

+47
-5
lines changed

Sources/RecombinePackage/Store/BaseStore.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,6 @@ public class BaseStore<State: Equatable, RawAction, RefinedAction>: StoreProtoco
200200
}
201201
// Cancel if dispatch is manually reenabled.
202202
.prefix(untilOutputFrom: $dispatchEnabled.filter { $0 })
203-
.print("REPLAY::")
204203
.sink(
205204
receiveCompletion: { _ in
206205
self.dispatchEnabled = true

Tests/RecombineTests/Extensions.swift

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,7 @@ extension XCTestCase {
7575
_ store: Store,
7676
count: Int,
7777
timeout: TimeInterval = 1,
78-
serially: Bool = false,
79-
collect: Bool = false,
80-
actions: [ActionStrata<[Store.RawAction], [Store.SubRefinedAction]>],
78+
access: (Store) -> Void,
8179
keyPath: KeyPath<Store.SubState, State>,
8280
values: [State]
8381
) throws {
@@ -86,9 +84,29 @@ extension XCTestCase {
8684
store,
8785
count: count,
8886
timeout: timeout,
89-
access: { $0.dispatch(serially: serially, collect: collect, actions: actions) }
87+
access: access
9088
).map { $0[keyPath: keyPath] },
9189
values
9290
)
9391
}
92+
93+
func prefixEquals<Store: StoreProtocol, State: Equatable>(
94+
_ store: Store,
95+
count: Int,
96+
timeout: TimeInterval = 1,
97+
serially: Bool = false,
98+
collect: Bool = false,
99+
actions: [ActionStrata<[Store.RawAction], [Store.SubRefinedAction]>],
100+
keyPath: KeyPath<Store.SubState, State>,
101+
values: [State]
102+
) throws {
103+
try prefixEquals(
104+
store,
105+
count: count,
106+
timeout: timeout,
107+
access: { $0.dispatch(serially: serially, collect: collect, actions: actions) },
108+
keyPath: keyPath,
109+
values: values
110+
)
111+
}
94112
}

Tests/RecombineTests/StoreDispatchTests.swift

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,4 +176,29 @@ class ObservableStoreDispatchTests: XCTestCase {
176176
value.map { String($0) + String($0) }.joined()
177177
)
178178
}
179+
180+
func testReplay() throws {
181+
let store = BaseStore(
182+
state: "",
183+
reducer: reducer,
184+
thunk: thunk,
185+
publishOn: DispatchQueue.global()
186+
)
187+
188+
try prefixEquals(
189+
store,
190+
count: 2,
191+
timeout: 10,
192+
access: { store in
193+
store.replay(
194+
[
195+
(offset: 0, actions: ["1"]),
196+
(offset: 0.5, actions: ["2"]),
197+
]
198+
)
199+
},
200+
keyPath: \.self,
201+
values: ["1", "12"]
202+
)
203+
}
179204
}

0 commit comments

Comments
 (0)