Skip to content

Commit

Permalink
Add replay tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Qata committed Jul 29, 2021
1 parent d1b8dc4 commit c1cefae
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 5 deletions.
1 change: 0 additions & 1 deletion Sources/RecombinePackage/Store/BaseStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@ public class BaseStore<State: Equatable, RawAction, RefinedAction>: StoreProtoco
}
// Cancel if dispatch is manually reenabled.
.prefix(untilOutputFrom: $dispatchEnabled.filter { $0 })
.print("REPLAY::")
.sink(
receiveCompletion: { _ in
self.dispatchEnabled = true
Expand Down
26 changes: 22 additions & 4 deletions Tests/RecombineTests/Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,7 @@ extension XCTestCase {
_ store: Store,
count: Int,
timeout: TimeInterval = 1,
serially: Bool = false,
collect: Bool = false,
actions: [ActionStrata<[Store.RawAction], [Store.SubRefinedAction]>],
access: (Store) -> Void,
keyPath: KeyPath<Store.SubState, State>,
values: [State]
) throws {
Expand All @@ -86,9 +84,29 @@ extension XCTestCase {
store,
count: count,
timeout: timeout,
access: { $0.dispatch(serially: serially, collect: collect, actions: actions) }
access: access
).map { $0[keyPath: keyPath] },
values
)
}

func prefixEquals<Store: StoreProtocol, State: Equatable>(
_ store: Store,
count: Int,
timeout: TimeInterval = 1,
serially: Bool = false,
collect: Bool = false,
actions: [ActionStrata<[Store.RawAction], [Store.SubRefinedAction]>],
keyPath: KeyPath<Store.SubState, State>,
values: [State]
) throws {
try prefixEquals(
store,
count: count,
timeout: timeout,
access: { $0.dispatch(serially: serially, collect: collect, actions: actions) },
keyPath: keyPath,
values: values
)
}
}
25 changes: 25 additions & 0 deletions Tests/RecombineTests/StoreDispatchTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,29 @@ class ObservableStoreDispatchTests: XCTestCase {
value.map { String($0) + String($0) }.joined()
)
}

func testReplay() throws {
let store = BaseStore(
state: "",
reducer: reducer,
thunk: thunk,
publishOn: DispatchQueue.global()
)

try prefixEquals(
store,
count: 2,
timeout: 10,
access: { store in
store.replay(
[
(offset: 0, actions: ["1"]),
(offset: 0.5, actions: ["2"]),
]
)
},
keyPath: \.self,
values: ["1", "12"]
)
}
}

0 comments on commit c1cefae

Please sign in to comment.