From b58fd93772446c143d20e82b6afd2955904db728 Mon Sep 17 00:00:00 2001 From: ykisana Date: Wed, 18 Nov 2026 22:52:03 -0600 Subject: [PATCH] feat: let a blocked group's default duration and key change While anything is blocked the group sheet is read-only, which also locked the Unblocking section #123 added. Changing a group's Default Duration or Default Key doesn't loosen anything: an unblock still needs a key, and the duration sheet already offers every duration. The two pickers now stay editable while blocked, and Done saves them. Name, apps, websites and keys stay locked. --- Normal/Views/Groups/GroupFormSheet.swift | 12 +++++++-- NormalUITests/BlockingUITests.swift | 31 ++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/Normal/Views/Groups/GroupFormSheet.swift b/Normal/Views/Groups/GroupFormSheet.swift index 822b0b0..344d9d2 100644 --- a/Normal/Views/Groups/GroupFormSheet.swift +++ b/Normal/Views/Groups/GroupFormSheet.swift @@ -171,7 +171,7 @@ struct GroupFormSheet: View { .toolbar { if isReadOnly { ToolbarItem(placement: .confirmationAction) { - Button("Done") { dismiss() }.fontWeight(.semibold) + Button("Done", action: saveDefaults).fontWeight(.semibold) } } else { ToolbarItem(placement: .cancellationAction) { @@ -249,7 +249,6 @@ struct GroupFormSheet: View { } .accessibilityIdentifier("groupForm.defaultKey") } - .disabled(isReadOnly) } @ViewBuilder @@ -315,6 +314,15 @@ struct GroupFormSheet: View { screenTimeService.ifAuthorized { isShowingAppSelectSheet = true } } + private func saveDefaults() { + if let existing, existing.durationOverride != durationOverride || existing.keyOverride != keyOverride { + existing.durationOverride = durationOverride + existing.keyOverride = keyOverride + existing.lastUpdated = .now + } + dismiss() + } + private func save() { let trimmed = name.trimmingCharacters(in: .whitespaces) guard !trimmed.isEmpty else { return } diff --git a/NormalUITests/BlockingUITests.swift b/NormalUITests/BlockingUITests.swift index e4c1d4b..442a2a6 100644 --- a/NormalUITests/BlockingUITests.swift +++ b/NormalUITests/BlockingUITests.swift @@ -361,6 +361,37 @@ final class BlockingUITests: XCTestCase { XCTAssertFalse(app.buttons["timedUnblock.confirm"].exists, "The group's default should skip the duration sheet") } + func testGroupDefaultDurationCanBeSetWhileBlocked() { + let app = launch(["-uiTestSeedGroupKey", "-uiTestStartBlocked"]) + app.mainTab("Groups").tap() + + let group = app.staticTexts["Test Group"] + require(group, "Seeded group should render") + group.tap() + + let picker = app.buttons["groupForm.defaultDuration"] + require(picker, "The blocked group should show its default duration") + picker.tap() + let fourHours = app.buttons["4 hours"] + require(fourHours, "The menu should list the unblock durations") + fourHours.tap() + let chosen = app.buttons.matching(identifier: "groupForm.defaultDuration") + .matching(NSPredicate(format: "label CONTAINS '4 hours' OR value CONTAINS '4 hours'")) + .firstMatch + require(chosen, "The default duration should be editable while blocked") + app.buttons["Done"].tap() + + let unblockButton = app.buttons["group.unblockButton"] + require(unblockButton, "The group should still be blocked") + unblockButton.tap() + let keyRow = app.buttons["keySelect.row.QR"] + require(keyRow, "Unblocking the group should ask for a key") + keyRow.tap() + + require(app.staticTexts["Timed Unblock"], "The default set while blocked should start the unblock") + XCTAssertFalse(app.buttons["timedUnblock.confirm"].exists, "The default set while blocked should skip the duration sheet") + } + func testFailedDefaultDurationUnblockShowsError() { let app = launch(["-uiTestDefaultDuration", "900", "-uiTestTimedUnblockFails"]) blockViaBypass(app)