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
12 changes: 10 additions & 2 deletions Normal/Views/Groups/GroupFormSheet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -249,7 +249,6 @@ struct GroupFormSheet: View {
}
.accessibilityIdentifier("groupForm.defaultKey")
}
.disabled(isReadOnly)
}

@ViewBuilder
Expand Down Expand Up @@ -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 }
Expand Down
31 changes: 31 additions & 0 deletions NormalUITests/BlockingUITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down