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
5 changes: 4 additions & 1 deletion Normal/App/NormalApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down
6 changes: 5 additions & 1 deletion Normal/App/UITestSupport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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])

Expand Down
3 changes: 1 addition & 2 deletions Normal/Intents/IntentContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ struct IntentContext {

func mainSelection(settings: Settings) throws -> SelectedApps {
guard let mainSelection = try context.fetch(FetchDescriptor<SelectedApps>()).first,
!mainSelection.selection.isEmpty
|| (settings.enableCustomDomains && !mainSelection.customDomains.isEmpty)
mainSelection.hasItemsToBlock(customDomainsEnabled: settings.enableCustomDomains)
else { throw BlockIntentError.noAppsSelected }
return mainSelection
}
Expand Down
4 changes: 4 additions & 0 deletions Normal/Models/SelectedApps.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@ final class SelectedApps {
lastUpdated = .now
self.customDomains = customDomains
}

func hasItemsToBlock(customDomainsEnabled: Bool) -> Bool {
!selection.isEmpty || (customDomainsEnabled && !customDomains.isEmpty)
}
}
2 changes: 1 addition & 1 deletion Normal/Services/ShieldStoring.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion Normal/Views/Home/HomeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
18 changes: 18 additions & 0 deletions NormalUITests/BlockingUITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading