-
Notifications
You must be signed in to change notification settings - Fork 139
[PM-39361] fix: Restart card scanner after camera interruption or reopen #2847
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+129
β4
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
dba68b2
PM-39361 Fix card scanner unresponsive
fedemkr 9ad5eb3
Merge remote-tracking branch 'origin/main' into PM-39361/fix-card-scaβ¦
fedemkr 883cb02
Fix scenePhase reliability and retry-budget double-counting in CardScβ¦
fedemkr d552b1c
Merge branch 'main' into PM-39361/fix-card-scanner-unresponsive
fedemkr c499327
PM-39361 Fix CardScannerViewTests
fedemkr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
BitwardenShared/UI/Vault/VaultItem/AddEditItem/AddEditCardItem/CardScannerViewTests.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| import VisionKit | ||
| import XCTest | ||
|
|
||
| @testable import BitwardenShared | ||
|
|
||
| // MARK: - CardScannerViewTests | ||
|
|
||
| /// Tests for `CardScannerView.Coordinator`. | ||
| /// | ||
| /// `CardScannerWrapperView`'s retry/foreground-resume logic is driven by SwiftUI `@State` and cannot | ||
| /// be meaningfully exercised without a live view host, so it is not covered here. | ||
| /// | ||
| @available(iOS 16.0, *) | ||
| class CardScannerViewTests: BitwardenTestCase { | ||
| // MARK: Tests | ||
|
|
||
| /// `dataScanner(_:becameUnavailableWithError:)` calls `onScannerUnavailable` when the scanner | ||
| /// reports an `unsupported` error. | ||
| @MainActor | ||
| func test_becameUnavailableWithError_callsOnScannerUnavailable_unsupported() { | ||
| var callbackInvoked = false | ||
| let subject = CardScannerView.Coordinator( | ||
| onLinesUpdated: { _ in }, | ||
| onScannerUnavailable: { callbackInvoked = true }, | ||
| ) | ||
|
|
||
| subject.dataScanner(CardScannerView.makeScanner(), becameUnavailableWithError: .unsupported) | ||
|
|
||
| XCTAssertTrue(callbackInvoked) | ||
| } | ||
|
|
||
| /// `dataScanner(_:becameUnavailableWithError:)` calls `onScannerUnavailable` when the scanner | ||
| /// reports a `cameraRestricted` error. | ||
| @MainActor | ||
| func test_becameUnavailableWithError_callsOnScannerUnavailable_cameraRestricted() { | ||
| var callbackInvoked = false | ||
| let subject = CardScannerView.Coordinator( | ||
| onLinesUpdated: { _ in }, | ||
| onScannerUnavailable: { callbackInvoked = true }, | ||
| ) | ||
|
|
||
| subject.dataScanner(CardScannerView.makeScanner(), becameUnavailableWithError: .cameraRestricted) | ||
|
|
||
| XCTAssertTrue(callbackInvoked) | ||
| } | ||
|
|
||
| /// `dataScanner(_:becameUnavailableWithError:)` does not crash when `onScannerUnavailable` is nil. | ||
| @MainActor | ||
| func test_becameUnavailableWithError_nilCallback_doesNotCrash() { | ||
| let subject = CardScannerView.Coordinator( | ||
| onLinesUpdated: { _ in }, | ||
| onScannerUnavailable: nil, | ||
| ) | ||
|
|
||
| subject.dataScanner(CardScannerView.makeScanner(), becameUnavailableWithError: .unsupported) | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@matt-livefront I wasn't sure whether this would be a good idea to put it directly here. It seems more like SwiftUI but less testable so if needed I can move it to the processor and do the logic somehow there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's ok given that we would have used scene phase here and it's for a minor and self-contained use.