Simplify LinkNewDeviceScreen preview test setup and fix preview and accessibility test reliability.

This commit is contained in:
Stefan Ceriu
2026-02-24 17:58:41 +02:00
committed by Stefan Ceriu
parent e1d2c1d415
commit f6510c8577
6 changed files with 17 additions and 38 deletions

View File

@@ -19,9 +19,14 @@ class LinkNewDeviceScreenViewModel: LinkNewDeviceScreenViewModelType, LinkNewDev
actionsSubject.eraseToAnyPublisher()
}
init(clientProxy: ClientProxyProtocol) {
init(clientProxy: ClientProxyProtocol, initialState: LinkNewDeviceScreenViewState? = nil) {
self.clientProxy = clientProxy
if let initialState {
super.init(initialViewState: initialState)
return
}
let isQRCodeScanningSupported = !ProcessInfo.processInfo.isiOSAppOnMac
super.init(initialViewState: LinkNewDeviceScreenViewState(showLinkDesktopComputerButton: isQRCodeScanningSupported))

View File

@@ -141,34 +141,8 @@ struct LinkNewDeviceScreen_Previews: PreviewProvider, TestablePreview {
}
static func makeViewModel(mode: LinkNewDeviceScreenViewState.Mode) -> LinkNewDeviceScreenViewModel {
let clientProxy = ClientProxyMock(.init())
clientProxy.isLoginWithQRCodeSupportedClosure = {
switch mode {
case .loading:
try? await Task.sleep(for: .seconds(20))
return false
case .error(.notSupported):
return false
case .readyToLink, .error:
return true
}
}
let linkMobileProgressSubject = CurrentValueSubject<LinkNewDeviceService.LinkMobileProgress, QRCodeLoginError>(.starting)
clientProxy.linkNewDeviceServiceReturnValue = LinkNewDeviceServiceMock(.init(linkMobileProgressPublisher: linkMobileProgressSubject.asCurrentValuePublisher()))
let viewModel = LinkNewDeviceScreenViewModel(clientProxy: clientProxy)
Task {
try? await Task.sleep(for: .milliseconds(100))
if case .readyToLink(isGeneratingCode: true) = mode {
viewModel.context.send(viewAction: .linkMobileDevice)
} else if case .error = mode {
viewModel.context.send(viewAction: .linkMobileDevice)
linkMobileProgressSubject.send(completion: .failure(.unknown))
}
}
return viewModel
LinkNewDeviceScreenViewModel(clientProxy: ClientProxyMock(.init()),
initialState: .init(mode: mode,
showLinkDesktopComputerButton: true))
}
}