From f6510c85771efa0008b7203350341fde474129d1 Mon Sep 17 00:00:00 2001 From: Stefan Ceriu Date: Tue, 24 Feb 2026 17:58:41 +0200 Subject: [PATCH] Simplify LinkNewDeviceScreen preview test setup and fix preview and accessibility test reliability. --- .../LinkNewDeviceScreenViewModel.swift | 7 +++- .../View/LinkNewDeviceScreen.swift | 32 ++----------------- ...NewDeviceScreen.Unsupported-iPad-en-GB.png | 4 +-- ...ewDeviceScreen.Unsupported-iPad-pseudo.png | 4 +-- ...wDeviceScreen.Unsupported-iPhone-en-GB.png | 4 +-- ...DeviceScreen.Unsupported-iPhone-pseudo.png | 4 +-- 6 files changed, 17 insertions(+), 38 deletions(-) diff --git a/ElementX/Sources/Screens/LinkNewDeviceScreen/LinkNewDeviceScreenViewModel.swift b/ElementX/Sources/Screens/LinkNewDeviceScreen/LinkNewDeviceScreenViewModel.swift index 40e9b30c5..b9b14097d 100644 --- a/ElementX/Sources/Screens/LinkNewDeviceScreen/LinkNewDeviceScreenViewModel.swift +++ b/ElementX/Sources/Screens/LinkNewDeviceScreen/LinkNewDeviceScreenViewModel.swift @@ -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)) diff --git a/ElementX/Sources/Screens/LinkNewDeviceScreen/View/LinkNewDeviceScreen.swift b/ElementX/Sources/Screens/LinkNewDeviceScreen/View/LinkNewDeviceScreen.swift index 69d6a5466..5ffac086b 100644 --- a/ElementX/Sources/Screens/LinkNewDeviceScreen/View/LinkNewDeviceScreen.swift +++ b/ElementX/Sources/Screens/LinkNewDeviceScreen/View/LinkNewDeviceScreen.swift @@ -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(.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)) } } diff --git a/PreviewTests/Sources/__Snapshots__/PreviewTests/linkNewDeviceScreen.Unsupported-iPad-en-GB.png b/PreviewTests/Sources/__Snapshots__/PreviewTests/linkNewDeviceScreen.Unsupported-iPad-en-GB.png index aea78b5bb..666d17c7d 100644 --- a/PreviewTests/Sources/__Snapshots__/PreviewTests/linkNewDeviceScreen.Unsupported-iPad-en-GB.png +++ b/PreviewTests/Sources/__Snapshots__/PreviewTests/linkNewDeviceScreen.Unsupported-iPad-en-GB.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:865ad5f990f5afef41e924c286aebb8c99d9629577f4d75b237aa9972aa4a167 -size 96939 +oid sha256:bd46a891e0688e239d97d83fb2b4baecc148d263b8e242a190435803e87a8246 +size 93795 diff --git a/PreviewTests/Sources/__Snapshots__/PreviewTests/linkNewDeviceScreen.Unsupported-iPad-pseudo.png b/PreviewTests/Sources/__Snapshots__/PreviewTests/linkNewDeviceScreen.Unsupported-iPad-pseudo.png index 33d836a2d..3e2354c59 100644 --- a/PreviewTests/Sources/__Snapshots__/PreviewTests/linkNewDeviceScreen.Unsupported-iPad-pseudo.png +++ b/PreviewTests/Sources/__Snapshots__/PreviewTests/linkNewDeviceScreen.Unsupported-iPad-pseudo.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:9619af1b33240507268b5b8ff1934e025758aaf23ad8b6d5a42a5e3baaed20d0 -size 106049 +oid sha256:2a4de98d1a8011bf49f47a1d361ebb67ea80d0311d8d202f3ff72b19b2bd0542 +size 106647 diff --git a/PreviewTests/Sources/__Snapshots__/PreviewTests/linkNewDeviceScreen.Unsupported-iPhone-en-GB.png b/PreviewTests/Sources/__Snapshots__/PreviewTests/linkNewDeviceScreen.Unsupported-iPhone-en-GB.png index 3fd4fbada..35d4918a1 100644 --- a/PreviewTests/Sources/__Snapshots__/PreviewTests/linkNewDeviceScreen.Unsupported-iPhone-en-GB.png +++ b/PreviewTests/Sources/__Snapshots__/PreviewTests/linkNewDeviceScreen.Unsupported-iPhone-en-GB.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:d59e49988fd995a3af8ec3ed54a951a6f7e6675d135cc8c0ffba780f64535365 -size 53470 +oid sha256:99c2ade9e1c6580b8898e71e1399cdc2692049e0ec8637c706ff0bee62c14639 +size 53340 diff --git a/PreviewTests/Sources/__Snapshots__/PreviewTests/linkNewDeviceScreen.Unsupported-iPhone-pseudo.png b/PreviewTests/Sources/__Snapshots__/PreviewTests/linkNewDeviceScreen.Unsupported-iPhone-pseudo.png index 63fda4777..c271844e1 100644 --- a/PreviewTests/Sources/__Snapshots__/PreviewTests/linkNewDeviceScreen.Unsupported-iPhone-pseudo.png +++ b/PreviewTests/Sources/__Snapshots__/PreviewTests/linkNewDeviceScreen.Unsupported-iPhone-pseudo.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:84dcb8268c7f3f878ffd5d32beb9991a6e7212894e799b1df509a0e4a314516c -size 66759 +oid sha256:6c3677cfc9cb46a3adc07d65ba53db8353f2922c38fd051e35fafa8c3e8adc28 +size 70486