From c1cefae5e22228e6027e5d5c576adb142e5ccee4 Mon Sep 17 00:00:00 2001 From: Charles Maria Tor Date: Thu, 29 Jul 2021 12:19:02 +1000 Subject: [PATCH] Add replay tests --- .../RecombinePackage/Store/BaseStore.swift | 1 - Tests/RecombineTests/Extensions.swift | 26 ++++++++++++++++--- Tests/RecombineTests/StoreDispatchTests.swift | 25 ++++++++++++++++++ 3 files changed, 47 insertions(+), 5 deletions(-) diff --git a/Sources/RecombinePackage/Store/BaseStore.swift b/Sources/RecombinePackage/Store/BaseStore.swift index 4dd1ccb..abcc6f9 100644 --- a/Sources/RecombinePackage/Store/BaseStore.swift +++ b/Sources/RecombinePackage/Store/BaseStore.swift @@ -200,7 +200,6 @@ public class BaseStore: StoreProtoco } // Cancel if dispatch is manually reenabled. .prefix(untilOutputFrom: $dispatchEnabled.filter { $0 }) - .print("REPLAY::") .sink( receiveCompletion: { _ in self.dispatchEnabled = true diff --git a/Tests/RecombineTests/Extensions.swift b/Tests/RecombineTests/Extensions.swift index 4f88200..5d5e840 100644 --- a/Tests/RecombineTests/Extensions.swift +++ b/Tests/RecombineTests/Extensions.swift @@ -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, values: [State] ) throws { @@ -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: Store, + count: Int, + timeout: TimeInterval = 1, + serially: Bool = false, + collect: Bool = false, + actions: [ActionStrata<[Store.RawAction], [Store.SubRefinedAction]>], + keyPath: KeyPath, + values: [State] + ) throws { + try prefixEquals( + store, + count: count, + timeout: timeout, + access: { $0.dispatch(serially: serially, collect: collect, actions: actions) }, + keyPath: keyPath, + values: values + ) + } } diff --git a/Tests/RecombineTests/StoreDispatchTests.swift b/Tests/RecombineTests/StoreDispatchTests.swift index 69a969d..012fffd 100644 --- a/Tests/RecombineTests/StoreDispatchTests.swift +++ b/Tests/RecombineTests/StoreDispatchTests.swift @@ -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"] + ) + } }