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
11 changes: 8 additions & 3 deletions Normal/App/NormalApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ struct NormalApp: App {
if (try? context.fetchCount(descriptor)) == 0 {
let settings = Settings()
settings.hasCompletedOnboarding = UITestSupport.skipOnboarding
settings.enableCustomDomains = UITestSupport.customDomains
settings.enableCustomDomains = UITestSupport.customDomains || UITestSupport.crowdedSelections
settings.skipBlockWithoutKeyConfirmation = UITestSupport.skipBypassConfirm
settings.customUnblockDurationSeconds = UITestSupport.unblockDurationSeconds
settings.defaultUnblockSeconds = UITestSupport.defaultDurationSeconds
Expand All @@ -50,7 +50,8 @@ struct NormalApp: App {
let group = AppGroup(
id: UITestSupport.seedGroupID,
name: "Test Group",
selection: UITestSupport.groupSelection
selection: UITestSupport.groupSelection,
customDomains: UITestSupport.crowdedSelections ? UITestSupport.crowdedDomains : []
)
context.insert(group)
context.insert(Key(name: "Group Key", type: .qr, rawValue: "GROUP-VALUE", groupID: group.id))
Expand All @@ -76,9 +77,13 @@ struct NormalApp: App {
weekdays: [2, 3, 4, 5, 6],
shouldBlock: true,
isTimed: false,
isEnabled: true
isEnabled: true,
customDomains: UITestSupport.crowdedSelections ? UITestSupport.crowdedDomains : []
))
}
if UITestSupport.seedUsageLimit {
context.insert(UsageLimit(selection: UITestSupport.usageLimitSelection, minutesPerDay: 45))
}
}

