From 3c398014aefa3f387488038ac4dde2aa791b8fb9 Mon Sep 17 00:00:00 2001 From: ykisana Date: Fri, 13 Nov 2026 17:08:26 -0600 Subject: [PATCH] test: cover turning off key-protected toggles Turning off Prevent App Deletion or Block Adult Websites now needs a key proof (#101). These UI tests check that turning either off asks for a key with no block-without-key option, and that turning the adult filter on still offers it. --- NormalUITests/BlockingUITests.swift | 46 +++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/NormalUITests/BlockingUITests.swift b/NormalUITests/BlockingUITests.swift index 8ed8c0a..c920dde 100644 --- a/NormalUITests/BlockingUITests.swift +++ b/NormalUITests/BlockingUITests.swift @@ -104,6 +104,52 @@ final class BlockingUITests: XCTestCase { ) } + func testTurningOffPreventAppDeleteNeedsAKey() { + let app = launch() + blockViaBypass(app) + let toggle = app.switches["home.preventDeleteToggle"] + requireValue("1", of: toggle, "Blocking should disable app deletion") + + tapSwitch(toggle) + requireKeyWithoutBypass(app) + requireValue("0", of: toggle, "Passing the key should turn the toggle off") + } + + func testBlockAdultWebsitesTurnsOnWithoutAKeyAndOffWithOne() { + let app = launch() + app.buttons["nav.settings"].tap() + let toggle = app.switches["settings.blockAdultContentToggle"] + require(toggle, "Settings should show the adult content toggle") + XCTAssertEqual(toggle.value as? String, "0", "Starts off") + + tapSwitch(toggle) + let bypass = app.buttons["keySelect.blockWithoutKey"] + require(bypass, "Turning on should offer blocking without a key") + bypass.tap() + confirmBypass(app) + requireValue("1", of: toggle, "Bypass should turn the filter on") + + tapSwitch(toggle) + requireKeyWithoutBypass(app) + requireValue("0", of: toggle, "Passing the key should turn the filter off") + } + + private func tapSwitch(_ toggle: XCUIElement) { + toggle.coordinate(withNormalizedOffset: CGVector(dx: 0.92, dy: 0.5)).tap() + } + + private func requireKeyWithoutBypass(_ app: XCUIApplication) { + let keyRow = app.buttons["keySelect.row.QR"] + require(keyRow, "Turning off should ask for a key") + XCTAssertFalse(app.buttons["keySelect.blockWithoutKey"].exists, "Turning off must not offer a bypass") + keyRow.tap() + } + + private func requireValue(_ value: String, of element: XCUIElement, _ message: String) { + let expectation = XCTNSPredicateExpectation(predicate: NSPredicate(format: "value == %@", value), object: element) + XCTAssertEqual(XCTWaiter().wait(for: [expectation], timeout: timeout), .completed, message) + } + func testTimedUnblockBannerThenBlockNowReblocks() { let app = launch() blockViaBypass(app)