mirror of
https://github.com/pointfreeco/swift-composable-architecture.git
synced 2025-12-20 09:11:33 +01:00
* Merge Test Support Module An attempt to fix #70. * Remove import * Update README * Assertion failure * Cleanup * Add NB * Revert format change * Update Sources/ComposableArchitecture/TestSupport/TestStore.swift * TicTacToe fixes * Hide test store in debug flag Co-authored-by: Brandon Williams <mbw234@gmail.com>
48 lines
1.3 KiB
Swift
48 lines
1.3 KiB
Swift
import Combine
|
|
import ComposableArchitecture
|
|
import CoreMotion
|
|
import XCTest
|
|
|
|
@testable import MotionManager
|
|
|
|
class MotionManagerTests: XCTestCase {
|
|
func testExample() {
|
|
let motionSubject = PassthroughSubject<MotionClient.Action, MotionClient.Error>()
|
|
var motionUpdatesStarted = false
|
|
|
|
let store = TestStore(
|
|
initialState: .init(),
|
|
reducer: appReducer,
|
|
environment: .init(
|
|
motionClient: .mock(
|
|
create: { _ in motionSubject.eraseToEffect() },
|
|
startDeviceMotionUpdates: { _ in .fireAndForget { motionUpdatesStarted = true } },
|
|
stopDeviceMotionUpdates: { _ in
|
|
.fireAndForget { motionSubject.send(completion: .finished) }
|
|
}
|
|
)
|
|
)
|
|
)
|
|
|
|
let deviceMotion = DeviceMotion(
|
|
gravity: CMAcceleration(x: 1, y: 2, z: 3),
|
|
userAcceleration: CMAcceleration(x: 4, y: 5, z: 6)
|
|
)
|
|
|
|
store.assert(
|
|
.send(.onAppear),
|
|
.send(.recordingButtonTapped) {
|
|
$0.isRecording = true
|
|
XCTAssertTrue(motionUpdatesStarted)
|
|
},
|
|
.do { motionSubject.send(.motionUpdate(deviceMotion)) },
|
|
.receive(.motionClient(.success(.motionUpdate(deviceMotion)))) {
|
|
$0.z = [32]
|
|
},
|
|
.send(.recordingButtonTapped) {
|
|
$0.isRecording = false
|
|
}
|
|
)
|
|
}
|
|
}
|