Skip to content
Open
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
8 changes: 4 additions & 4 deletions Normal/Resources/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -1614,14 +1614,14 @@
"comment" : "Message displayed at the bottom of the screen in a `SafeAreaInset` modifier, when the user is blocked from deleting keys.",
"isCommentAutoGenerated" : true
},
"Unblock all apps to edit custom domains." : {
"comment" : "A footer text displayed below the list of custom domains, explaining that unblocking all apps is necessary to edit the list.",
"isCommentAutoGenerated" : true
},
"Unblock all apps to edit selection." : {
"comment" : "A footer text that appears when \"Select Apps\" is tapped, explaining that unblocking apps is necessary to edit the selection.",
"isCommentAutoGenerated" : true
},
"Unblock all apps to remove custom domains." : {
"comment" : "A footer text displayed below the list of custom domains, explaining that unblocking all apps is necessary to remove domains from the list.",
"isCommentAutoGenerated" : true
},
"Unblock all apps to turn this off." : {
"comment" : "A footer explaining why the custom websites toggle is disabled while custom domains are blocked.",
"isCommentAutoGenerated" : true
Expand Down
12 changes: 5 additions & 7 deletions Normal/Shared/Components/CustomDomainsEditor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ struct CustomDomainsEditor: View {
@Binding var domains: [String]

var otherItemCount: Int = 0
var isEditable: Bool = true
var canRemove: Bool = true

@State private var input = ""
@State private var message: FieldMessage?
Expand All @@ -24,17 +24,15 @@ struct CustomDomainsEditor: View {

var body: some View {
Form {
if isEditable {
inputSection
}
inputSection
if !domains.isEmpty {
domainsSection
}
}
.navigationTitle("Custom Domains")
.navigationBarTitleDisplayMode(.inline)
.safeAreaInset(edge: .bottom) {
if !isEditable {
if !canRemove {
FooterMessage(text: BlockedMessage.customDomains)
}
}
Expand Down Expand Up @@ -77,7 +75,7 @@ struct CustomDomainsEditor: View {
HStack {
Label(domain, systemImage: "globe")
.lineLimit(1)
if isEditable {
if canRemove {
Spacer()
deleteButton(domain)
}
Expand Down Expand Up @@ -127,7 +125,7 @@ struct CustomDomainsEditor: View {
}

private var deleteAction: ((IndexSet) -> Void)? {
guard isEditable else { return nil }
guard canRemove else { return nil }
return { offsets in
domains.remove(atOffsets: offsets)
show(nil)
Expand Down
2 changes: 1 addition & 1 deletion Normal/Shared/Components/FooterMessage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ enum BlockedMessage {
static let groups: LocalizedStringKey = "Unblock all apps to add or edit groups."
static let schedules: LocalizedStringKey = "Unblock all apps to add or edit schedules."
static let keys: LocalizedStringKey = "Unblock all apps to add or delete keys."
static let customDomains: LocalizedStringKey = "Unblock all apps to edit custom domains."
static let customDomains: LocalizedStringKey = "Unblock all apps to remove custom domains."
}
3 changes: 1 addition & 2 deletions Normal/Views/AppSelect/AppSelectView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,10 @@ struct AppSelectView: View {
CustomDomainsEditor(
domains: $customDomains,
otherItemCount: selection.count,
isEditable: !isBlocked
canRemove: !isBlocked
)
} label: {
CountRow(title: "Custom Domains", count: customDomains.count)
.opacity(isBlocked ? DS.Opacity.dim : 1)
}
.accessibilityIdentifier("appSelect.customDomainsLink")
}
Expand Down
31 changes: 26 additions & 5 deletions NormalUITests/NormalUITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,12 @@ final class NormalUITests: XCTestCase {
}

@MainActor
func testCustomDomainsEditorIsReadOnlyWhileBlocked() {
let app = launch(["-uiTestMode", "-uiTestSkipOnboarding", "-uiTestCustomDomains", "-uiTestStartBlocked"])
func testCustomDomainsEditorAddsButDoesNotRemoveWhileBlocked() {
let app = launch([
"-uiTestMode", "-uiTestSkipOnboarding", "-uiTestCustomDomains", "-uiTestWebsitesOnly", "-uiTestStartBlocked",
])
require(app.buttons["home.unblockAll"], "The seeded website should start blocked")
XCTAssertFalse(app.buttons["home.blockAll"].exists, "Everything selected should already be blocked")

let appSelectTab = app.mainTab("App Select")
require(appSelectTab, "App Select tab should be reachable")
Expand All @@ -230,11 +234,28 @@ final class NormalUITests: XCTestCase {
require(link, "Custom Domains row should remain visible while blocked")
link.tap()

require(app.staticTexts["example.com"], "The blocked website should be listed")
XCTAssertFalse(
app.textFields["customDomains.field"].waitForExistence(timeout: 3),
"Add field should be hidden while apps are blocked"
app.buttons["customDomains.delete.example.com"].exists,
"Websites can't be removed while blocked"
)
XCTAssertFalse(app.buttons["customDomains.addButton"].exists, "Add button should be hidden while blocked")

let field = app.textFields["customDomains.field"]
require(field, "Websites can be added while blocked")
field.tap()
field.typeText("reddit.com")
app.buttons["customDomains.addButton"].tap()

require(app.staticTexts["reddit.com"], "Added website should appear in the list")
XCTAssertFalse(
app.buttons["customDomains.delete.reddit.com"].exists,
"A website added while blocked can't be removed either"
)

app.navigationBars.buttons.element(boundBy: 0).tap()
require(link, "Going back should return to App Select")
app.mainTab("Home").tap()
require(app.buttons["home.blockAll"], "The added website stays unblocked until Block All is tapped")
}

@MainActor
Expand Down
Loading