From fb492ed55358094d8c85bcfee384e339967e3023 Mon Sep 17 00:00:00 2001 From: ykisana Date: Thu, 12 Nov 2026 15:41:34 -0600 Subject: [PATCH] feat: route widget requests through one unblock request Prepares the in-app side for Shortcuts unblocks: - One UnblockRequest (group or all apps, duration, key type) replaces the coordinator's group-only request. "Block with no group" can no longer be represented. - The widget responder can unblock all apps, and binds the key check and duration sheet to the requested target. - A requested key type is selected directly, so a widget set to QR Code / Barcode goes straight to the scanner. The scan, its keys and its flow are captured when the key is chosen. - A widget link that arrives while Settings is open closes it first, so the key prompt can appear. --- Normal/App/ContentView.swift | 2 +- .../Modifiers/ProtectedActionModifier.swift | 4 ++ Normal/Modifiers/WidgetActionResponder.swift | 50 ++++++++++++------- Normal/Services/Keys/KeyCheckFlow.swift | 4 +- Normal/Services/Keys/KeySelectLogic.swift | 7 ++- Normal/Services/NavigationCoordinator.swift | 46 ++++++++++------- Normal/Services/UnblockRequest.swift | 7 +++ Normal/Services/UnblockTarget.swift | 7 +++ .../KeySelect/KeySelectModifier.swift | 6 ++- NormalTests/Services/KeyCheckFlowTests.swift | 8 +++ .../Services/KeySelectLogicTests.swift | 40 +++++++++++++++ .../Services/NavigationCoordinatorTests.swift | 29 +++++++++++ .../NavigationCoordinatorWidgetTests.swift | 42 +++++++--------- NormalUITests/BlockingUITests.swift | 16 ++++++ 14 files changed, 205 insertions(+), 63 deletions(-) create mode 100644 Normal/Services/UnblockRequest.swift diff --git a/Normal/App/ContentView.swift b/Normal/App/ContentView.swift index 91d1cba..46a68ab 100644 --- a/Normal/App/ContentView.swift +++ b/Normal/App/ContentView.swift @@ -30,7 +30,7 @@ struct ContentView: View { .environment(\.navigationCoordinator, navigationCoordinator) .widgetActionResponder(coordinator: navigationCoordinator, selectedTab: $selectedTab) .liveActivitySync() - .sheet(isPresented: $navigationCoordinator.isSettingsPresented) { + .sheet(isPresented: $navigationCoordinator.isSettingsPresented, onDismiss: navigationCoordinator.settingsDidDismiss) { SettingsView(initialTab: navigationCoordinator.settingsInitialTab) } .onChange(of: onboardingService.requiredTab) { _, newTab in diff --git a/Normal/Modifiers/ProtectedActionModifier.swift b/Normal/Modifiers/ProtectedActionModifier.swift index 989775d..d631d2f 100644 --- a/Normal/Modifiers/ProtectedActionModifier.swift +++ b/Normal/Modifiers/ProtectedActionModifier.swift @@ -4,6 +4,7 @@ struct ProtectedActionModifier: ViewModifier { @Binding var action: (@MainActor () -> Void)? var allowBypass: Bool var defaultKeyType: KeyType? + var requestedKeyType: KeyType? var keyGroupID: UUID? var requestID: UUID? @@ -14,6 +15,7 @@ struct ProtectedActionModifier: ViewModifier { action: $action, allowBypass: allowBypass, defaultKeyType: defaultKeyType, + requestedKeyType: requestedKeyType, keyGroupID: keyGroupID, requestID: requestID ) @@ -25,6 +27,7 @@ extension View { _ action: Binding<(@MainActor () -> Void)?>, allowBypass: Bool = false, defaultKeyType: KeyType? = nil, + requestedKeyType: KeyType? = nil, keyGroupID: UUID? = nil, requestID: UUID? = nil ) -> some View { @@ -32,6 +35,7 @@ extension View { action: action, allowBypass: allowBypass, defaultKeyType: defaultKeyType, + requestedKeyType: requestedKeyType, keyGroupID: keyGroupID, requestID: requestID )) diff --git a/Normal/Modifiers/WidgetActionResponder.swift b/Normal/Modifiers/WidgetActionResponder.swift index 21bb691..3abfb3e 100644 --- a/Normal/Modifiers/WidgetActionResponder.swift +++ b/Normal/Modifiers/WidgetActionResponder.swift @@ -8,18 +8,19 @@ private struct WidgetActionResponder: ViewModifier { @Query private var allSettings: [Settings] @Query(sort: [SortDescriptor(\AppGroup.sortIndex)]) private var groups: [AppGroup] @Query private var keys: [Key] + @Query private var selectedApps: [SelectedApps] let coordinator: NavigationCoordinator @Binding var selectedTab: AppTab @State private var authAction: (@MainActor () -> Void)? @State private var active: ActiveRequest? - @State private var heldRequest: GroupActionRequest? + @State private var heldRequest: ActionRequest? @State private var durationTarget: UnblockTarget? private struct ActiveRequest { let token: UUID - let group: AppGroup + let target: UnblockTarget let keyType: KeyType? let allowBypass: Bool } @@ -33,15 +34,15 @@ private struct WidgetActionResponder: ViewModifier { .protectedAction( $authAction, allowBypass: active?.allowBypass ?? false, - defaultKeyType: active?.keyType, - keyGroupID: active?.group.id, + requestedKeyType: active?.keyType, + keyGroupID: active?.target.groupID, requestID: active?.token ) .sheet(item: $durationTarget, onDismiss: replayHeldRequest) { target in UnblockDurationSheet(target: target) } .onOpenURL { coordinator.handle(url: $0) } - .onChange(of: coordinator.pendingGroupAction) { _, request in resolve(request) } + .onChange(of: coordinator.pendingAction) { _, request in resolve(request) } .onChange(of: groups) { _, _ in syncGroups() } .onChange(of: keys) { _, _ in syncWidget() } .onChange(of: screenTimeService.lastUpdate) { _, _ in syncWidget() } @@ -63,24 +64,23 @@ private struct WidgetActionResponder: ViewModifier { NormalShortcuts.updateAppShortcutParameters() } - private func resolve(_ request: GroupActionRequest?) { + private func resolve(_ request: ActionRequest?) { guard let request else { return } - coordinator.clearPendingGroupAction() + coordinator.clearPendingAction() guard durationTarget == nil else { heldRequest = request return } - guard allSettings.first?.hasCompletedOnboarding == true, - let group = groups.first(where: { $0.id == request.groupID }) - else { return } - selectedTab = .groups + guard allSettings.first?.hasCompletedOnboarding == true else { return } switch request.action { - case let .unlock(duration, keyType): - active = ActiveRequest(token: request.token, group: group, keyType: keyType, allowBypass: false) - authAction = { unlock(group, duration: duration) } - case .block: - active = ActiveRequest(token: request.token, group: group, keyType: nil, allowBypass: true) + case let .unblock(unblock): + guard let target = target(for: unblock.groupID) else { return } + present(ActiveRequest(token: request.token, target: target, keyType: unblock.keyType, allowBypass: false)) + authAction = { unlock(target, duration: unblock.duration) } + case let .blockGroup(groupID): + guard let group = groups.first(where: { $0.id == groupID }) else { return } + present(ActiveRequest(token: request.token, target: .group(group), keyType: nil, allowBypass: true)) authAction = { block(group) } } } @@ -91,13 +91,25 @@ private struct WidgetActionResponder: ViewModifier { resolve(held) } - private func unlock(_ group: AppGroup, duration request: UnlockDurationRequest) { + private func target(for groupID: UUID?) -> UnblockTarget? { + if let groupID { + return groups.first { $0.id == groupID }.map(UnblockTarget.group) + } + return selectedApps.first.map(UnblockTarget.all) + } + + private func present(_ request: ActiveRequest) { + selectedTab = request.target.groupID == nil ? .home : .groups + active = request + } + + private func unlock(_ target: UnblockTarget, duration request: UnlockDurationRequest) { guard let settings = allSettings.first, let duration = settings.duration(for: request) else { - durationTarget = .group(group) + durationTarget = target return } try? timedUnblockService.start( - .group(group), + target, duration: duration, settings: settings, screenTimeService: screenTimeService diff --git a/Normal/Services/Keys/KeyCheckFlow.swift b/Normal/Services/Keys/KeyCheckFlow.swift index f702a3d..d3582e0 100644 --- a/Normal/Services/Keys/KeyCheckFlow.swift +++ b/Normal/Services/Keys/KeyCheckFlow.swift @@ -16,6 +16,7 @@ final class KeyCheckFlow { let availableKeyTypes: [KeyType] let allowBypass: Bool let defaultKeyType: KeyType? + var requestedKeyType: KeyType? } enum Stage: Equatable { @@ -64,7 +65,8 @@ final class KeyCheckFlow { switch KeySelectLogic.decide( availableKeyTypes: request.availableKeyTypes, allowBypass: request.allowBypass, - defaultKeyType: request.defaultKeyType + defaultKeyType: request.defaultKeyType, + requestedKeyType: request.requestedKeyType ) { case .showNoKeysAlert: stage = .noKeys diff --git a/Normal/Services/Keys/KeySelectLogic.swift b/Normal/Services/Keys/KeySelectLogic.swift index 5be6eab..f2c83be 100644 --- a/Normal/Services/Keys/KeySelectLogic.swift +++ b/Normal/Services/Keys/KeySelectLogic.swift @@ -10,7 +10,8 @@ enum KeySelectLogic { static func decide( availableKeyTypes: [KeyType], allowBypass: Bool, - defaultKeyType: KeyType? + defaultKeyType: KeyType?, + requestedKeyType: KeyType? = nil ) -> KeySelectAction { guard !availableKeyTypes.isEmpty else { return .showNoKeysAlert @@ -20,6 +21,10 @@ enum KeySelectLogic { return .showSheet } + if let requestedKeyType, availableKeyTypes.contains(requestedKeyType) { + return .autoSelect(requestedKeyType) + } + if let keyType = defaultKeyType, availableKeyTypes.contains(keyType), keyType.autoSelectable { return .autoSelect(keyType) } diff --git a/Normal/Services/NavigationCoordinator.swift b/Normal/Services/NavigationCoordinator.swift index 918c3c6..e7922b0 100644 --- a/Normal/Services/NavigationCoordinator.swift +++ b/Normal/Services/NavigationCoordinator.swift @@ -1,14 +1,13 @@ import SwiftUI -enum GroupAction: Equatable { - case unlock(duration: UnlockDurationRequest, keyType: KeyType?) - case block +enum PendingAction: Equatable { + case unblock(UnblockRequest) + case blockGroup(UUID) } -struct GroupActionRequest: Equatable { +struct ActionRequest: Equatable { let token: UUID - let groupID: UUID - let action: GroupAction + let action: PendingAction } @MainActor @@ -17,7 +16,8 @@ final class NavigationCoordinator { var isSettingsPresented = false private(set) var settingsInitialTab: SettingsTab = .general - var pendingGroupAction: GroupActionRequest? + private(set) var pendingAction: ActionRequest? + private var actionAfterSettings: ActionRequest? func presentSettings(tab: SettingsTab = .general) { settingsInitialTab = tab @@ -28,16 +28,18 @@ final class NavigationCoordinator { isSettingsPresented = false } - func requestGroupUnlock(groupID: UUID, duration: UnlockDurationRequest, keyType: KeyType?) { - pendingGroupAction = GroupActionRequest( - token: UUID(), - groupID: groupID, - action: .unlock(duration: duration, keyType: keyType) - ) + func settingsDidDismiss() { + guard let actionAfterSettings else { return } + self.actionAfterSettings = nil + pendingAction = actionAfterSettings + } + + func requestUnblock(_ request: UnblockRequest) { + post(.unblock(request)) } func requestGroupBlock(groupID: UUID) { - pendingGroupAction = GroupActionRequest(token: UUID(), groupID: groupID, action: .block) + post(.blockGroup(groupID)) } func handle(url: URL) { @@ -57,7 +59,7 @@ final class NavigationCoordinator { ) let keyType = items.first { $0.name == WidgetDeepLink.keyQueryItem }?.value .flatMap { KeyType(rawValue: $0) } - requestGroupUnlock(groupID: groupID, duration: duration, keyType: keyType) + requestUnblock(UnblockRequest(groupID: groupID, duration: duration, keyType: keyType)) case WidgetDeepLink.blockHost: requestGroupBlock(groupID: groupID) default: @@ -65,8 +67,18 @@ final class NavigationCoordinator { } } - func clearPendingGroupAction() { - pendingGroupAction = nil + func clearPendingAction() { + pendingAction = nil + } + + private func post(_ action: PendingAction) { + let request = ActionRequest(token: UUID(), action: action) + if isSettingsPresented { + actionAfterSettings = request + isSettingsPresented = false + } else { + pendingAction = request + } } } diff --git a/Normal/Services/UnblockRequest.swift b/Normal/Services/UnblockRequest.swift new file mode 100644 index 0000000..4b6a6d2 --- /dev/null +++ b/Normal/Services/UnblockRequest.swift @@ -0,0 +1,7 @@ +import Foundation + +nonisolated struct UnblockRequest: Equatable, Sendable { + let groupID: UUID? + let duration: UnlockDurationRequest + let keyType: KeyType? +} diff --git a/Normal/Services/UnblockTarget.swift b/Normal/Services/UnblockTarget.swift index 34e827d..23b6eb0 100644 --- a/Normal/Services/UnblockTarget.swift +++ b/Normal/Services/UnblockTarget.swift @@ -12,6 +12,13 @@ enum UnblockTarget: Identifiable { } } + var groupID: UUID? { + if case let .group(group) = self { + return group.id + } + return nil + } + var selection: FamilyActivitySelection { switch self { case let .all(mainSelection): mainSelection.selection diff --git a/Normal/Views/BlockUnblockViews/KeySelect/KeySelectModifier.swift b/Normal/Views/BlockUnblockViews/KeySelect/KeySelectModifier.swift index 59ca25a..836335b 100644 --- a/Normal/Views/BlockUnblockViews/KeySelect/KeySelectModifier.swift +++ b/Normal/Views/BlockUnblockViews/KeySelect/KeySelectModifier.swift @@ -10,6 +10,7 @@ struct KeySelectModifier: ViewModifier { @Binding var action: (@MainActor () -> Void)? var allowBypass: Bool var defaultKeyType: KeyType? + var requestedKeyType: KeyType? var keyGroupID: UUID? var requestID: UUID? @@ -138,7 +139,8 @@ struct KeySelectModifier: ViewModifier { keys: scopedKeys, availableKeyTypes: KeyType.selectable(registered: scopedKeys.map(\.type)), allowBypass: allowBypass, - defaultKeyType: defaultKeyType + defaultKeyType: defaultKeyType, + requestedKeyType: requestedKeyType ), action: action ) @@ -150,6 +152,7 @@ extension View { action: Binding<(@MainActor () -> Void)?>, allowBypass: Bool = false, defaultKeyType: KeyType? = nil, + requestedKeyType: KeyType? = nil, keyGroupID: UUID? = nil, requestID: UUID? = nil ) -> some View { @@ -157,6 +160,7 @@ extension View { action: action, allowBypass: allowBypass, defaultKeyType: defaultKeyType, + requestedKeyType: requestedKeyType, keyGroupID: keyGroupID, requestID: requestID )) diff --git a/NormalTests/Services/KeyCheckFlowTests.swift b/NormalTests/Services/KeyCheckFlowTests.swift index c6123fd..ddbae25 100644 --- a/NormalTests/Services/KeyCheckFlowTests.swift +++ b/NormalTests/Services/KeyCheckFlowTests.swift @@ -107,6 +107,14 @@ struct KeyCheckFlowTests { #expect(qr.scanCount == 1) } + @Test func requestedQRKeyGoesStraightToTheScanner() { + var request = qrAndNFC + request.requestedKeyType = .qr + start(request) + #expect(flow.stage == .scanningQR) + #expect(flow.sheetScreen == .qrScanner) + } + @Test func repeatedChoiceIsIgnored() async { start(qrAndNFC) flow.choose(.qr) diff --git a/NormalTests/Services/KeySelectLogicTests.swift b/NormalTests/Services/KeySelectLogicTests.swift index a1fd287..3c25447 100644 --- a/NormalTests/Services/KeySelectLogicTests.swift +++ b/NormalTests/Services/KeySelectLogicTests.swift @@ -56,4 +56,44 @@ struct KeySelectLogicTests { let result = KeySelectLogic.decide(availableKeyTypes: [.qr], allowBypass: false, defaultKeyType: .nfc) #expect(result == .showSheet) } + + @Test func requestedQRAutoSelects() { + let result = KeySelectLogic.decide( + availableKeyTypes: [.nfc, .qr], + allowBypass: false, + defaultKeyType: nil, + requestedKeyType: .qr + ) + #expect(result == .autoSelect(.qr)) + } + + @Test func requestedKeyBeatsDefault() { + let result = KeySelectLogic.decide( + availableKeyTypes: [.nfc, .qr], + allowBypass: false, + defaultKeyType: .nfc, + requestedKeyType: .qr + ) + #expect(result == .autoSelect(.qr)) + } + + @Test func requestedKeyWithBypassShowsSheet() { + let result = KeySelectLogic.decide( + availableKeyTypes: [.qr], + allowBypass: true, + defaultKeyType: nil, + requestedKeyType: .qr + ) + #expect(result == .showSheet) + } + + @Test func unavailableRequestedKeyFallsBackToDefault() { + let result = KeySelectLogic.decide( + availableKeyTypes: [.nfc, .qr], + allowBypass: false, + defaultKeyType: .nfc, + requestedKeyType: .location + ) + #expect(result == .autoSelect(.nfc)) + } } diff --git a/NormalTests/Services/NavigationCoordinatorTests.swift b/NormalTests/Services/NavigationCoordinatorTests.swift index 5fe7aee..5d7f95f 100644 --- a/NormalTests/Services/NavigationCoordinatorTests.swift +++ b/NormalTests/Services/NavigationCoordinatorTests.swift @@ -1,3 +1,4 @@ +import Foundation @testable import Normal import Testing @@ -20,4 +21,32 @@ struct NavigationCoordinatorTests { c.dismissSettings() #expect(!c.isSettingsPresented) } + + @Test func unblockWithoutGroupTargetsAllApps() { + let c = NavigationCoordinator() + let request = UnblockRequest(groupID: nil, duration: .fixed(.oneHour), keyType: .nfc) + c.requestUnblock(request) + #expect(c.pendingAction?.action == .unblock(request)) + } + + @Test func requestWhileSettingsIsOpenWaitsForItToClose() { + let c = NavigationCoordinator() + c.presentSettings() + let request = UnblockRequest(groupID: nil, duration: .ask, keyType: .qr) + + c.requestUnblock(request) + + #expect(!c.isSettingsPresented) + #expect(c.pendingAction == nil) + c.settingsDidDismiss() + #expect(c.pendingAction?.action == .unblock(request)) + } + + @Test func dismissingSettingsWithoutARequestDoesNothing() { + let c = NavigationCoordinator() + c.presentSettings() + c.dismissSettings() + c.settingsDidDismiss() + #expect(c.pendingAction == nil) + } } diff --git a/NormalTests/Services/NavigationCoordinatorWidgetTests.swift b/NormalTests/Services/NavigationCoordinatorWidgetTests.swift index 98b1be7..8ee71c5 100644 --- a/NormalTests/Services/NavigationCoordinatorWidgetTests.swift +++ b/NormalTests/Services/NavigationCoordinatorWidgetTests.swift @@ -13,8 +13,7 @@ struct NavigationCoordinatorWidgetTests { let id = UUID() c.handle(url: unlockURL(groupID: id, duration: .fixed(.thirtyMinutes), key: "NFC")) - #expect(c.pendingGroupAction?.groupID == id) - #expect(c.pendingGroupAction?.action == .unlock(duration: .fixed(.thirtyMinutes), keyType: .nfc)) + #expect(c.pendingAction?.action == .unblock(UnblockRequest(groupID: id, duration: .fixed(.thirtyMinutes), keyType: .nfc))) } @Test func handleAllowsMissingDurationAndKey() { @@ -22,8 +21,7 @@ struct NavigationCoordinatorWidgetTests { let id = UUID() c.handle(url: unlockURL(groupID: id)) - #expect(c.pendingGroupAction?.groupID == id) - #expect(c.pendingGroupAction?.action == .unlock(duration: .useDefault, keyType: nil)) + #expect(c.pendingAction?.action == .unblock(UnblockRequest(groupID: id, duration: .useDefault, keyType: nil))) } @Test func handleAcceptsCustomDurationNotInPresets() throws { @@ -32,7 +30,7 @@ struct NavigationCoordinatorWidgetTests { let custom = try #require(TimedUnblockDuration(validating: 5700)) c.handle(url: unlockURL(groupID: id, duration: .fixed(custom))) - #expect(c.pendingGroupAction?.action == .unlock(duration: .fixed(custom), keyType: nil)) + #expect(c.pendingAction?.action == .unblock(UnblockRequest(groupID: id, duration: .fixed(custom), keyType: nil))) } @Test func handleParsesAskEachTime() { @@ -40,7 +38,7 @@ struct NavigationCoordinatorWidgetTests { let id = UUID() c.handle(url: unlockURL(groupID: id, duration: .ask)) - #expect(c.pendingGroupAction?.action == .unlock(duration: .ask, keyType: nil)) + #expect(c.pendingAction?.action == .unblock(UnblockRequest(groupID: id, duration: .ask, keyType: nil))) } @Test(arguments: ["999", "60", "90000", "abc"]) @@ -49,8 +47,7 @@ struct NavigationCoordinatorWidgetTests { let id = UUID() try c.handle(url: #require(URL(string: "normal://unlock?group=\(id.uuidString)&duration=\(value)"))) - #expect(c.pendingGroupAction?.groupID == id) - #expect(c.pendingGroupAction?.action == .unlock(duration: .ask, keyType: nil), + #expect(c.pendingAction?.action == .unblock(UnblockRequest(groupID: id, duration: .ask, keyType: nil)), "An invalid duration shows the sheet rather than guessing") } @@ -59,54 +56,53 @@ struct NavigationCoordinatorWidgetTests { let id = UUID() c.handle(url: WidgetDeepLink.blockURL(groupID: id)) - #expect(c.pendingGroupAction?.groupID == id) - #expect(c.pendingGroupAction?.action == .block) + #expect(c.pendingAction?.action == .blockGroup(id)) } @Test func requestGroupBlockSetsBlockAction() { let c = NavigationCoordinator() let id = UUID() c.requestGroupBlock(groupID: id) - #expect(c.pendingGroupAction?.action == .block) + #expect(c.pendingAction?.action == .blockGroup(id)) } @Test func handleRejectsWrongScheme() throws { let c = NavigationCoordinator() try c.handle(url: #require(URL(string: "https://unlock?group=\(UUID().uuidString)"))) - #expect(c.pendingGroupAction == nil) + #expect(c.pendingAction == nil) } @Test func handleRejectsWrongHost() throws { let c = NavigationCoordinator() try c.handle(url: #require(URL(string: "normal://settings?group=\(UUID().uuidString)"))) - #expect(c.pendingGroupAction == nil) + #expect(c.pendingAction == nil) } @Test func handleRejectsInvalidGroupID() throws { let c = NavigationCoordinator() try c.handle(url: #require(URL(string: "normal://unlock?group=not-a-uuid"))) - #expect(c.pendingGroupAction == nil) + #expect(c.pendingAction == nil) } @Test func handleRejectsMissingGroup() throws { let c = NavigationCoordinator() try c.handle(url: #require(URL(string: "normal://unlock?duration=1800"))) - #expect(c.pendingGroupAction == nil) + #expect(c.pendingAction == nil) } @Test func handleRejectsBlockWithoutGroup() throws { let c = NavigationCoordinator() try c.handle(url: #require(URL(string: "normal://block"))) - #expect(c.pendingGroupAction == nil) + #expect(c.pendingAction == nil) } @Test func eachRequestGetsAUniqueToken() { let c = NavigationCoordinator() let id = UUID() - c.requestGroupUnlock(groupID: id, duration: .useDefault, keyType: nil) - let first = c.pendingGroupAction?.token - c.requestGroupUnlock(groupID: id, duration: .useDefault, keyType: nil) - let second = c.pendingGroupAction?.token + c.requestUnblock(UnblockRequest(groupID: id, duration: .useDefault, keyType: nil)) + let first = c.pendingAction?.token + c.requestUnblock(UnblockRequest(groupID: id, duration: .useDefault, keyType: nil)) + let second = c.pendingAction?.token #expect(first != nil) #expect(first != second, "Repeated taps of the same widget must re-trigger the flow") @@ -115,8 +111,8 @@ struct NavigationCoordinatorWidgetTests { @Test func clearPendingResetsRequest() { let c = NavigationCoordinator() c.handle(url: unlockURL(groupID: UUID())) - #expect(c.pendingGroupAction != nil) - c.clearPendingGroupAction() - #expect(c.pendingGroupAction == nil) + #expect(c.pendingAction != nil) + c.clearPendingAction() + #expect(c.pendingAction == nil) } } diff --git a/NormalUITests/BlockingUITests.swift b/NormalUITests/BlockingUITests.swift index 67110e9..8ed8c0a 100644 --- a/NormalUITests/BlockingUITests.swift +++ b/NormalUITests/BlockingUITests.swift @@ -180,6 +180,22 @@ final class BlockingUITests: XCTestCase { XCTAssertTrue(app.buttons["group.blockButton"].exists, "Group state should be untouched") } + func testUnlockLinkWithQRKeySkipsKeyPicker() throws { + let app = launch(["-uiTestSeedGroupKey"]) + let groupID = "6E0A1C9B-2D4F-4B7A-9C3E-5F8D1A2B3C4D" + + app.open(try XCTUnwrap(URL(string: "normal://block?group=\(groupID)"))) + let bypass = app.buttons["keySelect.blockWithoutKey"] + require(bypass, "Block link should offer bypass") + bypass.tap() + confirmBypass(app) + require(app.buttons["group.unblockButton"], "Group should be blocked") + + app.open(try XCTUnwrap(URL(string: "normal://unlock?group=\(groupID)&duration=3600&key=QR"))) + + require(app.buttons["Block Now"], "A requested QR key should scan without waiting on the key picker") + } + func testSeededScheduleAppears() { let app = launch(["-uiTestSeedSchedule"])