modelContainer = container
Expand Down
13 changes: 12 additions & 1 deletion Normal/App/UITestSupport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ enum UITestSupport {

static let customDomains = arguments.contains("-uiTestCustomDomains")

static let crowdedSelections = arguments.contains("-uiTestCrowdedSelections")

static let seedUsageLimit = arguments.contains("-uiTestSeedUsageLimit")

static let crowdedDomains = [
"apple.com", "bbc.com", "cnn.com", "dropbox.com", "espn.com",
"figma.com", "github.com", "hulu.com", "imdb.com",
]

static let websitesOnly = arguments.contains("-uiTestWebsitesOnly")

static let timedUnblockFails = arguments.contains("-uiTestTimedUnblockFails")
Expand Down Expand Up @@ -49,7 +58,9 @@ enum UITestSupport {

static let mainSelection = selection(apps: websitesOnly ? [] : [1, 2, 3])

static let mainCustomDomains = websitesOnly ? ["example.com"] : []
static let mainCustomDomains = websitesOnly ? ["example.com"] : (crowdedSelections ? crowdedDomains : [])

static let usageLimitSelection = selection(apps: [1, 2, 3, 4, 5, 6, 7, 8])

static let groupSelection = selection(apps: [1])

Expand Down
4 changes: 4 additions & 0 deletions Normal/Resources/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@
"comment" : "A badge displaying the number of apps selected for a group.",
"isCommentAutoGenerated" : true
},
"%lld more" : {
"comment" : "VoiceOver label for the badge after a row of app and website icons, counting the ones that didn't fit.",
"isCommentAutoGenerated" : true
},
"%lld Apps" : {
"comment" : "A string describing the number of selected apps. The argument is the count of selected apps.",
"isCommentAutoGenerated" : true
Expand Down
44 changes: 44 additions & 0 deletions Normal/Shared/Components/SelectionIconRow.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import SwiftUI

struct SelectionIconRow: View {
let tokens: [AnyHashable]
var customDomains: [String] = []
let maxCount: Int

private var total: Int {
tokens.count + customDomains.count
}

var body: some View {
ViewThatFits(in: .horizontal) {
ForEach(Array(stride(from: min(maxCount, total), through: 0, by: -1)), id: \.self) { shown in
HStack(spacing: DS.Spacing.sm) {
SelectionIconsView(tokens: tokens, customDomains: customDomains, limit: shown)
if total > shown {
SelectionOverflowBadge(count: total - shown)
}
}
}
}
.accessibilityElement(children: .contain)
.accessibilityIdentifier("selectionIcons.row")
}
}

private struct SelectionOverflowBadge: View {
let count: Int
@ScaledMetric(relativeTo: .body) private var size: CGFloat = 24

var body: some View {
Text("+\(count)")
.font(.caption.weight(.semibold).monospacedDigit())
.foregroundStyle(.secondary)
.lineLimit(1)
.padding(.horizontal, DS.Spacing.xs)
.frame(minWidth: size, minHeight: size)
.background(.quaternary, in: RoundedRectangle(cornerRadius: size / 4, style: .continuous))
.fixedSize()
.accessibilityLabel(Text("\(count) more"))
.accessibilityIdentifier("selectionIcons.overflow")
}
}
10 changes: 0 additions & 10 deletions Normal/Shared/Components/SelectionIconsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ struct SelectionIconsView: View {
var body: some View {
let items = tokens.sortedStably.map(Item.token) + customDomains.map(Item.domain)
let shown = limit.map { Array(items.prefix($0)) } ?? items
let overflow = items.count - shown.count

ForEach(shown, id: \.self) { item in
Group {
Expand All @@ -36,14 +35,5 @@ struct SelectionIconsView: View {
}
.labelStyle(.iconOnly)
}

if overflow > 0 {
Text("+\(overflow)")
.font(.caption.weight(.semibold))
.foregroundStyle(.secondary)
.padding(.horizontal, DS.Spacing.sm)
.padding(.vertical, DS.Spacing.xs)
.background(.quaternary, in: Capsule())
}
}
}
12 changes: 5 additions & 7 deletions Normal/Views/Groups/GroupListCardView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,11 @@ struct GroupListCardView: View {
}

private var tokenStrip: some View {
HStack(spacing: DS.Spacing.sm) {
SelectionIconsView(
tokens: appGroup.selection.allTokens,
customDomains: customDomains,
limit: 6
)
}
SelectionIconRow(
tokens: appGroup.selection.allTokens,
customDomains: customDomains,
maxCount: 6
)
}

private var reselectionBinding: Binding<FamilyActivitySelection> {
Expand Down
2 changes: 1 addition & 1 deletion Normal/Views/Home/StatusDetailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ struct StatusDetailView: View {
private func limitRow(_ limit: UsageLimit, state: UsageLimitState, isOff: Bool, isPaused: Bool) -> some View {
HStack {
VStack(alignment: .leading, spacing: DS.Spacing.xs) {
SelectionIconsView(tokens: limit.selection.allTokens, limit: 5)
SelectionIconRow(tokens: limit.selection.allTokens, maxCount: 5)
Text("\(limit.selection.selectedTokenCounts) · \(DurationFormat.compact(minutes: limit.minutesPerDay)) a day")
.font(.caption)
.foregroundStyle(.secondary)
Expand Down
12 changes: 5 additions & 7 deletions Normal/Views/Schedules/ScheduleCardView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -200,13 +200,11 @@ struct ScheduleCardView: View {
@ViewBuilder
private var tokenStrip: some View {
if !schedule.selection.allTokens.isEmpty || !customDomains.isEmpty {
HStack(spacing: DS.Spacing.sm) {
SelectionIconsView(
tokens: schedule.selection.allTokens,
customDomains: customDomains,
limit: 6
)
}
SelectionIconRow(
tokens: schedule.selection.allTokens,
customDomains: customDomains,
maxCount: 6
)
}
}

Expand Down
2 changes: 1 addition & 1 deletion Normal/Views/Usage/UsageLimitEditor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ struct UsageLimitEditor: View {

private var duplicatesWarning: some View {
VStack(alignment: .leading, spacing: DS.Spacing.sm) {
SelectionIconsView(tokens: duplicates.allTokens, limit: 5)
SelectionIconRow(tokens: duplicates.allTokens, maxCount: 5)
Text("Already in another limit. Remove them here, or change that limit instead.")
.foregroundStyle(.red)
}
Expand Down
4 changes: 1 addition & 3 deletions Normal/Views/Usage/UsageLimitRow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ struct UsageLimitRow: View {
var body: some View {
HStack(spacing: DS.Spacing.md) {
VStack(alignment: .leading, spacing: DS.Spacing.xs) {
HStack(spacing: DS.Spacing.sm) {
SelectionIconsView(tokens: limit.selection.allTokens, limit: 5)
}
SelectionIconRow(tokens: limit.selection.allTokens, maxCount: 5)
Text(verbatim: limit.selection.selectedTokenCounts)
.font(.caption)
.foregroundStyle(.secondary)
Expand Down
28 changes: 28 additions & 0 deletions NormalUITests/BlockingUITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,34 @@ final class BlockingUITests: XCTestCase {
return (request.results ?? []).compactMap { $0.topCandidates(1).first?.string }
}

func testStatusShowsDailyLimitIconsInOneRow() {
let app = launch(["-uiTestSeedUsageLimit"])
let status = app.buttons["home.statusLink"]
require(status, "Home should link to Status")
status.tap()

let row = app.descendants(matching: .any)["selectionIcons.row"].firstMatch
require(row, "The daily limit should show its icons")
let more = app.descendants(matching: .any)["selectionIcons.overflow"].firstMatch
require(more, "Eight apps should end in a count of the ones that don't fit")
XCTAssertLessThan(row.frame.height, more.frame.height * 1.5, "The icons should sit in one row, not a column")
}

func testCardIconRowsKeepTheOverflowCountReadableAtTheLargestTextSize() {
let app = launch([
"-uiTestCrowdedSelections", "-uiTestSeedGroupKey",
"-UIPreferredContentSizeCategoryName", "UICTContentSizeCategoryAccessibilityXXXL",
])
app.mainTab("Groups").tap()

let more = app.descendants(matching: .any)["selectionIcons.overflow"].firstMatch
require(more, "Ten items should end in a count of the ones that don't fit")
XCTAssertGreaterThanOrEqual(more.frame.width, more.frame.height * 0.9, "The count should not be squeezed")
XCTAssertTrue(more.label.hasSuffix("more"), "VoiceOver should read the count: \(more.label)")
let row = app.descendants(matching: .any)["selectionIcons.row"].firstMatch
XCTAssertLessThanOrEqual(row.frame.maxX, app.windows.firstMatch.frame.maxX, "The row should fit on screen")
}

func testScheduleCardShowsDayChipsWhenTheyFit() {
let app = launch(["-uiTestSeedSchedule"])
app.mainTab("Schedules").tap()
Expand Down