diff --git a/Normal/App/NormalApp.swift b/Normal/App/NormalApp.swift index 88a48a3..2f2133c 100644 --- a/Normal/App/NormalApp.swift +++ b/Normal/App/NormalApp.swift @@ -38,7 +38,10 @@ struct NormalApp: App { } if UITestSupport.isActive { - context.insert(SelectedApps(selection: UITestSupport.mainSelection)) + context.insert(SelectedApps( + selection: UITestSupport.mainSelection, + customDomains: UITestSupport.mainCustomDomains + )) if !UITestSupport.noKeys { context.insert(Key(name: "Test Key", type: .qr, rawValue: UITestSupport.stubScanValue)) } diff --git a/Normal/App/UITestSupport.swift b/Normal/App/UITestSupport.swift index 12a4678..9504fbf 100644 --- a/Normal/App/UITestSupport.swift +++ b/Normal/App/UITestSupport.swift @@ -20,6 +20,8 @@ enum UITestSupport { static let customDomains = arguments.contains("-uiTestCustomDomains") + static let websitesOnly = arguments.contains("-uiTestWebsitesOnly") + static let seedGroupKey = arguments.contains("-uiTestSeedGroupKey") static let seedLocationKey = arguments.contains("-uiTestSeedLocationKey") @@ -36,7 +38,9 @@ enum UITestSupport { static let stubScanValue = "UITEST-SCAN-VALUE" - static let mainSelection = selection(apps: [1, 2, 3]) + static let mainSelection = selection(apps: websitesOnly ? [] : [1, 2, 3]) + + static let mainCustomDomains = websitesOnly ? ["example.com"] : [] static let groupSelection = selection(apps: [1]) diff --git a/Normal/Intents/IntentContext.swift b/Normal/Intents/IntentContext.swift index f7ab2ee..d888a56 100644 --- a/Normal/Intents/IntentContext.swift +++ b/Normal/Intents/IntentContext.swift @@ -46,8 +46,7 @@ struct IntentContext { func mainSelection(settings: Settings) throws -> SelectedApps { guard let mainSelection = try context.fetch(FetchDescriptor()).first, - !mainSelection.selection.isEmpty - || (settings.enableCustomDomains && !mainSelection.customDomains.isEmpty) + mainSelection.hasItemsToBlock(customDomainsEnabled: settings.enableCustomDomains) else { throw BlockIntentError.noAppsSelected } return mainSelection } diff --git a/Normal/Models/SelectedApps.swift b/Normal/Models/SelectedApps.swift index 7fcded8..67a20d7 100644 --- a/Normal/Models/SelectedApps.swift +++ b/Normal/Models/SelectedApps.swift @@ -14,4 +14,8 @@ final class SelectedApps { lastUpdated = .now self.customDomains = customDomains } + + func hasItemsToBlock(customDomainsEnabled: Bool) -> Bool { + !selection.isEmpty || (customDomainsEnabled && !customDomains.isEmpty) + } } diff --git a/Normal/Services/ShieldStoring.swift b/Normal/Services/ShieldStoring.swift index 58eeec9..6381621 100644 --- a/Normal/Services/ShieldStoring.swift +++ b/Normal/Services/ShieldStoring.swift @@ -81,7 +81,7 @@ final class InMemoryShieldStore: ShieldStoring { init(startBlocked: Bool = UITestSupport.startBlocked) { guard startBlocked else { return } - plan.formUnion(UITestSupport.mainSelection, customDomains: []) + plan.formUnion(UITestSupport.mainSelection, customDomains: UITestSupport.mainCustomDomains) plan.denyAppRemoval = true } diff --git a/Normal/Views/Home/HomeView.swift b/Normal/Views/Home/HomeView.swift index 4e0d3a5..b9ecdd9 100644 --- a/Normal/Views/Home/HomeView.swift +++ b/Normal/Views/Home/HomeView.swift @@ -30,7 +30,7 @@ struct HomeView: View { var body: some View { NavigationStack { List { - if let mainSelection, !mainSelection.selection.isEmpty || UITestSupport.isActive { + if let mainSelection, mainSelection.hasItemsToBlock(customDomainsEnabled: settings.enableCustomDomains) { TimedUnblockBannerView( selection: mainSelection.selection, customDomains: mainSelection.customDomains, diff --git a/NormalUITests/BlockingUITests.swift b/NormalUITests/BlockingUITests.swift index 4ced346..b23c5fa 100644 --- a/NormalUITests/BlockingUITests.swift +++ b/NormalUITests/BlockingUITests.swift @@ -61,6 +61,24 @@ final class BlockingUITests: XCTestCase { XCTAssertTrue(app.buttons["home.blockAll"].waitForExistence(timeout: timeout)) } + func testBlockedWebsitesWithoutAppsCanBeUnblockedFromHome() { + let app = launch(["-uiTestCustomDomains", "-uiTestWebsitesOnly", "-uiTestStartBlocked"]) + + let unblock = app.buttons["home.unblockAll"] + require(unblock, "Home should offer Unblock All while only websites are blocked") + unblock.tap() + let keyRow = app.buttons["keySelect.row.QR"] + require(keyRow, "Unblock should require choosing the registered key") + keyRow.tap() + + let permanent = app.buttons["timedUnblock.permanent"] + require(permanent, "Unblock duration sheet should appear after key scan") + permanent.tap() + app.buttons["timedUnblock.confirm"].tap() + + require(app.staticTexts["No Active Blocks"], "Websites should be unblocked") + } + func testLocationKeyIsCheckedFromThePicker() { let app = launch(["-uiTestSeedLocationKey"]) blockViaBypass(app)