diff --git a/Vault/Tests/VaultiOSTests/BackupImportFlowViewSnapshotTests.swift b/Vault/Tests/VaultiOSTests/BackupImportFlowViewSnapshotTests.swift new file mode 100644 index 000000000..b6f2f040d --- /dev/null +++ b/Vault/Tests/VaultiOSTests/BackupImportFlowViewSnapshotTests.swift @@ -0,0 +1,42 @@ +import Foundation +import FoundationExtensions +import SwiftUI +import TestHelpers +import Testing +@testable import VaultFeed +@testable import VaultiOS + +@MainActor +final class BackupImportFlowViewSnapshotTests { + @Test + func layout() { + for context in [BackupImportContext.toEmptyVault, .merge, .override] { + for colorScheme in [ColorScheme.light, .dark] { + let snapshottingView = BackupImportFlowView(viewModel: makeViewModel(context: context)) + .dynamicTypeSize(.medium) + .preferredColorScheme(colorScheme) + .framedForTest() + .environment(anyVaultInjector()) + + assertSnapshot( + of: snapshottingView, + as: .image, + named: "\(context)_\(colorScheme)", + ) + } + } + } +} + +// MARK: - Helpers + +extension BackupImportFlowViewSnapshotTests { + private func makeViewModel(context: BackupImportContext) -> BackupImportFlowViewModel { + BackupImportFlowViewModel( + importContext: context, + dataModel: anyVaultDataModel(), + existingBackupPassword: nil, + encryptedVaultDecoder: EncryptedVaultDecoderMock(), + ) + } +} diff --git a/Vault/Tests/VaultiOSTests/BackupKeyDecryptorViewSnapshotTests.swift b/Vault/Tests/VaultiOSTests/BackupKeyDecryptorViewSnapshotTests.swift new file mode 100644 index 000000000..687150a2c --- /dev/null +++ b/Vault/Tests/VaultiOSTests/BackupKeyDecryptorViewSnapshotTests.swift @@ -0,0 +1,83 @@ +import Combine +import Foundation +import FoundationExtensions +import SwiftUI +import TestHelpers +import Testing +import VaultBackup +import VaultKeygen +@testable import VaultFeed +@testable import VaultiOS + +@MainActor +final class BackupKeyDecryptorViewSnapshotTests { + @Test + func layout() { + for colorScheme in [ColorScheme.light, .dark] { + for dynamicTypeSize in [DynamicTypeSize.xSmall, .medium, .xxLarge] { + let snapshottingView = NavigationStack { + BackupKeyDecryptorView(viewModel: makeViewModel()) + } + .dynamicTypeSize(dynamicTypeSize) + .preferredColorScheme(colorScheme) + .framedForTest() + + assertSnapshot( + of: snapshottingView, + as: .image, + named: "\(colorScheme)_\(dynamicTypeSize)", + ) + } + } + } + + @Test + func layoutDecryptFailure() async { + let decoder = EncryptedVaultDecoderMock() + decoder.decryptAndDecodeHandler = { _, _ in throw TestError() } + let viewModel = makeViewModel(decoder: decoder) + viewModel.enteredPassword = "wrong password" + + // Fully await the failed decryption (fast testing deriver) so the + // error state renders deterministically. + await viewModel.attemptDecryption() + #expect(viewModel.decryptionKeyState.isError) + + let snapshottingView = NavigationStack { + BackupKeyDecryptorView(viewModel: viewModel) + } + .dynamicTypeSize(.medium) + .preferredColorScheme(.light) + .framedForTest() + + assertSnapshot(of: snapshottingView, as: .image) + } +} + +// MARK: - Helpers + +extension BackupKeyDecryptorViewSnapshotTests { + private func makeViewModel( + decoder: EncryptedVaultDecoderMock = EncryptedVaultDecoderMock(), + ) -> BackupKeyDecryptorViewModel { + let deriverFactory = VaultKeyDeriverFactoryMock() + deriverFactory.lookupVaultKeyDeriverHandler = { _ in .testing } + return BackupKeyDecryptorViewModel( + encryptedVault: anyEncryptedVault(), + keyDeriverFactory: deriverFactory, + encryptedVaultDecoder: decoder, + decryptedVaultSubject: PassthroughSubject(), + ) + } + + private func anyEncryptedVault() -> EncryptedVault { + EncryptedVault( + version: "1.0.0", + data: Data(repeating: 0xAB, count: 50), + authentication: Data(), + encryptionIV: Data(), + keygenSalt: Data(repeating: 0xCD, count: 32), + keygenSignature: VaultKeyDeriver.Signature.testing.rawValue, + ) + } +} diff --git a/Vault/Tests/VaultiOSTests/VaultDetailEncryptionEditViewSnapshotTests.swift b/Vault/Tests/VaultiOSTests/VaultDetailEncryptionEditViewSnapshotTests.swift new file mode 100644 index 000000000..1d8e93cd5 --- /dev/null +++ b/Vault/Tests/VaultiOSTests/VaultDetailEncryptionEditViewSnapshotTests.swift @@ -0,0 +1,56 @@ +import Foundation +import SwiftUI +import TestHelpers +import Testing +@testable import VaultiOS + +@MainActor +final class VaultDetailEncryptionEditViewSnapshotTests { + @Test + func layoutEncryptionDisabled() { + for colorScheme in [ColorScheme.light, .dark] { + for dynamicTypeSize in [DynamicTypeSize.xSmall, .medium, .xxLarge] { + let snapshottingView = makeView(encryptionInitiallyEnabled: false) + .dynamicTypeSize(dynamicTypeSize) + .preferredColorScheme(colorScheme) + .framedForTest() + + assertSnapshot( + of: snapshottingView, + as: .image, + named: "\(colorScheme)_\(dynamicTypeSize)", + ) + } + } + } + + @Test + func layoutEncryptionEnabled() { + for colorScheme in [ColorScheme.light, .dark] { + let snapshottingView = makeView(encryptionInitiallyEnabled: true) + .dynamicTypeSize(.medium) + .preferredColorScheme(colorScheme) + .framedForTest() + + assertSnapshot( + of: snapshottingView, + as: .image, + named: "\(colorScheme)_medium", + ) + } + } +} + +// MARK: - Helpers + +extension VaultDetailEncryptionEditViewSnapshotTests { + private func makeView(encryptionInitiallyEnabled: Bool) -> some View { + VaultDetailEncryptionEditView( + title: "Encryption", + description: "Encrypt this item with a separate password.", + encryptionInitiallyEnabled: encryptionInitiallyEnabled, + didSetNewEncryptionPassword: { _ in }, + didRemoveEncryption: {}, + ) + } +} diff --git a/Vault/Tests/VaultiOSTests/__Snapshots__/BackupImportFlowViewSnapshotTests/layout.merge_dark.png b/Vault/Tests/VaultiOSTests/__Snapshots__/BackupImportFlowViewSnapshotTests/layout.merge_dark.png new file mode 100644 index 000000000..da60cc589 Binary files /dev/null and b/Vault/Tests/VaultiOSTests/__Snapshots__/BackupImportFlowViewSnapshotTests/layout.merge_dark.png differ diff --git a/Vault/Tests/VaultiOSTests/__Snapshots__/BackupImportFlowViewSnapshotTests/layout.merge_light.png b/Vault/Tests/VaultiOSTests/__Snapshots__/BackupImportFlowViewSnapshotTests/layout.merge_light.png new file mode 100644 index 000000000..da60cc589 Binary files /dev/null and b/Vault/Tests/VaultiOSTests/__Snapshots__/BackupImportFlowViewSnapshotTests/layout.merge_light.png differ diff --git a/Vault/Tests/VaultiOSTests/__Snapshots__/BackupImportFlowViewSnapshotTests/layout.override_dark.png b/Vault/Tests/VaultiOSTests/__Snapshots__/BackupImportFlowViewSnapshotTests/layout.override_dark.png new file mode 100644 index 000000000..da60cc589 Binary files /dev/null and b/Vault/Tests/VaultiOSTests/__Snapshots__/BackupImportFlowViewSnapshotTests/layout.override_dark.png differ diff --git a/Vault/Tests/VaultiOSTests/__Snapshots__/BackupImportFlowViewSnapshotTests/layout.override_light.png b/Vault/Tests/VaultiOSTests/__Snapshots__/BackupImportFlowViewSnapshotTests/layout.override_light.png new file mode 100644 index 000000000..da60cc589 Binary files /dev/null and b/Vault/Tests/VaultiOSTests/__Snapshots__/BackupImportFlowViewSnapshotTests/layout.override_light.png differ diff --git a/Vault/Tests/VaultiOSTests/__Snapshots__/BackupImportFlowViewSnapshotTests/layout.toEmptyVault_dark.png b/Vault/Tests/VaultiOSTests/__Snapshots__/BackupImportFlowViewSnapshotTests/layout.toEmptyVault_dark.png new file mode 100644 index 000000000..da60cc589 Binary files /dev/null and b/Vault/Tests/VaultiOSTests/__Snapshots__/BackupImportFlowViewSnapshotTests/layout.toEmptyVault_dark.png differ diff --git a/Vault/Tests/VaultiOSTests/__Snapshots__/BackupImportFlowViewSnapshotTests/layout.toEmptyVault_light.png b/Vault/Tests/VaultiOSTests/__Snapshots__/BackupImportFlowViewSnapshotTests/layout.toEmptyVault_light.png new file mode 100644 index 000000000..da60cc589 Binary files /dev/null and b/Vault/Tests/VaultiOSTests/__Snapshots__/BackupImportFlowViewSnapshotTests/layout.toEmptyVault_light.png differ diff --git a/Vault/Tests/VaultiOSTests/__Snapshots__/BackupKeyDecryptorViewSnapshotTests/layout.dark_medium.png b/Vault/Tests/VaultiOSTests/__Snapshots__/BackupKeyDecryptorViewSnapshotTests/layout.dark_medium.png new file mode 100644 index 000000000..7591eb893 Binary files /dev/null and b/Vault/Tests/VaultiOSTests/__Snapshots__/BackupKeyDecryptorViewSnapshotTests/layout.dark_medium.png differ diff --git a/Vault/Tests/VaultiOSTests/__Snapshots__/BackupKeyDecryptorViewSnapshotTests/layout.dark_xSmall.png b/Vault/Tests/VaultiOSTests/__Snapshots__/BackupKeyDecryptorViewSnapshotTests/layout.dark_xSmall.png new file mode 100644 index 000000000..7e522a8f3 Binary files /dev/null and b/Vault/Tests/VaultiOSTests/__Snapshots__/BackupKeyDecryptorViewSnapshotTests/layout.dark_xSmall.png differ diff --git a/Vault/Tests/VaultiOSTests/__Snapshots__/BackupKeyDecryptorViewSnapshotTests/layout.dark_xxLarge.png b/Vault/Tests/VaultiOSTests/__Snapshots__/BackupKeyDecryptorViewSnapshotTests/layout.dark_xxLarge.png new file mode 100644 index 000000000..3bc68eb00 Binary files /dev/null and b/Vault/Tests/VaultiOSTests/__Snapshots__/BackupKeyDecryptorViewSnapshotTests/layout.dark_xxLarge.png differ diff --git a/Vault/Tests/VaultiOSTests/__Snapshots__/BackupKeyDecryptorViewSnapshotTests/layout.light_medium.png b/Vault/Tests/VaultiOSTests/__Snapshots__/BackupKeyDecryptorViewSnapshotTests/layout.light_medium.png new file mode 100644 index 000000000..7591eb893 Binary files /dev/null and b/Vault/Tests/VaultiOSTests/__Snapshots__/BackupKeyDecryptorViewSnapshotTests/layout.light_medium.png differ diff --git a/Vault/Tests/VaultiOSTests/__Snapshots__/BackupKeyDecryptorViewSnapshotTests/layout.light_xSmall.png b/Vault/Tests/VaultiOSTests/__Snapshots__/BackupKeyDecryptorViewSnapshotTests/layout.light_xSmall.png new file mode 100644 index 000000000..7e522a8f3 Binary files /dev/null and b/Vault/Tests/VaultiOSTests/__Snapshots__/BackupKeyDecryptorViewSnapshotTests/layout.light_xSmall.png differ diff --git a/Vault/Tests/VaultiOSTests/__Snapshots__/BackupKeyDecryptorViewSnapshotTests/layout.light_xxLarge.png b/Vault/Tests/VaultiOSTests/__Snapshots__/BackupKeyDecryptorViewSnapshotTests/layout.light_xxLarge.png new file mode 100644 index 000000000..3bc68eb00 Binary files /dev/null and b/Vault/Tests/VaultiOSTests/__Snapshots__/BackupKeyDecryptorViewSnapshotTests/layout.light_xxLarge.png differ diff --git a/Vault/Tests/VaultiOSTests/__Snapshots__/BackupKeyDecryptorViewSnapshotTests/layoutDecryptFailure.1.png b/Vault/Tests/VaultiOSTests/__Snapshots__/BackupKeyDecryptorViewSnapshotTests/layoutDecryptFailure.1.png new file mode 100644 index 000000000..418e29e60 Binary files /dev/null and b/Vault/Tests/VaultiOSTests/__Snapshots__/BackupKeyDecryptorViewSnapshotTests/layoutDecryptFailure.1.png differ diff --git a/Vault/Tests/VaultiOSTests/__Snapshots__/VaultDetailEncryptionEditViewSnapshotTests/layoutEncryptionDisabled.dark_medium.png b/Vault/Tests/VaultiOSTests/__Snapshots__/VaultDetailEncryptionEditViewSnapshotTests/layoutEncryptionDisabled.dark_medium.png new file mode 100644 index 000000000..55bc1095e Binary files /dev/null and b/Vault/Tests/VaultiOSTests/__Snapshots__/VaultDetailEncryptionEditViewSnapshotTests/layoutEncryptionDisabled.dark_medium.png differ diff --git a/Vault/Tests/VaultiOSTests/__Snapshots__/VaultDetailEncryptionEditViewSnapshotTests/layoutEncryptionDisabled.dark_xSmall.png b/Vault/Tests/VaultiOSTests/__Snapshots__/VaultDetailEncryptionEditViewSnapshotTests/layoutEncryptionDisabled.dark_xSmall.png new file mode 100644 index 000000000..bd8b6739f Binary files /dev/null and b/Vault/Tests/VaultiOSTests/__Snapshots__/VaultDetailEncryptionEditViewSnapshotTests/layoutEncryptionDisabled.dark_xSmall.png differ diff --git a/Vault/Tests/VaultiOSTests/__Snapshots__/VaultDetailEncryptionEditViewSnapshotTests/layoutEncryptionDisabled.dark_xxLarge.png b/Vault/Tests/VaultiOSTests/__Snapshots__/VaultDetailEncryptionEditViewSnapshotTests/layoutEncryptionDisabled.dark_xxLarge.png new file mode 100644 index 000000000..590dc1aa5 Binary files /dev/null and b/Vault/Tests/VaultiOSTests/__Snapshots__/VaultDetailEncryptionEditViewSnapshotTests/layoutEncryptionDisabled.dark_xxLarge.png differ diff --git a/Vault/Tests/VaultiOSTests/__Snapshots__/VaultDetailEncryptionEditViewSnapshotTests/layoutEncryptionDisabled.light_medium.png b/Vault/Tests/VaultiOSTests/__Snapshots__/VaultDetailEncryptionEditViewSnapshotTests/layoutEncryptionDisabled.light_medium.png new file mode 100644 index 000000000..55bc1095e Binary files /dev/null and b/Vault/Tests/VaultiOSTests/__Snapshots__/VaultDetailEncryptionEditViewSnapshotTests/layoutEncryptionDisabled.light_medium.png differ diff --git a/Vault/Tests/VaultiOSTests/__Snapshots__/VaultDetailEncryptionEditViewSnapshotTests/layoutEncryptionDisabled.light_xSmall.png b/Vault/Tests/VaultiOSTests/__Snapshots__/VaultDetailEncryptionEditViewSnapshotTests/layoutEncryptionDisabled.light_xSmall.png new file mode 100644 index 000000000..bd8b6739f Binary files /dev/null and b/Vault/Tests/VaultiOSTests/__Snapshots__/VaultDetailEncryptionEditViewSnapshotTests/layoutEncryptionDisabled.light_xSmall.png differ diff --git a/Vault/Tests/VaultiOSTests/__Snapshots__/VaultDetailEncryptionEditViewSnapshotTests/layoutEncryptionDisabled.light_xxLarge.png b/Vault/Tests/VaultiOSTests/__Snapshots__/VaultDetailEncryptionEditViewSnapshotTests/layoutEncryptionDisabled.light_xxLarge.png new file mode 100644 index 000000000..590dc1aa5 Binary files /dev/null and b/Vault/Tests/VaultiOSTests/__Snapshots__/VaultDetailEncryptionEditViewSnapshotTests/layoutEncryptionDisabled.light_xxLarge.png differ diff --git a/Vault/Tests/VaultiOSTests/__Snapshots__/VaultDetailEncryptionEditViewSnapshotTests/layoutEncryptionEnabled.dark_medium.png b/Vault/Tests/VaultiOSTests/__Snapshots__/VaultDetailEncryptionEditViewSnapshotTests/layoutEncryptionEnabled.dark_medium.png new file mode 100644 index 000000000..e9312e0af Binary files /dev/null and b/Vault/Tests/VaultiOSTests/__Snapshots__/VaultDetailEncryptionEditViewSnapshotTests/layoutEncryptionEnabled.dark_medium.png differ diff --git a/Vault/Tests/VaultiOSTests/__Snapshots__/VaultDetailEncryptionEditViewSnapshotTests/layoutEncryptionEnabled.light_medium.png b/Vault/Tests/VaultiOSTests/__Snapshots__/VaultDetailEncryptionEditViewSnapshotTests/layoutEncryptionEnabled.light_medium.png new file mode 100644 index 000000000..e9312e0af Binary files /dev/null and b/Vault/Tests/VaultiOSTests/__Snapshots__/VaultDetailEncryptionEditViewSnapshotTests/layoutEncryptionEnabled.light_medium.png differ