Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions Vault/Tests/VaultiOSTests/BackupImportFlowViewSnapshotTests.swift
Original file line number Diff line number Diff line change
@@ -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(),
)
}
}
Original file line number Diff line number Diff line change
@@ -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,
)
}
}
Original file line number Diff line number Diff line change
@@ -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: {},
)
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.