2022-05-23 23:30:12 -07:00
|
|
|
//
|
|
|
|
// ScanTests.swift
|
|
|
|
// secantTests
|
|
|
|
//
|
|
|
|
// Created by Lukáš Korba on 17.05.2022.
|
|
|
|
//
|
|
|
|
|
|
|
|
import XCTest
|
|
|
|
@testable import secant_testnet
|
|
|
|
import ComposableArchitecture
|
|
|
|
import ZcashLightClientKit
|
|
|
|
|
|
|
|
class ScanTests: XCTestCase {
|
|
|
|
func testOnAppearResetValues() throws {
|
|
|
|
let store = TestStore(
|
|
|
|
initialState:
|
2022-11-04 23:11:25 -07:00
|
|
|
ScanReducer.State(
|
2022-05-23 23:30:12 -07:00
|
|
|
isTorchAvailable: true,
|
|
|
|
isTorchOn: true,
|
|
|
|
isValidValue: true,
|
|
|
|
scanStatus: .value("t1gXqfSSQt6WfpwyuCU3Wi7sSVZ66DYQ3Po")
|
|
|
|
),
|
2022-11-04 23:11:25 -07:00
|
|
|
reducer: ScanReducer()
|
2022-11-18 02:34:33 -08:00
|
|
|
) {
|
|
|
|
$0.captureDevice = .noOp
|
|
|
|
}
|
2022-11-14 10:36:51 -08:00
|
|
|
|
2022-05-23 23:30:12 -07:00
|
|
|
store.send(.onAppear) { state in
|
|
|
|
state.isTorchAvailable = false
|
|
|
|
state.isTorchOn = false
|
|
|
|
state.isValidValue = false
|
|
|
|
state.scanStatus = .unknown
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func testTorchOn() throws {
|
|
|
|
let store = TestStore(
|
2022-11-04 23:11:25 -07:00
|
|
|
initialState: ScanReducer.State(),
|
|
|
|
reducer: ScanReducer()
|
2022-11-18 02:34:33 -08:00
|
|
|
) {
|
|
|
|
$0.captureDevice = .noOp
|
|
|
|
}
|
2022-11-14 10:36:51 -08:00
|
|
|
|
2022-05-23 23:30:12 -07:00
|
|
|
store.send(.torchPressed) { state in
|
|
|
|
state.isTorchOn = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func testTorchOff() throws {
|
|
|
|
let store = TestStore(
|
2022-11-04 23:11:25 -07:00
|
|
|
initialState: ScanReducer.State(
|
2022-05-23 23:30:12 -07:00
|
|
|
isTorchOn: true
|
|
|
|
),
|
2022-11-04 23:11:25 -07:00
|
|
|
reducer: ScanReducer()
|
2022-11-18 02:34:33 -08:00
|
|
|
) {
|
|
|
|
$0.captureDevice = .noOp
|
|
|
|
}
|
2022-11-14 10:36:51 -08:00
|
|
|
|
2022-05-23 23:30:12 -07:00
|
|
|
store.send(.torchPressed) { state in
|
|
|
|
state.isTorchOn = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func testScannedInvalidValue() throws {
|
|
|
|
let store = TestStore(
|
2022-11-04 23:11:25 -07:00
|
|
|
initialState: ScanReducer.State(),
|
|
|
|
reducer: ScanReducer()
|
2022-11-18 02:34:33 -08:00
|
|
|
) {
|
|
|
|
$0.uriParser.isValidURI = { _ in false }
|
|
|
|
}
|
2022-11-17 03:25:55 -08:00
|
|
|
|
2022-05-23 23:30:12 -07:00
|
|
|
store.send(.scan("test")) { state in
|
|
|
|
state.scanStatus = .value("test")
|
|
|
|
state.isValidValue = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func testScannedValidAddress() throws {
|
|
|
|
let testScheduler = DispatchQueue.test
|
|
|
|
|
|
|
|
let store = TestStore(
|
2022-11-04 23:11:25 -07:00
|
|
|
initialState: ScanReducer.State(),
|
|
|
|
reducer: ScanReducer()
|
2022-11-18 02:34:33 -08:00
|
|
|
) { dependencies in
|
|
|
|
dependencies.mainQueue = testScheduler.eraseToAnyScheduler()
|
|
|
|
dependencies.uriParser.isValidURI = { _ in true }
|
|
|
|
}
|
2022-11-17 03:25:55 -08:00
|
|
|
|
2022-05-23 23:30:12 -07:00
|
|
|
store.send(.scan("t1gXqfSSQt6WfpwyuCU3Wi7sSVZ66DYQ3Po")) { state in
|
|
|
|
state.scanStatus = .value("t1gXqfSSQt6WfpwyuCU3Wi7sSVZ66DYQ3Po")
|
|
|
|
state.isValidValue = true
|
|
|
|
}
|
|
|
|
|
|
|
|
testScheduler.advance(by: 1.01)
|
|
|
|
|
|
|
|
store.receive(.found("t1gXqfSSQt6WfpwyuCU3Wi7sSVZ66DYQ3Po"))
|
|
|
|
}
|
|
|
|
|
|
|
|
func testScanFailed() throws {
|
|
|
|
let store = TestStore(
|
2022-11-04 23:11:25 -07:00
|
|
|
initialState: ScanReducer.State(),
|
|
|
|
reducer: ScanReducer()
|
2022-05-23 23:30:12 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
store.send(.scanFailed) { state in
|
|
|
|
state.scanStatus = .failed
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|