DomainDigUITests/AccessibilityAuditTests.swift
367 lines · 15000 bytes
19 symbols in this file
AccessibilityAuditTestssetUptestInspectScreentestDashboardScreentestAuditScreentestHistoryScreentestSettingsScreentestTrackedDomainsScreentestAllScreensAtLargestAccessibilitySizetestSeededDashboardtestSeededTrackedDomainstestSeededBatchResultstestSeededScreensAtIntermediateAccessibilitySizetestSeededScreensAtLargestAccessibilitySizetestIntegrationsScreentestIntegrationEditorScreentestSeededRecentSearchestestSettingsDestinationsauditRootTab
1import XCTest
2
3/// One accessibility audit per primary screen, plus a Dynamic Type sweep.
4///
5/// See `AccessibilityAuditHarness` for why these report rather than fail by
6/// default, and how to make them enforcing.
7@MainActor
8final class AccessibilityAuditTests: XCTestCase {
9 override func setUp() {
10 // Keep going after a failure so an enforced audit still collects and
11 // attaches every finding. With this off, XCTest aborts at the first
12 // reported issue and the burndown list is lost precisely when a category
13 // is being enforced.
14 continueAfterFailure = true
15 }
16
17 // MARK: Per-screen audits
18
19 func testInspectScreen() throws {
20 try auditRootTab("Inspect")
21 }
22
23 func testDashboardScreen() throws {
24 try auditRootTab("Dashboard")
25 }
26
27 func testAuditScreen() throws {
28 try auditRootTab("Audit")
29 }
30
31 func testHistoryScreen() throws {
32 try auditRootTab("History")
33 }
34
35 func testSettingsScreen() throws {
36 try auditRootTab("Settings")
37 }
38
39 func testTrackedDomainsScreen() throws {
40 let app = AccessibilityAuditHarness.launch()
41 app.selectRootTab("Dashboard")
42
43 let watchlist = app.buttons["Watchlist"]
44 XCTAssertTrue(
45 watchlist.waitForExistence(timeout: 5),
46 "Dashboard no longer offers a Watchlist row"
47 )
48 watchlist.tap()
49
50 let audited = try AccessibilityAuditHarness.audit(app, screen: "tracked-domains", test: self)
51 try XCTSkipUnless(audited, "Tracked Domains audit did not complete in time")
52 }
53
54 // MARK: Dynamic Type
55
56 /// Re-audits every root screen at the largest accessibility content size.
57 ///
58 /// This is where clipped text and fixed-height containers surface — the
59 /// `.accessibility5`-class failures that the fixed geometry in
60 /// `AppDensityMetrics` is expected to produce until phase 3 of #21 lands.
61 ///
62 /// Every screen is attempted even if an earlier one times out, so one slow
63 /// screen cannot silently drop the rest; the skip is reported at the end.
64 func testAllScreensAtLargestAccessibilitySize() throws {
65 let app = AccessibilityAuditHarness.launch(
66 contentSizeCategory: "UICTContentSizeCategoryAccessibilityXXXL"
67 )
68
69 var unaudited: [String] = []
70
71 for tab in ["Inspect", "Dashboard", "Audit", "History", "Settings"] {
72 app.selectRootTab(tab)
73 let screen = "\(tab.lowercased())-accessibilityXXXL"
74 if try !AccessibilityAuditHarness.audit(app, screen: screen, test: self) {
75 unaudited.append(tab)
76 }
77 }
78
79 try XCTSkipUnless(
80 unaudited.isEmpty,
81 "Audit did not complete in time for: \(unaudited.joined(separator: ", "))"
82 )
83 }
84
85 // MARK: Seeded audits — dense rows that never render on an empty simulator
86
87 /// Dashboard with a populated portfolio: summary tiles, quick filters,
88 /// activity/attention/expiry rows, and the grouped portfolio list.
89 func testSeededDashboard() throws {
90 let app = AccessibilityAuditHarness.launch(seeded: true)
91 app.selectRootTab("Dashboard")
92 let audited = try AccessibilityAuditHarness.audit(app, screen: "seeded-dashboard", test: self, reportOnly: true)
93 try XCTSkipUnless(audited, "Audit did not complete in time for seeded Dashboard")
94 }
95
96 /// The watchlist's dense rows (up to nine text elements each).
97 func testSeededTrackedDomains() throws {
98 let app = AccessibilityAuditHarness.launch(seeded: true)
99 app.selectRootTab("Dashboard")
100 let watchlist = app.buttons["Watchlist"]
101 XCTAssertTrue(watchlist.waitForExistence(timeout: 5))
102 watchlist.tap()
103 let audited = try AccessibilityAuditHarness.audit(app, screen: "seeded-tracked-domains", test: self, reportOnly: true)
104 try XCTSkipUnless(audited, "Audit did not complete in time for seeded Tracked Domains")
105 }
106
107 /// Batch result rows on the Inspect tab, including a failed lookup.
108 func testSeededBatchResults() throws {
109 let app = AccessibilityAuditHarness.launch(seeded: true)
110 app.selectRootTab("Inspect")
111 let audited = try AccessibilityAuditHarness.audit(app, screen: "seeded-batch", test: self, reportOnly: true)
112 try XCTSkipUnless(audited, "Audit did not complete in time for seeded batch results")
113 }
114
115 /// The seeded screens at an **intermediate** accessibility size.
116 ///
117 /// The default/`AccessibilityXXXL` pair brackets the range but skips the
118 /// middle band, and two production layout bugs lived exactly there — a
119 /// bordered button letter-wrapping vertically at a merely-large size, which
120 /// neither endpoint reproduced. `AccessibilityL` samples that band across the
121 /// dense seeded screens so a regression in it cannot slip between the two
122 /// existing test points. Reports rather than gates, matching the other
123 /// seeded audits.
124 func testSeededScreensAtIntermediateAccessibilitySize() throws {
125 let app = AccessibilityAuditHarness.launch(
126 contentSizeCategory: "UICTContentSizeCategoryAccessibilityL",
127 seeded: true
128 )
129
130 var unaudited: [String] = []
131
132 app.selectRootTab("Dashboard")
133 if try !AccessibilityAuditHarness.audit(app, screen: "seeded-dashboard-accessibilityL", test: self, reportOnly: true) {
134 unaudited.append("Dashboard")
135 }
136
137 app.selectRootTab("Inspect")
138 if try !AccessibilityAuditHarness.audit(app, screen: "seeded-batch-accessibilityL", test: self, reportOnly: true) {
139 unaudited.append("Inspect batch")
140 }
141
142 app.selectRootTab("Dashboard")
143 let watchlist = app.buttons["Watchlist"]
144 if watchlist.waitForExistence(timeout: 5) {
145 watchlist.tap()
146 if try !AccessibilityAuditHarness.audit(app, screen: "seeded-tracked-domains-accessibilityL", test: self, reportOnly: true) {
147 unaudited.append("Tracked Domains")
148 }
149 }
150
151 try XCTSkipUnless(
152 unaudited.isEmpty,
153 "Audit did not complete in time for: \(unaudited.joined(separator: ", "))"
154 )
155 }
156
157 /// The seeded screens again at the largest accessibility size — the case the
158 /// deferred ViewThatFits work exists for.
159 func testSeededScreensAtLargestAccessibilitySize() throws {
160 let app = AccessibilityAuditHarness.launch(
161 contentSizeCategory: "UICTContentSizeCategoryAccessibilityXXXL",
162 seeded: true
163 )
164
165 var unaudited: [String] = []
166
167 app.selectRootTab("Dashboard")
168 if try !AccessibilityAuditHarness.audit(app, screen: "seeded-dashboard-accessibilityXXXL", test: self, reportOnly: true) {
169 unaudited.append("Dashboard")
170 }
171
172 app.selectRootTab("Inspect")
173 if try !AccessibilityAuditHarness.audit(app, screen: "seeded-batch-accessibilityXXXL", test: self, reportOnly: true) {
174 unaudited.append("Inspect batch")
175 }
176
177 app.selectRootTab("Dashboard")
178 let watchlist = app.buttons["Watchlist"]
179 if watchlist.waitForExistence(timeout: 5) {
180 watchlist.tap()
181 if try !AccessibilityAuditHarness.audit(app, screen: "seeded-tracked-domains-accessibilityXXXL", test: self, reportOnly: true) {
182 unaudited.append("Tracked Domains")
183 }
184 }
185
186 try XCTSkipUnless(
187 unaudited.isEmpty,
188 "Audit did not complete in time for: \(unaudited.joined(separator: ", "))"
189 )
190 }
191
192 // MARK: Helpers
193
194 // MARK: Screens reached through Settings (C9)
195
196 /// Integrations was not audited, so the SMTP port caption added in !5 had
197 /// never been rendered at the largest Dynamic Type under audit and nothing
198 /// here would have caught it wrapping badly.
199 ///
200 /// Report-only: these screens have never been through the ratchet, so
201 /// gating them now would fail the build on findings that predate the
202 /// coverage. They are a burndown list for #21 like the seeded screens, and
203 /// `enforcedAuditTypes` widens to cover them once they are clear.
204 func testIntegrationsScreen() throws {
205 let app = AccessibilityAuditHarness.launch()
206 app.selectRootTab("Settings")
207
208 let integrations = app.buttons["Integrations"]
209 XCTAssertTrue(
210 integrations.waitForExistence(timeout: 5),
211 "Settings no longer offers an Integrations row"
212 )
213 integrations.tap()
214
215 let audited = try AccessibilityAuditHarness.audit(
216 app,
217 screen: "integrations",
218 test: self,
219 reportOnly: true
220 )
221 try XCTSkipUnless(audited, "Audit did not complete in time for Integrations")
222 }
223
224 /// The integration editor's whole form, which is the densest set of text
225 /// fields and captions in the app and the one C9 named.
226 func testIntegrationEditorScreen() throws {
227 let app = AccessibilityAuditHarness.launch()
228 app.selectRootTab("Settings")
229
230 let integrations = app.buttons["Integrations"]
231 guard integrations.waitForExistence(timeout: 5) else {
232 throw XCTSkip("Settings no longer offers an Integrations row")
233 }
234 integrations.tap()
235
236 let add = app.buttons["Add Integration"]
237 guard add.waitForExistence(timeout: 5) else {
238 throw XCTSkip("the integrations screen offers no add button to reach the editor")
239 }
240 add.tap()
241
242 let audited = try AccessibilityAuditHarness.audit(
243 app,
244 screen: "integration-editor",
245 test: self,
246 reportOnly: true
247 )
248 try XCTSkipUnless(audited, "Audit did not complete in time for the integration editor")
249 }
250
251 /// Every remaining screen behind a Settings row.
252 ///
253 /// Integrations and the integration editor were covered in !42; these are
254 /// the ten that were still unaudited, which was the largest blind spot left
255 /// in the suite — five phases of row and caption treatment shipped without
256 /// any of them being rendered under audit.
257 ///
258 /// Report-only for the same reason as Integrations: they have never been
259 /// through the ratchet, so gating them on first contact would fail the
260 /// build on findings that predate the coverage. They are a burndown list
261 /// for #21, and the enforced set widens per screen as each one clears.
262 ///
263 /// Monitoring Settings and Display gate on `.textClipped` alone: their
264 /// clipped picker values are fixed (`AdaptivePicker`) and that category is
265 /// now empty on both runtimes. Their `dynamicType` findings stay reported —
266 /// those land on a position rather than on the row they name, which
267 /// reordering proves, so no fix follows from them.
268 ///
269 /// Import & Export is not gated although its picker value is fixed too: its
270 /// one remaining clipped finding is the navigation title, which only a
271 /// shorter screen name would change. Same for History & Network, Scheduled
272 /// Reports and Data Management. See `Docs/ACCESSIBILITY.txt`.
273 ///
274 /// One launch rather than ten: re-selecting the Settings tab pops it back
275 /// to root, so each destination is reached from a known place, and the
276 /// store reset means the launch state is the same for all of them.
277 /// Inspect with its recent-searches section present.
278 ///
279 /// The section renders only once a lookup has been run, so the empty-state
280 /// suite never has it in the tree. Four findings in it were found by
281 /// accident, by driving one real lookup; seeding `recentSearches` puts them
282 /// under the suite on purpose and keeps the launch deterministic.
283 ///
284 /// Gated on everything the project enforces except `.dynamicType`, which
285 /// still reports against the "RECENT" header. That one is the
286 /// position-dependent finding described in `Docs/ACCESSIBILITY.txt`, not a
287 /// property of the header — unlike the other seeded tests, nothing else
288 /// here needs to stay report-only.
289 func testSeededRecentSearches() throws {
290 let app = AccessibilityAuditHarness.launch(recentSearches: true)
291 app.selectRootTab("Inspect")
292 XCTAssertTrue(
293 app.staticTexts["RECENT"].waitForExistence(timeout: 10),
294 "The recent-searches section must render, or this audits nothing"
295 )
296 try AccessibilityAuditHarness.audit(
297 app,
298 screen: "recent-searches",
299 test: self,
300 enforcing: AccessibilityAuditHarness.enforcedAuditTypes.subtracting(.dynamicType)
301 )
302 }
303
304 func testSettingsDestinations() throws {
305 let destinations = [
306 "Display",
307 "History & Network",
308 "Monitoring Log",
309 "Local API",
310 "iCloud Sync",
311 "Monitoring Settings",
312 "Scheduled Reports",
313 "Import & Export",
314 "Data Management",
315 "App Info"
316 ]
317 let enforcedPerScreen: [String: XCUIAccessibilityAuditType] = [
318 "Display": .textClipped,
319 "Monitoring Settings": .textClipped
320 ]
321
322 let app = AccessibilityAuditHarness.launch()
323 var unreachable: [String] = []
324 var unaudited: [String] = []
325
326 for destination in destinations {
327 // Pops any previous push, so each row is tapped from the root.
328 app.selectRootTab("Settings")
329
330 let row = app.buttons[destination]
331 guard row.waitForExistence(timeout: 5) else {
332 unreachable.append(destination)
333 continue
334 }
335 row.tap()
336
337 let screen = destination
338 .lowercased()
339 .replacingOccurrences(of: " & ", with: "-")
340 .replacingOccurrences(of: " ", with: "-")
341 let enforced = enforcedPerScreen[destination]
342 let audited = try AccessibilityAuditHarness.audit(
343 app,
344 screen: screen,
345 test: self,
346 reportOnly: enforced == nil,
347 enforcing: enforced ?? []
348 )
349 if !audited {
350 unaudited.append(destination)
351 }
352 }
353
354 XCTAssertEqual(unreachable, [], "Settings no longer offers these rows")
355 try XCTSkipUnless(
356 unaudited.isEmpty,
357 "Audit did not complete in time for: \(unaudited.joined(separator: ", "))"
358 )
359 }
360
361 private func auditRootTab(_ tab: String) throws {
362 let app = AccessibilityAuditHarness.launch()
363 app.selectRootTab(tab)
364 let audited = try AccessibilityAuditHarness.audit(app, screen: tab.lowercased(), test: self)
365 try XCTSkipUnless(audited, "Audit did not complete in time for \(tab)")
366 }
367}