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
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public protocol TOTPPreviewViewRepository: VaultItemCache, VaultItemCopyActionHa
func restartAllTimers()
func stopAllTimers()
func obfuscateForPrivacy()
func unobfuscateForPrivacy()
}

public final class TOTPPreviewViewRepositoryImpl: TOTPPreviewViewRepository {
Expand Down Expand Up @@ -78,6 +79,12 @@ public final class TOTPPreviewViewRepositoryImpl: TOTPPreviewViewRepository {
viewModel.update(.obfuscated(.privacy))
}
}

public func unobfuscateForPrivacy() {
for viewModel in viewModelCache.values {
viewModel.updateRemovePrivacyObfuscation()
}
}
}

extension TOTPPreviewViewRepositoryImpl: VaultItemCopyActionHandler {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ public final class TOTPPreviewViewGenerator<Factory: TOTPPreviewViewFactory>: Va
repository.obfuscateForPrivacy()
repository.stopAllTimers()
case .active:
// Unobfuscate before restarting so the codes reappear
// immediately rather than waiting for the next timer tick.
repository.unobfuscateForPrivacy()
repository.restartAllTimers()
@unknown default:
break
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,18 @@ struct TOTPPreviewViewRepositoryImplTests {
#expect(viewModel.code == .obfuscated(.privacy))
}

@Test
func unobfuscateForPrivacy_unobfuscatesCodesHiddenForPrivacy() {
let sut = makeSUT()
let viewModel = sut.previewViewModel(metadata: anyVaultItemMetadata(), code: anyTOTPCode())
viewModel.update(.visible("123456"))
viewModel.update(.obfuscated(.privacy))

sut.unobfuscateForPrivacy()

#expect(viewModel.code == .visible("123456"))
}

@Test
func vaultItemCacheClear_removesItemsMatchingIDFromCache() async {
let sut = makeSUT()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,15 @@ final class TOTPPreviewViewGeneratorTests {
}

@Test
func scenePhaseDidChange_activeRestartsAllTimers() {
func scenePhaseDidChange_activeUnobfuscatesAndRestartsAllTimers() {
let factory = makeTOTPPreviewViewFactoryMock()
let repository = TOTPPreviewViewRepositoryMock()
let sut = makeSUT(factory: factory, repository: repository)

sut.scenePhaseDidChange(to: .active)

#expect(repository.restartAllTimersCallCount == 1)
#expect(repository.unobfuscateForPrivacyCallCount == 1)
#expect(repository.obfuscateForPrivacyCallCount == 0)
#expect(repository.stopAllTimersCallCount == 0)
}
Expand All @@ -85,6 +86,7 @@ final class TOTPPreviewViewGeneratorTests {

#expect(repository.restartAllTimersCallCount == 0)
#expect(repository.obfuscateForPrivacyCallCount == 1)
#expect(repository.unobfuscateForPrivacyCallCount == 0)
#expect(repository.stopAllTimersCallCount == 1)
}

Expand Down