Branchwell

Jotley / app · jotley.ai / Jotley-iOSUITests / Jotley_iOSUITests.swift

Raw 226.4 KB on d2c8e7812d9b8c1cc5857eb6dc912d99bc5c9048
1import XCTest
2import UIKit
3#if DEBUG
4import FoundationModels
5import Speech
6#endif
7
8final class Jotley_iOSUITests: XCTestCase {
9 override func setUpWithError() throws { continueAfterFailure = false }
10
11 @MainActor func testLocalizedStorefrontCaptures() throws {
12 let environment = ProcessInfo.processInfo.environment
13 guard let fixture = environment["JOTLEY_STORE_SCREENSHOT_FIXTURE"] else {
14 throw XCTSkip("Run scripts/capture-app-store.py to supply localized fixtures.")
15 }
16 let locales = try JSONDecoder().decode([String: CaptureLocale].self, from: Data(fixture.utf8))
17 let isPad = UIDevice.current.userInterfaceIdiom == .pad
18 XCUIDevice.shared.orientation = .portrait
19 let app = XCUIApplication()
20 app.launchEnvironment["JOTLEY_SCREENSHOT_APPEARANCE"] = "Light"
21 for (locale, sample) in locales.sorted(by: { $0.key < $1.key }) {
22 app.launchEnvironment["JOTLEY_SCREENSHOT_DATA"] = sample.notes
23 app.launchArguments = [
24 "-AppleLanguages", "(\(locale))", "-AppleLocale", sample.region,
25 "-jotleyWelcomeCompleted.v1", "YES", "-selectedThemeColor", "Purple"
26 ]
27 app.launch()
28 showNotesLibrary(app)
29 let row = app.buttons.containing(.staticText, identifier: sample.title).firstMatch
30 XCTAssertTrue(row.waitForExistence(timeout: 10), locale)
31 let library = app.staticTexts["notesListTitle"]
32 XCTAssertEqual(library.label, sample.libraryLabel, locale)
33 if isPad {
34 app.buttons["notesListFolderDrawerButton"].tap()
35 let done = app.buttons["folderDrawerDoneButton"]
36 XCTAssertTrue(done.waitForExistence(timeout: 5), locale)
37 capture(XCUIScreen.main.screenshot(), named: "\(locale)-03-folders")
38 done.tap()
39 } else {
40 capture(XCUIScreen.main.screenshot(), named: "\(locale)-01-library")
41 }
42
43 row.tap()
44 let transcript = app.buttons["noteDetailTranscriptTab"]
45 XCTAssertTrue(transcript.waitForExistence(timeout: 10), locale)
46 XCTAssertEqual(transcript.label, sample.transcriptLabel, locale)
47 XCTAssertTrue(app.buttons["noteDetailSummaryAskAIButton"].waitForExistence(timeout: 5), locale)
48 capture(XCUIScreen.main.screenshot(), named: "\(locale)-\(isPad ? "01" : "02")-summary")
49
50 transcript.tap()
51 XCTAssertTrue(app.buttons["noteDetailContinueTranscriptionButton"].waitForExistence(timeout: 5), locale)
52 capture(XCUIScreen.main.screenshot(), named: "\(locale)-\(isPad ? "02" : "03")-transcript")
53 app.terminate()
54 }
55 }
56
57 private struct CaptureLocale: Decodable {
58 let notes: String
59 let region: String
60 let title: String
61 let libraryLabel: String
62 let transcriptLabel: String
63 }
64
65 private func capture(_ screenshot: XCUIScreenshot, named name: String) {
66 let attachment = XCTAttachment(screenshot: screenshot)
67 attachment.name = "JotleyStore-\(name)"
68 attachment.lifetime = .keepAlways
69 add(attachment)
70 }
71
72 @MainActor func testCustomSummaryTemplateManagement() throws {
73 let app = XCUIApplication()
74 app.launchEnvironment["JOTLEY_SCREENSHOT_DATA"] = #"[{"title":"Template test note","folder":"","tags":[],"transcript":"Maya reviews onboarding Friday. Alex tests accessibility.","summary":"Existing summary remains unchanged."}]"#
75 app.launchArguments = ["-jotleyWelcomeCompleted.v1", "YES"]
76 app.launch()
77 showNotesLibrary(app)
78 app.buttons["notesListSettingsButton"].tap()
79 let templates = app.buttons["settingsTemplatesLink"]
80 XCTAssertTrue(templates.waitForExistence(timeout: 10)); templates.tap()
81 XCTAssertTrue(app.buttons["templatesNewButton"].waitForExistence(timeout: 10))
82 app.buttons["templatesNewButton"].tap()
83 let name = "Client recap " + UUID().uuidString.prefix(6)
84 let nameField = app.textFields["templateNameField"]
85 XCTAssertTrue(nameField.waitForExistence(timeout: 5)); nameField.tap(); nameField.typeText(String(name))
86 let instructions = app.textViews["templateInstructionsField"]
87 instructions.tap(); instructions.typeText("Use Decisions and Action Items sections. Include owners and dates only when stated.")
88 let save = app.buttons["templateSaveButton"]
89 if !save.isHittable { app.swipeUp() }
90 XCTAssertTrue(save.isEnabled); save.tap()
91 let row = app.staticTexts[String(name)]
92 XCTAssertTrue(row.waitForExistence(timeout: 10)); row.firstMatch.tap()
93 XCTAssertTrue(nameField.waitForExistence(timeout: 5))
94 XCTAssertEqual(nameField.value as? String, String(name))
95 XCTAssertTrue((instructions.value as? String)?.contains("Decisions") == true)
96 let attachment = XCTAttachment(screenshot: app.screenshot())
97 attachment.name = "Custom template editor"; attachment.lifetime = .keepAlways; add(attachment)
98 let delete = app.buttons["templateDeleteButton"]
99 if !delete.isHittable { app.swipeUp() }
100 delete.tap()
101 let confirmation = app.buttons["templateConfirmDeleteButton"].firstMatch
102 XCTAssertTrue(confirmation.waitForExistence(timeout: 5)); confirmation.tap()
103 XCTAssertTrue(app.buttons["templatesNewButton"].waitForExistence(timeout: 10))
104 XCTAssertFalse(app.staticTexts[String(name)].exists)
105 }
106
107 @MainActor func testCustomTemplateFromNoteStartsGeneration() throws {
108 let app = XCUIApplication()
109 app.launchEnvironment["JOTLEY_SCREENSHOT_DATA"] = #"[{"title":"Custom template note","folder":"","tags":[],"transcript":"Maya reviews onboarding Friday. Alex tests accessibility.","summary":"Existing summary stays safe until its replacement finishes."}]"#
110 app.launchEnvironment["JOTLEY_TEST_SUMMARY_SCROLL"] = "1"
111 app.launchArguments = ["-jotleyWelcomeCompleted.v1", "YES"]
112 app.launch()
113 XCTAssertTrue(app.buttons["noteDetailMoreActionsButton"].waitForExistence(timeout: 15))
114 app.buttons["noteDetailMoreActionsButton"].tap()
115 app.buttons["noteDetailSummaryTemplateMenu"].tap()
116 app.buttons["New Template…"].tap()
117 let nameField = app.textFields["templateNameField"]
118 XCTAssertTrue(nameField.waitForExistence(timeout: 10)); nameField.tap(); nameField.typeText("Note actions " + UUID().uuidString.prefix(6))
119 let instructions = app.textViews["templateInstructionsField"]
120 instructions.tap(); instructions.typeText("Only list action items with their stated owners and deadlines.")
121 let use = app.buttons["Save & Use"]
122 if !use.isHittable { app.swipeUp() }
123 use.tap()
124 let cancel = app.buttons["noteDetailCancelGenerationButton"]
125 XCTAssertTrue(cancel.waitForExistence(timeout: 15), "Save & Use must start generation using the new custom template")
126 cancel.tap()
127 XCTAssertTrue(app.staticTexts.matching(NSPredicate(format: "label CONTAINS %@", "Existing summary stays safe")).firstMatch.waitForExistence(timeout: 10))
128 }
129
130
131 @MainActor private func triggerSummaryAction(in app: XCUIApplication) {
132 let firstSummary = app.buttons["noteDetailGenerateSummaryButton"]
133 if firstSummary.exists && firstSummary.isHittable { firstSummary.tap() }
134 else {
135 app.buttons["noteDetailMoreActionsButton"].tap()
136 let generate = app.buttons["noteDetailGenerateSummaryMenuButton"]
137 if generate.exists { generate.tap() }
138 else {
139 app.buttons["noteDetailSummaryTemplateMenu"].tap()
140 app.buttons["Lecture"].tap()
141 }
142 }
143 }
144
145 @MainActor func testMoreMenuRegeneratesExistingSummaryWithTheCurrentTemplate() {
146 let app = XCUIApplication()
147 app.launchEnvironment["JOTLEY_SCREENSHOT_DATA"] = #"""
148 [{"title":"Launch plan","folder":"Work","tags":["Design","Planning","Research"],
149 "transcript":"AI and design guide the project research and planning.",
150 "summary":"The previous launch summary.","template":"Concise"}]
151 """#
152 app.launchEnvironment["JOTLEY_TEST_SUMMARY_TAGS"] = "1"
153 app.launchEnvironment["JOTLEY_SCREENSHOT_APPEARANCE"] = "Light"
154 app.launchArguments = ["-jotleyWelcomeCompleted.v1", "YES", "-selectedThemeColor", "Magenta"]
155 app.launch()
156 let more = app.buttons["noteDetailMoreActionsButton"]
157 if !more.waitForExistence(timeout: 4) {
158 let row = app.buttons.containing(.staticText, identifier: "Launch plan").firstMatch
159 XCTAssertTrue(row.waitForExistence(timeout: 10))
160 row.tap()
161 }
162 let original = app.staticTexts["The previous launch summary."].firstMatch
163 XCTAssertTrue(original.waitForExistence(timeout: 5))
164 more.tap()
165 let regenerate = app.buttons["noteDetailRegenerateSummaryMenuButton"]
166 XCTAssertTrue(regenerate.waitForExistence(timeout: 5))
167 XCTAssertTrue(regenerate.isEnabled)
168 XCTAssertEqual(regenerate.label, "Regenerate Summary")
169 XCTAssertFalse(app.buttons["noteDetailGenerateSummaryMenuButton"].exists)
170 let menu = XCTAttachment(screenshot: XCUIScreen.main.screenshot())
171 menu.name = "01 Regenerate Summary in More"
172 menu.lifetime = .keepAlways
173 add(menu)
174 regenerate.tap()
175 let revision = app.staticTexts["AI and design guide the project research and planning."].firstMatch
176 XCTAssertTrue(revision.waitForExistence(timeout: 15))
177 let askAI = app.buttons["noteDetailSummaryAskAIButton"]
178 wait(for: [expectation(for: NSPredicate(format: "exists == true AND enabled == true"),
179 evaluatedWith: askAI)], timeout: 15)
180 XCTAssertFalse(original.exists)
181 XCTAssertEqual(app.staticTexts["noteDetailTitle"].label, "Launch plan")
182 XCTAssertEqual(app.buttons["noteDetailTagCount"].label, "3 tags")
183 let result = XCTAttachment(screenshot: XCUIScreen.main.screenshot())
184 result.name = "02 Regenerated summary saved"
185 result.lifetime = .keepAlways
186 add(result)
187 more.tap()
188 app.buttons["noteDetailSummaryTemplateMenu"].tap()
189 XCTAssertTrue(app.buttons["Concise"].waitForExistence(timeout: 5))
190 }
191
192 @MainActor func testTemplateChangeRegeneratesExistingSummaryAutomatically() throws {
193 let app = XCUIApplication()
194 app.launchEnvironment["JOTLEY_SCREENSHOT_DATA"] = #"[{"title":"Template update","folder":"","tags":[],"transcript":"Maya reviews milestones Friday. Sam tests the next steps.","summary":"Existing summary stays safe until its replacement finishes."}]"#
195 app.launchEnvironment["JOTLEY_TEST_SUMMARY_SCROLL"] = "1"
196 app.launch()
197 XCTAssertTrue(app.buttons["noteDetailMoreActionsButton"].waitForExistence(timeout: 15))
198 app.buttons["noteDetailMoreActionsButton"].tap()
199 XCTAssertFalse(app.buttons["noteDetailGenerateSummaryMenuButton"].exists)
200 app.buttons["noteDetailSummaryTemplateMenu"].tap()
201 app.buttons["Lecture"].tap()
202 let cancel = app.buttons["noteDetailCancelGenerationButton"]
203 XCTAssertTrue(cancel.waitForExistence(timeout: 10), "Changing a template must start generation without another button")
204 cancel.tap()
205 XCTAssertTrue(app.staticTexts.matching(NSPredicate(format: "label CONTAINS %@", "Existing summary stays safe")).firstMatch.waitForExistence(timeout: 10))
206 XCTAssertFalse(app.buttons["noteDetailGenerateSummaryButton"].exists)
207 }
208
209 @MainActor func testAutomaticFirstNoteSelectionAndDeletion() throws {
210 let isIPad = (ProcessInfo.processInfo.environment["SIMULATOR_MODEL_IDENTIFIER"] ?? "").hasPrefix("iPad")
211 XCUIDevice.shared.orientation = isIPad ? .landscapeLeft : .portrait
212 defer { XCUIDevice.shared.orientation = .portrait }
213 let app = XCUIApplication()
214 app.launchEnvironment["JOTLEY_SCREENSHOT_DATA"] = #"[{"title":"Newest note","folder":"","tags":[],"transcript":"First note.","summary":"A useful summary."},{"title":"Older note","folder":"","tags":[],"transcript":"Second note.","summary":""},{"title":"Oldest note","folder":"","tags":[],"transcript":"Third note.","summary":""}]"#
215 app.launchArguments = ["-jotleyWelcomeCompleted.v1", "YES"]
216 app.launch()
217 let title = app.staticTexts["noteDetailTitle"]
218 XCTAssertTrue(title.waitForExistence(timeout: 15))
219 XCTAssertEqual(title.label, "Newest note")
220 let transcriptTab = app.buttons["noteDetailTranscriptTab"]
221 let summaryTab = app.buttons["noteDetailSummaryTab"]
222 transcriptTab.tap(); XCTAssertTrue(transcriptTab.isSelected)
223 summaryTab.tap(); XCTAssertTrue(summaryTab.isSelected)
224 if !isIPad { app.buttons["BackButton"].tap() }
225 let older = app.buttons.containing(.staticText, identifier: "Older note").firstMatch
226 XCTAssertTrue(older.waitForExistence(timeout: 5)); older.tap()
227 XCTAssertEqual(title.label, "Older note")
228 app.buttons["noteDetailMoreActionsButton"].tap()
229 app.buttons["Move to Trash"].tap()
230 app.alerts["Move to Trash?"].buttons["Move to Trash"].tap()
231 if isIPad {
232 let selectedNewest = expectation(for: NSPredicate(format: "label == %@", "Newest note"), evaluatedWith: title)
233 wait(for: [selectedNewest], timeout: 10)
234 XCTAssertTrue(app.buttons.containing(.staticText, identifier: "Newest note").firstMatch.isHittable)
235 } else {
236 XCTAssertTrue(title.waitForNonExistence(timeout: 10), "Deleting on a single-column iPhone must return to the list, not open the newest note")
237 let settings = app.buttons["notesListSettingsButton"]
238 XCTAssertTrue(settings.waitForExistence(timeout: 5)); XCTAssertTrue(settings.isHittable)
239 XCTAssertTrue(app.buttons.containing(.staticText, identifier: "Newest note").firstMatch.isHittable)
240 }
241 let oldest = app.buttons.containing(.staticText, identifier: "Oldest note").firstMatch
242 XCTAssertTrue(oldest.waitForExistence(timeout: 5)); oldest.tap()
243 XCTAssertEqual(title.label, "Oldest note", "A remaining note must still open normally")
244 app.terminate(); app.launch()
245 XCTAssertTrue(title.waitForExistence(timeout: 15))
246 XCTAssertEqual(title.label, "Newest note") // Initial selection is unchanged; fixtures reset on launch.
247 }
248
249 @MainActor func testSummaryStyleAppliesToEveryNoteAndPersistsInSettings() throws {
250 let app = XCUIApplication()
251 app.launchEnvironment["JOTLEY_SCREENSHOT_DATA"] = ###"[{"title":"First summary","folder":"","tags":[],"transcript":"Maya reviews Friday.","summary":"## Summary\nA focused launch.\n\n## Next Steps\n- **Maya:** Review Friday."},{"title":"Second summary","folder":"","tags":[],"transcript":"Alex tests Monday.","summary":"## Summary\nA clear plan.\n\n## Next Steps\n- Test Monday."}]"###
252 app.launchEnvironment["JOTLEY_SCREENSHOT_APPEARANCE"] = "Dark"
253 app.launch()
254 func showLibrary() {
255 let row = app.buttons.containing(.staticText, identifier: "Second summary").firstMatch
256 if row.exists && row.isHittable { return }
257 let back = app.buttons["BackButton"]
258 if back.exists && back.isHittable { back.tap() }
259 else {
260 let sidebar = app.navigationBars.buttons.matching(NSPredicate(format: "label CONTAINS[c] 'sidebar'")).firstMatch
261 XCTAssertTrue(sidebar.waitForExistence(timeout: 5)); sidebar.tap()
262 }
263 XCTAssertTrue(row.waitForExistence(timeout: 5)); XCTAssertTrue(row.isHittable)
264 }
265 func openNote(_ title: String) {
266 let row = app.buttons.containing(.staticText, identifier: title).firstMatch
267 XCTAssertTrue(row.waitForExistence(timeout: 15)); row.tap()
268 XCTAssertTrue(app.buttons["noteDetailMoreActionsButton"].waitForExistence(timeout: 5))
269 }
270 func changeStyle(_ title: String) {
271 app.buttons["noteDetailMoreActionsButton"].tap()
272 app.buttons["noteDetailSummaryStyleMenu"].tap()
273 let option = app.buttons[title]
274 XCTAssertTrue(option.waitForExistence(timeout: 5)); option.tap()
275 }
276 openNote("First summary")
277 changeStyle("Standard Text")
278 XCTAssertTrue(app.staticTexts["summaryTextLine-0"].waitForExistence(timeout: 5))
279 XCTAssertTrue(app.staticTexts["A focused launch."].waitForExistence(timeout: 5))
280 XCTAssertTrue(app.staticTexts["Next Steps"].exists)
281 XCTAssertFalse(app.staticTexts.matching(NSPredicate(format: "label CONTAINS '**Maya**' OR label CONTAINS '## Next'")).firstMatch.exists)
282 let shot = XCTAttachment(screenshot: app.screenshot())
283 shot.name = "Standard Text summary Dark with neutral headings and bullets"; shot.lifetime = .keepAlways; add(shot)
284 showLibrary(); openNote("Second summary")
285 XCTAssertTrue(app.staticTexts["summaryTextLine-0"].waitForExistence(timeout: 5))
286 XCTAssertTrue(app.staticTexts["A clear plan."].waitForExistence(timeout: 5))
287 app.terminate(); app.launch()
288 XCTAssertTrue(app.buttons["notesListSettingsButton"].waitForExistence(timeout: 15))
289 app.buttons["notesListSettingsButton"].tap()
290 let picker = app.descendants(matching: .any)["summaryDisplayStylePicker"].firstMatch
291 XCTAssertTrue(picker.waitForExistence(timeout: 5))
292 XCTAssertTrue(picker.label.contains("Standard Text") || (picker.value as? String)?.contains("Standard Text") == true, picker.debugDescription)
293 picker.tap(); app.buttons["Cards"].tap()
294 app.buttons["settingsDoneButton"].tap()
295 openNote("Second summary")
296 XCTAssertTrue(app.descendants(matching: .any)["structuredSummaryOverview"].firstMatch.waitForExistence(timeout: 5))
297 showLibrary(); openNote("First summary")
298 XCTAssertTrue(app.descendants(matching: .any)["structuredSummaryOverview"].firstMatch.waitForExistence(timeout: 5))
299 }
300
301 @MainActor private func showNotesLibrary(_ app: XCUIApplication) {
302 let settings = app.buttons["notesListSettingsButton"]
303 if settings.exists && settings.isHittable { return }
304 let back = app.buttons["BackButton"]
305 if back.waitForExistence(timeout: 3) && back.isHittable { back.tap() }
306 else {
307 let sidebar = app.navigationBars.buttons.matching(NSPredicate(format: "label CONTAINS[c] 'sidebar'")).firstMatch
308 if sidebar.exists && sidebar.isHittable { sidebar.tap() }
309 }
310 XCTAssertTrue(settings.waitForExistence(timeout: 10), app.debugDescription)
311 }
312
313 @MainActor func testNotesTrashRestoreDeleteAndEmpty() {
314 let app = XCUIApplication()
315 app.launchEnvironment["JOTLEY_SCREENSHOT_DATA"] = #"[{"title":"Friday launch plan","folder":"Work","tags":["Launch"],"transcript":"Confirm Friday’s launch checklist.","summary":"The checklist is ready."},{"title":"Meeting follow-up","folder":"","tags":[],"transcript":"Send the meeting follow-up.","summary":""},{"title":"Voice memo draft","folder":"","tags":[],"transcript":"First draft of the recording.","summary":""}]"#
316 app.launchEnvironment["JOTLEY_SCREENSHOT_APPEARANCE"] = "Light"
317 app.launchArguments = ["-jotleyWelcomeCompleted.v1", "YES", "-AppleLanguages", "(en)"]
318 XCUIDevice.shared.orientation = .portrait
319 app.launch()
320 showNotesLibrary(app)
321 let trash = app.buttons["notesTrashLink"]
322 XCTAssertTrue(trash.waitForExistence(timeout: 10))
323 capture(XCUIScreen.main.screenshot(), named: "trash-01-notes-list")
324
325 func noteRow(_ title: String) -> XCUIElement {
326 app.buttons.containing(.staticText, identifier: title).firstMatch
327 }
328
329 func moveToTrash(_ title: String) {
330 let row = noteRow(title)
331 XCTAssertTrue(row.waitForExistence(timeout: 5))
332 row.tap()
333 app.buttons["noteDetailMoreActionsButton"].tap()
334 app.buttons["Move to Trash"].tap()
335 app.alerts["Move to Trash?"].buttons["Move to Trash"].tap()
336 showNotesLibrary(app)
337 XCTAssertTrue(row.waitForNonExistence(timeout: 5))
338 }
339
340 moveToTrash("Friday launch plan")
341 moveToTrash("Meeting follow-up")
342 moveToTrash("Voice memo draft")
343 trash.tap()
344 let emptyTrash = app.buttons["notesEmptyTrash"]
345 XCTAssertTrue(emptyTrash.waitForExistence(timeout: 5))
346 capture(XCUIScreen.main.screenshot(), named: "trash-02-management")
347
348 func menu(_ title: String) -> XCUIElement {
349 app.buttons.matching(identifier: "notesTrashActions")
350 .matching(NSPredicate(format: "label == %@", title)).firstMatch
351 }
352 menu("Friday launch plan").tap()
353 capture(XCUIScreen.main.screenshot(), named: "trash-03-note-actions")
354 app.buttons["Restore"].tap()
355 XCTAssertTrue(menu("Friday launch plan").waitForNonExistence(timeout: 5))
356
357 menu("Meeting follow-up").tap()
358 app.buttons["Delete Permanently"].tap()
359 let permanentAlert = app.alerts["Delete Note Permanently?"]
360 XCTAssertTrue(permanentAlert.waitForExistence(timeout: 5))
361 capture(XCUIScreen.main.screenshot(), named: "trash-04-permanent-confirmation")
362 permanentAlert.buttons["Delete Permanently"].tap()
363 XCTAssertTrue(menu("Meeting follow-up").waitForNonExistence(timeout: 5))
364
365 emptyTrash.tap()
366 app.alerts["Empty Trash?"].buttons["Empty Trash"].tap()
367 XCTAssertTrue(app.staticTexts["Trash Is Empty"].waitForExistence(timeout: 5))
368 capture(XCUIScreen.main.screenshot(), named: "trash-05-empty")
369 app.buttons["notesTrashDone"].tap()
370 let restored = noteRow("Friday launch plan")
371 XCTAssertTrue(restored.waitForExistence(timeout: 5))
372 restored.tap()
373 XCTAssertTrue(app.staticTexts["noteDetailTitle"].waitForExistence(timeout: 5))
374 XCTAssertEqual(app.staticTexts["noteDetailTitle"].label, "Friday launch plan")
375 }
376
377 @MainActor func testPhoneCornerCaptureStaysClearOfNoteActions() throws {
378 guard (ProcessInfo.processInfo.environment["SIMULATOR_MODEL_IDENTIFIER"] ?? "").hasPrefix("iPhone") else {
379 throw XCTSkip("Requires iPhone")
380 }
381 defer { XCUIDevice.shared.orientation = .portrait }
382 let app = XCUIApplication()
383 app.launchEnvironment["JOTLEY_SCREENSHOT_DATA"] = ###"[{"title":"Duo interface checks","folder":"Work","tags":["Planning"],"transcript":"Maya will review the launch plan on Friday.","summary":"## Decisions\n- Review the launch plan Friday."}]"###
384 app.launchEnvironment["JOTLEY_TEST_TRANSCRIPTION_LIFECYCLE"] = "1"
385 for orientation in [UIDeviceOrientation.portrait, .landscapeLeft] {
386 XCUIDevice.shared.orientation = orientation
387 app.launch()
388 showNotesLibrary(app)
389 let row = app.buttons.containing(.staticText, identifier: "Duo interface checks").firstMatch
390 XCTAssertTrue(row.waitForExistence(timeout: 15))
391 XCTAssertTrue(app.buttons["notesListNewNoteButton"].isHittable)
392 let gear = app.buttons["notesListSettingsButton"]
393 let folders = app.buttons["notesListFolderDrawerButton"]
394 XCTAssertEqual(gear.frame.width, folders.frame.width, accuracy: 1)
395 XCTAssertEqual(gear.frame.height, folders.frame.height, accuracy: 1)
396 XCTAssertTrue(gear.isHittable)
397 XCTAssertEqual(app.buttons.matching(identifier: "notesListSettingsButton").count, 1)
398 XCTAssertGreaterThan(gear.frame.minY, folders.frame.maxY)
399 XCTAssertEqual(gear.frame.midY, app.buttons["notesListNewNoteButton"].frame.midY, accuracy: 1)
400 if orientation == .portrait {
401 XCTAssertEqual(gear.frame.minX - app.frame.minX, 20, accuracy: 1)
402 }
403 let libraryShot = XCTAttachment(screenshot: app.screenshot())
404 libraryShot.name = "Phone bottom-left Settings - \(orientation.rawValue)"
405 libraryShot.lifetime = .keepAlways; add(libraryShot)
406 gear.tap()
407 XCTAssertTrue(app.buttons["settingsDoneButton"].waitForExistence(timeout: 5))
408 app.buttons["settingsDoneButton"].tap()
409 row.tap()
410 let plus = app.buttons["notesListNewNoteButton"]
411 XCTAssertTrue(plus.waitForExistence(timeout: 5)); XCTAssertTrue(plus.isHittable)
412 XCTAssertEqual(app.buttons.matching(identifier: "notesListNewNoteButton").count, 1)
413 XCTAssertGreaterThanOrEqual(plus.frame.width, 44)
414 XCTAssertEqual(plus.frame.width, 44, accuracy: 1)
415 XCTAssertGreaterThanOrEqual(app.frame.maxX - plus.frame.maxX, 0)
416 for tab in ["noteDetailSummaryTab", "noteDetailTranscriptTab"] {
417 app.buttons[tab].tap()
418 let quickAction = app.buttons[tab == "noteDetailSummaryTab" ? "noteDetailSummaryAskAIButton" : "noteDetailContinueTranscriptionButton"]
419 XCTAssertTrue(quickAction.isHittable)
420 XCTAssertFalse(app.buttons["noteDetailGenerateSummaryButton"].exists)
421 XCTAssertFalse(plus.frame.intersects(quickAction.frame))
422 XCTAssertEqual(quickAction.frame.height, 44, accuracy: 1)
423 XCTAssertEqual(plus.frame.midY, quickAction.frame.midY, accuracy: 1)
424 let title = app.staticTexts["noteDetailTitle"]
425 let sidebarIsBesideNote = row.isHittable && row.frame.maxX <= title.frame.minX
426 let detailLeading = sidebarIsBesideNote ? title.frame.minX - 16 : app.frame.minX
427 XCTAssertEqual(app.frame.maxX - plus.frame.maxX, 24, accuracy: 1)
428 XCTAssertEqual(quickAction.frame.midX, (detailLeading + app.frame.maxX) / 2, accuracy: 1)
429 XCTAssertTrue(app.buttons["noteDetailShareButton"].isHittable)
430 XCTAssertTrue(app.buttons["noteDetailMoreActionsButton"].isHittable)
431 }
432 let attachment = XCTAttachment(screenshot: app.screenshot())
433 attachment.name = "Duo corner controls - \(orientation.rawValue)"
434 attachment.lifetime = .keepAlways; add(attachment)
435 plus.tap()
436 let pause = app.buttons["transcriptionPauseButton"]
437 XCTAssertTrue(pause.waitForExistence(timeout: 10)); XCTAssertEqual(pause.frame.height, 84, accuracy: 1); pause.tap()
438 XCTAssertEqual(pause.label, "Resume transcription"); pause.tap()
439 XCTAssertEqual(pause.label, "Pause transcription")
440 let stop = app.buttons["transcriptionStopButton"]
441 XCTAssertEqual(stop.frame.height, 60, accuracy: 1)
442 let recording = XCTAttachment(screenshot: app.screenshot())
443 recording.name = "Large themed Pause and larger glass Stop"; recording.lifetime = .keepAlways; add(recording)
444 stop.tap()
445 XCTAssertTrue(app.staticTexts["Completed transcript."].waitForExistence(timeout: 10))
446 let settled = expectation(for: NSPredicate(format: "hittable == true"), evaluatedWith: app.buttons["noteDetailMoreActionsButton"])
447 wait(for: [settled], timeout: 5)
448 app.buttons["noteDetailContinueTranscriptionButton"].tap()
449 XCTAssertTrue(pause.waitForExistence(timeout: 10))
450 app.buttons["transcriptionCloseButton"].tap()
451 XCTAssertTrue(app.staticTexts["noteDetailTitle"].waitForExistence(timeout: 10))
452 app.terminate()
453 }
454 }
455
456 @MainActor func testCompactAddTagSheetSavesAndCancels() throws {
457 XCUIDevice.shared.orientation = .portrait
458 let app = XCUIApplication()
459 app.launchEnvironment["JOTLEY_SCREENSHOT_DATA"] = ###"[{"title":"Tag design check","folder":"Work","tags":[],"transcript":"Review Friday’s plan.","summary":""}]"###
460 app.launchEnvironment["JOTLEY_SCREENSHOT_APPEARANCE"] = "Dark"
461 app.launch()
462 if !app.staticTexts["noteDetailTitle"].waitForExistence(timeout: 5) {
463 let row = app.buttons.containing(.staticText, identifier: "Tag design check").firstMatch
464 XCTAssertTrue(row.waitForExistence(timeout: 10)); row.tap()
465 }
466 let addButton = app.buttons["noteDetailAddTagButton"]
467 XCTAssertTrue(addButton.waitForExistence(timeout: 5)); addButton.tap()
468 let field = app.textFields["addTagTextField"]
469 let save = app.buttons["addTagSaveButton"]
470 let cancel = app.buttons["addTagCancelButton"]
471 XCTAssertTrue(field.waitForExistence(timeout: 5))
472 XCTAssertTrue(app.keyboards.firstMatch.waitForExistence(timeout: 5))
473 XCTAssertGreaterThanOrEqual(field.frame.height, 52)
474 XCTAssertTrue(save.isHittable && cancel.isHittable)
475 XCTAssertFalse(save.isEnabled)
476 XCTAssertGreaterThan(cancel.frame.minY, app.frame.height * 0.15, "The tag sheet must leave the note visible above it, even with the keyboard")
477 field.tap(); field.typeText("Launch review")
478 XCTAssertTrue(save.isEnabled)
479 let shot = XCTAttachment(screenshot: app.screenshot())
480 shot.name = "Compact Add Tag with styled input and glass action"; shot.lifetime = .keepAlways; add(shot)
481 // Return also submits the compact form when a hardware keyboard is
482 // connected to a foldable simulator with a separate keyboard surface.
483 field.typeText("\n")
484 let tag = app.descendants(matching: .any)["noteDetailTag-Launch-review"].firstMatch
485 let tagCount = app.buttons["noteDetailTagCount"]
486 XCTAssertTrue(tagCount.waitForExistence(timeout: 5))
487 XCTAssertEqual(tagCount.label, "1 tag")
488 XCTAssertFalse(tag.exists)
489 tagCount.tap()
490 XCTAssertTrue(tag.waitForExistence(timeout: 5))
491 addButton.tap(); XCTAssertTrue(field.waitForExistence(timeout: 5))
492 field.tap(); field.typeText("Draft")
493 cancel.tap()
494 XCTAssertTrue(addButton.waitForExistence(timeout: 5))
495 XCTAssertFalse(app.descendants(matching: .any)["noteDetailTag-Draft"].firstMatch.exists)
496 }
497
498 @MainActor func testOnboardingSwipeNavigation() throws {
499 let app = XCUIApplication()
500 app.launchEnvironment["JOTLEY_SCREENSHOT_DATA"] = "[]"
501 app.launchEnvironment["JOTLEY_TEST_ONBOARDING"] = "1"
502 app.launchEnvironment["JOTLEY_TEST_RESET_ONBOARDING"] = "1"
503 app.launch()
504 let title = app.staticTexts["onboardingTitle"]
505 XCTAssertTrue(title.waitForExistence(timeout: 15))
506 func expectTitle(_ text: String) {
507 let match = expectation(for: NSPredicate(format: "label == %@", onboardingTitle(text, in: app)), evaluatedWith: title)
508 wait(for: [match], timeout: 5)
509 }
510 title.swipeRight(); expectTitle("Stay in the conversation.")
511 title.swipeLeft(); expectTitle("Find the useful parts.")
512 title.swipeRight(); expectTitle("Stay in the conversation.")
513 app.buttons["onboardingContinue"].tap(); expectTitle("Find the useful parts.")
514 title.swipeLeft(); expectTitle("Start with your language.")
515 title.swipeLeft(); expectTitle("Give your words a place.")
516 title.swipeLeft(); expectTitle("Summary notifications")
517 XCTAssertFalse(app.alerts.firstMatch.exists, "Swiping must not request microphone access")
518 title.swipeLeft(); expectTitle("Summary notifications")
519 XCTAssertTrue(app.buttons["onboardingContinue"].exists, "Swiping past the end must not finish setup")
520 app.buttons["onboardingBack"].tap(); expectTitle("Give your words a place.")
521 }
522
523 @MainActor private func onboardingTitle(_ text: String, in app: XCUIApplication) -> String {
524 guard UIDevice.current.model.hasPrefix("iPad"), app.frame.width >= 620 else { return text }
525 return switch text {
526 case "Stay in the conversation.": "Stay in the\nconversation."
527 case "Find the useful parts.": "Find clarity in\nevery conversation."
528 case "Start with your language.": "Start with\nyour language."
529 case "Give your words a place.": "Give your words\na place."
530 default: text
531 }
532 }
533
534 @MainActor func testOnboardingFitsWithoutScrolling() throws {
535 try verifyCenteredOnboarding(orientation: .portrait)
536 }
537
538 @MainActor func testOnboardingIsCenteredInIPadLandscape() throws {
539 guard (ProcessInfo.processInfo.environment["SIMULATOR_MODEL_IDENTIFIER"] ?? "").hasPrefix("iPad") else { throw XCTSkip("iPad landscape layout") }
540 try verifyCenteredOnboarding(orientation: .landscapeLeft, appearance: "Dark")
541 }
542
543 @MainActor func testOnboardingDarkModeKeepsCenteredLayout() throws {
544 try verifyCenteredOnboarding(orientation: .portrait, appearance: "Dark")
545 }
546
547 @MainActor private func verifyCenteredOnboarding(orientation: UIDeviceOrientation, appearance: String = "Light") throws {
548 continueAfterFailure = true
549 XCUIDevice.shared.orientation = orientation
550 defer { XCUIDevice.shared.orientation = .portrait }
551 let app = XCUIApplication()
552 app.launchArguments = ["-selectedThemeColor", "Purple"]
553 app.launchEnvironment["JOTLEY_SCREENSHOT_DATA"] = "[]"
554 app.launchEnvironment["JOTLEY_TEST_ONBOARDING"] = "1"
555 app.launchEnvironment["JOTLEY_TEST_RESET_ONBOARDING"] = "1"
556 app.launchEnvironment["JOTLEY_TEST_STOREFRONT"] = "USA"
557 app.launchEnvironment["JOTLEY_SCREENSHOT_APPEARANCE"] = appearance
558 app.launch()
559 XCTAssertTrue(app.staticTexts["onboardingTitle"].waitForExistence(timeout: 15))
560 let initialAction = app.buttons["onboardingContinue"].frame
561 let initialTitleTop = app.staticTexts["onboardingTitle"].frame.minY
562 let block = app.descendants(matching: .any)["onboardingContentBlock"].firstMatch
563 XCTAssertTrue(block.waitForExistence(timeout: 5))
564 let initialBlock = block.frame
565 if UIDevice.current.model.hasPrefix("iPad") {
566 let skip = app.buttons["onboardingSkip"].frame
567 let brand = app.staticTexts["onboardingBrand"].frame
568 XCTAssertLessThan(brand.minX, 100, "Brand belongs at the window's top-left corner")
569 XCTAssertLessThan(app.frame.maxX - skip.maxX, 60, "Skip setup belongs at the window's top-right corner")
570 if app.frame.width >= 1000 {
571 XCTAssertGreaterThan(initialBlock.width, 800, "Roomy iPad windows should enlarge the whole content area")
572 XCTAssertGreaterThan(app.staticTexts["onboardingTitle"].frame.height, 40)
573 }
574 }
575 var tallestPageHeight: CGFloat = 0
576 let titles = ["Stay in the conversation.", "Find the useful parts.", "Start with your language.", "Give your words a place.", "Summary notifications"]
577 .map { onboardingTitle($0, in: app) }
578 for index in titles.indices {
579 let titleMatches = XCTNSPredicateExpectation(predicate: NSPredicate(format: "label == %@", titles[index]), object: app.staticTexts["onboardingTitle"])
580 XCTAssertEqual(XCTWaiter.wait(for: [titleMatches], timeout: 15), .completed)
581 if index == 2 {
582 let ready = XCTNSPredicateExpectation(predicate: NSPredicate(format: "enabled == true"), object: app.buttons["onboardingLanguagePicker"])
583 XCTAssertEqual(XCTWaiter.wait(for: [ready], timeout: 60), .completed)
584 }
585 let contentFits = XCTNSPredicateExpectation(predicate: NSPredicate { _, _ in
586 let title = app.staticTexts["onboardingTitle"]
587 return title.exists && title.isHittable && !app.scrollViews["onboardingFallbackScroll"].exists
588 }, object: nil)
589 let fitted = XCTWaiter.wait(for: [contentFits], timeout: 5)
590 for (screenIndex, screen) in XCUIScreen.screens.enumerated() {
591 let shot = XCTAttachment(screenshot: screen.screenshot())
592 shot.name = "Fitted onboarding step \(index + 1) screen \(screenIndex)"
593 shot.lifetime = .keepAlways; add(shot)
594 }
595 XCTAssertFalse(app.scrollViews["onboardingFallbackScroll"].exists, "Normal text should use a layout without a scroll view")
596 XCTAssertEqual(fitted, .completed, "The settled page must fit without scrolling")
597 XCTAssertTrue(app.staticTexts["onboardingTitle"].isHittable)
598 if index == 2 {
599 let hint = app.staticTexts["onboardingLanguageHint"]
600 XCTAssertTrue(hint.isHittable)
601 XCTAssertLessThan(hint.frame.maxY, app.descendants(matching: .any)["onboardingProgress"].firstMatch.frame.minY - 8)
602 if app.buttons["onboardingSpeechSetup"].exists { XCTAssertTrue(app.buttons["onboardingSpeechSetup"].isHittable) }
603 }
604 if titles[index] == "Summary notifications" {
605 XCTAssertTrue(app.switches["onboardingSummaryNotificationsToggle"].isHittable)
606 }
607 XCTAssertEqual(block.frame.minY, initialBlock.minY, accuracy: 1, "Center one outer block, not each page individually")
608 tallestPageHeight = max(tallestPageHeight, block.frame.height)
609 let headerBottom = app.descendants(matching: .any)["onboardingHeader"].firstMatch.frame.maxY
610 let footerTop = app.descendants(matching: .any)["onboardingProgress"].firstMatch.frame.minY
611 print("ONBOARDING step=\(index) block=\(block.frame) headerBottom=\(headerBottom) footerTop=\(footerTop) heading=\(app.staticTexts["onboardingTitle"].frame)")
612 XCTAssertEqual(app.buttons["onboardingContinue"].frame.minY, initialAction.minY, accuracy: 1)
613 XCTAssertEqual(app.staticTexts["onboardingTitle"].frame.minY, initialTitleTop, accuracy: 1, "Onboarding headings must stay at the same height on every page")
614 if index < titles.count - 1 {
615 if index == 3 && app.buttons["onboardingNotNow"].exists { app.buttons["onboardingNotNow"].tap() }
616 else { app.buttons["onboardingContinue"].tap() }
617 }
618 }
619 let headerBottom = app.descendants(matching: .any)["onboardingHeader"].firstMatch.frame.maxY
620 let footerTop = app.descendants(matching: .any)["onboardingProgress"].firstMatch.frame.minY
621 XCTAssertGreaterThan(initialBlock.minY + tallestPageHeight / 2, (headerBottom + footerTop) / 2 + 8,
622 "The shared content block should sit lower in the available area")
623 XCTAssertLessThanOrEqual(initialBlock.minY + tallestPageHeight, footerTop - 8,
624 "Even the tallest page must remain clear of the footer")
625 }
626
627 @MainActor func testOnboardingFinishesAfterNotifications() throws {
628 XCUIDevice.shared.orientation = .portrait
629 let app = XCUIApplication()
630 app.launchArguments = ["-selectedThemeColor", "Purple"]
631 app.launchEnvironment["JOTLEY_SCREENSHOT_DATA"] = ###"[{"title":"Keep this note","folder":"","tags":[],"transcript":"Existing notes stay safe.","summary":""}]"###
632 app.launchEnvironment["JOTLEY_TEST_ONBOARDING"] = "1"
633 for country in ["USA", "GBR"] {
634 app.launchEnvironment["JOTLEY_TEST_RESET_NOTIFICATIONS"] = "1"
635 app.launchEnvironment["JOTLEY_TEST_STOREFRONT"] = country
636 app.launchEnvironment["JOTLEY_TEST_RESET_ONBOARDING"] = "1"
637 app.launchEnvironment["JOTLEY_SCREENSHOT_APPEARANCE"] = country == "USA" ? "Dark" : "Light"
638 app.launch()
639 let title = app.staticTexts["onboardingTitle"]
640 XCTAssertTrue(title.waitForExistence(timeout: 15))
641 for _ in 0..<3 { app.buttons["onboardingContinue"].tap() }
642 if app.buttons["onboardingNotNow"].exists { app.buttons["onboardingNotNow"].tap() }
643 else { app.buttons["onboardingContinue"].tap() }
644 let notifications = app.switches["onboardingSummaryNotificationsToggle"]
645 XCTAssertTrue(notifications.waitForExistence(timeout: 5))
646 XCTAssertEqual(notifications.value as? String, "1")
647 let notificationScreen = XCTAttachment(screenshot: XCUIScreen.main.screenshot())
648 notificationScreen.name = "Onboarding notifications enabled - \(country)"
649 notificationScreen.lifetime = .keepAlways
650 add(notificationScreen)
651 notifications.coordinate(withNormalizedOffset: CGVector(dx: 0.95, dy: 0.5)).tap()
652 let switchedOff = XCTNSPredicateExpectation(
653 predicate: NSPredicate(format: "value == %@", "0"), object: notifications)
654 XCTAssertEqual(XCTWaiter.wait(for: [switchedOff], timeout: 4), .completed)
655 if country == "USA" {
656 let optedOut = XCTAttachment(screenshot: XCUIScreen.main.screenshot())
657 optedOut.name = "Onboarding notifications disabled"
658 optedOut.lifetime = .keepAlways
659 add(optedOut)
660 }
661 XCTAssertEqual(app.alerts.count, 0)
662 app.buttons["onboardingContinue"].tap()
663 XCTAssertTrue(app.staticTexts["Keep this note"].waitForExistence(timeout: 8))
664 app.terminate()
665 app.launchEnvironment.removeValue(forKey: "JOTLEY_TEST_RESET_ONBOARDING")
666 app.launchEnvironment.removeValue(forKey: "JOTLEY_TEST_RESET_NOTIFICATIONS")
667 app.launch()
668 showNotesLibrary(app)
669 XCTAssertTrue(app.buttons["notesListSettingsButton"].waitForExistence(timeout: 10))
670 XCTAssertFalse(title.exists)
671 app.terminate()
672 }
673 }
674
675 @MainActor func testFirstSummaryFooterClearsLastTranscriptLine() throws {
676 XCUIDevice.shared.orientation = .portrait
677 let app = XCUIApplication()
678 let text = (1...20).map { "Paragraph \($0): Review the next steps and keep a clear record of the conversation." }.joined(separator: "\n\n") + "\n\nFinal line above summary controls."
679 let fixture: [[String: Any]] = [["title": "First summary footer", "folder": "Work", "tags": [], "transcript": text, "summary": ""]]
680 app.launchEnvironment["JOTLEY_SCREENSHOT_DATA"] = String(decoding: try JSONSerialization.data(withJSONObject: fixture), as: UTF8.self)
681 app.launchEnvironment["JOTLEY_SCREENSHOT_APPEARANCE"] = ProcessInfo.processInfo.environment["JOTLEY_REVIEW_APPEARANCE"] ?? "Dark"
682 app.launchArguments = ["-selectedThemeColor", "Magenta"]
683 app.launch()
684 showNotesLibrary(app)
685 let row = app.buttons.containing(.staticText, identifier: "First summary footer").firstMatch
686 XCTAssertTrue(row.waitForExistence(timeout: 15)); row.tap()
687 let primary = app.buttons["noteDetailGenerateSummaryButton"]
688 XCTAssertTrue(primary.waitForExistence(timeout: 5)); XCTAssertTrue(primary.isHittable)
689 let last = app.staticTexts.matching(NSPredicate(format: "label CONTAINS 'Final line above summary controls.'")).firstMatch
690 let scroll = app.scrollViews.firstMatch
691 for _ in 0..<14 {
692 if last.exists && last.isHittable && last.frame.maxY < primary.frame.minY - 8 { break }
693 scroll.swipeUp()
694 }
695 XCTAssertTrue(last.exists && last.isHittable)
696 XCTAssertLessThan(last.frame.maxY, primary.frame.minY - 8)
697 XCTAssertTrue(primary.isHittable)
698 XCTAssertTrue(app.buttons["noteDetailTemplatesButton"].isHittable)
699 XCTAssertLessThan(primary.frame.maxY, app.buttons["noteDetailContinueTranscriptionButton"].frame.minY)
700 let shot = XCTAttachment(screenshot: app.screenshot())
701 shot.name = "First-time summary controls above Continue and Plus"; shot.lifetime = .keepAlways; add(shot)
702 }
703
704 @MainActor func testSummaryFooterStaysInDetailColumnWithSidebar() throws {
705 defer { XCUIDevice.shared.orientation = .portrait }
706 let app = XCUIApplication()
707 let isDuo = (ProcessInfo.processInfo.environment["SIMULATOR_MODEL_IDENTIFIER"] ?? "").hasPrefix("iPhone")
708 app.launchEnvironment["JOTLEY_SCREENSHOT_DATA"] = ###"[{"title":"Column alignment check","folder":"Work","tags":[],"transcript":"Keep the controls with this note, without covering the notes list.","summary":""}]"###
709 app.launchEnvironment["JOTLEY_SCREENSHOT_APPEARANCE"] = isDuo ? "Light" : "Dark"
710 app.launchArguments = ["-selectedThemeColor", "Magenta", "-jotleyWelcomeCompleted.v1", "YES"]
711 XCUIDevice.shared.orientation = .landscapeLeft
712 app.launch()
713 let row = app.buttons.containing(.staticText, identifier: "Column alignment check").firstMatch
714 let primary = app.buttons["noteDetailGenerateSummaryButton"]
715 if !primary.waitForExistence(timeout: 5) {
716 showNotesLibrary(app)
717 XCTAssertTrue(row.waitForExistence(timeout: 15)); row.tap()
718 }
719 var verifiedSideBySideLayout = false
720 for orientation in [UIDeviceOrientation.landscapeLeft, .portrait, .landscapeLeft] {
721 XCUIDevice.shared.orientation = orientation
722 XCTAssertTrue(primary.waitForExistence(timeout: 5))
723 let title = app.staticTexts["noteDetailTitle"]
724 let template = app.buttons["noteDetailTemplatesButton"]
725 let quick = app.buttons["noteDetailContinueTranscriptionButton"]
726 XCTAssertTrue(primary.isHittable && template.isHittable && quick.isHittable)
727 if row.isHittable && row.frame.maxX <= title.frame.minX {
728 verifiedSideBySideLayout = true
729 XCTAssertGreaterThanOrEqual(template.frame.minX, title.frame.minX - 1)
730 XCTAssertGreaterThanOrEqual(primary.frame.minX, title.frame.minX - 1)
731 XCTAssertGreaterThan(quick.frame.minX, row.frame.maxX)
732 }
733 XCTAssertEqual(quick.frame.midX, (template.frame.minX + primary.frame.maxX) / 2, accuracy: 1)
734 XCTAssertLessThanOrEqual(primary.frame.maxX - template.frame.minX, 385)
735 XCTAssertLessThan(primary.frame.maxY, quick.frame.minY)
736 for (index, screen) in XCUIScreen.screens.enumerated() {
737 let capture = XCTAttachment(screenshot: screen.screenshot())
738 capture.name = "Detail-column footer - \(orientation.rawValue) - screen \(index)"
739 capture.lifetime = .keepAlways; add(capture)
740 }
741 }
742 if !isDuo { XCTAssertTrue(verifiedSideBySideLayout, "Run this check on iPad with an adjacent sidebar") }
743 }
744
745 @MainActor func testSummaryActionsKeepPaddingAcrossWindowChanges() throws {
746 defer { XCUIDevice.shared.orientation = .portrait }
747 let app = XCUIApplication()
748 for hasSummary in [true, false] {
749 let title = hasSummary ? "Summary ready" : "Transcript ready"
750 let fixture: [[String: Any]] = [["title": title, "folder": "Work", "tags": [],
751 "transcript": "Maya will review Friday’s launch plan. Alex will finish the accessibility checks.",
752 "summary": hasSummary ? "## Key Points\n- Review Friday’s launch plan." : ""]]
753 app.launchEnvironment["JOTLEY_SCREENSHOT_DATA"] = String(decoding: try JSONSerialization.data(withJSONObject: fixture), as: UTF8.self)
754 XCUIDevice.shared.orientation = .portrait
755 app.launch()
756 let row = app.buttons.containing(.staticText, identifier: title).firstMatch
757 XCTAssertTrue(row.waitForExistence(timeout: 15)); row.tap()
758 for orientation in [UIDeviceOrientation.portrait, .landscapeLeft, .portrait] {
759 XCUIDevice.shared.orientation = orientation
760 let primary = app.buttons["noteDetailGenerateSummaryButton"]
761 if hasSummary {
762 XCTAssertFalse(primary.exists, "Regeneration belongs in More after a summary exists")
763 XCTAssertFalse(app.buttons["noteDetailTemplatesButton"].exists)
764 let quickAction = app.buttons["noteDetailSummaryAskAIButton"]
765 let settled = expectation(for: NSPredicate(format: "hittable == true"), evaluatedWith: quickAction)
766 wait(for: [settled], timeout: 5)
767 XCTAssertEqual(quickAction.frame.height, 44, accuracy: 1)
768 app.buttons["noteDetailMoreActionsButton"].tap()
769 XCTAssertFalse(app.buttons["noteDetailGenerateSummaryMenuButton"].exists)
770 app.buttons["noteDetailSummaryTemplateMenu"].tap()
771 let template = app.buttons["Personal Note"]
772 XCTAssertTrue(template.waitForExistence(timeout: 5))
773 // Opening the template menu must not start inference.
774 app.tap()
775 XCTAssertTrue(app.buttons["noteDetailSummaryAskAIButton"].exists)
776 } else {
777 XCTAssertTrue(primary.waitForExistence(timeout: 5))
778 XCTAssertEqual(primary.label, "Generate Summary")
779 let textWidth = ("Generate Summary" as NSString).size(withAttributes: [.font: UIFont.systemFont(ofSize: 15, weight: .semibold)]).width
780 XCTAssertGreaterThanOrEqual(primary.frame.width, textWidth + 31)
781 XCTAssertTrue(app.buttons["noteDetailTemplatesButton"].isHittable)
782 if orientation == .portrait {
783 XCTAssertGreaterThan(primary.frame.minY, app.frame.midY, "First-time generation stays at the bottom")
784 }
785 XCTAssertLessThan(primary.frame.maxY, app.buttons["noteDetailContinueTranscriptionButton"].frame.minY,
786 "First-time generation belongs above the bottom quick actions")
787 }
788 if orientation == .portrait {
789 let isPhone = (ProcessInfo.processInfo.environment["SIMULATOR_MODEL_IDENTIFIER"] ?? "").hasPrefix("iPhone")
790 let cornerButton = isPhone ? app.buttons["notesListNewNoteButton"] : app.buttons[hasSummary ? "noteDetailSummaryAskAIButton" : "noteDetailContinueTranscriptionButton"]
791 XCTAssertEqual(app.frame.maxY - cornerButton.frame.maxY, isPhone ? 24 : 16, accuracy: 2)
792 if isPhone { XCTAssertEqual(app.frame.maxX - cornerButton.frame.maxX, 24, accuracy: 2) }
793 }
794 for (index, screen) in XCUIScreen.screens.enumerated() {
795 let capture = XCTAttachment(screenshot: screen.screenshot())
796 capture.name = "\(hasSummary ? "Regenerate" : "Generate") Summary - \(orientation.rawValue) - screen \(index)"
797 capture.lifetime = .keepAlways; add(capture)
798 }
799 }
800 app.terminate()
801 }
802 }
803
804 @MainActor func testNotesListLastNoteScrollsAboveCaptureButton() throws {
805 defer { XCUIDevice.shared.orientation = .portrait }
806 let app = XCUIApplication()
807 let fixture: [[String: Any]] = (1...20).map { index in
808 ["title": "Scroll note \(index)", "folder": "", "tags": [],
809 "transcript": "Example note \(index).", "summary": "Summary \(index).",
810 "timestampOffset": -Double(index * 86_400)]
811 }
812 app.launchEnvironment["JOTLEY_SCREENSHOT_DATA"] = String(decoding: try JSONSerialization.data(withJSONObject: fixture), as: UTF8.self)
813 for orientation in [UIDeviceOrientation.portrait, .landscapeLeft] {
814 XCUIDevice.shared.orientation = orientation
815 app.launch()
816 XCTAssertTrue(app.staticTexts["Scroll note 1"].waitForExistence(timeout: 15))
817 let last = app.buttons.containing(.staticText, identifier: "Scroll note 20").firstMatch
818 let plus = app.buttons["notesListNewNoteButton"]
819 let list = app.collectionViews.firstMatch
820 // An open portrait Duo drawer covers the detail footer; its rows
821 // can use the drawer's full height. Adjacent/compact lists clear it.
822 let isPortraitDrawer = app.frame.height > app.frame.width && UIDevice.current.userInterfaceIdiom == .phone && app.frame.width > 500
823 let bottomLimit = isPortraitDrawer ? list.frame.maxY - 8 : plus.frame.minY - 8
824 for _ in 0..<12 {
825 if last.exists && last.isHittable && last.frame.maxY < bottomLimit { break }
826 if list.exists { list.swipeUp() } else { app.swipeUp() }
827 }
828 let screenshot = XCTAttachment(screenshot: app.screenshot())
829 screenshot.name = "Last library note above footer - \(orientation.rawValue)"
830 screenshot.lifetime = .keepAlways
831 add(screenshot)
832 XCTAssertTrue(last.exists && last.isHittable, "The oldest note must be reachable by scrolling")
833 XCTAssertLessThan(last.frame.maxY, bottomLimit, "The complete last row must remain above visible controls or within the drawer")
834 last.tap()
835 XCTAssertTrue(app.staticTexts["noteDetailTitle"].waitForExistence(timeout: 10))
836 XCTAssertEqual(app.staticTexts["noteDetailTitle"].label, "Scroll note 20")
837 }
838 }
839
840 @MainActor func testNoteScrollJumpFollowsDirection() throws {
841 XCUIDevice.shared.orientation = UIDevice.current.userInterfaceIdiom == .pad ? .landscapeLeft : .portrait
842 defer { XCUIDevice.shared.orientation = .portrait }
843 let app = XCUIApplication()
844 let transcript = (1...24).map { "Transcript paragraph \($0). Review the launch plan and share the latest draft." }
845 .joined(separator: "\n\n")
846 let summary = "## Launch checklist\n" + (1...28).map { "- Checkpoint \($0). Review the next steps and share the launch plan with the team." }
847 .joined(separator: "\n")
848 let fixture = [["title": "Launch planning", "folder": "Work", "tags": ["Planning"],
849 "transcript": transcript, "summary": summary] as [String: Any]]
850 app.launchEnvironment["JOTLEY_SCREENSHOT_DATA"] = String(decoding: try JSONSerialization.data(withJSONObject: fixture), as: UTF8.self)
851 app.launchEnvironment["JOTLEY_SCREENSHOT_APPEARANCE"] = "Dark"
852 app.launchArguments = ["-selectedThemeColor", "Magenta", "-jotleyWelcomeCompleted.v1", "YES"]
853 app.launch()
854 if !app.staticTexts["noteDetailTitle"].exists {
855 showNotesLibrary(app)
856 let row = app.buttons.containing(.staticText, identifier: "Launch planning").firstMatch
857 XCTAssertTrue(row.waitForExistence(timeout: 10))
858 row.tap()
859 }
860
861 let title = app.staticTexts["noteDetailTitle"]
862 let scroll = app.scrollViews.containing(.staticText, identifier: "noteDetailTitle").firstMatch
863 let top = app.buttons["noteDetailJumpTop"]
864 let bottom = app.buttons["noteDetailJumpBottom"]
865 for tab in ["Summary", "Transcript"] {
866 let tabButton = app.buttons["noteDetail\(tab)Tab"]
867 let action = app.buttons[tab == "Summary" ? "noteDetailSummaryAskAIButton" : "noteDetailContinueTranscriptionButton"]
868 XCTAssertTrue(tabButton.isHittable)
869 if tab == "Transcript" {
870 tabButton.tap()
871 XCTAssertTrue(tabButton.isSelected)
872 XCTAssertFalse(app.buttons["noteDetailSummaryTab"].isSelected)
873 XCTAssertFalse(app.staticTexts["Launch checklist"].exists)
874 XCTAssertTrue(app.staticTexts.matching(NSPredicate(format: "label CONTAINS %@", "Transcript paragraph 1.")).firstMatch.isHittable)
875 XCTAssertTrue(app.buttons["noteDetailContinueTranscriptionButton"].isHittable)
876 capture(XCUIScreen.main.screenshot(), named: "Continue Transcription theme icon")
877 }
878 XCTAssertFalse(top.exists || bottom.exists)
879
880 // Scroll inside the note pane, clear of the sidebar and footer.
881 let lower = scroll.coordinate(withNormalizedOffset: CGVector(dx: 0.72, dy: 0.66))
882 let upper = scroll.coordinate(withNormalizedOffset: CGVector(dx: 0.72, dy: 0.3))
883 let nearTop = scroll.coordinate(withNormalizedOffset: CGVector(dx: 0.72, dy: 0.52))
884 let reverse = scroll.coordinate(withNormalizedOffset: CGVector(dx: 0.72, dy: 0.56))
885 lower.press(forDuration: 0.12, thenDragTo: nearTop, withVelocity: .slow, thenHoldForDuration: 0.12)
886 XCTAssertTrue(bottom.exists)
887 nearTop.press(forDuration: 0.12, thenDragTo: reverse, withVelocity: .slow, thenHoldForDuration: 0.12)
888 XCTAssertTrue(top.exists && !bottom.exists, "Reversing direction close to the top should offer Jump to Top")
889 XCTAssertTrue(top.waitForNonExistence(timeout: 3))
890 lower.press(forDuration: 0.12, thenDragTo: upper, withVelocity: .slow, thenHoldForDuration: 0.12)
891 XCTAssertTrue(bottom.exists && bottom.isHittable)
892 XCTAssertFalse(top.exists)
893 XCTAssertEqual(bottom.frame.midY, action.frame.midY, accuracy: 1)
894 capture(XCUIScreen.main.screenshot(), named: "\(tab) jump to bottom")
895 bottom.tap()
896 XCTAssertTrue(bottom.waitForNonExistence(timeout: 4))
897 capture(XCUIScreen.main.screenshot(), named: "\(tab) at bottom")
898 let lastText = tab == "Summary" ? "Checkpoint 28." : "Transcript paragraph 24."
899 let lastLine = app.staticTexts.containing(NSPredicate(format: "label CONTAINS %@", lastText)).firstMatch
900 let reachedBottom = XCTNSPredicateExpectation(predicate: NSPredicate { _, _ in
901 lastLine.exists && lastLine.isHittable
902 }, object: nil)
903 XCTAssertEqual(XCTWaiter.wait(for: [reachedBottom], timeout: 4), .completed, app.debugDescription)
904
905 upper.press(forDuration: 0.12, thenDragTo: lower, withVelocity: .slow, thenHoldForDuration: 0.12)
906 XCTAssertTrue(top.exists && top.isHittable)
907 XCTAssertFalse(bottom.exists)
908 XCTAssertEqual(top.frame.midY, action.frame.midY, accuracy: 1)
909 capture(XCUIScreen.main.screenshot(), named: "\(tab) jump to top")
910 top.tap()
911 XCTAssertTrue(top.waitForNonExistence(timeout: 4))
912 XCTAssertEqual(XCTWaiter.wait(for: [XCTNSPredicateExpectation(predicate: NSPredicate { _, _ in title.isHittable }, object: nil)], timeout: 4), .completed)
913 lower.press(forDuration: 0.12, thenDragTo: upper, withVelocity: .slow, thenHoldForDuration: 0.12)
914 XCTAssertTrue(bottom.exists)
915 XCTAssertTrue(bottom.waitForNonExistence(timeout: 3), "The arrow should disappear after scrolling settles")
916 upper.press(forDuration: 0.12, thenDragTo: lower, withVelocity: .slow, thenHoldForDuration: 0.12)
917 XCTAssertTrue(title.isHittable)
918 }
919 let summaryTab = app.buttons["noteDetailSummaryTab"]
920 summaryTab.tap()
921 XCTAssertTrue(summaryTab.isSelected)
922 XCTAssertFalse(app.buttons["noteDetailTranscriptTab"].isSelected)
923 XCTAssertTrue(app.staticTexts["Launch checklist"].isHittable)
924 XCTAssertTrue(app.buttons["noteDetailSummaryAskAIButton"].isHittable)
925 capture(XCUIScreen.main.screenshot(), named: "Summary tab with summary content")
926 }
927
928 @MainActor func testNoteHeaderActionsScrollWithTranscript() throws {
929 continueAfterFailure = false
930 let app = XCUIApplication()
931 let model = ProcessInfo.processInfo.environment["SIMULATOR_MODEL_IDENTIFIER"] ?? ""
932 let useLandscape = model.hasPrefix("iPad") || model.hasPrefix("iPhone18,8")
933 XCUIDevice.shared.orientation = useLandscape ? .landscapeLeft : .portrait
934 defer { XCUIDevice.shared.orientation = .portrait }
935 let transcript = (1...25).map {
936 "Paragraph \($0): Review the next steps and keep a clear record of the conversation."
937 }.joined(separator: "\n\n")
938 let fixture: [[String: Any]] = [["title": "Launch planning", "folder": "Work", "tags": [String](),
939 "transcript": transcript, "summary": ""]]
940 app.launchEnvironment["JOTLEY_SCREENSHOT_DATA"] = String(decoding: try JSONSerialization.data(withJSONObject: fixture), as: UTF8.self)
941 app.launchArguments = ["-selectedThemeColor", "Magenta", "-jotleyWelcomeCompleted.v1", "YES"]
942
943 for appearance in ["Dark", "Light"] {
944 app.launchEnvironment["JOTLEY_SCREENSHOT_APPEARANCE"] = appearance
945 app.launch()
946 let title = app.staticTexts["noteDetailTitle"]
947 if !title.exists {
948 showNotesLibrary(app)
949 let row = app.buttons.containing(.staticText, identifier: "Launch planning").firstMatch
950 XCTAssertTrue(row.waitForExistence(timeout: 15), app.debugDescription); row.tap()
951 }
952 let share = app.buttons["noteDetailShareButton"]
953 let more = app.buttons["noteDetailMoreActionsButton"]
954 XCTAssertTrue(share.waitForExistence(timeout: 10) && share.isHittable && more.isHittable)
955 let scroll = app.scrollViews.containing(.staticText, identifier: "noteDetailTitle").firstMatch
956 XCTAssertTrue(scroll.exists)
957
958 func capture(_ state: String) {
959 let shot = XCTAttachment(screenshot: XCUIScreen.main.screenshot())
960 shot.name = "Note header actions - \(appearance) - \(state)"
961 shot.lifetime = .keepAlways
962 add(shot)
963 }
964
965 capture("Top")
966 share.tap()
967 XCTAssertTrue(app.buttons["shareNoteButton"].waitForExistence(timeout: 5))
968 scroll.coordinate(withNormalizedOffset: CGVector(dx: 0.2, dy: 0.6)).tap()
969 more.tap()
970 XCTAssertTrue(app.buttons["noteDetailEditTranscriptButton"].waitForExistence(timeout: 5))
971 scroll.coordinate(withNormalizedOffset: CGVector(dx: 0.2, dy: 0.6)).tap()
972 scroll.swipeUp(velocity: .slow)
973 XCTAssertFalse(share.isHittable)
974 XCTAssertFalse(more.isHittable)
975 capture("Scrolled")
976 scroll.swipeDown(velocity: .slow)
977 XCTAssertTrue(share.isHittable && more.isHittable)
978 }
979 }
980
981 @MainActor func testTranscriptLastLineClearsFloatingControls() throws {
982 defer { XCUIDevice.shared.orientation = .portrait }
983 let app = XCUIApplication()
984 let text = (1...25).map { "Paragraph \($0): Review the next steps and keep a clear record of the conversation." }.joined(separator: "\n\n") + "\n\nFinal transcript line stays readable."
985 let fixture: [[String: Any]] = [["title": "Floating footer check", "folder": "", "tags": [], "transcript": text, "summary": "A long conversation."]]
986 app.launchEnvironment["JOTLEY_SCREENSHOT_DATA"] = String(decoding: try JSONSerialization.data(withJSONObject: fixture), as: UTF8.self)
987 for appearance in ["Light", "Dark"] {
988 XCUIDevice.shared.orientation = .portrait
989 app.launchEnvironment["JOTLEY_SCREENSHOT_APPEARANCE"] = appearance
990 app.launch()
991 let row = app.buttons.containing(.staticText, identifier: "Floating footer check").firstMatch
992 XCTAssertTrue(row.waitForExistence(timeout: 15)); row.tap()
993 app.buttons["noteDetailTranscriptTab"].tap()
994 let last = app.staticTexts.matching(NSPredicate(format: "label CONTAINS %@", "Final transcript line stays readable.")).firstMatch
995 let continueButton = app.buttons["noteDetailContinueTranscriptionButton"]
996 let content = app.scrollViews.firstMatch
997 for _ in 0..<14 {
998 if last.exists && last.isHittable && last.frame.maxY < continueButton.frame.minY - 8 { break }
999 content.swipeUp()
1000 }
1001 let hierarchy = XCTAttachment(string: app.debugDescription)
1002 hierarchy.name = "Transcript hierarchy - \(appearance)"
1003 hierarchy.lifetime = .keepAlways; add(hierarchy)
1004 for (index, screen) in XCUIScreen.screens.enumerated() {
1005 let capture = XCTAttachment(screenshot: screen.screenshot())
1006 capture.name = "Transcript screen \(index) - \(appearance)"
1007 capture.lifetime = .keepAlways; add(capture)
1008 }
1009 XCTAssertTrue(last.exists && last.isHittable)
1010 XCTAssertLessThan(last.frame.maxY, continueButton.frame.minY - 8, "The last line must scroll fully clear of the floating controls")
1011 XCTAssertTrue(continueButton.isHittable)
1012 XCTAssertEqual(continueButton.frame.height, 44, accuracy: 1)
1013 XCTAssertFalse(app.buttons["noteDetailGenerateSummaryButton"].exists)
1014 let isPhone = (ProcessInfo.processInfo.environment["SIMULATOR_MODEL_IDENTIFIER"] ?? "").hasPrefix("iPhone")
1015 let cornerButton = isPhone ? app.buttons["notesListNewNoteButton"] : continueButton
1016 XCTAssertEqual(app.frame.maxY - cornerButton.frame.maxY, isPhone ? 24 : 16, accuracy: 2)
1017 if isPhone { XCTAssertEqual(app.frame.maxX - cornerButton.frame.maxX, 24, accuracy: 2) }
1018 let screenshot = XCTAttachment(screenshot: app.screenshot())
1019 screenshot.name = "Floating controls with complete transcript - \(appearance)"
1020 screenshot.lifetime = .keepAlways; add(screenshot)
1021 }
1022 }
1023
1024 @MainActor func testSimulatedCaptureTimerMatchesElapsedTimeAndPauses() throws {
1025 XCUIDevice.shared.orientation = .portrait
1026 let app = XCUIApplication()
1027 app.launchEnvironment["JOTLEY_SCREENSHOT_DATA"] = "[]"
1028 app.launchEnvironment["JOTLEY_TEST_TRANSCRIPTION_LIFECYCLE"] = "1"
1029 app.launch()
1030 let plus = app.buttons["notesListNewNoteButton"]
1031 XCTAssertTrue(plus.waitForExistence(timeout: 15)); plus.tap()
1032 let duration = app.staticTexts["transcriptionDurationText"]
1033 XCTAssertTrue(duration.waitForExistence(timeout: 10))
1034 func seconds() -> Int {
1035 let numbers = duration.label.split(whereSeparator: { !$0.isNumber }).compactMap { Int($0) }
1036 return numbers.count == 2 ? numbers[0] * 60 + numbers[1] : -1
1037 }
1038 let before = seconds()
1039 let started = ProcessInfo.processInfo.systemUptime
1040 Thread.sleep(forTimeInterval: 3)
1041 let after = seconds()
1042 let elapsed = ProcessInfo.processInfo.systemUptime - started
1043 XCTAssertEqual(Double(after - before), elapsed, accuracy: 1.5, "Simulator capture must advance at real time")
1044 app.buttons["transcriptionPauseButton"].tap()
1045 let paused = seconds()
1046 Thread.sleep(forTimeInterval: 2)
1047 XCTAssertEqual(seconds(), paused, "Pause must freeze the timer")
1048 app.buttons["transcriptionCloseButton"].tap()
1049 XCTAssertTrue(app.staticTexts["noteDetailTitle"].waitForExistence(timeout: 10))
1050 }
1051
1052 @MainActor func testOnboardingSpeechSetupStartsOrReportsItsResult() throws {
1053 let app = XCUIApplication()
1054 app.launchArguments = ["-transcriptionLanguage", "en-US"]
1055 app.launchEnvironment["JOTLEY_SCREENSHOT_DATA"] = "[]"
1056 app.launchEnvironment["JOTLEY_TEST_ONBOARDING"] = "1"
1057 app.launchEnvironment["JOTLEY_TEST_RESET_ONBOARDING"] = "1"
1058 app.launch()
1059 XCTAssertTrue(app.buttons["onboardingContinue"].waitForExistence(timeout: 15))
1060 app.buttons["onboardingContinue"].tap()
1061 app.buttons["onboardingContinue"].tap()
1062 let setup = app.buttons["onboardingSpeechSetup"]
1063 guard setup.waitForExistence(timeout: 10) else { throw XCTSkip("This runtime does not need speech setup") }
1064 setup.tap()
1065 let activeOrFinished = NSPredicate { _, _ in
1066 app.buttons["onboardingCancelSpeechSetup"].exists ||
1067 app.descendants(matching: .any)["onboardingSpeechError"].firstMatch.exists ||
1068 app.staticTexts["Ready to transcribe offline"].exists
1069 }
1070 let changed = expectation(for: activeOrFinished, evaluatedWith: app)
1071 wait(for: [changed], timeout: 15)
1072 let capture = XCTAttachment(screenshot: app.screenshot())
1073 capture.name = "Real Apple speech setup action"; capture.lifetime = .keepAlways; add(capture)
1074 if app.buttons["onboardingCancelSpeechSetup"].exists {
1075 app.buttons["onboardingCancelSpeechSetup"].tap()
1076 XCTAssertTrue(setup.waitForExistence(timeout: 15), "Cancellation must leave setup available to retry")
1077 }
1078 }
1079
1080 @MainActor func testWelcomeSetupPersistsAndCanBeReopenedWithoutLosingNotes() throws {
1081 let isPad = (ProcessInfo.processInfo.environment["SIMULATOR_MODEL_IDENTIFIER"] ?? "").hasPrefix("iPad")
1082 XCUIDevice.shared.orientation = isPad ? .landscapeLeft : .portrait
1083 defer { XCUIDevice.shared.orientation = .portrait }
1084 let app = XCUIApplication()
1085 app.launchArguments = ["-selectedThemeColor", "Purple"]
1086 app.launchEnvironment["JOTLEY_SCREENSHOT_DATA"] = ###"[{"title":"Keep this note","folder":"","tags":[],"transcript":"Existing words remain safe while setting up Jotley.","summary":"A saved note."}]"###
1087 app.launchEnvironment["JOTLEY_TEST_ONBOARDING"] = "1"
1088 for mode in ["Dark", "Light"] {
1089 let selectedLanguage = mode == "Dark" ? "French" : "German"
1090 app.launchEnvironment["JOTLEY_SCREENSHOT_APPEARANCE"] = mode
1091 app.launchEnvironment["JOTLEY_TEST_RESET_ONBOARDING"] = "1"
1092 app.launch()
1093 let title = app.staticTexts["onboardingTitle"]
1094 XCTAssertTrue(title.waitForExistence(timeout: 15))
1095 let actionFrame = app.buttons["onboardingContinue"].frame
1096 let progressY = app.descendants(matching: .any)["onboardingProgress"].firstMatch.frame.midY
1097 for expected in ["Stay in the conversation.", "Find the useful parts.", "Start with your language.", "Give your words a place."] {
1098 XCTAssertEqual(title.label, onboardingTitle(expected, in: app))
1099 XCTAssertTrue(app.buttons["onboardingContinue"].isHittable, "The primary action must remain visible")
1100 XCTAssertLessThanOrEqual(app.buttons["onboardingContinue"].frame.maxX, app.frame.maxX - 12, "The action must fit completely inside the window")
1101 XCTAssertGreaterThanOrEqual(app.buttons["onboardingContinue"].frame.minX, app.frame.minX + 12)
1102 XCTAssertEqual(app.buttons["onboardingContinue"].frame.minY, actionFrame.minY, accuracy: 1)
1103 XCTAssertEqual(app.buttons["onboardingContinue"].frame.minX, actionFrame.minX, accuracy: 1)
1104 XCTAssertEqual(app.descendants(matching: .any)["onboardingProgress"].firstMatch.frame.midY, progressY, accuracy: 1)
1105 if expected == "Give your words a place.", app.buttons["onboardingNotNow"].exists {
1106 let secondary = app.buttons["onboardingNotNow"].frame
1107 let primary = app.buttons["onboardingContinue"].frame
1108 XCTAssertEqual(secondary.midX, primary.midX, accuracy: 1)
1109 XCTAssertGreaterThanOrEqual(secondary.minY, primary.maxY + 8)
1110 }
1111 XCTAssertEqual(app.alerts.count, 0, "No permission alert should appear without an explicit request")
1112 if expected == "Start with your language." {
1113 let picker = app.buttons["onboardingLanguagePicker"]
1114 XCTAssertTrue(picker.waitForExistence(timeout: 10))
1115 let enabled = NSPredicate(format: "enabled == true")
1116 expectation(for: enabled, evaluatedWith: picker)
1117 waitForExpectations(timeout: 15)
1118 picker.tap()
1119 for unsupported in ["Arabic", "Russian", "Hindi", "Polish", "Ukrainian"] {
1120 XCTAssertFalse(app.buttons.matching(NSPredicate(format: "label BEGINSWITH %@", unsupported)).firstMatch.exists)
1121 }
1122 XCTAssertFalse(app.buttons["English (United Kingdom)"].exists, "Regional variants must not become extra languages")
1123 let choice = app.buttons[selectedLanguage]
1124 XCTAssertTrue(choice.waitForExistence(timeout: 5))
1125 choice.tap()
1126 XCTAssertTrue(picker.label.contains(selectedLanguage))
1127 }
1128 let attachment = XCTAttachment(screenshot: XCUIScreen.main.screenshot())
1129 attachment.name = "Jotley welcome \(mode) - \(expected)"
1130 attachment.lifetime = .keepAlways; add(attachment)
1131 if expected != "Give your words a place." { app.buttons["onboardingContinue"].tap() }
1132 }
1133 if app.buttons["onboardingNotNow"].exists { app.buttons["onboardingNotNow"].tap() }
1134 else { app.buttons["onboardingContinue"].tap() }
1135 XCTAssertEqual(title.label, "Summary notifications")
1136 XCTAssertTrue(app.switches["onboardingSummaryNotificationsToggle"].isHittable)
1137 app.buttons["onboardingContinue"].tap()
1138 XCTAssertTrue(app.staticTexts["Keep this note"].waitForExistence(timeout: 8))
1139 app.terminate()
1140 app.launchEnvironment.removeValue(forKey: "JOTLEY_TEST_RESET_ONBOARDING")
1141 app.launch()
1142 let settings = app.buttons["notesListSettingsButton"]
1143 if !settings.exists {
1144 let back = app.buttons["BackButton"]
1145 if back.waitForExistence(timeout: 5) { back.tap() }
1146 else {
1147 let sidebar = app.navigationBars.buttons.matching(NSPredicate(format: "label CONTAINS[c] 'sidebar'")).firstMatch
1148 XCTAssertTrue(sidebar.waitForExistence(timeout: 5)); sidebar.tap()
1149 }
1150 }
1151 XCTAssertTrue(settings.waitForExistence(timeout: 10))
1152 XCTAssertFalse(title.exists, "Completed setup must not appear again on launch")
1153 app.buttons["notesListSettingsButton"].tap()
1154 XCTAssertTrue(app.buttons["settingsDoneButton"].waitForExistence(timeout: 8))
1155 let form = app.descendants(matching: .any)["settingsForm"].firstMatch
1156 XCTAssertTrue(form.waitForExistence(timeout: 5))
1157 let savedLanguage = app.descendants(matching: .any)["settingsLanguagePicker"].firstMatch
1158 for _ in 0..<9 {
1159 if savedLanguage.exists && savedLanguage.isHittable { break }
1160 form.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.8))
1161 .press(forDuration: 0.1, thenDragTo: form.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.45)))
1162 }
1163 XCTAssertTrue(savedLanguage.waitForExistence(timeout: 3), app.debugDescription)
1164 XCTAssertEqual(savedLanguage.value as? String, selectedLanguage, "Settings and onboarding must use the same saved language")
1165 let replay = app.buttons["settingsWelcomeJotley"]
1166 for _ in 0..<8 {
1167 if replay.isHittable { break }
1168 app.swipeUp()
1169 }
1170 XCTAssertTrue(replay.isHittable)
1171 replay.tap()
1172 XCTAssertTrue(title.waitForExistence(timeout: 5))
1173 XCTAssertEqual(title.label, onboardingTitle("Stay in the conversation.", in: app))
1174 XCTAssertFalse(app.buttons["settingsDoneButton"].exists, "Replaying welcome must dismiss Settings first")
1175 if mode == "Dark" {
1176 app.buttons["onboardingSkip"].tap()
1177 } else {
1178 for _ in 0..<5 {
1179 if app.buttons["onboardingNotNow"].exists { app.buttons["onboardingNotNow"].tap() }
1180 else { app.buttons["onboardingContinue"].tap() }
1181 }
1182 }
1183 XCTAssertTrue(app.staticTexts["Keep this note"].waitForExistence(timeout: 5))
1184 XCTAssertFalse(app.buttons["settingsDoneButton"].exists, "Finishing or skipping welcome must return to notes")
1185 app.terminate()
1186 }
1187 }
1188
1189 @MainActor func testWelcomeSkipRemainsAccessibleWithLargeTextAndYellowTheme() throws {
1190 XCUIDevice.shared.orientation = .portrait
1191 let app = XCUIApplication()
1192 app.launchArguments = ["-selectedThemeColor", "Yellow", "-UIPreferredContentSizeCategoryName", "UICTContentSizeCategoryAccessibilityXL"]
1193 app.launchEnvironment["JOTLEY_SCREENSHOT_DATA"] = "[]"
1194 app.launchEnvironment["JOTLEY_SCREENSHOT_APPEARANCE"] = "Light"
1195 app.launchEnvironment["JOTLEY_TEST_ONBOARDING"] = "1"
1196 app.launchEnvironment["JOTLEY_TEST_RESET_ONBOARDING"] = "1"
1197 app.launch()
1198 XCTAssertTrue(app.staticTexts["onboardingTitle"].waitForExistence(timeout: 15))
1199 XCTAssertTrue(app.buttons["onboardingSkip"].isHittable)
1200 XCTAssertTrue(app.buttons["onboardingContinue"].isHittable)
1201 let attachment = XCTAttachment(screenshot: XCUIScreen.main.screenshot())
1202 attachment.name = "Welcome with accessibility text and Yellow theme"
1203 attachment.lifetime = .keepAlways; add(attachment)
1204 app.buttons["onboardingSkip"].tap()
1205 XCTAssertTrue(app.buttons["notesListSettingsButton"].waitForExistence(timeout: 5))
1206 XCTAssertEqual(app.alerts.count, 0)
1207 }
1208
1209 @MainActor func testIPadSplitSelectionHighlightsOnlyTheOpenNote() throws {
1210 guard (ProcessInfo.processInfo.environment["SIMULATOR_MODEL_IDENTIFIER"] ?? "").hasPrefix("iPad") else {
1211 throw XCTSkip("Split selection requires iPad")
1212 }
1213 let app = XCUIApplication()
1214 app.launchArguments = ["-selectedThemeColor", "Purple"]
1215 app.launchEnvironment["JOTLEY_SCREENSHOT_DATA"] = ###"[{"title":"Design review","folder":"Work","tags":[],"transcript":"Maya reviews the new interface Friday.","summary":"## Next Steps\n- Review the interface."},{"title":"Garden plans","folder":"Personal","tags":[],"transcript":"Plant herbs by the kitchen window.","summary":"## Weekend\n- Plant herbs."}]"###
1216 defer { XCUIDevice.shared.orientation = .portrait }
1217
1218 func assertHighlight(_ row: XCUIElement, selected: Bool) throws {
1219 XCTAssertEqual(row.isSelected, selected)
1220 let image = try XCTUnwrap(row.screenshot().image.cgImage)
1221 let context = try XCTUnwrap(CGContext(data: nil, width: image.width, height: image.height,
1222 bitsPerComponent: 8, bytesPerRow: image.width * 4, space: CGColorSpaceCreateDeviceRGB(),
1223 bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue | CGBitmapInfo.byteOrder32Big.rawValue))
1224 context.draw(image, in: CGRect(x: 0, y: 0, width: image.width, height: image.height))
1225 let pixels = try XCTUnwrap(context.data).assumingMemoryBound(to: UInt8.self)
1226 var colored = 0
1227 for index in 0..<(image.width * image.height) {
1228 let rgb = (0..<3).map { Int(pixels[index * 4 + $0]) }
1229 if rgb.max()! - rgb.min()! > 20 { colored += 1 }
1230 }
1231 let fraction = Double(colored) / Double(image.width * image.height)
1232 XCTAssertLessThan(fraction, 0.04, "The row should keep a neutral background")
1233 if selected { XCTAssertGreaterThan(fraction, 0.001, "The open note must retain its small accent marker") }
1234 else { XCTAssertLessThan(fraction, 0.001, "The previous selection should clear its accent marker") }
1235 }
1236
1237 for orientation in [UIDeviceOrientation.landscapeLeft, .portrait] {
1238 XCUIDevice.shared.orientation = orientation
1239 for mode in ["Dark", "Light"] {
1240 app.launchEnvironment["JOTLEY_SCREENSHOT_APPEARANCE"] = mode
1241 app.launch()
1242 let first = app.buttons.containing(.staticText, identifier: "Design review").firstMatch
1243 let second = app.buttons.containing(.staticText, identifier: "Garden plans").firstMatch
1244 XCTAssertTrue(first.waitForExistence(timeout: 15)); first.tap()
1245 XCTAssertEqual(app.staticTexts["noteDetailTitle"].label, "Design review")
1246 try assertHighlight(first, selected: true); try assertHighlight(second, selected: false)
1247 second.tap()
1248 XCTAssertEqual(app.staticTexts["noteDetailTitle"].label, "Garden plans")
1249 try assertHighlight(first, selected: false); try assertHighlight(second, selected: true)
1250 app.buttons["notesListSettingsButton"].tap()
1251 let done = app.buttons["settingsDoneButton"]
1252 XCTAssertTrue(done.waitForExistence(timeout: 5)); done.tap()
1253 try assertHighlight(second, selected: true)
1254 let attachment = XCTAttachment(screenshot: XCUIScreen.main.screenshot())
1255 attachment.name = "iPad split selection and smaller gear - \(mode) \(orientation == .portrait ? "portrait" : "landscape")"
1256 attachment.lifetime = .keepAlways; add(attachment)
1257 app.terminate()
1258 }
1259 }
1260 }
1261
1262 @MainActor func testAutomaticNoteOrganizationSettingsAndFiling() throws {
1263 XCUIDevice.shared.orientation = .portrait
1264 let app = XCUIApplication()
1265 app.launchEnvironment["JOTLEY_SCREENSHOT_DATA"] = ###"[{"title":"Launch planning","folder":"","tags":[],"transcript":"Review the design for the upcoming launch and send the latest project plan to the team before Friday.","summary":""},{"title":"AI research","folder":"","tags":["AI"],"transcript":"Related work.","summary":""}]"###
1266 app.launchEnvironment["JOTLEY_SCREENSHOT_APPEARANCE"] = "Light"
1267 app.launchEnvironment["JOTLEY_TEST_SUMMARY_TAGS"] = "1"
1268 app.launchArguments = ["-selectedThemeColor", "Purple", "-jotleySummaryNotificationsEnabled", "NO",
1269 "-jotleyWelcomeCompleted.v1", "YES"]
1270 app.launch()
1271
1272 let settings = app.buttons["notesListSettingsButton"]
1273 let back = app.buttons["BackButton"]
1274 if back.waitForExistence(timeout: 3), back.isHittable { back.tap() }
1275 XCTAssertTrue(settings.waitForExistence(timeout: 15))
1276 settings.tap()
1277 let autoTags = app.switches["settingsAutoTags"]
1278 let autoFolders = app.switches["settingsAutoFolders"]
1279 XCTAssertTrue(autoTags.waitForExistence(timeout: 5))
1280 if !autoFolders.isHittable { app.swipeUp(velocity: .slow) }
1281 XCTAssertTrue(autoFolders.isHittable)
1282 func toggle(_ control: XCUIElement) {
1283 control.coordinate(withNormalizedOffset: CGVector(dx: 0.95, dy: 0.5)).tap()
1284 }
1285 if autoTags.value as? String == "0" { toggle(autoTags) }
1286 if autoFolders.value as? String == "0" { toggle(autoFolders) }
1287 XCTAssertEqual(autoTags.value as? String, "1")
1288 XCTAssertEqual(autoFolders.value as? String, "1")
1289 let settingsShot = XCTAttachment(screenshot: app.screenshot())
1290 settingsShot.name = "Auto Tags and Auto File Notes on"
1291 settingsShot.lifetime = .keepAlways; add(settingsShot)
1292 toggle(autoTags)
1293 XCTAssertEqual(autoTags.value as? String, "0")
1294 XCTAssertEqual(autoFolders.value as? String, "1")
1295 toggle(autoFolders)
1296 XCTAssertEqual(autoFolders.value as? String, "0")
1297 toggle(autoTags)
1298 toggle(autoFolders)
1299 app.buttons["settingsDoneButton"].tap()
1300
1301 if !app.staticTexts["noteDetailTitle"].exists {
1302 let row = app.buttons.containing(.staticText, identifier: "Launch planning").firstMatch
1303 XCTAssertTrue(row.waitForExistence(timeout: 5)); row.tap()
1304 }
1305 XCTAssertTrue(app.buttons["noteDetailAddTagButton"].waitForExistence(timeout: 5))
1306 let folder = app.buttons["noteDetailFolderPicker"]
1307 XCTAssertTrue(folder.label.contains("No Folder"))
1308 triggerSummaryAction(in: app)
1309 let filed = expectation(for: NSPredicate(format: "label CONTAINS %@", "Work"), evaluatedWith: folder)
1310 wait(for: [filed], timeout: 10)
1311 let tagCount = app.buttons["noteDetailTagCount"]
1312 XCTAssertTrue(tagCount.waitForExistence(timeout: 5))
1313 tagCount.tap()
1314 XCTAssertTrue(app.descendants(matching: .any)["noteDetailTag-AI"].firstMatch.waitForExistence(timeout: 5))
1315 let noteShot = XCTAttachment(screenshot: app.screenshot())
1316 noteShot.name = "Generated summary with the Work folder and automatic tags"
1317 noteShot.lifetime = .keepAlways; add(noteShot)
1318 }
1319
1320 @MainActor func testSummaryAddsThreeTagsAndLeavesTwoEditableSlots() throws {
1321 XCUIDevice.shared.orientation = .portrait
1322 let app = XCUIApplication()
1323 app.launchEnvironment["JOTLEY_SCREENSHOT_DATA"] = #"[{"title":"Untitled Note","folder":"Work","tags":[],"transcript":"AI and design guide the project research and planning.","summary":""}]"#
1324 app.launchEnvironment["JOTLEY_SCREENSHOT_APPEARANCE"] = "Light"
1325 app.launchEnvironment["JOTLEY_TEST_SUMMARY_TAGS"] = "1"
1326 app.launchArguments = ["-jotleySummaryNotificationsEnabled", "NO", "-jotleyWelcomeCompleted.v1", "YES",
1327 "-jotley.autoTags", "YES", "-selectedThemeColor", "Magenta"]
1328 app.launch()
1329 showNotesLibrary(app)
1330 let row = app.buttons.containing(.staticText, identifier: "Untitled Note").firstMatch
1331 XCTAssertTrue(row.waitForExistence(timeout: 15))
1332 row.tap()
1333 let addTag = app.buttons["noteDetailAddTagButton"]
1334 func tag(_ name: String) -> XCUIElement {
1335 app.descendants(matching: .any)["noteDetailTag-" + name].firstMatch
1336 }
1337 func capture(_ name: String) {
1338 let image = XCTAttachment(screenshot: app.screenshot())
1339 image.name = name
1340 image.lifetime = .keepAlways
1341 add(image)
1342 }
1343 let generated = ["Artificial-Intelligence", "Design", "Research"]
1344 XCTAssertTrue(addTag.waitForExistence(timeout: 5))
1345 for name in generated { XCTAssertFalse(tag(name).exists) }
1346 let templates = app.buttons["noteDetailTemplatesButton"]
1347 let generate = app.buttons["noteDetailGenerateSummaryButton"]
1348 XCTAssertTrue(templates.isHittable)
1349 XCTAssertEqual(templates.frame.height, generate.frame.height, accuracy: 1)
1350 capture("01 Transcript before summary with zero tags")
1351
1352 templates.tap()
1353 let auto = app.buttons["Auto"]
1354 XCTAssertTrue(auto.waitForExistence(timeout: 5))
1355 auto.tap()
1356 triggerSummaryAction(in: app)
1357 let tagCount = app.buttons["noteDetailTagCount"]
1358 XCTAssertTrue(tagCount.waitForExistence(timeout: 15))
1359 XCTAssertEqual(tagCount.label, "3 tags")
1360 XCTAssertFalse(tag("Research").exists)
1361 tagCount.tap()
1362 XCTAssertTrue(tag("Research").waitForExistence(timeout: 15))
1363 for name in generated { XCTAssertTrue(tag(name).exists) }
1364 XCTAssertFalse(tag("Planning").exists)
1365 XCTAssertTrue(app.staticTexts["Launch Design Plan"].exists)
1366 XCTAssertTrue(addTag.isEnabled)
1367 capture("02 Saved title and summary with three automatic tags")
1368
1369 for name in ["My-Project", "Follow-up"] {
1370 addTag.tap()
1371 let field = app.textFields["addTagTextField"]
1372 XCTAssertTrue(field.waitForExistence(timeout: 5))
1373 field.tap()
1374 field.typeText(name + "\n")
1375 XCTAssertTrue(tag(name).waitForExistence(timeout: 5))
1376 }
1377 XCTAssertFalse(addTag.isEnabled)
1378 capture("03 Both manual slots filled and five tag maximum reached")
1379 }
1380
1381 @MainActor func testNoteMetadataMatchesMacAndTagsStartCollapsed() throws {
1382 let isPad = UIDevice.current.userInterfaceIdiom == .pad
1383 XCUIDevice.shared.orientation = isPad ? .landscapeLeft : .portrait
1384 defer { XCUIDevice.shared.orientation = .portrait }
1385 let app = XCUIApplication()
1386 app.launchEnvironment["JOTLEY_SCREENSHOT_DATA"] = #"""
1387 [{"title":"Launch plan","folder":"Work","tags":["Design","Planning","Research"],
1388 "transcript":"Maya will review the launch plan and Sam will finish the accessibility checks.","summary":""},
1389 {"title":"Weekend plans","folder":"Personal","tags":["Home"],"transcript":"Pick up the groceries.","summary":""}]
1390 """#
1391 app.launchArguments = ["-jotleyWelcomeCompleted.v1", "YES", "-selectedThemeColor", "Purple"]
1392 let title = app.staticTexts["noteDetailTitle"]
1393 let folder = app.buttons["noteDetailFolderPicker"]
1394 let count = app.buttons["noteDetailTagCount"]
1395 let design = app.descendants(matching: .any)["noteDetailTag-Design"].firstMatch
1396 let add = app.buttons["noteDetailAddTagButton"]
1397 func attachment(_ name: String) {
1398 let screenshot = XCTAttachment(screenshot: XCUIScreen.main.screenshot())
1399 screenshot.name = name
1400 screenshot.lifetime = .keepAlways
1401 self.add(screenshot)
1402 }
1403 func open(_ name: String) {
1404 if title.exists && title.label == name { return }
1405 showNotesLibrary(app)
1406 let row = app.buttons.containing(.staticText, identifier: name).firstMatch
1407 XCTAssertTrue(row.waitForExistence(timeout: 10))
1408 row.tap()
1409 XCTAssertTrue(title.waitForExistence(timeout: 5))
1410 XCTAssertEqual(title.label, name)
1411 }
1412 for appearance in ["Light", "Dark"] {
1413 app.launchEnvironment["JOTLEY_SCREENSHOT_APPEARANCE"] = appearance
1414 app.launch()
1415 open("Launch plan")
1416 XCTAssertTrue(count.waitForExistence(timeout: 5))
1417 XCTAssertEqual(count.label, "3 tags")
1418 XCTAssertEqual(folder.label, "Work")
1419 XCTAssertEqual(folder.frame.midY, count.frame.midY, accuracy: 1)
1420 XCTAssertFalse(design.exists)
1421 XCTAssertFalse(add.exists)
1422 let generate = app.buttons["noteDetailGenerateSummaryButton"]
1423 let template = app.buttons["noteDetailTemplatesButton"]
1424 XCTAssertTrue(generate.isHittable && template.isHittable)
1425 XCTAssertEqual(generate.frame.height, template.frame.height, accuracy: 1)
1426 attachment("\(appearance)-collapsed")
1427 count.tap()
1428 XCTAssertTrue(design.waitForExistence(timeout: 5))
1429 XCTAssertTrue(add.isEnabled)
1430 attachment("\(appearance)-expanded")
1431 count.tap()
1432 XCTAssertTrue(design.waitForNonExistence(timeout: 5))
1433 folder.tap()
1434 let personal = app.buttons["Personal"]
1435 XCTAssertTrue(personal.waitForExistence(timeout: 5))
1436 personal.tap()
1437 let assigned = NSPredicate(format: "label == %@", "Personal")
1438 wait(for: [expectation(for: assigned, evaluatedWith: folder)], timeout: 5)
1439 count.tap()
1440 XCTAssertTrue(design.waitForExistence(timeout: 5))
1441 open("Weekend plans")
1442 XCTAssertEqual(count.label, "1 tag")
1443 XCTAssertFalse(app.descendants(matching: .any)["noteDetailTag-Home"].firstMatch.exists)
1444 app.terminate()
1445 }
1446 }
1447
1448 @MainActor func testSettingsDoneGlassRemainsNeutralAcrossThemesAndAppearances() throws {
1449 XCUIDevice.shared.orientation = .portrait
1450 let app = XCUIApplication()
1451 app.launchEnvironment["JOTLEY_SCREENSHOT_DATA"] = "[]"
1452 app.launchEnvironment["JOTLEY_SCREENSHOT_APPEARANCE"] = "Dark"
1453 app.launch()
1454 XCTAssertTrue(app.buttons["notesListSettingsButton"].waitForExistence(timeout: 15))
1455 app.buttons["notesListSettingsButton"].tap()
1456 for mode in ["Dark", "Light"] {
1457 app.descendants(matching: .any)["settingsAppearanceModePicker"].firstMatch.tap()
1458 app.buttons[mode].tap()
1459 for theme in ["Purple", "Magenta", "Orange", "Yellow", "Light Blue", "Neutral"] {
1460 app.descendants(matching: .any)["settingsThemeColorPicker"].firstMatch.tap()
1461 app.buttons[theme].tap()
1462 let done = app.buttons["settingsDoneButton"]
1463 XCTAssertTrue(done.isHittable)
1464 XCTAssertGreaterThanOrEqual(done.frame.width, 55, "Done must fit without truncating its label")
1465 let image = try XCTUnwrap(done.screenshot().image.cgImage)
1466 let context = try XCTUnwrap(CGContext(data: nil, width: image.width, height: image.height,
1467 bitsPerComponent: 8, bytesPerRow: image.width * 4, space: CGColorSpaceCreateDeviceRGB(),
1468 bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue | CGBitmapInfo.byteOrder32Big.rawValue))
1469 context.draw(image, in: CGRect(x: 0, y: 0, width: image.width, height: image.height))
1470 let pixels = try XCTUnwrap(context.data).assumingMemoryBound(to: UInt8.self)
1471 var colored = 0
1472 for index in 0..<(image.width * image.height) {
1473 let rgb = (0..<3).map { Int(pixels[index * 4 + $0]) }
1474 if rgb.max()! - rgb.min()! > 45 { colored += 1 }
1475 }
1476 let fraction = Double(colored) / Double(image.width * image.height)
1477 XCTAssertLessThan(fraction, 0.18, "Done must keep a neutral glass surface: \(mode), \(theme)")
1478 if theme == "Purple" || theme == "Magenta" {
1479 XCTAssertGreaterThan(fraction, 0.002, "Done must use the selected accent for its label: \(mode), \(theme)")
1480 }
1481 if theme == "Magenta" || theme == "Neutral" {
1482 let attachment = XCTAttachment(screenshot: app.screenshot())
1483 attachment.name = "Done with \(theme) theme - \(mode)"
1484 attachment.lifetime = .keepAlways; add(attachment)
1485 }
1486 }
1487 }
1488 app.buttons["settingsDoneButton"].tap()
1489 XCTAssertTrue(app.buttons["notesListSettingsButton"].isHittable)
1490 }
1491
1492 @MainActor func testMacStyleDateRowsStayReadableWhileScrolling() throws {
1493 guard (ProcessInfo.processInfo.environment["SIMULATOR_MODEL_IDENTIFIER"] ?? "").hasPrefix("iPad") else {
1494 throw XCTSkip("Sidebar rendering regression requires iPad")
1495 }
1496 XCUIDevice.shared.orientation = .portrait
1497 let app = XCUIApplication()
1498 app.launchEnvironment["JOTLEY_TEST_INLINE_NOTE_HEADERS"] = "1"
1499 var fixture: [[String: Any]] = []
1500 for index in 0..<48 {
1501 let dayOffset = index / 3 * 86400
1502 let minuteOffset = index % 3 * 600
1503 let sample: [String: Any] = [
1504 "title": String(format: "Readable note %02d", index), "folder": "", "tags": [String](),
1505 "transcript": "Keep every note readable while browsing earlier dates.",
1506 "summary": "## Decisions\n- Keep the sidebar sharp.",
1507 "timestampOffset": -Double(dayOffset + minuteOffset)
1508 ]
1509 fixture.append(sample)
1510 }
1511 app.launchEnvironment["JOTLEY_SCREENSHOT_DATA"] = String(decoding: try JSONSerialization.data(withJSONObject: fixture), as: UTF8.self)
1512
1513 func assertVisibleRowsAreSharp(dark: Bool) throws {
1514 let screenshot = XCUIScreen.main.screenshot()
1515 let normalized = UIGraphicsImageRenderer(size: screenshot.image.size).image { _ in
1516 screenshot.image.draw(at: .zero)
1517 }
1518 let image = try XCTUnwrap(normalized.cgImage)
1519 let context = try XCTUnwrap(CGContext(data: nil, width: image.width, height: image.height,
1520 bitsPerComponent: 8, bytesPerRow: image.width * 4,
1521 space: CGColorSpaceCreateDeviceRGB(),
1522 bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue | CGBitmapInfo.byteOrder32Big.rawValue))
1523 context.draw(image, in: CGRect(x: 0, y: 0, width: image.width, height: image.height))
1524 let pixels = try XCTUnwrap(context.data).assumingMemoryBound(to: UInt8.self)
1525 let appFrame = app.frame
1526 let scale = CGFloat(image.width) / appFrame.width
1527 let searchBottom = app.textFields["notesListSearchField"].frame.maxY
1528 let footerTop = app.buttons["notesListSettingsButton"].frame.minY
1529 let rows = app.buttons.matching(NSPredicate(format: "identifier BEGINSWITH %@", "notesListNoteRow-"))
1530 var checked = 0
1531 for row in rows.allElementsBoundByIndex {
1532 let frame = row.frame
1533 guard frame.minY > searchBottom + 8, frame.maxY < footerTop, frame.height > 35 else { continue }
1534 // Inspect title glyphs, not accessibility text: a blurred row can
1535 // still expose a perfectly readable label to VoiceOver.
1536 let title = CGRect(x: frame.minX + 12, y: frame.minY + 8,
1537 width: min(230, frame.width - 24), height: 20)
1538 var contrastingPixels = 0
1539 for y in max(0, Int((title.minY - appFrame.minY) * scale))..<min(image.height, Int((title.maxY - appFrame.minY) * scale)) {
1540 for x in max(0, Int((title.minX - appFrame.minX) * scale))..<min(image.width, Int((title.maxX - appFrame.minX) * scale)) {
1541 let offset = y * context.bytesPerRow + x * 4
1542 let r = Int(pixels[offset]), g = Int(pixels[offset + 1]), b = Int(pixels[offset + 2])
1543 if (dark ? min(r, g, b) > 185 : max(r, g, b) < 90) && max(r, g, b) - min(r, g, b) < 15 { contrastingPixels += 1 }
1544 }
1545 }
1546 if contrastingPixels <= 35 {
1547 let attachment = XCTAttachment(screenshot: screenshot)
1548 attachment.name = "Unreadable sidebar row - \(row.label)"
1549 attachment.lifetime = .keepAlways; add(attachment)
1550 }
1551 XCTAssertGreaterThan(contrastingPixels, 35, "Visible note title must remain sharp: \(row.label), frame \(frame), app \(appFrame), image \(image.width)x\(image.height), orientation \(screenshot.image.imageOrientation.rawValue)")
1552 checked += 1
1553 }
1554 XCTAssertGreaterThan(checked, 2, "Must inspect several visible note rows")
1555 }
1556
1557 for mode in ["Dark", "Light"] {
1558 app.launchEnvironment["JOTLEY_SCREENSHOT_APPEARANCE"] = mode
1559 app.launch()
1560 XCTAssertTrue(app.textFields["notesListSearchField"].waitForExistence(timeout: 15))
1561 let list = app.collectionViews.firstMatch
1562 XCTAssertTrue(list.waitForExistence(timeout: 5))
1563 for _ in 0..<4 { list.swipeUp(); try assertVisibleRowsAreSharp(dark: mode == "Dark") }
1564 for _ in 0..<3 { list.swipeDown(); try assertVisibleRowsAreSharp(dark: mode == "Dark") }
1565 let row = app.buttons.matching(NSPredicate(format: "identifier BEGINSWITH %@", "notesListNoteRow-")).allElementsBoundByIndex.first { $0.isHittable }
1566 try XCTUnwrap(row).tap()
1567 XCTAssertTrue(app.staticTexts["noteDetailTitle"].waitForExistence(timeout: 5))
1568 try assertVisibleRowsAreSharp(dark: mode == "Dark")
1569 let attachment = XCTAttachment(screenshot: app.screenshot())
1570 attachment.name = "Mac-style date rows after scrolling - \(mode)"
1571 attachment.lifetime = .keepAlways; add(attachment)
1572 app.terminate()
1573 }
1574 }
1575
1576 @MainActor func testSettingsPlacementKeepsIPadWindowControlsClear() throws {
1577 let permission = XCUIApplication(bundleIdentifier: "com.apple.springboard").alerts.firstMatch
1578 if permission.exists, permission.label.contains("Jotley"), permission.buttons["Allow"].exists {
1579 permission.buttons["Allow"].tap()
1580 }
1581 let app = XCUIApplication()
1582 app.launchArguments = ["-selectedThemeColor", "Purple"]
1583 let isPad = (ProcessInfo.processInfo.environment["SIMULATOR_MODEL_IDENTIFIER"] ?? "").hasPrefix("iPad")
1584 defer { XCUIDevice.shared.orientation = .portrait }
1585 app.launchEnvironment["JOTLEY_SCREENSHOT_DATA"] = ###"[{"title":"Weekly Design Review","folder":"Work","tags":["design","meeting"],"transcript":"Keep live transcription simple. Maya will test the next build on Friday.","summary":"## Key Decisions\n- Keep live transcription simple.\n- Make Settings easy to reach in every iPad window.\n\n## Next Steps\n- Maya: test the transcription flow.\n- Alex: review the summary templates.\n\n## Next Check-in\nFriday at 10:00. Bring one useful summary and one idea to simplify the experience."},{"title":"Lecture: Working Memory","folder":"Study","tags":[],"transcript":"Group related ideas and write down the next step.","summary":"## Main Ideas\n- Group related ideas.\n- Write down the next step."},{"title":"Weekend Ideas","folder":"Personal","tags":[],"transcript":"Walk the river trail. Try a new recipe.","summary":""}]"###
1586 let orientations: [UIDeviceOrientation] = isPad ? [.landscapeLeft, .portrait] : [.portrait]
1587 for orientation in orientations {
1588 XCUIDevice.shared.orientation = orientation
1589 for mode in ["Dark", "Light"] {
1590 app.terminate()
1591 app.launchEnvironment["JOTLEY_SCREENSHOT_APPEARANCE"] = mode
1592 app.launch()
1593 let settings = app.buttons["notesListSettingsButton"]
1594 let search = app.textFields["notesListSearchField"]
1595 let plus = app.buttons["notesListNewNoteButton"]
1596 XCTAssertTrue(settings.waitForExistence(timeout: 15))
1597 XCTAssertTrue(search.isHittable && plus.isHittable && settings.isHittable)
1598 XCTAssertEqual(app.buttons.matching(identifier: "notesListSettingsButton").count, 1)
1599 if isPad {
1600 XCTAssertGreaterThan(settings.frame.minY, search.frame.maxY + 200)
1601 XCTAssertEqual(settings.frame.midY, plus.frame.midY, accuracy: 1)
1602 XCTAssertLessThan(settings.frame.maxX, plus.frame.minX)
1603 let navigationBar = app.navigationBars.firstMatch
1604 XCTAssertTrue(navigationBar.exists, "Native navigation chrome must reserve space for iPad window controls")
1605 XCTAssertGreaterThanOrEqual(search.frame.minY + 1, navigationBar.frame.maxY)
1606 let row = app.buttons.containing(.staticText, identifier: "Weekly Design Review").firstMatch
1607 XCTAssertTrue(row.waitForExistence(timeout: 5)); row.tap()
1608 XCTAssertTrue(app.staticTexts["noteDetailTitle"].waitForExistence(timeout: 5))
1609 XCTAssertTrue(settings.isHittable)
1610 } else {
1611 XCTAssertGreaterThan(settings.frame.minY, search.frame.maxY + 200)
1612 XCTAssertEqual(settings.frame.midY, plus.frame.midY, accuracy: 1)
1613 XCTAssertEqual(settings.frame.minX - app.frame.minX, 20, accuracy: 1)
1614 }
1615 let attachment = XCTAttachment(screenshot: XCUIScreen.main.screenshot())
1616 attachment.name = "iPad Settings placement \(orientation == .portrait ? "portrait" : "landscape") \(mode)"
1617 attachment.lifetime = .keepAlways; add(attachment)
1618 // Hit the full target, including padding beyond the smaller visible iPad circle.
1619 for point in [CGVector(dx: 0.05, dy: 0.5), CGVector(dx: 0.95, dy: 0.5),
1620 CGVector(dx: 0.5, dy: 0.05), CGVector(dx: 0.5, dy: 0.95)] {
1621 settings.coordinate(withNormalizedOffset: point).tap()
1622 let done = app.buttons["settingsDoneButton"]
1623 XCTAssertTrue(done.waitForExistence(timeout: 5), "The entire Settings circle must intercept taps")
1624 done.tap()
1625 XCTAssertTrue(settings.waitForExistence(timeout: 5)); XCTAssertTrue(settings.isHittable)
1626 }
1627 }
1628 }
1629 }
1630
1631 @MainActor func testIPadSettingsInResizedWindowPreview() throws {
1632 guard (ProcessInfo.processInfo.environment["SIMULATOR_MODEL_IDENTIFIER"] ?? "").hasPrefix("iPad") else {
1633 throw XCTSkip("iPad window management only")
1634 }
1635 XCUIDevice.shared.orientation = .landscapeLeft
1636 defer { XCUIDevice.shared.orientation = .portrait }
1637 let app = XCUIApplication()
1638 app.launchArguments = ["-selectedThemeColor", "Purple"]
1639 app.launchEnvironment["JOTLEY_SCREENSHOT_APPEARANCE"] = "Dark"
1640 app.launchEnvironment["JOTLEY_SCREENSHOT_DATA"] = ###"[{"title":"Weekly Design Review","folder":"Work","tags":["design"],"transcript":"Keep live transcription simple.","summary":"## Key Decisions\n- Keep live transcription simple.\n- Make Settings easy to reach in every iPad window.\n\n## Next Steps\n- Maya: test the transcription flow.\n- Alex: review the summary templates."}]"###
1641 app.launch()
1642 let settings = app.buttons["notesListSettingsButton"]
1643 XCTAssertTrue(settings.waitForExistence(timeout: 15))
1644 let fullScreenWidth = max(UIScreen.main.bounds.width, UIScreen.main.bounds.height)
1645 func maximizeWindow() {
1646 guard app.windows.firstMatch.frame.width < fullScreenWidth - 40 else { return }
1647 app.navigationBars.firstMatch.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).doubleTap()
1648 let expanded = expectation(for: NSPredicate { _, _ in app.windows.firstMatch.frame.width > fullScreenWidth - 40 }, evaluatedWith: nil)
1649 XCTAssertEqual(XCTWaiter.wait(for: [expanded], timeout: 5), .completed, "Return the simulator to full screen after window testing")
1650 }
1651 maximizeWindow()
1652 defer { maximizeWindow() }
1653 let row = app.buttons.containing(.staticText, identifier: "Weekly Design Review").firstMatch
1654 XCTAssertTrue(row.waitForExistence(timeout: 5)); row.tap()
1655 let before = app.windows.firstMatch.frame
1656 // The iPad window manager owns the curved resize handle at this corner.
1657 app.coordinate(withNormalizedOffset: CGVector(dx: 0.993, dy: 0.993))
1658 .press(forDuration: 0.5, thenDragTo: app.coordinate(withNormalizedOffset: CGVector(dx: 0.9, dy: 0.88)))
1659 let resized = expectation(for: NSPredicate { _, _ in app.windows.firstMatch.frame.width < before.width - 40 }, evaluatedWith: nil)
1660 guard XCTWaiter.wait(for: [resized], timeout: 5) == .completed else {
1661 let attachment = XCTAttachment(screenshot: XCUIScreen.main.screenshot())
1662 attachment.name = "Window resize unavailable in Simulator"; attachment.lifetime = .keepAlways; add(attachment)
1663 throw XCTSkip("Simulator window manager did not expose a resizable app window")
1664 }
1665 app.activate()
1666 let search = app.textFields["notesListSearchField"]
1667 if !search.isHittable {
1668 let sidebar = app.navigationBars.buttons.matching(NSPredicate(format: "label CONTAINS[c] 'sidebar'")).firstMatch
1669 if sidebar.exists { sidebar.tap() }
1670 }
1671 let ready = expectation(for: NSPredicate { _, _ in settings.isHittable && search.isHittable }, evaluatedWith: nil)
1672 XCTAssertEqual(XCTWaiter.wait(for: [ready], timeout: 10), .completed, app.debugDescription)
1673 XCTAssertGreaterThan(settings.frame.minY, search.frame.maxY + 100)
1674 let attachment = XCTAttachment(screenshot: XCUIScreen.main.screenshot())
1675 attachment.name = "iPad Settings resized window Dark"; attachment.lifetime = .keepAlways; add(attachment)
1676 settings.tap()
1677 XCTAssertTrue(app.buttons["settingsDoneButton"].waitForExistence(timeout: 5))
1678 app.buttons["settingsDoneButton"].tap()
1679 }
1680
1681 @MainActor func testMobileSheetDonePlacementAndDarkActionContrast() throws {
1682 let app = XCUIApplication()
1683 app.launchEnvironment["JOTLEY_SCREENSHOT_DATA"] = ##"[{"title":"Readable actions","folder":"Work","tags":["design"],"transcript":"Maya will test the new interface.","summary":"# Next Steps\n- Test the sheets in both appearances."}]"##
1684 app.launchEnvironment["JOTLEY_SCREENSHOT_APPEARANCE"] = "Dark"
1685 app.launch()
1686
1687 func capture(_ name: String) {
1688 let attachment = XCTAttachment(screenshot: app.screenshot())
1689 attachment.name = name; attachment.lifetime = .keepAlways; add(attachment)
1690 }
1691 func assertTopRightDone(_ id: String) {
1692 let done = app.buttons[id]
1693 XCTAssertTrue(done.waitForExistence(timeout: 5), app.debugDescription)
1694 XCTAssertTrue(done.isHittable)
1695 XCTAssertEqual(done.label, "Done")
1696 // Sheets may be centered on iPad; compare with their own title/header.
1697 let surface = app.windows.firstMatch.frame
1698 XCTAssertGreaterThan(done.frame.midX, surface.midX)
1699 // Native toolbar accessibility frames describe the glass capsule, not its enclosing touch target.
1700 XCTAssertGreaterThanOrEqual(done.frame.height, 32)
1701 XCTAssertEqual(app.buttons.matching(NSPredicate(format: "label == 'Done'")).count, 1)
1702 }
1703 func assertTextContrast(_ id: String, lightText: Bool = true, themed: Bool = false) throws {
1704 let element = app.descendants(matching: .any)[id].firstMatch
1705 XCTAssertTrue(element.waitForExistence(timeout: 5)); XCTAssertTrue(element.isHittable)
1706 let image = try XCTUnwrap(element.screenshot().image.cgImage)
1707 let context = try XCTUnwrap(CGContext(data: nil, width: image.width, height: image.height,
1708 bitsPerComponent: 8, bytesPerRow: image.width * 4, space: CGColorSpaceCreateDeviceRGB(),
1709 bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue | CGBitmapInfo.byteOrder32Big.rawValue))
1710 context.draw(image, in: CGRect(x: 0, y: 0, width: image.width, height: image.height))
1711 let pixels = try XCTUnwrap(context.data).assumingMemoryBound(to: UInt8.self)
1712 var matchingPixels = 0
1713 let startX = lightText ? 0 : image.width * 7 / 10
1714 for y in 0..<image.height {
1715 for x in startX..<image.width {
1716 let offset = y * context.bytesPerRow + x * 4
1717 let r = Int(pixels[offset]), g = Int(pixels[offset + 1]), b = Int(pixels[offset + 2])
1718 if themed {
1719 if max(r, g, b) > 195 && max(r, g, b) - min(r, g, b) > 30 { matchingPixels += 1 }
1720 } else if (lightText ? min(r, g, b) > 185 : max(r, g, b) < 120) && max(r, g, b) - min(r, g, b) < 12 {
1721 matchingPixels += 1
1722 }
1723 }
1724 }
1725 XCTAssertGreaterThan(matchingPixels, 20, "Action text must have contrast in the selected appearance: \(id)")
1726 }
1727 for (index, mode) in ["Dark", "Light", "Dark"].enumerated() {
1728 app.buttons["notesListSettingsButton"].tap()
1729 let picker = app.descendants(matching: .any)["settingsAppearanceModePicker"].firstMatch
1730 XCTAssertTrue(picker.waitForExistence(timeout: 5)); picker.tap(); app.buttons[mode].tap()
1731 let themePicker = app.descendants(matching: .any)["settingsThemeColorPicker"].firstMatch
1732 themePicker.tap(); app.buttons[index == 2 ? "Orange" : "Purple"].tap()
1733 assertTopRightDone("settingsDoneButton")
1734 if mode == "Dark" {
1735 // The centered iPad sheet can place the links below the visible form.
1736 let start = app.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.72))
1737 let end = app.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.48))
1738 start.press(forDuration: 0.05, thenDragTo: end)
1739 try assertTextContrast("settingsMacDownloadLink", themed: true)
1740 try assertTextContrast("settingsShareMacDownloadLink", themed: true)
1741 try assertTextContrast("settingsDoneButton", themed: true)
1742 } else {
1743 try assertTextContrast("settingsAppearanceModePicker", lightText: false)
1744 try assertTextContrast("settingsThemeColorPicker", lightText: false)
1745 }
1746 capture("360 Settings \(mode) \(index == 2 ? "Orange" : "Purple")")
1747 app.buttons["settingsDoneButton"].tap()
1748
1749 app.buttons["notesListFolderDrawerButton"].tap()
1750 assertTopRightDone("folderDrawerDoneButton")
1751 if mode == "Dark" { try assertTextContrast("folderDrawerDoneButton", themed: true) }
1752 capture("360 Folders \(mode)")
1753 app.buttons["folderDrawerManageButton"].tap()
1754 assertTopRightDone("folderManagementDoneButton")
1755 capture("360 Manage Folders \(mode)")
1756 app.buttons["folderManagementDoneButton"].tap()
1757
1758 app.buttons["notesListTagFilterButton"].tap()
1759 assertTopRightDone("filterSortDoneButton")
1760 let done = app.buttons["filterSortDoneButton"]
1761 let sort = app.descendants(matching: .any)["filterSortPicker"].firstMatch
1762 XCTAssertTrue(sort.waitForExistence(timeout: 5))
1763 XCTAssertLessThan(done.frame.maxY, sort.frame.minY)
1764 if mode == "Dark" {
1765 try assertTextContrast("filterSortPicker")
1766 try assertTextContrast("filterSortDoneButton", themed: true)
1767 }
1768 capture("360 Filter and Sort \(mode)")
1769 done.tap()
1770 }
1771 let row = app.buttons.containing(.staticText, identifier: "Readable actions").firstMatch
1772 XCTAssertTrue(row.waitForExistence(timeout: 5)); row.tap()
1773 let ask = app.buttons["noteDetailSummaryAskAIButton"]
1774 XCTAssertTrue(ask.waitForExistence(timeout: 5)); try assertTextContrast("noteDetailSummaryAskAIButton", themed: true)
1775 capture("360 Summary actions Dark")
1776 ask.tap()
1777 assertTopRightDone("askAIDoneButton")
1778 capture("360 Ask AI Done Dark")
1779 app.buttons["askAIDoneButton"].tap()
1780 app.buttons["Transcript"].tap()
1781 try assertTextContrast("noteDetailContinueTranscriptionButton", themed: true)
1782 capture("360 Transcript actions Dark")
1783 }
1784
1785 @MainActor func testStreamingSummaryFollowsBottomAndPinsCancelGeneration() throws {
1786 let app = XCUIApplication()
1787 app.launchEnvironment["JOTLEY_SCREENSHOT_DATA"] = ##"[{"title":"Summary scrolling","folder":"","tags":[],"transcript":"Maya reviews milestones Friday. Sam tests the next steps.","summary":"Existing summary remains after Cancel."}]"##
1788 app.launchEnvironment["JOTLEY_TEST_SUMMARY_SCROLL"] = "1"
1789 app.launchEnvironment["JOTLEY_TEST_SUMMARY_SCROLL_HOLD"] = "1"
1790 app.launch()
1791 showNotesLibrary(app)
1792 let row = app.buttons.matching(NSPredicate(format: "identifier BEGINSWITH 'notesListNoteRow-'")).firstMatch
1793 XCTAssertTrue(row.waitForExistence(timeout: 15)); row.tap()
1794 triggerSummaryAction(in: app)
1795 let cancel = app.buttons["noteDetailCancelGenerationButton"]
1796 XCTAssertTrue(cancel.waitForExistence(timeout: 10)); XCTAssertTrue(cancel.isHittable)
1797 XCTAssertEqual(cancel.frame.height, 44, accuracy: 1)
1798 XCTAssertTrue(app.staticTexts["Preparing summary"].exists)
1799 XCTAssertFalse(app.alerts.firstMatch.exists)
1800 let preparing = XCTAttachment(screenshot: app.screenshot())
1801 preparing.name = "Visible summary preparation before first words"; preparing.lifetime = .keepAlways; add(preparing)
1802 let latest = app.staticTexts.matching(NSPredicate(format: "label == 'Summary update 18'")).firstMatch
1803 XCTAssertTrue(latest.waitForExistence(timeout: 10)); XCTAssertTrue(latest.isHittable)
1804 XCTAssertTrue(cancel.isHittable)
1805 XCTAssertLessThan(latest.frame.maxY, cancel.frame.minY)
1806 XCTAssertLessThanOrEqual(cancel.frame.maxY, app.frame.maxY)
1807 let screenshot = XCTAttachment(screenshot: app.screenshot())
1808 screenshot.name = "Summary follows latest words with pinned Cancel Generation"; screenshot.lifetime = .keepAlways; add(screenshot)
1809 cancel.tap()
1810 let stopped = expectation(for: NSPredicate(format: "exists == false"), evaluatedWith: cancel)
1811 wait(for: [stopped], timeout: 10)
1812 XCTAssertTrue(app.staticTexts["Existing summary remains after Cancel."].exists)
1813 XCTAssertTrue(app.buttons["noteDetailSummaryAskAIButton"].isEnabled)
1814 XCTAssertFalse(app.staticTexts["Summary update 25"].waitForExistence(timeout: 2))
1815 }
1816
1817 @MainActor func testNarrowNoteWrapsFiveTagsAndKeepsSummaryBadgesBelowText() throws {
1818 XCUIDevice.shared.orientation = .portrait
1819 let app = XCUIApplication()
1820 let tags = ["Design-Process", "Prototyping", "Touch-Interaction", "UI-Design", "User-Experience"]
1821 let body = "Currently centered above prototypes, this layout may feel less visible due to the tight left panel."
1822 let fixture: [[String: Any]] = [["title": "Design review", "folder": "Jotley", "tags": tags,
1823 "transcript": "Reviewed prototype spacing.", "summary": "## Open Questions\n- **Intern’s line placement:** \(body)"]]
1824 app.launchEnvironment["JOTLEY_SCREENSHOT_DATA"] = String(decoding: try JSONSerialization.data(withJSONObject: fixture), as: UTF8.self)
1825 app.launchEnvironment["JOTLEY_SCREENSHOT_APPEARANCE"] = "Light"
1826 app.launchArguments = ["-selectedThemeColor", "Magenta"]
1827 app.launch()
1828 if !app.staticTexts["noteDetailTitle"].waitForExistence(timeout: 5) {
1829 let note = app.staticTexts["Design review"].firstMatch
1830 XCTAssertTrue(note.waitForExistence(timeout: 8)); note.tap()
1831 }
1832 let tagCount = app.buttons["noteDetailTagCount"]
1833 XCTAssertTrue(tagCount.waitForExistence(timeout: 5))
1834 XCTAssertEqual(tagCount.label, "5 tags")
1835 XCTAssertFalse(app.staticTexts[tags[0]].exists)
1836 tagCount.tap()
1837 let first = app.staticTexts[tags[0]]
1838 let last = app.staticTexts[tags[4]]
1839 XCTAssertTrue(first.waitForExistence(timeout: 5))
1840 XCTAssertTrue(last.isHittable)
1841 XCTAssertGreaterThan(last.frame.minY, first.frame.minY)
1842 let addButton = app.buttons["noteDetailAddTagButton"]
1843 XCTAssertFalse(addButton.isEnabled)
1844 let attachment = XCTAttachment(screenshot: app.screenshot())
1845 attachment.name = "Wrapped magenta tags and stacked summary badge"
1846 attachment.lifetime = .keepAlways; add(attachment)
1847 first.tap()
1848 let remove = app.buttons["Remove \(tags[0])"]
1849 XCTAssertTrue(remove.waitForExistence(timeout: 5)); remove.tap()
1850 XCTAssertTrue(addButton.isEnabled)
1851 }
1852
1853 @MainActor func testSummaryContinuesAfterLeavingNoteAndBackgroundingApp() throws {
1854 let app = XCUIApplication()
1855 app.launchEnvironment["JOTLEY_SCREENSHOT_DATA"] = ##"[{"title":"Background summary","folder":"","tags":[],"transcript":"Maya reviews Friday.","summary":"Existing summary"}]"##
1856 app.launchEnvironment["JOTLEY_TEST_SUMMARY_SCROLL"] = "1"
1857 app.launch()
1858 let row = app.buttons.matching(NSPredicate(format: "identifier BEGINSWITH 'notesListNoteRow-'")).firstMatch
1859 XCTAssertTrue(row.waitForExistence(timeout: 15)); row.tap()
1860 triggerSummaryAction(in: app)
1861 XCTAssertTrue(app.buttons["noteDetailCancelGenerationButton"].waitForExistence(timeout: 10))
1862 XCUIDevice.shared.press(.home)
1863 Thread.sleep(forTimeInterval: 6)
1864 app.activate()
1865 let cancel = app.buttons["noteDetailCancelGenerationButton"]
1866 XCTAssertTrue(cancel.waitForExistence(timeout: 10))
1867 XCTAssertFalse(app.alerts.firstMatch.exists)
1868 XCTAssertTrue(app.staticTexts.matching(NSPredicate(format: "label BEGINSWITH 'Summary update '")).firstMatch.waitForExistence(timeout: 5))
1869 let back = app.navigationBars.buttons.matching(NSPredicate(format: "label IN {'Back', 'Notes'}")).firstMatch
1870 XCTAssertTrue(back.exists); back.tap()
1871 XCTAssertTrue(row.waitForExistence(timeout: 5)); row.tap()
1872 XCTAssertTrue(cancel.waitForExistence(timeout: 5))
1873 let shot = XCTAttachment(screenshot: app.screenshot())
1874 shot.name = "Summary continues after app background and note navigation"; shot.lifetime = .keepAlways; add(shot)
1875 cancel.tap()
1876 let stopped = expectation(for: NSPredicate(format: "exists == false"), evaluatedWith: cancel)
1877 wait(for: [stopped], timeout: 10)
1878 XCTAssertTrue(app.staticTexts["Existing summary"].exists)
1879 }
1880
1881 #if DEBUG
1882
1883 @MainActor func testSummaryAskAIAndTranscriptFooterWithReadableAnswerActions() throws {
1884 guard case .available = SystemLanguageModel.default.availability else {
1885 throw XCTSkip("Apple model is not ready in this simulator")
1886 }
1887 let app = XCUIApplication()
1888 app.launchArguments = ["-transcriptionLanguage", "en-US"]
1889 app.launchEnvironment["JOTLEY_SCREENSHOT_APPEARANCE"] = "Dark"
1890 app.launchEnvironment["JOTLEY_SCREENSHOT_DATA"] = ##"[{"title":"Weekly Design Review","folder":"Work","tags":[],"transcript":"We agreed to keep live transcription simple. Maya will test the microphone on Friday. Sam will review summary templates on Monday.","summary":"# Key Decisions\nKeep live transcription simple.\n\n## Next Steps\n- Maya: test the microphone on Friday.\n- Sam: review summary templates on Monday."}]"##
1891 app.launch()
1892 let row = app.buttons.containing(.staticText, identifier: "Weekly Design Review").firstMatch
1893 XCTAssertTrue(row.waitForExistence(timeout: 15)); row.tap()
1894 let ask = app.buttons["noteDetailSummaryAskAIButton"]
1895 let resume = app.buttons["noteDetailContinueTranscriptionButton"]
1896 XCTAssertTrue(ask.waitForExistence(timeout: 5)); XCTAssertFalse(resume.exists)
1897 for _ in 0..<2 {
1898 app.buttons["noteDetailTranscriptTab"].tap()
1899 XCTAssertTrue(resume.waitForExistence(timeout: 5)); XCTAssertFalse(ask.exists)
1900 app.buttons["noteDetailSummaryTab"].tap()
1901 XCTAssertTrue(ask.waitForExistence(timeout: 5)); XCTAssertFalse(resume.exists)
1902 XCTAssertFalse(app.buttons["noteDetailTemplatesButton"].exists)
1903 XCTAssertFalse(app.buttons["noteDetailGenerateSummaryButton"].exists)
1904 }
1905 let footer = XCTAttachment(screenshot: app.screenshot())
1906 footer.name = "Summary tab with contextual Ask AI"; footer.lifetime = .keepAlways; add(footer)
1907 ask.tap()
1908 let question = app.textViews["askAIQuestionField"]
1909 XCTAssertTrue(question.waitForExistence(timeout: 10))
1910 app.buttons["List any action items"].tap()
1911 let send = app.buttons["askAISendButton"]
1912 XCTAssertEqual(question.frame.midY, send.frame.midY, accuracy: 2, "Send arrow should be centered beside its input")
1913 XCTAssertTrue(app.staticTexts["List any action items"].waitForExistence(timeout: 5))
1914 XCTAssertNotEqual(question.value as? String, "List any action items")
1915 let copy = app.buttons["askAICopyConversationButton"]
1916 let share = app.buttons["askAIShareConversationButton"]
1917 let done = app.buttons["askAIDoneButton"]
1918 XCTAssertGreaterThan(done.frame.minX, share.frame.midX)
1919 XCTAssertGreaterThan(done.frame.minX, app.buttons["askAIClearButton"].frame.midX)
1920 let answered = expectation(for: NSPredicate(format: "enabled == YES"), evaluatedWith: copy)
1921 wait(for: [answered], timeout: 90)
1922 XCTAssertFalse(app.buttons["askAICopyAnswerButton"].exists, "Answers no longer carry their own Copy/Share")
1923 for button in [copy, share] {
1924 XCTAssertTrue(button.isHittable)
1925 XCTAssertGreaterThanOrEqual(button.frame.height, 44)
1926 XCTAssertGreaterThanOrEqual(button.frame.width, 44)
1927 }
1928 let actions = XCTAttachment(screenshot: app.screenshot())
1929 actions.name = "Ask AI conversation Copy and Share"; actions.lifetime = .keepAlways; add(actions)
1930 copy.tap()
1931 XCTAssertTrue(share.isHittable)
1932 XCTAssertTrue(app.buttons["askAIDoneButton"].waitForExistence(timeout: 5))
1933 app.buttons["askAIDoneButton"].tap()
1934 XCTAssertTrue(ask.waitForExistence(timeout: 5))
1935 let returnedToNote = expectation(for: NSPredicate(format: "hittable == YES"), evaluatedWith: ask)
1936 wait(for: [returnedToNote], timeout: 5)
1937 app.buttons["noteDetailTranscriptTab"].tap()
1938 XCTAssertTrue(resume.waitForExistence(timeout: 5)); XCTAssertFalse(ask.exists)
1939 app.buttons["noteDetailSummaryTab"].tap()
1940 XCTAssertTrue(ask.waitForExistence(timeout: 5)); ask.tap()
1941 XCTAssertTrue(share.waitForExistence(timeout: 10))
1942 share.tap()
1943 let nativeCopy = app.cells["Copy"]
1944 XCTAssertTrue(nativeCopy.waitForExistence(timeout: 10), app.debugDescription)
1945 // Verify the native local-sharing action without sending to another person.
1946 nativeCopy.tap()
1947 }
1948 @MainActor func testLongTranscriptShowsRealPreparationAndSavesActualSummary() throws {
1949 guard case .available = SystemLanguageModel.default.availability else {
1950 throw XCTSkip("Apple summary model is not ready in this simulator")
1951 }
1952 let app = XCUIApplication()
1953 let transcript = Array(repeating: "Maya owns accessibility testing for the native notes app. Sam will check that transcripts remain on the device. The team agreed to review the completed checklist on Friday and keep all features free.", count: 192).joined(separator: "\n\n")
1954 let fixture = [["title": "Weekly accessibility review", "folder": "Work", "tags": ["meeting"], "transcript": transcript, "summary": ""]] as [[String: Any]]
1955 app.launchEnvironment["JOTLEY_SCREENSHOT_DATA"] = String(decoding: try JSONSerialization.data(withJSONObject: fixture), as: UTF8.self)
1956 app.launchArguments = ["-transcriptionLanguage", "en-US", "-selectedAppearanceMode", "Dark"]
1957 app.launch()
1958 let row = app.buttons.matching(NSPredicate(format: "identifier BEGINSWITH 'notesListNoteRow-'")).firstMatch
1959 XCTAssertTrue(row.waitForExistence(timeout: 15)); row.tap()
1960 let generate = app.buttons["noteDetailGenerateSummaryButton"]
1961 generate.tap()
1962 XCTAssertTrue(app.staticTexts["Reading transcript"].waitForExistence(timeout: 10))
1963 XCTAssertTrue(app.buttons["noteDetailCancelGenerationButton"].isHittable)
1964 XCTAssertFalse(app.alerts.firstMatch.exists)
1965 let preparation = XCTAttachment(screenshot: app.screenshot())
1966 preparation.name = "Actual long transcript preparation with section progress"; preparation.lifetime = .keepAlways; add(preparation)
1967 XCUIDevice.shared.press(.home)
1968 Thread.sleep(forTimeInterval: 4)
1969 app.activate()
1970 XCTAssertFalse(app.alerts.firstMatch.exists)
1971 let finished = expectation(for: NSPredicate(format: "exists == true AND enabled == true"), evaluatedWith: generate)
1972 wait(for: [finished], timeout: 90)
1973 XCTAssertFalse(app.buttons["noteDetailCancelGenerationButton"].exists)
1974 XCTAssertTrue(app.descendants(matching: .any)["noteDetailSummaryContent"].exists)
1975 XCTAssertTrue(app.staticTexts.matching(NSPredicate(format: "label CONTAINS[c] 'Maya'")).firstMatch.exists)
1976 XCTAssertFalse(app.alerts.firstMatch.exists, app.debugDescription)
1977 let completed = XCTAttachment(screenshot: app.screenshot())
1978 completed.name = "Actual long transcript summary completed"; completed.lifetime = .keepAlways; add(completed)
1979 }
1980 #endif
1981
1982 @MainActor func testLiveTranscriptFillsFromTopThenFollowsBottom() throws {
1983 XCUIDevice.shared.orientation = .portrait
1984 let app = XCUIApplication()
1985 app.launchEnvironment["JOTLEY_SCREENSHOT_DATA"] = "[]"
1986 app.launchEnvironment["JOTLEY_TEST_TRANSCRIPTION_LIFECYCLE"] = "layout"
1987 app.launchEnvironment["JOTLEY_SCREENSHOT_APPEARANCE"] =
1988 ProcessInfo.processInfo.environment["SIMULATOR_MODEL_IDENTIFIER"]?.hasPrefix("iPad") == true ? "Light" : "Dark"
1989 app.launch()
1990 let plus = app.buttons["notesListNewNoteButton"]
1991 XCTAssertTrue(plus.waitForExistence(timeout: 15)); plus.tap()
1992 let viewport = app.scrollViews["liveTranscript"]
1993 XCTAssertTrue(viewport.waitForExistence(timeout: 10))
1994 let first = viewport.staticTexts["First spoken words."].firstMatch
1995 XCTAssertTrue(first.waitForExistence(timeout: 10))
1996 let sheetTop = app.buttons["transcriptionCloseButton"].frame.minY
1997 let minimumTranscriptHeight = (viewport.frame.maxY - sheetTop) * 0.48
1998 let roomyViewport = XCTNSPredicateExpectation(
1999 predicate: NSPredicate { _, _ in viewport.frame.height > minimumTranscriptHeight }, object: nil)
2000 let layout = XCTAttachment(screenshot: app.screenshot()); layout.name = "Live capture viewport"; layout.lifetime = .keepAlways; add(layout)
2001 wait(for: [roomyViewport], timeout: 10)
2002 XCTAssertGreaterThan(viewport.frame.height, minimumTranscriptHeight,
2003 "The live transcript should have nearly half the sheet or more")
2004 let firstY = first.frame.minY
2005 XCTAssertGreaterThanOrEqual(firstY, viewport.frame.minY)
2006 XCTAssertLessThan(firstY - viewport.frame.minY, 60, "A new transcript must start near the top, with blank space below")
2007 let beginning = XCTAttachment(screenshot: app.screenshot())
2008 beginning.name = "New transcript starts at the top"; beginning.lifetime = .keepAlways; add(beginning)
2009 let second = viewport.staticTexts["Second spoken words."].firstMatch
2010 XCTAssertTrue(second.waitForExistence(timeout: 12))
2011 XCTAssertEqual(first.frame.minY, firstY, accuracy: 2, "The first card must not shift while the short transcript grows")
2012 XCTAssertGreaterThan(second.frame.minY, first.frame.maxY)
2013 XCTAssertTrue(second.isHittable)
2014 let growing = XCTAttachment(screenshot: app.screenshot())
2015 growing.name = "Short transcript grows downward"; growing.lifetime = .keepAlways; add(growing)
2016 for text in ["Full-page transcript words.", "Newest transcript words."] {
2017 let latest = viewport.staticTexts[text].firstMatch
2018 XCTAssertTrue(latest.waitForExistence(timeout: 12))
2019 let follows = expectation(for: NSPredicate(format: "hittable == YES"), evaluatedWith: latest)
2020 wait(for: [follows], timeout: 5)
2021 XCTAssertLessThanOrEqual(latest.frame.maxY, viewport.frame.maxY + 1)
2022 XCTAssertGreaterThan(latest.frame.maxY, viewport.frame.maxY - 90, "Once the page fills, the newest words should remain near the bottom")
2023 XCTAssertFalse(first.isHittable, "Earlier cards should scroll off the page once the transcript overflows")
2024 }
2025 let full = XCTAttachment(screenshot: app.screenshot())
2026 full.name = "Full transcript follows new words at the bottom"; full.lifetime = .keepAlways; add(full)
2027 app.buttons["transcriptionCloseButton"].tap()
2028 XCTAssertTrue(app.staticTexts["Completed transcript."].waitForExistence(timeout: 10))
2029 XCTAssertFalse(app.buttons["transcriptionStopButton"].exists)
2030 }
2031
2032 @MainActor func testSwitchingNotesResetsDetailAndContinueUsesSameTranscriber() throws {
2033 guard (ProcessInfo.processInfo.environment["SIMULATOR_MODEL_IDENTIFIER"] ?? "").hasPrefix("iPad") else {
2034 throw XCTSkip("Split-view selection regression requires iPad")
2035 }
2036 XCUIDevice.shared.orientation = .landscapeLeft
2037 defer { XCUIDevice.shared.orientation = .portrait }
2038 let app = XCUIApplication()
2039 app.launchEnvironment["JOTLEY_SCREENSHOT_DATA"] = ###"[{"title":"Summary note A","folder":"","tags":[],"transcript":"Transcript belonging to the first note.","summary":"## Decisions\n- Approved first note."},{"title":"Transcript note B","folder":"","tags":[],"transcript":"Transcript belonging only to the second note.","summary":""}]"###
2040 app.launchEnvironment["JOTLEY_TEST_TRANSCRIPTION_LIFECYCLE"] = "1"
2041 app.launch()
2042 let first = app.buttons.containing(.staticText, identifier: "Summary note A").firstMatch
2043 let second = app.buttons.containing(.staticText, identifier: "Transcript note B").firstMatch
2044 XCTAssertTrue(first.waitForExistence(timeout: 15))
2045 for _ in 0..<3 {
2046 first.tap()
2047 XCTAssertTrue(app.staticTexts["noteDetailTitle"].waitForExistence(timeout: 5))
2048 XCTAssertEqual(app.staticTexts["noteDetailTitle"].label, "Summary note A")
2049 XCTAssertTrue(app.buttons["noteDetailSummaryAskAIButton"].waitForExistence(timeout: 5))
2050 second.tap()
2051 XCTAssertEqual(app.staticTexts["noteDetailTitle"].label, "Transcript note B")
2052 XCTAssertTrue(app.staticTexts["Transcript belonging only to the second note."].exists)
2053 XCTAssertFalse(app.staticTexts["Approved first note."].exists)
2054 }
2055 app.buttons["noteDetailContinueTranscriptionButton"].tap()
2056 XCTAssertTrue(app.buttons["transcriptionStopButton"].waitForExistence(timeout: 10))
2057 app.buttons["transcriptionCloseButton"].tap()
2058 XCTAssertTrue(app.staticTexts["noteDetailTitle"].waitForExistence(timeout: 10))
2059 XCTAssertEqual(app.staticTexts["noteDetailTitle"].label, "Transcript note B")
2060 XCTAssertTrue(app.staticTexts.containing(NSPredicate(format: "label CONTAINS %@", "Completed transcript.")).firstMatch.exists)
2061 }
2062
2063 @MainActor func testStopAndCloseSaveWithoutConfirmationAndRejectLateWords() throws {
2064 for action in ["transcriptionStopButton", "transcriptionCloseButton"] {
2065 let app = XCUIApplication()
2066 app.launchEnvironment["JOTLEY_SCREENSHOT_DATA"] = "[]"
2067 app.launchEnvironment["JOTLEY_TEST_TRANSCRIPTION_LIFECYCLE"] = "1"
2068 app.launchArguments = ["-selectedAppearanceMode", action == "transcriptionCloseButton" ? "Dark" : "Light"]
2069 app.launch()
2070 let plus = app.buttons["notesListNewNoteButton"]
2071 XCTAssertTrue(plus.waitForExistence(timeout: 15)); plus.tap()
2072 let stop = app.buttons["transcriptionStopButton"]
2073 XCTAssertTrue(stop.waitForExistence(timeout: 10))
2074 let lastWords = app.staticTexts["Latest incoming words."]
2075 XCTAssertTrue(lastWords.waitForExistence(timeout: 10))
2076 XCTAssertTrue(lastWords.isHittable, "Live transcript should follow the last timestamped card")
2077 XCTAssertTrue(app.staticTexts["01:25"].exists)
2078 let live = XCTAttachment(screenshot: app.screenshot())
2079 live.name = "Timestamped live cards with automatic bottom scroll - " + action
2080 live.lifetime = .keepAlways; add(live)
2081 app.buttons[action].tap()
2082 XCTAssertTrue(app.staticTexts["noteDetailTitle"].waitForExistence(timeout: 10))
2083 XCTAssertFalse(app.buttons["Keep Transcribing"].exists)
2084 XCTAssertFalse(app.buttons["Stop and Save"].exists)
2085 XCTAssertTrue(app.staticTexts["Completed transcript."].exists)
2086 XCTAssertFalse(stop.exists)
2087 XCTAssertTrue(app.buttons["noteDetailContinueTranscriptionButton"].exists)
2088 XCTAssertEqual(app.buttons["noteDetailContinueTranscriptionButton"].label, "Continue Transcription")
2089 // The fixture attempts a callback two seconds after finalization.
2090 let late = app.staticTexts["LATE WORDS MUST NEVER APPEAR"]
2091 XCTAssertFalse(late.waitForExistence(timeout: 4))
2092 XCTAssertTrue(app.staticTexts["Completed transcript."].exists)
2093 app.buttons["noteDetailMoreActionsButton"].tap()
2094 XCTAssertEqual(app.buttons["noteDetailContinueTranscriptionMenuButton"].label, "Continue")
2095 XCTAssertFalse(app.buttons["View Live Transcription"].exists)
2096 app.buttons["noteDetailContinueTranscriptionMenuButton"].tap()
2097 XCTAssertTrue(stop.waitForExistence(timeout: 10))
2098 app.buttons["transcriptionCloseButton"].tap()
2099 XCTAssertTrue(app.staticTexts["noteDetailTitle"].waitForExistence(timeout: 10))
2100 XCTAssertFalse(stop.exists)
2101 app.terminate()
2102 }
2103 }
2104
2105 @MainActor func testRestoredQuickRecordAppearsInWidgetGallery() throws {
2106 let app = XCUIApplication()
2107 app.launchEnvironment["JOTLEY_SCREENSHOT_DATA"] = "[]"
2108 app.launch()
2109 XCTAssertTrue(app.buttons["notesListNewNoteButton"].waitForExistence(timeout: 15))
2110 XCUIDevice.shared.press(.home)
2111 let home = XCUIApplication(bundleIdentifier: "com.apple.springboard")
2112 let icon = home.icons["Jotley"].firstMatch
2113 XCTAssertTrue(icon.waitForExistence(timeout: 10)); icon.press(forDuration: 1.2)
2114 let editHome = home.buttons["Edit Home Screen"]
2115 XCTAssertTrue(editHome.waitForExistence(timeout: 5)); editHome.tap()
2116 let edit = home.buttons["Edit"]
2117 XCTAssertTrue(edit.waitForExistence(timeout: 5)); edit.tap()
2118 let add = home.buttons["Add Widget"]
2119 XCTAssertTrue(add.waitForExistence(timeout: 5)); add.tap()
2120 let search = home.searchFields.firstMatch
2121 XCTAssertTrue(search.waitForExistence(timeout: 5)); search.tap(); search.typeText("Jotley")
2122 let item = home.staticTexts["Jotley"].firstMatch
2123 XCTAssertTrue(item.waitForExistence(timeout: 10)); item.tap()
2124 XCTAssertTrue(home.staticTexts["Live Transcription"].waitForExistence(timeout: 10))
2125 let screenshotImage = home.screenshot()
2126 let screenshot = XCTAttachment(screenshot: screenshotImage)
2127 screenshot.name = "Restored Jotley Quick Record widget gallery"; screenshot.lifetime = .keepAlways; self.add(screenshot)
2128 try screenshotImage.pngRepresentation.write(to: FileManager.default.temporaryDirectory.appendingPathComponent("Jotley-widget-gallery.png"))
2129 print("JOTLEY_WIDGET_SCREENSHOT", FileManager.default.temporaryDirectory.appendingPathComponent("Jotley-widget-gallery.png").path)
2130 XCUIDevice.shared.press(.home)
2131 }
2132
2133 @MainActor func testRecordingActivityAppearsWithSelectedTheme() throws {
2134 guard UIDevice.current.userInterfaceIdiom == .phone else { throw XCTSkip("iPhone Lock Screen activity") }
2135 let app = XCUIApplication()
2136 app.launchEnvironment["JOTLEY_SCREENSHOT_DATA"] = "[]"
2137 app.launchEnvironment["JOTLEY_TEST_TRANSCRIPTION_LIFECYCLE"] = "1"
2138 app.launchArguments = ["-selectedThemeColor", "Light Blue", "-jotleyWelcomeCompleted.v1", "YES"]
2139 app.launch()
2140 let start = app.buttons["notesListNewNoteButton"].firstMatch
2141 XCTAssertTrue(start.waitForExistence(timeout: 15)); start.tap()
2142 let stop = app.buttons["transcriptionStopButton"]
2143 XCTAssertTrue(stop.waitForExistence(timeout: 10))
2144 XCUIDevice.shared.press(.home)
2145 let home = XCUIApplication(bundleIdentifier: "com.apple.springboard")
2146 capture(home.screenshot(), named: "Light Blue recording on the Home Screen")
2147 let top = home.coordinate(withNormalizedOffset: CGVector(dx: 0.22, dy: 0.002))
2148 let middle = home.coordinate(withNormalizedOffset: CGVector(dx: 0.22, dy: 0.65))
2149 top.press(forDuration: 0.05, thenDragTo: middle, withVelocity: .default, thenHoldForDuration: 0.15)
2150 let activity = home.staticTexts["Transcribing"].firstMatch
2151 XCTAssertTrue(activity.waitForExistence(timeout: 8))
2152 capture(home.screenshot(), named: "Light Blue recording activity banner")
2153 app.activate()
2154 if stop.isHittable { stop.tap() }
2155 }
2156
2157 @MainActor func testAskAIRestoredForExistingTranscribedNote() throws {
2158 let app = XCUIApplication()
2159 app.launchEnvironment["JOTLEY_SCREENSHOT_DATA"] = ##"[{"title":"Ask AI verification","folder":"","tags":[],"transcript":"Mina owns launch. We ship Friday.","summary":""}]"##
2160 app.launchEnvironment["JOTLEY_SCREENSHOT_CHAT_READY"] = "1"
2161 app.launchEnvironment["JOTLEY_SCREENSHOT_APPEARANCE"] = ProcessInfo.processInfo.environment["JOTLEY_REVIEW_APPEARANCE"] ?? "Light"
2162 app.launchArguments = ["-selectedThemeColor", "Magenta", "-jotleyWelcomeCompleted.v1", "YES"]
2163 app.launch()
2164 let more = app.buttons["noteDetailMoreActionsButton"]
2165 if !more.waitForExistence(timeout: 5) {
2166 let note = app.staticTexts["Ask AI verification"].firstMatch
2167 XCTAssertTrue(note.waitForExistence(timeout: 20)); note.tap()
2168 }
2169 XCTAssertTrue(more.waitForExistence(timeout: 10))
2170 XCTAssertFalse(app.buttons["noteDetailAskAIShortcut"].exists)
2171 XCTAssertFalse(app.buttons["noteDetailAskAIButton"].exists)
2172 more.tap()
2173 let menuAsk = app.buttons["noteDetailAskAIButton"]
2174 XCTAssertTrue(menuAsk.waitForExistence(timeout: 5)); menuAsk.tap()
2175 let field = app.textViews["askAIQuestionField"]
2176 XCTAssertTrue(field.waitForExistence(timeout: 10))
2177 XCTAssertTrue(app.staticTexts["Ask about your note"].exists)
2178 let screenshotImage = app.screenshot()
2179 let screenshot = XCTAttachment(screenshot: screenshotImage)
2180 screenshot.name = "Restored on-device Ask AI"; screenshot.lifetime = .keepAlways; add(screenshot)
2181 XCTAssertTrue(app.staticTexts.containing(NSPredicate(format: "label CONTAINS %@", "processed on this device")).firstMatch.exists)
2182 app.buttons["List any action items"].tap()
2183 XCTAssertTrue(app.staticTexts["List any action items"].waitForExistence(timeout: 5))
2184 XCTAssertFalse(app.buttons["List any action items"].exists)
2185 XCTAssertNotEqual(field.value as? String, "List any action items")
2186 XCTAssertFalse(app.buttons["askAISendButton"].isEnabled)
2187 let sent = XCTAttachment(screenshot: app.screenshot())
2188 sent.name = "Suggested question submitted"; sent.lifetime = .keepAlways; add(sent)
2189 app.buttons["askAIDoneButton"].tap()
2190 XCTAssertTrue(more.waitForExistence(timeout: 10))
2191 XCTAssertFalse(app.buttons["noteDetailAskAIShortcut"].exists)
2192 more.tap()
2193 XCTAssertTrue(menuAsk.waitForExistence(timeout: 5)); menuAsk.tap()
2194 XCTAssertTrue(app.buttons["askAIDoneButton"].waitForExistence(timeout: 5))
2195 }
2196
2197 @MainActor func testSpeechPreflightFailureCannotStartCaptureOrOfferAudioRetry() throws {
2198 let app = XCUIApplication()
2199 app.launchEnvironment["JOTLEY_SCREENSHOT_DATA"] = "[]"
2200 app.launchArguments = ["-transcriptionLanguage", "zxx"]
2201 app.launch()
2202 XCTAssertTrue(app.buttons["notesListNewNoteButton"].waitForExistence(timeout: 15))
2203 app.buttons["notesListNewNoteButton"].tap()
2204 let springboard = XCUIApplication(bundleIdentifier: "com.apple.springboard")
2205 for title in ["Allow", "OK"] {
2206 let button = springboard.alerts.buttons[title]
2207 if button.waitForExistence(timeout: 2) { button.tap() }
2208 }
2209 let alert = app.alerts["Transcription Needs Attention"]
2210 XCTAssertTrue(alert.waitForExistence(timeout: 15))
2211 XCTAssertTrue(alert.staticTexts.matching(NSPredicate(format: "label CONTAINS 'unavailable'")).firstMatch.exists)
2212 alert.buttons["OK"].tap()
2213 XCTAssertEqual(app.staticTexts["transcriptionDurationText"].label, "0m 0s")
2214 XCTAssertFalse(app.buttons["transcriptionStopButton"].exists)
2215 XCTAssertFalse(app.buttons["savedAudioPlayButton"].exists)
2216 let screenshot = XCTAttachment(screenshot: app.screenshot())
2217 screenshot.name = "Live-only preflight failure does not advertise active capture"
2218 screenshot.lifetime = .keepAlways; add(screenshot)
2219 app.buttons["transcriptionCloseButton"].tap()
2220 XCTAssertTrue(app.staticTexts["noteDetailTitle"].waitForExistence(timeout: 10))
2221 XCTAssertFalse(app.buttons["noteDetailTranscribeAudioButton"].exists)
2222 app.buttons["noteDetailMoreActionsButton"].tap()
2223 XCTAssertTrue(app.buttons["noteDetailContinueTranscriptionMenuButton"].exists)
2224 XCTAssertFalse(app.buttons["noteDetailPlayRecordingButton"].exists)
2225 XCTAssertFalse(app.buttons["retrySavedAudioButton"].exists)
2226 }
2227
2228
2229 @MainActor func testSpeechSettingsExplainUnsupportedLanguage() throws {
2230 let app = XCUIApplication()
2231 app.launchArguments = ["-transcriptionLanguage", "zxx", "-jotleyWelcomeCompleted.v1", "YES"]
2232 app.launch()
2233 let settings = app.buttons["notesListSettingsButton"]
2234 XCTAssertTrue(settings.waitForExistence(timeout: 15)); settings.tap()
2235 let status = app.staticTexts["settingsModelStatus"]
2236 for _ in 0..<4 where !status.isHittable { app.swipeUp() }
2237 XCTAssertTrue(status.waitForExistence(timeout: 10))
2238 let unsupported = expectation(for: NSPredicate(format: "label CONTAINS %@", "unavailable for the selected language"), evaluatedWith: status)
2239 wait(for: [unsupported], timeout: 10)
2240 XCTAssertFalse(app.buttons["settingsSpeechSetupButton"].exists)
2241 XCTAssertFalse(app.progressIndicators["settingsSpeechSetupProgress"].exists)
2242 XCTAssertTrue(app.buttons["settingsSpeechRefreshButton"].exists)
2243 let attachment = XCTAttachment(screenshot: app.screenshot())
2244 attachment.name = "Speech model readiness and explicit setup explanation"
2245 attachment.lifetime = .keepAlways; add(attachment)
2246 }
2247
2248 @MainActor func testAppearanceSwitchesBackAndForthAndPersists() throws {
2249 let app = XCUIApplication()
2250 app.launchArguments = ["-jotleyWelcomeCompleted.v1", "YES"]
2251 app.launch()
2252 let settings = app.buttons["notesListSettingsButton"]
2253 let picker = app.descendants(matching: .any)["settingsAppearanceModePicker"].firstMatch
2254 for mode in ["Light", "Dark", "Light", "Dark"] {
2255 XCTAssertTrue(settings.waitForExistence(timeout: 15)); settings.tap()
2256 XCTAssertFalse(app.switches["settingsThemedSummaryHeadersToggle"].exists)
2257 XCTAssertTrue(picker.waitForExistence(timeout: 5)); picker.tap()
2258 let choice = app.buttons[mode]
2259 XCTAssertTrue(choice.waitForExistence(timeout: 5), app.debugDescription); choice.tap()
2260 app.buttons["Done"].tap()
2261 let search = app.textFields["notesListSearchField"]
2262 XCTAssertTrue(search.waitForExistence(timeout: 5))
2263 XCTAssertEqual(search.frame.height, 44, accuracy: 0.01)
2264 let attachment = XCTAttachment(screenshot: app.screenshot())
2265 attachment.name = "Live appearance switch \(mode)"; attachment.lifetime = .keepAlways; add(attachment)
2266 }
2267 app.terminate(); app.launch()
2268 XCTAssertTrue(settings.waitForExistence(timeout: 15)); settings.tap()
2269 XCTAssertTrue(picker.waitForExistence(timeout: 5))
2270 XCTAssertTrue(picker.label.contains("Dark") || (picker.value as? String)?.contains("Dark") == true, app.debugDescription)
2271 }
2272
2273 @MainActor func testSettingsShowsVersionAndBuildOnOneLine() throws {
2274 let app = XCUIApplication()
2275 app.launchArguments = ["-jotleyWelcomeCompleted.v1", "YES"]
2276 app.launch()
2277 let settings = app.buttons["notesListSettingsButton"]
2278 XCTAssertTrue(settings.waitForExistence(timeout: 15)); settings.tap()
2279 let version = app.staticTexts["settingsAppVersion"]
2280 for _ in 0..<6 where !version.isHittable { app.swipeUp() }
2281 XCTAssertTrue(version.waitForExistence(timeout: 5))
2282 XCTAssertNotNil(version.label.range(of: #"^Version [0-9]+\.[0-9]+(?:\.[0-9]+)? \([0-9]+\)$"#, options: .regularExpression))
2283 XCTAssertFalse(version.label.contains("\n"))
2284 // SwiftUI exposes the full Form row (56 points), including its padding.
2285 XCTAssertLessThanOrEqual(version.frame.height, 60)
2286 let attachment = XCTAttachment(screenshot: app.screenshot())
2287 attachment.name = "Settings version and build on one line"
2288 attachment.lifetime = .keepAlways; add(attachment)
2289 }
2290
2291 @MainActor func testLocalNotesSearchAndControls() throws {
2292 let app = XCUIApplication()
2293 app.launchEnvironment["JOTLEY_TEST_TRANSCRIPTION_LIFECYCLE"] = "1"
2294 app.launchArguments = ["-jotleyWelcomeCompleted.v1", "YES"]
2295 app.launch()
2296 let model = ProcessInfo.processInfo.environment["SIMULATOR_MODEL_IDENTIFIER"] ?? ""
2297 if !((model.hasPrefix("iPhone18,") || model.hasPrefix("iPhone19,")) || model.hasPrefix("iPad17,")) {
2298 XCTAssertTrue(app.staticTexts["Jotley Unavailable"].waitForExistence(timeout: 15))
2299 XCTAssertTrue(app.staticTexts.containing(NSPredicate(format: "label CONTAINS %@", "iPhone 17 or newer")).firstMatch.exists)
2300 XCTAssertFalse(app.buttons["notesListNewNoteButton"].exists)
2301 return
2302 }
2303 let search = app.textFields["notesListSearchField"]
2304 XCTAssertTrue(search.waitForExistence(timeout: 15))
2305 // UIKit coordinate transforms can return 43.99999999999997 for 44 points.
2306 XCTAssertGreaterThanOrEqual(search.frame.height + 0.001, 44)
2307 XCTAssertLessThanOrEqual(search.frame.height, 45)
2308 let filter = app.buttons["notesListTagFilterButton"]
2309 XCTAssertGreaterThanOrEqual(filter.frame.height + 0.001, 44)
2310 XCTAssertGreaterThanOrEqual(filter.frame.width + 0.001, 44)
2311 filter.tap()
2312 XCTAssertTrue(app.staticTexts["Filter & Sort"].waitForExistence(timeout: 5))
2313 app.buttons["Done"].tap()
2314 app.buttons["notesListNewNoteButton"].tap()
2315 stopNewTranscriptionAndOpenNote(app)
2316 XCTAssertTrue(app.staticTexts["noteDetailTitle"].waitForExistence(timeout: 5))
2317 XCTAssertFalse(app.buttons["newNoteWriteButton"].exists)
2318 XCTAssertFalse(app.buttons["newNoteImportButton"].exists)
2319 XCTAssertFalse(app.buttons["newNoteRecordButton"].exists)
2320 XCTAssertFalse(app.buttons["transcriptionPauseButton"].exists, "Stopping capture should dismiss the recording screen")
2321 let marker = "Offline note \(UUID().uuidString.prefix(8))"
2322 app.staticTexts["noteDetailTitle"].tap()
2323 let title = app.textFields["noteDetailTitleEditor"]
2324 title.typeText(String(repeating: XCUIKeyboardKey.delete.rawValue, count: 8) + marker + "\n")
2325 app.terminate(); app.launch()
2326 XCTAssertTrue(search.waitForExistence(timeout: 10)); search.tap(); search.typeText(marker)
2327 let savedRow = app.buttons.matching(NSPredicate(format: "identifier BEGINSWITH 'notesListNoteRow-'")).firstMatch
2328 XCTAssertTrue(savedRow.waitForExistence(timeout: 5)); savedRow.tap()
2329 XCTAssertEqual(app.staticTexts["noteDetailTitle"].label, marker)
2330 XCTAssertFalse(app.buttons["Sign In"].exists)
2331 XCTAssertFalse(app.buttons["Subscribe"].exists)
2332 }
2333 @MainActor private func stopNewTranscriptionAndOpenNote(_ app: XCUIApplication) {
2334 let springboard = XCUIApplication(bundleIdentifier: "com.apple.springboard")
2335 let permission = springboard.alerts.buttons["Allow"]
2336 if permission.waitForExistence(timeout: 2) { permission.tap() }
2337 let ok = springboard.alerts.buttons["OK"]
2338 if ok.exists { ok.tap() }
2339 let pause = app.buttons["transcriptionPauseButton"]
2340 XCTAssertTrue(pause.waitForExistence(timeout: 15))
2341 let alert = app.alerts["Transcription Needs Attention"]
2342 if alert.waitForExistence(timeout: 10) {
2343 alert.buttons["OK"].tap()
2344 XCTAssertEqual(app.staticTexts["transcriptionDurationText"].label, "0m 0s")
2345 XCTAssertFalse(app.buttons["transcriptionStopButton"].exists)
2346 app.buttons["transcriptionCloseButton"].tap()
2347 } else {
2348 XCTAssertEqual(pause.label, "Pause transcription")
2349 app.buttons["transcriptionStopButton"].tap()
2350 }
2351 if app.alerts["Jotley"].waitForExistence(timeout: 3) { app.alerts["Jotley"].buttons["OK"].tap() }
2352 XCTAssertTrue(app.staticTexts["noteDetailTitle"].waitForExistence(timeout: 20))
2353 }
2354
2355
2356 @MainActor func testLiveOnlyNoteKeepsTemplatesAndContinueActionWithoutAudioControls() throws {
2357 XCUIDevice.shared.orientation = .portrait
2358 let app = XCUIApplication()
2359 app.launchArguments = ["-transcriptionLanguage", "zxx", "-selectedThemeColor", "Magenta"]
2360 app.launchEnvironment["JOTLEY_SCREENSHOT_DATA"] = ##"[{"title":"Live transcript","folder":"","tags":[],"transcript":"Mina ships Friday.","summary":""}]"##
2361 app.launchEnvironment["JOTLEY_TEST_TRANSCRIPTION_LIFECYCLE"] = "1"
2362 app.launchEnvironment["JOTLEY_SCREENSHOT_APPEARANCE"] = "Light"
2363 app.launch()
2364 if !app.buttons["noteDetailTemplatesButton"].waitForExistence(timeout: 5) {
2365 let row = app.buttons.containing(.staticText, identifier: "Live transcript").firstMatch
2366 XCTAssertTrue(row.waitForExistence(timeout: 15)); row.tap()
2367 }
2368 XCTAssertTrue(app.staticTexts["Mina ships Friday."].exists)
2369 XCTAssertTrue(app.buttons["noteDetailTemplatesButton"].exists)
2370 XCTAssertTrue(app.buttons["noteDetailGenerateSummaryButton"].isEnabled)
2371 XCTAssertFalse(app.buttons["savedAudioPlayButton"].exists)
2372 XCTAssertFalse(app.buttons["noteDetailTranscribeAudioButton"].exists)
2373 let screenshot = XCTAttachment(screenshot: app.screenshot())
2374 XCTAssertTrue(app.buttons["noteDetailContinueTranscriptionButton"].exists)
2375 screenshot.name = "Live-only note with templates and summary, without saved audio"
2376 screenshot.lifetime = .keepAlways; add(screenshot)
2377 app.buttons["noteDetailMoreActionsButton"].tap()
2378 let continued = app.buttons["noteDetailContinueTranscriptionMenuButton"]
2379 XCTAssertTrue(continued.exists); XCTAssertEqual(continued.label, "Continue")
2380 XCTAssertFalse(app.buttons["noteDetailPlayRecordingButton"].exists)
2381 continued.tap()
2382 XCTAssertTrue(app.buttons["transcriptionPauseButton"].waitForExistence(timeout: 10))
2383 app.buttons["transcriptionCloseButton"].tap()
2384 XCTAssertTrue(app.staticTexts["noteDetailTitle"].waitForExistence(timeout: 10))
2385 app.buttons["noteDetailTranscriptTab"].tap()
2386 XCTAssertTrue(app.staticTexts.containing(NSPredicate(format: "label CONTAINS %@", "Completed transcript.")).firstMatch.waitForExistence(timeout: 10))
2387 }
2388
2389 @MainActor func testExistingTranscriptTemplatesStayVisibleWithoutChangingTabs() throws {
2390 let app = XCUIApplication()
2391 app.launchEnvironment["JOTLEY_SCREENSHOT_DATA"] = ##"[{"title":"Template controls","folder":"","tags":[],"transcript":"Existing transcript words","summary":""}]"##
2392 app.launch()
2393 let row = app.buttons.matching(NSPredicate(format: "identifier BEGINSWITH 'notesListNoteRow-'")).firstMatch
2394 XCTAssertTrue(row.waitForExistence(timeout: 15)); row.tap()
2395 let templates = app.buttons["noteDetailTemplatesButton"]
2396 XCTAssertTrue(templates.waitForExistence(timeout: 5))
2397 XCTAssertEqual(templates.label, "Templates: Auto")
2398 XCTAssertTrue(app.buttons["noteDetailGenerateSummaryButton"].isEnabled)
2399 for key in ["lecture", "meetings/stand-up", "default-summary"] {
2400 templates.tap()
2401 let choice = app.buttons["noteTemplate-" + key]
2402 if !choice.isHittable { app.swipeUp() }
2403 XCTAssertTrue(choice.waitForExistence(timeout: 5)); choice.tap()
2404 XCTAssertTrue(app.descendants(matching: .any)["noteDetailTranscriptContent"].exists)
2405 XCTAssertFalse(app.buttons["noteDetailRecordButton"].exists)
2406 }
2407 XCTAssertEqual(templates.label, "Templates: Auto")
2408 }
2409
2410
2411 @MainActor func testOriginalShareMenuExportsLocalMarkdownWithoutSending() throws {
2412 guard ["iPhone18,", "iPhone19,"].contains(where: { ProcessInfo.processInfo.environment["SIMULATOR_MODEL_IDENTIFIER"]?.hasPrefix($0) == true }) else { return }
2413 let app = XCUIApplication()
2414 app.launchEnvironment["JOTLEY_TEST_TRANSCRIPTION_LIFECYCLE"] = "1"
2415 app.launchArguments = ["-jotleyWelcomeCompleted.v1", "YES"]
2416 app.launch()
2417 XCTAssertTrue(app.buttons["notesListNewNoteButton"].waitForExistence(timeout: 15))
2418 app.buttons["notesListNewNoteButton"].tap()
2419 stopNewTranscriptionAndOpenNote(app)
2420 XCTAssertTrue(app.staticTexts["noteDetailTitle"].waitForExistence(timeout: 5))
2421 let share = app.buttons["noteDetailShareButton"]
2422 XCTAssertTrue(share.exists); share.tap()
2423 XCTAssertTrue(app.buttons["shareNoteButton"].waitForExistence(timeout: 5))
2424 let more = app.buttons["More Export Options"]
2425 XCTAssertTrue(more.exists); more.tap()
2426 let formatted = app.buttons.matching(NSPredicate(format: "identifier == %@ OR label == %@", "exportMarkdownButton", "Full Note (Formatted)")).firstMatch
2427 XCTAssertTrue(formatted.waitForExistence(timeout: 5), app.debugDescription); formatted.tap()
2428 let saveToFiles = app.cells["Save to Files"]
2429 XCTAssertTrue(saveToFiles.waitForExistence(timeout: 10), app.debugDescription)
2430 let attachment = XCTAttachment(screenshot: app.screenshot())
2431 attachment.name = "Original file export opens native share sheet"
2432 attachment.lifetime = .keepAlways; add(attachment)
2433 // Inspect local export availability only; never choose a messaging service.
2434 let close = app.buttons["Close"]
2435 XCTAssertTrue(close.exists); close.tap()
2436 XCTAssertTrue(share.waitForExistence(timeout: 5))
2437 XCTAssertFalse(app.otherElements["ActivityListView"].isHittable)
2438 share.tap()
2439 let textShare = app.buttons["shareNoteButton"]
2440 XCTAssertTrue(textShare.waitForExistence(timeout: 5)); textShare.tap()
2441 XCTAssertTrue(app.cells["Copy"].waitForExistence(timeout: 10), app.debugDescription)
2442 XCTAssertTrue(close.exists); close.tap()
2443 XCTAssertFalse(app.otherElements["ActivityListView"].isHittable)
2444 }
2445
2446 #if DEBUG
2447
2448 /// Settings carries no support, feedback, sharing or promotion links.
2449 @MainActor func testSettingsHaveNoSupportFeedbackOrPromotionLinks() throws {
2450 continueAfterFailure = false
2451 let app = XCUIApplication()
2452 app.launchEnvironment["JOTLEY_SCREENSHOT_DATA"] = #"[{"title":"Launch planning","folder":"Work","tags":[],"transcript":"Review the next steps.","summary":"Share the launch plan."}]"#
2453 app.launchArguments += ["-AppleLanguages", "(en)", "-selectedThemeColor", "Purple"]
2454 app.launch()
2455 showNotesLibrary(app)
2456 let settings = app.buttons["notesListSettingsButton"]
2457 XCTAssertTrue(settings.waitForExistence(timeout: 10)); settings.tap()
2458 let form = app.descendants(matching: .any)["settingsForm"].firstMatch
2459 XCTAssertTrue(form.waitForExistence(timeout: 10))
2460 let welcome = app.buttons["settingsWelcomeJotley"]
2461 for _ in 0..<16 where !welcome.isHittable { form.swipeUp() }
2462 XCTAssertTrue(welcome.isHittable, app.debugDescription)
2463 for id in ["settingsAppHelp", "settingsSupportReminderCard", "settingsShareJotley", "settingsFeedbackJotley",
2464 "settingsSupportJotleyCard", "settingsAtomProduct", "settingsRateJotley"] {
2465 XCTAssertFalse(app.descendants(matching: .any)[id].exists, id)
2466 }
2467 XCTAssertFalse(app.staticTexts.containing(NSPredicate(format: "label CONTAINS[c] %@", "Project ATOM")).firstMatch.exists)
2468 let screenshot = XCUIScreen.main.screenshot()
2469 if let path = ProcessInfo.processInfo.environment["JOTLEY_SETTINGS_SCREENSHOT"] {
2470 try screenshot.pngRepresentation.write(to: URL(fileURLWithPath: path))
2471 }
2472 let attachment = XCTAttachment(screenshot: screenshot)
2473 attachment.name = "Settings without support links"; attachment.lifetime = .keepAlways; add(attachment)
2474 }
2475
2476 @MainActor func testActualSummaryCompletionDoesNotInterruptWithCustomReviewMenu() throws {
2477 guard case .available = SystemLanguageModel.default.availability else {
2478 throw XCTSkip("Apple summary model is not ready in this simulator")
2479 }
2480 let app = XCUIApplication()
2481 app.launchArguments = ["-transcriptionLanguage", "en-US"]
2482 app.launchEnvironment["JOTLEY_SCREENSHOT_DATA"] = #"""
2483 [{"title":"Support milestone","folder":"Work","tags":[],"transcript":"We agreed to keep recordings offline. Maya will test the microphone and Sam will verify the summary templates.","summary":""}]
2484 """#
2485 app.launchEnvironment["JOTLEY_SCREENSHOT_APPEARANCE"] = "Light"
2486 app.launchEnvironment["JOTLEY_TEST_STOREFRONT"] = "USA"
2487 app.launch()
2488 let row = app.buttons.matching(NSPredicate(format: "identifier BEGINSWITH 'notesListNoteRow-'")).firstMatch
2489 XCTAssertTrue(row.waitForExistence(timeout: 15)); row.tap()
2490 XCTAssertFalse(app.staticTexts["jotleySupportTitle"].exists)
2491 let generate = app.buttons["noteDetailGenerateSummaryButton"]
2492 XCTAssertTrue(generate.isEnabled); generate.tap()
2493 let cancel = app.buttons["noteDetailCancelGenerationButton"]
2494 XCTAssertTrue(cancel.waitForExistence(timeout: 10))
2495 let finished = expectation(for: NSPredicate(format: "exists == false"), evaluatedWith: cancel)
2496 wait(for: [finished], timeout: 60)
2497 XCTAssertFalse(generate.exists)
2498 XCTAssertFalse(app.staticTexts["jotleySupportTitle"].waitForExistence(timeout: 3), "A saved summary must not trigger any prompt")
2499 XCTAssertTrue(app.descendants(matching: .any)["noteDetailSummaryContent"].exists)
2500 }
2501 @MainActor func testNativeNoteBackNavigationWithoutCustomSwipes() throws {
2502 let isIPad = (ProcessInfo.processInfo.environment["SIMULATOR_MODEL_IDENTIFIER"] ?? "").hasPrefix("iPad")
2503 XCUIDevice.shared.orientation = isIPad ? .landscapeLeft : .portrait
2504 defer { XCUIDevice.shared.orientation = .portrait }
2505 let app = XCUIApplication()
2506 app.launchArguments = ["-jotleyWelcomeCompleted.v1", "YES"]
2507 app.launchEnvironment["JOTLEY_SCREENSHOT_DATA"] = #"""
2508 [{"title":"Native navigation","folder":"Work","tags":[],"transcript":"These are the original spoken words.","summary":"## Summary\nA short overview.\n\n## Key Points\n- Keep navigation familiar."},{"title":"Swipe-delete regression","folder":"Work","tags":[],"transcript":"Disposable test note.","summary":""}]
2509 """#
2510 app.launch()
2511 let row = app.buttons.containing(.staticText, identifier: "Native navigation").firstMatch
2512 let window = app.windows.firstMatch
2513 for tab in ["Summary", "Transcript"] {
2514 let tabButton = app.buttons["noteDetail\(tab)Tab"]
2515 XCTAssertTrue(tabButton.waitForExistence(timeout: 15)); tabButton.tap()
2516 if isIPad {
2517 // A persistent native split view already exposes the notes menu.
2518 let content = app.descendants(matching: .any)["noteDetail\(tab)Content"].firstMatch
2519 content.swipeLeft()
2520 XCTAssertTrue(tabButton.isSelected, "A swipe must not change note tabs")
2521 content.swipeRight()
2522 XCTAssertTrue(tabButton.isSelected, "A swipe must not change note tabs")
2523 } else {
2524 let start = window.coordinate(withNormalizedOffset: CGVector(dx: 0.005, dy: 0.5))
2525 let end = window.coordinate(withNormalizedOffset: CGVector(dx: 0.9, dy: 0.5))
2526 start.press(forDuration: 0.05, thenDragTo: end)
2527 XCTAssertTrue(app.buttons["BackButton"].waitForNonExistence(timeout: 5), "The native Back gesture must return directly to notes from either tab")
2528 }
2529 XCTAssertTrue(row.waitForExistence(timeout: 5)); XCTAssertTrue(row.isHittable)
2530 row.tap()
2531 XCTAssertTrue(app.buttons["noteDetailSummaryTab"].waitForExistence(timeout: 5))
2532 }
2533 if !isIPad { app.buttons["BackButton"].tap() }
2534 let disposable = app.buttons.containing(.staticText, identifier: "Swipe-delete regression").firstMatch
2535 XCTAssertTrue(disposable.waitForExistence(timeout: 5)); disposable.swipeLeft()
2536 let delete = app.buttons["Delete"].firstMatch
2537 XCTAssertTrue(delete.waitForExistence(timeout: 5)); delete.tap()
2538 XCTAssertTrue(disposable.waitForNonExistence(timeout: 5)); XCTAssertTrue(row.exists)
2539 }
2540
2541 @MainActor func testMoreMenuKeepsBothEditorsOnEitherTab() throws {
2542 let app = XCUIApplication()
2543 app.launchEnvironment["JOTLEY_SCREENSHOT_DATA"] = #"""
2544 [{"title":"Consistent note menu","folder":"Work","tags":[],"transcript":"Original spoken words.","summary":"## Summary\nA short overview.\n\n## Key Points\n- Keep both editors available."}]
2545 """#
2546 app.launchArguments = ["-jotleyWelcomeCompleted.v1", "YES"]
2547 app.launchEnvironment["JOTLEY_SCREENSHOT_APPEARANCE"] = "Light"
2548 app.launch()
2549 XCTAssertTrue(app.buttons["noteDetailSummaryTab"].waitForExistence(timeout: 15))
2550 for tab in ["Summary", "Transcript"] {
2551 let tabButton = app.buttons["noteDetail\(tab)Tab"]
2552 XCTAssertTrue(tabButton.waitForExistence(timeout: 5)); tabButton.tap()
2553 app.buttons["noteDetailMoreActionsButton"].tap()
2554 for identifier in ["noteDetailSummaryStyleMenu", "noteDetailSummaryTemplateMenu", "noteDetailEditTranscriptButton", "noteDetailEditSummaryButton"] {
2555 XCTAssertTrue(app.buttons[identifier].waitForExistence(timeout: 3), "\(identifier) is missing on \(tab)")
2556 }
2557 // Exercise the editor belonging to the other tab, not just its label.
2558 let other = tab == "Summary" ? "Transcript" : "Summary"
2559 app.buttons["noteDetailEdit\(other)Button"].tap()
2560 XCTAssertTrue(app.textViews["\(other.lowercased())EditorText"].waitForExistence(timeout: 5))
2561 app.buttons["\(other.lowercased())EditorCancelButton"].tap()
2562 }
2563 }
2564
2565 @MainActor func testTranscriptEditingAndSummaryMenuAvailability() throws {
2566 let app = XCUIApplication()
2567 app.launchEnvironment["JOTLEY_SCREENSHOT_DATA"] = #" [{"title":"Transcript editing verification","folder":"Work","tags":[],"transcript":"Original words.","summary":""}] "#
2568 app.launchEnvironment["JOTLEY_SCREENSHOT_APPEARANCE"] = "Dark"
2569 app.launchArguments = ["-jotleyWelcomeCompleted.v1", "YES"]
2570 app.launch()
2571 showNotesLibrary(app)
2572 for identifier in ["notesListFolderDrawerButton", "notesListTagFilterButton"] {
2573 let button = app.buttons[identifier]
2574 XCTAssertTrue(button.waitForExistence(timeout: 15))
2575 XCTAssertGreaterThanOrEqual(button.frame.width, 44)
2576 XCTAssertGreaterThanOrEqual(button.frame.height, 44)
2577 }
2578 app.buttons["notesListFolderDrawerButton"].tap()
2579 let manage = app.buttons["folderDrawerManageButton"]
2580 XCTAssertTrue(manage.waitForExistence(timeout: 5)); manage.tap()
2581 let folderName = app.textFields["newFolderNameField"]
2582 XCTAssertTrue(folderName.waitForExistence(timeout: 5))
2583 XCTAssertGreaterThanOrEqual(folderName.frame.height, 56)
2584 let create = app.buttons["createFolderButton"]
2585 XCTAssertGreaterThanOrEqual(create.frame.height, 44)
2586 XCTAssertFalse(create.isEnabled)
2587 folderName.tap(); folderName.typeText("Release Checks")
2588 XCTAssertTrue(create.isEnabled); create.tap()
2589 XCTAssertTrue(app.staticTexts["Release Checks"].waitForExistence(timeout: 5))
2590 let folderAttachment = XCTAttachment(screenshot: app.screenshot())
2591 folderAttachment.name = "Folder creation"; folderAttachment.lifetime = .keepAlways; add(folderAttachment)
2592 app.buttons["folderManagementDoneButton"].tap()
2593 let row = app.buttons.containing(.staticText, identifier: "Transcript editing verification").firstMatch
2594 XCTAssertTrue(row.waitForExistence(timeout: 15)); row.tap()
2595 func openEditor() {
2596 app.buttons["noteDetailMoreActionsButton"].tap()
2597 XCTAssertFalse(app.buttons["noteDetailEditSummaryButton"].exists)
2598 let edit = app.buttons["noteDetailEditTranscriptButton"]
2599 XCTAssertTrue(edit.waitForExistence(timeout: 5)); edit.tap()
2600 XCTAssertTrue(app.textViews["transcriptEditorText"].waitForExistence(timeout: 5))
2601 }
2602 openEditor()
2603 let editor = app.textViews["transcriptEditorText"]
2604 XCTAssertEqual(app.textViews.matching(identifier: "transcriptEditorText").count, 1)
2605 XCTAssertTrue((editor.value as? String ?? "").contains("[00:00]\nOriginal words."))
2606 editor.tap()
2607 editor.typeKey("a", modifierFlags: .command)
2608 editor.typeText("[00:00]\nCancelled.")
2609 app.buttons["transcriptEditorCancelButton"].tap()
2610 XCTAssertTrue(app.staticTexts["Original words."].waitForExistence(timeout: 5))
2611 XCTAssertFalse(app.staticTexts.containing(NSPredicate(format: "label CONTAINS %@", "Cancelled.")).firstMatch.exists)
2612 openEditor()
2613 editor.tap()
2614 editor.typeKey("a", modifierFlags: .command)
2615 editor.typeText("[00:00]\nOriginal words. Corrected.\nNew paragraph.")
2616 let editedDocument = editor.value as? String ?? ""
2617 XCTAssertTrue(editedDocument.contains("[00:00]\n"), editedDocument)
2618 let attachment = XCTAttachment(screenshot: app.screenshot())
2619 attachment.name = "Edit Transcript"; attachment.lifetime = .keepAlways; add(attachment)
2620 app.buttons["transcriptEditorSaveButton"].tap()
2621 XCTAssertTrue(app.staticTexts.containing(NSPredicate(format: "label CONTAINS %@", "Corrected.")).firstMatch.waitForExistence(timeout: 5))
2622 openEditor()
2623 XCTAssertTrue((editor.value as? String ?? "").contains("Corrected."))
2624 XCTAssertTrue((editor.value as? String ?? "").contains("\nNew paragraph."))
2625 XCTAssertTrue((editor.value as? String ?? "").contains("[00:00]\n"))
2626 app.buttons["transcriptEditorCancelButton"].tap()
2627 }
2628
2629 @MainActor func testPhoneNoteHeaderActionsScrollWithTheNote() throws {
2630 guard UIDevice.current.userInterfaceIdiom == .phone else { throw XCTSkip("iPhone note header") }
2631 let app = XCUIApplication()
2632 let summary = "# Scroll check\n" + (1...40).map { "- Paragraph \($0) stays in the scroll view." }.joined(separator: "\n")
2633 let fixture: [[String: Any]] = [["title": "Scrolling note", "folder": "Work", "tags": [],
2634 "transcript": "Recorded words.", "summary": summary]]
2635 app.launchEnvironment["JOTLEY_SCREENSHOT_DATA"] = String(decoding: try JSONSerialization.data(withJSONObject: fixture), as: UTF8.self)
2636 app.launchEnvironment["JOTLEY_SCREENSHOT_APPEARANCE"] = "Light"
2637 app.launchArguments = ["-selectedThemeColor", "Magenta", "-jotleyWelcomeCompleted.v1", "YES"]
2638 app.launch()
2639
2640 let share = app.buttons["noteDetailShareButton"]
2641 let more = app.buttons["noteDetailMoreActionsButton"]
2642 if !share.waitForExistence(timeout: 5) {
2643 let row = app.buttons.containing(.staticText, identifier: "Scrolling note").firstMatch
2644 XCTAssertTrue(row.waitForExistence(timeout: 10)); row.tap()
2645 }
2646 XCTAssertTrue(share.waitForExistence(timeout: 15))
2647 XCTAssertTrue(share.isHittable && more.isHittable)
2648 let scroll = app.scrollViews.containing(.staticText, identifier: "noteDetailTitle").firstMatch
2649 XCTAssertTrue(scroll.exists)
2650 let top = XCTAttachment(screenshot: app.screenshot())
2651 top.name = "iPhone note header and footer"; top.lifetime = .keepAlways; add(top)
2652 scroll.swipeUp(velocity: .slow)
2653 XCTAssertFalse(share.isHittable)
2654 XCTAssertFalse(more.isHittable)
2655 XCTAssertTrue(app.buttons["BackButton"].isHittable)
2656 let scrolled = XCTAttachment(screenshot: app.screenshot())
2657 scrolled.name = "iPhone note footer over scrolled content"; scrolled.lifetime = .keepAlways; add(scrolled)
2658 for _ in 0..<3 where !more.isHittable { scroll.swipeDown(velocity: .slow) }
2659 XCTAssertTrue(share.isHittable && more.isHittable)
2660 more.tap()
2661 XCTAssertTrue(app.buttons["noteDetailEditSummaryButton"].waitForExistence(timeout: 5))
2662 }
2663
2664 @MainActor func testTemplateChangesKeepLongSummaryVisibleAndResponsive() throws {
2665 let app = XCUIApplication()
2666 let summary = "# Long recording summary\n" + (0..<500).map { "- **Point \($0)**: decisions and action items from the recorded meeting." }.joined(separator: "\n")
2667 let fixture: [[String: Any]] = [["title": "Long template verification", "folder": "Work", "tags": [],
2668 "transcript": "Recorded meeting words.", "summary": summary]]
2669 app.launchEnvironment["JOTLEY_SCREENSHOT_DATA"] = String(decoding: try JSONSerialization.data(withJSONObject: fixture), as: UTF8.self)
2670 app.launchEnvironment["JOTLEY_SCREENSHOT_APPEARANCE"] = "Dark"
2671 app.launchEnvironment["JOTLEY_TEST_SUMMARY_SCROLL"] = "1"
2672 app.launch()
2673 let row = app.buttons.containing(.staticText, identifier: "Long template verification").firstMatch
2674 XCTAssertTrue(row.waitForExistence(timeout: 15)); row.tap()
2675 XCTAssertTrue(app.staticTexts["Long recording summary"].waitForExistence(timeout: 5))
2676 let quickAction = app.buttons["noteDetailSummaryAskAIButton"]
2677 let quickActionFrame = quickAction.frame
2678 for (key, title) in [("lecture", "Lecture"), ("meetings/general", "General Meeting"), ("default-summary", "Auto"), ("lecture", "Lecture")] {
2679 app.buttons["noteDetailMoreActionsButton"].tap()
2680 app.buttons["noteDetailSummaryTemplateMenu"].tap()
2681 let choice = app.buttons[title]
2682 XCTAssertTrue(choice.waitForExistence(timeout: 5))
2683 let start = Date(); choice.tap()
2684 if key != "default-summary" {
2685 let cancel = app.buttons["noteDetailCancelGenerationButton"]
2686 XCTAssertTrue(cancel.waitForExistence(timeout: 5)); cancel.tap()
2687 }
2688 XCTAssertTrue(quickAction.waitForExistence(timeout: 5))
2689 let actual = quickAction.frame
2690 XCTAssertEqual(actual.width, quickActionFrame.width, accuracy: 0.5)
2691 XCTAssertEqual(actual.height, quickActionFrame.height, accuracy: 0.5)
2692 XCTAssertEqual(actual.minX, quickActionFrame.minX, accuracy: 0.5)
2693 XCTAssertEqual(actual.minY, quickActionFrame.minY, accuracy: 0.5)
2694 print("Long-note template selection \(title): \(Date().timeIntervalSince(start))s")
2695 XCTAssertTrue(app.staticTexts["Long recording summary"].exists)
2696 XCTAssertTrue(app.descendants(matching: .any)["markdownListItem-1"].firstMatch.exists)
2697 XCTAssertFalse(app.textViews.firstMatch.exists, "Template selection must not enter editing")
2698 XCTAssertFalse(app.buttons["noteDetailGenerateSummaryButton"].exists)
2699 }
2700 app.buttons["noteDetailMoreActionsButton"].tap()
2701 let edit = app.buttons["noteDetailEditSummaryButton"]
2702 XCTAssertTrue(edit.waitForExistence(timeout: 5))
2703 let menu = XCTAttachment(screenshot: app.screenshot())
2704 menu.name = "Summary menu with pencil icon"; menu.lifetime = .keepAlways; add(menu)
2705 edit.tap()
2706 XCTAssertTrue(app.textViews["summaryEditorText"].waitForExistence(timeout: 5))
2707 XCTAssertTrue(app.buttons["summaryEditorCancelButton"].exists)
2708 XCTAssertTrue(app.buttons["summaryEditorSaveButton"].exists)
2709 app.buttons["summaryEditorCancelButton"].tap()
2710 XCTAssertTrue(app.staticTexts["Long recording summary"].waitForExistence(timeout: 5))
2711 }
2712
2713 @MainActor func testSummaryModalEditingAndMarkdownLists() throws {
2714 for appearance in ["Dark", "Light"] {
2715 let app = XCUIApplication()
2716 app.launchEnvironment["JOTLEY_SCREENSHOT_APPEARANCE"] = appearance
2717 app.launchEnvironment["JOTLEY_SCREENSHOT_DATA"] = ##"[{"title":"Summary editing verification","folder":"Work","tags":[],"transcript":"Original spoken words.","summary":"# Decisions\n- **Keep** the transcript.\n - Follow up Friday.\n* Review the plan.\n+ Share the checklist.\n1. First step.\n2) Second step."}]"##
2718 app.launch()
2719 let row = app.buttons.containing(.staticText, identifier: "Summary editing verification").firstMatch
2720 XCTAssertTrue(row.waitForExistence(timeout: 15)); row.tap()
2721 let bullet = app.descendants(matching: .any)["markdownListItem-1"].firstMatch
2722 XCTAssertTrue(bullet.waitForExistence(timeout: 5))
2723 XCTAssertEqual(bullet.label, "• Keep the transcript.")
2724 let nested = app.descendants(matching: .any)["markdownListItem-2"].firstMatch
2725 XCTAssertEqual(nested.label, "• Follow up Friday.")
2726 XCTAssertGreaterThan(nested.frame.minX, bullet.frame.minX)
2727 XCTAssertEqual(app.descendants(matching: .any)["markdownListItem-5"].firstMatch.label, "1. First step.")
2728 XCTAssertEqual(app.descendants(matching: .any)["markdownListItem-6"].firstMatch.label, "2. Second step.")
2729 let rendered = XCTAttachment(screenshot: app.screenshot())
2730 rendered.name = "Rendered summary Markdown lists - \(appearance)"; rendered.lifetime = .keepAlways; add(rendered)
2731
2732 func openEditor() {
2733 app.buttons["noteDetailMoreActionsButton"].tap()
2734 let edit = app.buttons["noteDetailEditSummaryButton"]
2735 XCTAssertTrue(edit.waitForExistence(timeout: 5)); XCTAssertEqual(edit.label, "Edit Summary"); edit.tap()
2736 XCTAssertTrue(app.textViews["summaryEditorText"].waitForExistence(timeout: 5))
2737 XCTAssertTrue(app.navigationBars["Edit Summary"].exists)
2738 }
2739 openEditor()
2740 let editor = app.textViews["summaryEditorText"]
2741 XCTAssertTrue((editor.value as? String ?? "").contains("- **Keep** the transcript."))
2742 let modal = XCTAttachment(screenshot: app.screenshot())
2743 modal.name = "Summary Save Cancel modal - \(appearance)"; modal.lifetime = .keepAlways; add(modal)
2744 editor.tap(); editor.typeText("\n\n- Cancelled summary edit.\n\n")
2745 app.buttons["summaryEditorCancelButton"].tap()
2746 XCTAssertTrue(bullet.waitForExistence(timeout: 5))
2747 XCTAssertEqual(bullet.label, "• Keep the transcript.")
2748 openEditor()
2749 XCTAssertFalse((editor.value as? String ?? "").contains("Cancelled summary edit."))
2750 editor.tap(); editor.typeText("\n\n- Approved summary edit.\n\n")
2751 app.buttons["summaryEditorSaveButton"].tap()
2752 let saved = app.descendants(matching: .any).matching(NSPredicate(format: "identifier BEGINSWITH 'markdownListItem-' AND label == %@", "• Approved summary edit.")).firstMatch
2753 XCTAssertTrue(saved.waitForExistence(timeout: 5))
2754 app.buttons["noteDetailTranscriptTab"].tap()
2755 XCTAssertTrue(app.staticTexts["Original spoken words."].waitForExistence(timeout: 5))
2756 openEditor()
2757 XCTAssertTrue((editor.value as? String ?? "").contains("Approved summary edit."))
2758 app.buttons["summaryEditorCancelButton"].tap()
2759 XCTAssertTrue(app.buttons["noteDetailSummaryAskAIButton"].waitForExistence(timeout: 5))
2760 app.terminate()
2761 }
2762 }
2763
2764 @MainActor func testOpenNoteHeadingsFollowLiveAppearanceChanges() throws {
2765 guard ProcessInfo.processInfo.environment["SIMULATOR_MODEL_IDENTIFIER"]?.hasPrefix("iPad") == true else { throw XCTSkip("Needs the iPad split view to keep the note open while changing Settings") }
2766 let app = XCUIApplication()
2767 app.launchEnvironment["JOTLEY_SCREENSHOT_DATA"] = ##"[{"title":"Appearance verification","folder":"Work","tags":[],"transcript":"Recorded words.","summary":"# Neutral Heading\nBody text and a standard bullet:\n- Recorded audio"}]"##
2768 app.launchEnvironment["JOTLEY_SCREENSHOT_APPEARANCE"] = "Dark"
2769 app.launch()
2770 let row = app.buttons.containing(.staticText, identifier: "Appearance verification").firstMatch
2771 XCTAssertTrue(row.waitForExistence(timeout: 15)); row.tap()
2772 let sidebarToggle = app.buttons["notesSidebarToggle"]
2773 XCTAssertTrue(sidebarToggle.waitForExistence(timeout: 5))
2774 XCTAssertEqual(sidebarToggle.label, "Hide Sidebar")
2775 sidebarToggle.tap()
2776 XCTAssertTrue(app.buttons.matching(NSPredicate(format: "identifier == %@ AND label == %@", "notesSidebarToggle", "Show Sidebar")).firstMatch.waitForExistence(timeout: 5))
2777 sidebarToggle.tap()
2778 XCTAssertTrue(app.buttons["notesListSettingsButton"].waitForExistence(timeout: 5))
2779 for mode in ["Light", "Dark", "Light", "Dark"] {
2780 app.buttons["notesListSettingsButton"].tap()
2781 let picker = app.descendants(matching: .any)["settingsAppearanceModePicker"].firstMatch
2782 XCTAssertTrue(picker.waitForExistence(timeout: 5)); picker.tap()
2783 app.buttons[mode].tap(); app.buttons["Done"].tap()
2784 XCTAssertTrue(app.staticTexts["Neutral Heading"].waitForExistence(timeout: 5))
2785 let snapshot = app.screenshot()
2786 let cgImage = try XCTUnwrap(snapshot.image.cgImage)
2787 let context = try XCTUnwrap(CGContext(data: nil, width: cgImage.width, height: cgImage.height,
2788 bitsPerComponent: 8, bytesPerRow: cgImage.width * 4, space: CGColorSpaceCreateDeviceRGB(),
2789 bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue | CGBitmapInfo.byteOrder32Big.rawValue))
2790 context.draw(cgImage, in: CGRect(x: 0, y: 0, width: cgImage.width, height: cgImage.height))
2791 let pixels = try XCTUnwrap(context.data).assumingMemoryBound(to: UInt8.self)
2792 let labels = [app.staticTexts["Neutral Heading"], app.staticTexts["Body text and a standard bullet:"],
2793 app.buttons["noteDetailFolderPicker"], app.buttons["noteDetailAddTagButton"],
2794 app.buttons["noteDetailSummaryAskAIButton"]]
2795 for label in labels {
2796 XCTAssertTrue(label.isHittable)
2797 let frame = label.frame
2798 let scaleX = CGFloat(cgImage.width) / app.frame.width
2799 let scaleY = CGFloat(cgImage.height) / app.frame.height
2800 var levels: [Double] = []
2801 for y in max(0, Int(frame.minY * scaleY))..<min(cgImage.height, Int(frame.maxY * scaleY)) {
2802 for x in max(0, Int(frame.minX * scaleX))..<min(cgImage.width, Int(frame.maxX * scaleX)) {
2803 let offset = y * context.bytesPerRow + x * 4
2804 let channels = [pixels[offset], pixels[offset + 1], pixels[offset + 2]]
2805 if Int(channels.max()!) - Int(channels.min()!) <= 3 { levels.append(Double(channels[0]) / 255) }
2806 }
2807 }
2808 XCTAssertFalse(levels.isEmpty)
2809 if mode == "Light" { XCTAssertLessThan(levels.min() ?? 1, 0.35, "\(label.identifier) must become dark in an already open note") }
2810 else { XCTAssertGreaterThan(levels.max() ?? 0, 0.65, "\(label.identifier) must become light in an already open note") }
2811 }
2812 let attachment = XCTAttachment(screenshot: snapshot)
2813 attachment.name = "Open note live appearance \(mode)"; attachment.lifetime = .keepAlways; add(attachment)
2814 }
2815 }
2816
2817
2818 @MainActor func testExistingNoteGeneratesActualSummaryTitleAndRegeneratesTemplate() throws {
2819 guard case .available = SystemLanguageModel.default.availability else {
2820 throw XCTSkip("Apple summary model is not ready in this simulator")
2821 }
2822 let app = XCUIApplication()
2823 app.launchArguments = ["-transcriptionLanguage", "en-US"]
2824 app.launchEnvironment["JOTLEY_SCREENSHOT_DATA"] = #"""
2825 [{"title":"Untitled","folder":"Work","tags":[],"transcript":"We agreed to keep recordings offline. Maya will test the microphone and Sam will verify the summary templates.","summary":""}]
2826 """#
2827 app.launchEnvironment["JOTLEY_SCREENSHOT_APPEARANCE"] = "Dark"
2828 app.launch()
2829 let row = app.buttons.matching(NSPredicate(format: "identifier BEGINSWITH 'notesListNoteRow-'")).firstMatch
2830 XCTAssertTrue(row.waitForExistence(timeout: 15)); row.tap()
2831 let templates = app.buttons["noteDetailTemplatesButton"]
2832 XCTAssertEqual(templates.label, "Templates: Auto")
2833 let generate = app.buttons["noteDetailGenerateSummaryButton"]
2834 XCTAssertTrue(generate.isEnabled); generate.tap()
2835 let title = app.staticTexts["noteDetailTitle"]
2836 let titled = expectation(for: NSPredicate(format: "exists == true AND label != 'Untitled'"), evaluatedWith: title)
2837 wait(for: [titled], timeout: 60)
2838 XCTAssertTrue(app.descendants(matching: .any)["noteDetailSummaryContent"].exists)
2839 XCTAssertFalse(app.alerts.firstMatch.exists, app.debugDescription)
2840 let generatedTitle = title.label
2841 app.buttons["noteDetailMoreActionsButton"].tap()
2842 app.buttons["noteDetailSummaryTemplateMenu"].tap()
2843 app.buttons["General Meeting"].tap()
2844 XCTAssertTrue(app.descendants(matching: .any)["noteDetailSummaryContent"].exists,
2845 "Changing templates keeps the rendered summary open")
2846 triggerSummaryAction(in: app)
2847 XCTAssertFalse(app.alerts.firstMatch.exists, "Regenerate starts without a confirmation")
2848 let finished = expectation(for: NSPredicate(format: "exists == true AND enabled == true"), evaluatedWith: app.buttons["noteDetailSummaryAskAIButton"])
2849 wait(for: [finished], timeout: 60)
2850 XCTAssertFalse(templates.exists)
2851 XCTAssertEqual(title.label, generatedTitle, "Regeneration preserves the generated title")
2852 XCTAssertFalse(app.alerts.firstMatch.exists, app.debugDescription)
2853 let summary = XCTAttachment(screenshot: app.screenshot())
2854 summary.name = "Actual simulator summary title and template regeneration"; summary.lifetime = .keepAlways; add(summary)
2855 }
2856 #endif
2857
2858 @MainActor func testFloatingButtonShadowsStayNeutralAcrossAppearancesAndThemes() throws {
2859 continueAfterFailure = false
2860 let isPad = UIDevice.current.userInterfaceIdiom == .pad
2861 XCUIDevice.shared.orientation = isPad ? .landscapeLeft : .portrait
2862 defer { XCUIDevice.shared.orientation = .portrait }
2863 let app = XCUIApplication()
2864 app.launchArguments = ["-selectedThemeColor", "Purple", "-jotleyWelcomeCompleted.v1", "YES"]
2865 app.launchEnvironment["JOTLEY_SCREENSHOT_APPEARANCE"] = "Dark"
2866 app.launchEnvironment["JOTLEY_SCREENSHOT_DATA"] = #"""
2867 [{"title":"Launch planning","folder":"Work","tags":[],"transcript":"The team will review the launch on Friday.\n\nMaya will send the revised notes.","summary":""}]
2868 """#
2869 app.launch()
2870 XCTAssertTrue(app.buttons["noteDetailTranscriptTab"].waitForExistence(timeout: 15))
2871 if !isPad { app.buttons["BackButton"].tap() }
2872
2873 func assertShadow(_ button: XCUIElement, theme: String, mode: String) throws {
2874 XCTAssertTrue(button.isHittable)
2875 let screenshot = app.screenshot()
2876 let image = try XCTUnwrap(screenshot.image.cgImage)
2877 let context = try XCTUnwrap(CGContext(data: nil, width: image.width, height: image.height,
2878 bitsPerComponent: 8, bytesPerRow: image.width * 4, space: CGColorSpaceCreateDeviceRGB(),
2879 bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue | CGBitmapInfo.byteOrder32Big.rawValue))
2880 context.draw(image, in: CGRect(x: 0, y: 0, width: image.width, height: image.height))
2881 let pixels = try XCTUnwrap(context.data).assumingMemoryBound(to: UInt8.self)
2882 let frame = button.frame
2883 let scale = CGFloat(image.width) / app.frame.width
2884 var sum = [Double](repeating: 0, count: 3)
2885 var count = 0.0
2886 // Sample outside the capsule to isolate its shadow from the label and surface.
2887 for edge in [frame.minY - 7, frame.maxY + 2] {
2888 for y in max(0, Int(edge * scale))..<min(image.height, Int((edge + 5) * scale)) {
2889 for x in max(0, Int((frame.midX - 5) * scale))..<min(image.width, Int((frame.midX + 5) * scale)) {
2890 let offset = y * context.bytesPerRow + x * 4
2891 for channel in 0..<3 { sum[channel] += Double(pixels[offset + channel]) }
2892 count += 1
2893 }
2894 }
2895 }
2896 XCTAssertGreaterThan(count, 0)
2897 let rgb = sum.map { $0 / max(1, count) }
2898 XCTAssertLessThan(rgb.max()! - rgb.min()!, 2, "Shadow must stay neutral in \(mode) with the \(theme) theme")
2899 }
2900 for theme in ["Purple", "Orange", "Magenta", "Yellow", "Light Blue", "Neutral"] {
2901 for mode in ["Light", "Dark"] {
2902 let gear = app.buttons["notesListSettingsButton"]
2903 gear.tap()
2904 app.descendants(matching: .any)["settingsAppearanceModePicker"].firstMatch.tap()
2905 app.buttons[mode].tap()
2906 app.descendants(matching: .any)["settingsThemeColorPicker"].firstMatch.tap()
2907 app.buttons[theme].tap()
2908 app.buttons["settingsDoneButton"].tap()
2909 XCTAssertTrue(gear.waitForExistence(timeout: 5))
2910 let shot = XCTAttachment(screenshot: app.screenshot())
2911 shot.name = "Live floating shadows - \(mode) - \(theme)"; shot.lifetime = .keepAlways; add(shot)
2912 try assertShadow(app.buttons["notesListNewNoteButton"].firstMatch, theme: theme, mode: mode)
2913 // In a split view, the window controls can overlap the sidebar's
2914 // Settings sample. Check the same surface on Plus and Continue.
2915 if !isPad { try assertShadow(gear, theme: theme, mode: mode) }
2916 if !isPad { app.buttons.containing(.staticText, identifier: "Launch planning").firstMatch.tap() }
2917 let resume = app.buttons["noteDetailContinueTranscriptionButton"]
2918 XCTAssertTrue(resume.waitForExistence(timeout: 5))
2919 XCTAssertTrue(app.buttons["noteDetailTemplatesButton"].isHittable)
2920 XCTAssertTrue(app.buttons["noteDetailGenerateSummaryButton"].isHittable)
2921 let detail = XCTAttachment(screenshot: XCUIScreen.main.screenshot())
2922 detail.name = "Theme detail - \(mode) - \(theme)"; detail.lifetime = .keepAlways; add(detail)
2923 try assertShadow(resume, theme: theme, mode: mode)
2924 if !isPad { app.buttons["BackButton"].tap() }
2925 }
2926 }
2927 }
2928
2929 @MainActor func testBrandedEmptyLibrary() throws {
2930 let isPad = UIDevice.current.userInterfaceIdiom == .pad
2931 XCUIDevice.shared.orientation = isPad ? .landscapeLeft : .portrait
2932 defer { XCUIDevice.shared.orientation = .portrait }
2933 let app = XCUIApplication()
2934 app.launchArguments = ["-jotleyWelcomeCompleted.v1", "YES", "-selectedThemeColor", "Purple"]
2935 app.launchEnvironment["JOTLEY_SCREENSHOT_DATA"] = "[]"
2936 app.launchEnvironment["JOTLEY_SCREENSHOT_APPEARANCE"] = "Light"
2937 app.launch()
2938 let heading = app.staticTexts["libraryWelcomeHeading"]
2939 XCTAssertTrue(heading.waitForExistence(timeout: 10))
2940 XCTAssertEqual(heading.label, "Your words. Your device.")
2941 XCTAssertTrue(app.buttons["libraryWelcomeStartButton"].isHittable)
2942 if isPad { XCTAssertTrue(app.staticTexts["New transcripts and summaries will appear here."].exists) }
2943 let screen = XCUIScreen.main.screenshot()
2944 if isPad { XCTAssertGreaterThan(screen.image.size.width, screen.image.size.height) }
2945 let screenshot = XCTAttachment(screenshot: screen)
2946 screenshot.name = isPad ? "Jotley iPad Welcome" : "Jotley iPhone Welcome"
2947 screenshot.lifetime = .keepAlways
2948 add(screenshot)
2949 }
2950
2951 @MainActor func testCustomWordsCanBeSavedAndReopened() throws {
2952 continueAfterFailure = false
2953 let app = XCUIApplication()
2954 app.launchArguments = ["-jotleyWelcomeCompleted.v1", "YES"]
2955 app.launchEnvironment["JOTLEY_TEST_RESET_CUSTOM_WORDS"] = "1"
2956 app.launchEnvironment["JOTLEY_SCREENSHOT_DATA"] = "[]"
2957 app.launchEnvironment["JOTLEY_SCREENSHOT_APPEARANCE"] = "Light"
2958 app.launch()
2959 let gear = app.buttons["notesListSettingsButton"]
2960 XCTAssertTrue(gear.waitForExistence(timeout: 15)); gear.tap()
2961 let words = app.buttons["settingsCustomWordsButton"]
2962 for _ in 0..<6 where !words.isHittable { app.swipeUp(velocity: .slow) }
2963 XCTAssertTrue(words.isHittable); words.tap()
2964 let editor = app.textViews["customWordsEditor"]
2965 XCTAssertTrue(editor.waitForExistence(timeout: 5)); editor.tap()
2966 editor.typeText("Jason\nProtomota")
2967 XCTAssertTrue(app.staticTexts["2 of 100 entries"].exists)
2968 app.buttons["customWordsSaveButton"].tap()
2969 XCTAssertTrue(words.waitForExistence(timeout: 5)); words.tap()
2970 XCTAssertTrue(editor.waitForExistence(timeout: 5))
2971 XCTAssertEqual(editor.value as? String, "Jason\nProtomota")
2972 Thread.sleep(forTimeInterval: 1.5)
2973 app.buttons["Cancel"].tap()
2974 }
2975
2976 @MainActor func testCustomWordsImportsDelimitedFile() throws {
2977 continueAfterFailure = false
2978 let isPad = UIDevice.current.userInterfaceIdiom == .pad
2979 XCUIDevice.shared.orientation = isPad ? .landscapeLeft : .portrait
2980 defer { XCUIDevice.shared.orientation = .portrait }
2981 let app = XCUIApplication()
2982 app.launchArguments = ["-jotleyWelcomeCompleted.v1", "YES"]
2983 app.launchEnvironment["JOTLEY_TEST_RESET_CUSTOM_WORDS"] = "1"
2984 app.launchEnvironment["JOTLEY_SCREENSHOT_DATA"] = "[]"
2985 app.launchEnvironment["JOTLEY_SCREENSHOT_APPEARANCE"] = "Light"
2986 app.launch()
2987 let gear = app.buttons["notesListSettingsButton"]
2988 XCTAssertTrue(gear.waitForExistence(timeout: 15)); gear.tap()
2989 let words = app.buttons["settingsCustomWordsButton"]
2990 let settings = app.scrollViews.firstMatch
2991 for _ in 0..<6 where !words.isHittable {
2992 if settings.isHittable { settings.swipeUp(velocity: .slow) }
2993 else { app.swipeUp(velocity: .slow) }
2994 }
2995 XCTAssertTrue(words.isHittable); words.tap()
2996 let importer = app.buttons["customWordsImportButton"]
2997 XCTAssertTrue(importer.waitForExistence(timeout: 5)); importer.tap()
2998
2999 let file = app.descendants(matching: .any).matching(NSPredicate(format: "label BEGINSWITH[c] %@", "jotley-custom-words-demo")).firstMatch
3000 let local = app.descendants(matching: .any).matching(NSPredicate(format: "label == %@", isPad ? "On My iPad" : "On My iPhone")).firstMatch
3001 if !file.isHittable && !local.isHittable {
3002 let browse = app.buttons["Browse"].firstMatch
3003 if browse.waitForExistence(timeout: 5) { browse.tap() }
3004 }
3005 if !file.isHittable && local.waitForExistence(timeout: 3) { local.tap() }
3006 try XCTSkipUnless(file.waitForExistence(timeout: 5), "Seed the sample word-list CSV in the simulator's local Files storage.")
3007 file.tap()
3008 let editor = app.textViews["customWordsEditor"]
3009 XCTAssertTrue(editor.waitForExistence(timeout: 5))
3010 XCTAssertEqual(editor.value as? String, "PulseCanvas\nTextley\nJason")
3011 XCTAssertTrue(app.staticTexts["3 of 100 entries"].exists)
3012 Thread.sleep(forTimeInterval: 1.5)
3013 app.buttons["customWordsSaveButton"].tap()
3014 XCTAssertTrue(words.waitForExistence(timeout: 5)); words.tap()
3015 XCTAssertTrue(editor.waitForExistence(timeout: 5))
3016 XCTAssertEqual(editor.value as? String, "PulseCanvas\nTextley\nJason")
3017 Thread.sleep(forTimeInterval: 1.5)
3018 }
3019
3020 @MainActor func testFindReplaceAllKeepsTranscriptTiming() throws {
3021 continueAfterFailure = false
3022 let isPad = UIDevice.current.userInterfaceIdiom == .pad
3023 XCUIDevice.shared.orientation = isPad ? .landscapeLeft : .portrait
3024 defer { XCUIDevice.shared.orientation = .portrait }
3025 let app = XCUIApplication()
3026 app.launchArguments = ["-jotleyWelcomeCompleted.v1", "YES"]
3027 app.launchEnvironment["JOTLEY_SCREENSHOT_APPEARANCE"] = "Light"
3028 app.launchEnvironment["JOTLEY_SCREENSHOT_DATA"] = #"[{"title":"Launch planning","folder":"Work","tags":[],"transcript":"JSON is reviewing the design.\n\nSend JSON the revised notes. Keep JSONKit as written.","summary":""}]"#
3029 app.launch()
3030 let menu = app.buttons["noteDetailMoreActionsButton"]
3031 XCTAssertTrue(menu.waitForExistence(timeout: 15))
3032 XCTAssertGreaterThanOrEqual(menu.frame.width, 43)
3033 let continuation = app.buttons["noteDetailContinueTranscriptionButton"]
3034 let capture = app.buttons["notesListNewNoteButton"].firstMatch
3035 XCTAssertTrue(continuation.isHittable && capture.isHittable)
3036 XCTAssertEqual(continuation.frame.midY, capture.frame.midY, accuracy: 1.0)
3037 if isPad {
3038 let gear = app.buttons["notesListSettingsButton"]
3039 XCTAssertEqual(gear.frame.midY, capture.frame.midY, accuracy: 1.0)
3040 }
3041 let toolbar = XCTAttachment(screenshot: XCUIScreen.main.screenshot())
3042 toolbar.name = "Jotley More button"
3043 toolbar.lifetime = .keepAlways
3044 add(toolbar)
3045 menu.tap()
3046 app.buttons["noteDetailEditTranscriptButton"].tap()
3047 let replaceHeader = app.buttons["transcriptFindReplace"]
3048 XCTAssertTrue(replaceHeader.waitForExistence(timeout: 5)); replaceHeader.tap()
3049 let find = app.textFields["transcriptFindField"]
3050 XCTAssertTrue(find.waitForExistence(timeout: 5))
3051 let replacement = app.textFields["transcriptReplaceField"]
3052 XCTAssertGreaterThanOrEqual(find.frame.height, 44)
3053 XCTAssertGreaterThanOrEqual(replacement.frame.height, 44)
3054 let editor = XCTAttachment(screenshot: XCUIScreen.main.screenshot())
3055 editor.name = "Full-size Find and Replace fields"
3056 editor.lifetime = .keepAlways
3057 add(editor)
3058 find.tap(); find.typeText("JSON")
3059 replacement.tap(); replacement.typeText("Jason")
3060 XCTAssertTrue(app.staticTexts["2 matches in this transcript"].exists)
3061 let replace = app.buttons["transcriptReplaceAllButton"]
3062 if !replace.isHittable { app.swipeUp(velocity: .slow) }
3063 replace.tap()
3064 XCTAssertTrue(app.staticTexts["Replaced 2 matches."].waitForExistence(timeout: 4))
3065 Thread.sleep(forTimeInterval: 1)
3066 app.buttons["transcriptEditorSaveButton"].tap()
3067 XCTAssertTrue(app.staticTexts.containing(NSPredicate(format: "label CONTAINS %@", "Jason is reviewing")).firstMatch.waitForExistence(timeout: 5))
3068 XCTAssertTrue(app.staticTexts.containing(NSPredicate(format: "label CONTAINS %@", "Send Jason the revised notes. Keep JSONKit")).firstMatch.exists)
3069 XCTAssertTrue(app.staticTexts["00:00"].exists)
3070 XCTAssertTrue(app.staticTexts["00:25"].exists)
3071 Thread.sleep(forTimeInterval: 1.5)
3072 }
3073
3074 @MainActor func testSummaryFindReplaceSavesEditedMarkdown() throws {
3075 continueAfterFailure = false
3076 let app = XCUIApplication()
3077 app.launchArguments = ["-jotleyWelcomeCompleted.v1", "YES", "-selectedThemeColor", "Magenta"]
3078 app.launchEnvironment["JOTLEY_SCREENSHOT_APPEARANCE"] = "Dark"
3079 app.launchEnvironment["JOTLEY_SCREENSHOT_DATA"] = ###"[{"title":"Launch plan","folder":"Work","tags":[],"transcript":"The team agreed to review the launch.","summary":"## Action Items\n- **Alex**: Review the launch.\n- Ask Alex for feedback. Keep Alexa as written."}]"###
3080 app.launch()
3081
3082 let more = app.buttons["noteDetailMoreActionsButton"]
3083 XCTAssertTrue(more.waitForExistence(timeout: 15))
3084 more.tap()
3085 app.buttons["noteDetailEditSummaryButton"].tap()
3086 let panel = app.buttons["summaryFindReplace"]
3087 XCTAssertTrue(panel.waitForExistence(timeout: 5))
3088 panel.tap()
3089 let openPanel = XCTAttachment(screenshot: XCUIScreen.main.screenshot())
3090 openPanel.name = "Find and Replace in Edit Summary"
3091 openPanel.lifetime = .keepAlways
3092 add(openPanel)
3093
3094 let find = app.textFields["summaryFindField"]
3095 find.tap(); find.typeText("Alex")
3096 let replacement = app.textFields["summaryReplaceField"]
3097 replacement.tap(); replacement.typeText("Sam")
3098 XCTAssertTrue(app.staticTexts["2 matches in this summary"].exists)
3099 let replace = app.buttons["summaryReplaceAllButton"]
3100 if !replace.isHittable { app.swipeUp(velocity: .slow) }
3101 replace.tap()
3102 XCTAssertTrue(app.staticTexts["Replaced 2 matches."].waitForExistence(timeout: 5))
3103 let editor = app.textViews["summaryEditorText"]
3104 XCTAssertEqual(editor.value as? String, "## Action Items\n- **Sam**: Review the launch.\n- Ask Sam for feedback. Keep Alexa as written.")
3105 let result = XCTAttachment(screenshot: XCUIScreen.main.screenshot())
3106 result.name = "Two matches replaced in the summary"
3107 result.lifetime = .keepAlways
3108 add(result)
3109 app.buttons["summaryEditorSaveButton"].tap()
3110 XCTAssertTrue(more.waitForExistence(timeout: 5))
3111 more.tap()
3112 app.buttons["noteDetailEditSummaryButton"].tap()
3113 XCTAssertTrue(editor.waitForExistence(timeout: 5))
3114 XCTAssertEqual(editor.value as? String, "## Action Items\n- **Sam**: Review the launch.\n- Ask Sam for feedback. Keep Alexa as written.")
3115 }
3116
3117 @MainActor func testFloatingGlassWhileScrollingNotes() throws {
3118 continueAfterFailure = false
3119 let app = XCUIApplication()
3120 app.launchArguments = ["-selectedThemeColor", "Purple", "-jotleyWelcomeCompleted.v1", "YES"]
3121 app.launchEnvironment["JOTLEY_SCREENSHOT_CHAT_READY"] = "1"
3122 let summary = "## Project plan\n" + (1...25).map {
3123 "- **Checkpoint \($0):** Review launch notes with Jason and share the updated design plan with the whole team."
3124 }.joined(separator: "\n")
3125 let notes: [[String: Any]] = (1...24).map { index in
3126 ["title": "Launch planning \(index)", "folder": "Work", "tags": [String](),
3127 "transcript": "Jason reviewed the launch notes and agreed to update the design plan.",
3128 "summary": index == 1 ? summary : "The team agreed to share the revised launch plan on Friday."]
3129 }
3130 app.launchEnvironment["JOTLEY_SCREENSHOT_DATA"] = String(decoding: try JSONSerialization.data(withJSONObject: notes), as: UTF8.self)
3131 for mode in ["Light", "Dark"] {
3132 app.launchEnvironment["JOTLEY_SCREENSHOT_APPEARANCE"] = mode
3133 app.launch()
3134 let ask = app.buttons["noteDetailSummaryAskAIButton"]
3135 XCTAssertTrue(ask.waitForExistence(timeout: 15))
3136 let scroll = app.scrollViews.firstMatch
3137 scroll.swipeUp(velocity: .slow)
3138 let shot = XCTAttachment(screenshot: XCUIScreen.main.screenshot())
3139 shot.name = "Glass over scrolling text - \(mode)"; shot.lifetime = .keepAlways; add(shot)
3140 scroll.swipeDown(velocity: .slow)
3141 XCTAssertTrue(ask.isHittable)
3142 ask.tap(); app.buttons["askAIDoneButton"].tap()
3143 showNotesLibrary(app)
3144 let gear = app.buttons["notesListSettingsButton"]
3145 let add = app.buttons["notesListNewNoteButton"].firstMatch
3146 XCTAssertTrue(gear.isHittable); XCTAssertTrue(add.isHittable)
3147 app.swipeUp(velocity: .slow)
3148 app.swipeDown(velocity: .slow)
3149 XCTAssertTrue(gear.isHittable); XCTAssertTrue(add.isHittable)
3150 Thread.sleep(forTimeInterval: 1)
3151 }
3152 }
3153
3154 @MainActor func testSettingsGlassAndAskAIReadability() throws {
3155 let isPad = (ProcessInfo.processInfo.environment["SIMULATOR_MODEL_IDENTIFIER"] ?? "").hasPrefix("iPad")
3156 XCUIDevice.shared.orientation = isPad ? .landscapeLeft : .portrait
3157 defer { XCUIDevice.shared.orientation = .portrait }
3158 let app = XCUIApplication()
3159 app.launchArguments = ["-selectedThemeColor", "Purple", "-jotleyWelcomeCompleted.v1", "YES"]
3160 app.launchEnvironment["JOTLEY_SCREENSHOT_CHAT_READY"] = "1"
3161 app.launchEnvironment["JOTLEY_TEST_TRANSCRIPTION_LIFECYCLE"] = "1"
3162 app.launchEnvironment["JOTLEY_SCREENSHOT_DATA"] = #"""
3163 [{"title":"Readable Ask AI controls","folder":"Work","tags":[],"transcript":"The team will review the launch on Friday.\n\nJason will send the revised notes.","summary":"## Summary\nThe team has a clear plan for Friday."}]
3164 """#
3165 for mode in ["Dark", "Light"] {
3166 app.launchEnvironment["JOTLEY_SCREENSHOT_APPEARANCE"] = mode
3167 app.launch()
3168 XCTAssertTrue(app.buttons["noteDetailSummaryTab"].waitForExistence(timeout: 15))
3169 if !isPad { app.buttons["BackButton"].tap() }
3170 let gear = app.buttons["notesListSettingsButton"]
3171 XCTAssertTrue(gear.waitForExistence(timeout: 5)); XCTAssertTrue(gear.isHittable)
3172 XCTAssertEqual(gear.frame.width, 44, accuracy: 1); XCTAssertEqual(gear.frame.height, 44, accuracy: 1)
3173 let gearShot = XCTAttachment(screenshot: app.screenshot())
3174 gearShot.name = "Settings glass - \(mode)"; gearShot.lifetime = .keepAlways; add(gearShot)
3175 gear.tap()
3176 let settingsDone = app.buttons["settingsDoneButton"]
3177 XCTAssertTrue(settingsDone.waitForExistence(timeout: 5))
3178 let settingsShot = XCTAttachment(screenshot: XCUIScreen.main.screenshot())
3179 settingsShot.name = "Settings Done - \(mode)"; settingsShot.lifetime = .keepAlways; add(settingsShot)
3180 settingsDone.tap()
3181 if !isPad { app.buttons.containing(.staticText, identifier: "Readable Ask AI controls").firstMatch.tap() }
3182 let ask = app.buttons["noteDetailSummaryAskAIButton"]
3183 XCTAssertTrue(ask.waitForExistence(timeout: 5))
3184 let askShot = XCTAttachment(screenshot: XCUIScreen.main.screenshot())
3185 askShot.name = "Ask AI button - \(mode)"; askShot.lifetime = .keepAlways; add(askShot)
3186 ask.tap()
3187 let done = app.buttons["askAIDoneButton"]
3188 XCTAssertTrue(done.waitForExistence(timeout: 5)); XCTAssertTrue(done.isEnabled)
3189 for identifier in ["askAICopyConversationButton", "askAIShareConversationButton", "askAIClearButton"] {
3190 let button = app.buttons[identifier]
3191 XCTAssertTrue(button.exists); XCTAssertFalse(button.isEnabled, "An empty conversation action must stay disabled")
3192 XCTAssertGreaterThanOrEqual(button.frame.height, 44)
3193 }
3194 let chatShot = XCTAttachment(screenshot: app.screenshot())
3195 chatShot.name = "Ask AI contrast - \(mode)"; chatShot.lifetime = .keepAlways; add(chatShot)
3196 done.tap()
3197 app.buttons["noteDetailMoreActionsButton"].tap()
3198 XCTAssertEqual(app.buttons["noteDetailSummaryTemplateMenu"].label, "Template")
3199 XCTAssertEqual(app.buttons["noteDetailContinueTranscriptionMenuButton"].label, "Continue")
3200 let menuShot = XCTAttachment(screenshot: XCUIScreen.main.screenshot())
3201 menuShot.name = "More menu - \(mode)"; menuShot.lifetime = .keepAlways; add(menuShot)
3202 app.buttons["noteDetailEditTranscriptButton"].tap()
3203 let cancel = app.buttons["transcriptEditorCancelButton"]
3204 XCTAssertTrue(cancel.waitForExistence(timeout: 5)); XCTAssertTrue(cancel.isHittable)
3205 XCTAssertGreaterThanOrEqual(cancel.frame.width, 62, "Cancel must fit on one line in the toolbar")
3206 let editorShot = XCTAttachment(screenshot: XCUIScreen.main.screenshot())
3207 editorShot.name = "Transcript editor Cancel - \(mode)"; editorShot.lifetime = .keepAlways; add(editorShot)
3208 cancel.tap()
3209 app.buttons["noteDetailTranscriptTab"].tap()
3210 XCTAssertTrue(app.staticTexts["00:00"].exists)
3211 XCTAssertTrue(app.staticTexts["00:25"].exists)
3212 XCTAssertTrue(app.staticTexts["The team will review the launch on Friday."].exists)
3213 XCTAssertTrue(app.staticTexts["Jason will send the revised notes."].exists)
3214 let resume = app.buttons["noteDetailContinueTranscriptionButton"]
3215 XCTAssertTrue(resume.isHittable)
3216 let transcriptShot = XCTAttachment(screenshot: XCUIScreen.main.screenshot())
3217 transcriptShot.name = "Continue Transcription button - \(mode)"; transcriptShot.lifetime = .keepAlways; add(transcriptShot)
3218 resume.tap()
3219 let stop = app.buttons["transcriptionStopButton"]
3220 XCTAssertTrue(stop.waitForExistence(timeout: 10))
3221 let pause = app.buttons["transcriptionPauseButton"]
3222 XCTAssertTrue(pause.waitForExistence(timeout: 5))
3223 XCTAssertTrue(app.buttons["transcriptionCloseButton"].isHittable)
3224 let liveShot = XCTAttachment(screenshot: XCUIScreen.main.screenshot())
3225 liveShot.name = "Live transcription controls - \(mode)"; liveShot.lifetime = .keepAlways; add(liveShot)
3226 pause.tap()
3227 let paused = XCTNSPredicateExpectation(predicate: NSPredicate(format: "label == %@", "Resume transcription"), object: pause)
3228 XCTAssertEqual(XCTWaiter.wait(for: [paused], timeout: 5), .completed)
3229 let pausedShot = XCTAttachment(screenshot: XCUIScreen.main.screenshot())
3230 pausedShot.name = "Paused transcription controls - \(mode)"; pausedShot.lifetime = .keepAlways; add(pausedShot)
3231 pause.tap()
3232 let resumed = XCTNSPredicateExpectation(predicate: NSPredicate(format: "label == %@", "Pause transcription"), object: pause)
3233 XCTAssertEqual(XCTWaiter.wait(for: [resumed], timeout: 5), .completed)
3234 stop.tap()
3235 }
3236 }
3237
3238 @MainActor func testMarketingChatCaptureAndControls() throws {
3239 let app = XCUIApplication()
3240 app.launchEnvironment["JOTLEY_SCREENSHOT_CHAT_READY"] = "1"
3241 app.launchEnvironment["JOTLEY_SCREENSHOT_DATA"] = #"[{"title":"Friday Launch Plan","folder":"Work","tags":["Design","Planning","Product"],"transcript":"Alex will finish accessibility checks Thursday. Sam will share the launch checklist. Maya leads the review Friday at 10:00.","summary":"The team agreed on a focused Friday launch.","messages":[{"role":"user","content":"Who is doing what before Friday?"},{"role":"assistant","content":"- **Alex:** finish the accessibility checks by Thursday.\n- **Sam:** share the launch checklist and gather feedback.\n- **Maya:** lead the final review on Friday at 10:00."}]}]"#
3242 app.launchEnvironment["JOTLEY_SCREENSHOT_APPEARANCE"] = "Light"
3243 app.launchArguments = ["-selectedThemeColor", "Purple", "-jotleyWelcomeCompleted.v1", "YES"]
3244 XCUIDevice.shared.orientation = .portrait
3245 app.launch()
3246 let ask = app.buttons["noteDetailSummaryAskAIButton"]
3247 XCTAssertTrue(ask.waitForExistence(timeout: 15)); ask.tap()
3248 let done = app.buttons["askAIDoneButton"]
3249 XCTAssertTrue(done.waitForExistence(timeout: 10))
3250 XCTAssertTrue(app.buttons["askAICopyConversationButton"].isEnabled)
3251 XCTAssertTrue(app.buttons["askAIShareConversationButton"].isEnabled)
3252 for (index, screen) in XCUIScreen.screens.enumerated() {
3253 let shot = XCTAttachment(screenshot: screen.screenshot())
3254 shot.name = "Marketing-chat-screen-\(index)"; shot.lifetime = .keepAlways; add(shot)
3255 }
3256 app.buttons["askAICopyConversationButton"].tap()
3257 app.buttons["askAIClearButton"].tap()
3258 XCTAssertTrue(app.buttons["askAIClearCancelButton"].waitForExistence(timeout: 5))
3259 for (index, screen) in XCUIScreen.screens.enumerated() {
3260 let shot = XCTAttachment(screenshot: screen.screenshot())
3261 shot.name = "Local-clear-confirmation-screen-\(index)"; shot.lifetime = .keepAlways; add(shot)
3262 }
3263 app.buttons["askAIClearCancelButton"].tap()
3264 XCTAssertTrue(app.buttons["askAICopyConversationButton"].isEnabled)
3265 done.tap(); XCTAssertTrue(ask.waitForExistence(timeout: 5))
3266 ask.tap(); XCTAssertTrue(done.waitForExistence(timeout: 5)); done.tap()
3267 }
3268
3269 // BEGIN LOCAL MARKETING CAPTURE
3270 @MainActor func testMarketingLiveWaveformCapture() throws {
3271 guard let levels = ProcessInfo.processInfo.environment["JOTLEY_MARKETING_AUDIO_LEVELS"] else {
3272 throw XCTSkip("Marketing waveform capture requires measured speech PCM peaks")
3273 }
3274 let app = XCUIApplication()
3275 app.launchEnvironment["JOTLEY_SCREENSHOT_DATA"] = "[]"
3276 app.launchEnvironment["JOTLEY_SCREENSHOT_APPEARANCE"] = "Light"
3277 app.launchEnvironment["JOTLEY_TEST_TRANSCRIPTION_LIFECYCLE"] = "1"
3278 app.launchEnvironment["JOTLEY_SCREENSHOT_AUDIO_LEVELS"] = levels
3279 app.launchEnvironment["JOTLEY_SCREENSHOT_LIVE_TEXT"] = "Let’s keep Friday’s launch focused. One clear welcome, readable notes and a final review. Alex will finish the accessibility checks by Thursday. Sam will share the launch checklist."
3280 app.launchArguments = ["-selectedThemeColor", "Purple", "-jotleyWelcomeCompleted.v1", "YES", "-jotley.summaryDisplayStyle", "cards"]
3281 XCUIDevice.shared.orientation = .portrait
3282 app.launch()
3283 let start = app.buttons["notesListNewNoteButton"].firstMatch
3284 XCTAssertTrue(start.waitForExistence(timeout: 15)); start.tap()
3285 XCTAssertTrue(app.buttons["transcriptionPauseButton"].waitForExistence(timeout: 10))
3286 let waveform = app.descendants(matching: .any).matching(NSPredicate(format: "label == %@", "Live microphone waveform")).firstMatch
3287 XCTAssertTrue(waveform.waitForExistence(timeout: 5))
3288 Thread.sleep(forTimeInterval: 3.5) // Fill the native bar history with measured speech peaks.
3289 let first = waveform.screenshot().pngRepresentation
3290 for (index, screen) in XCUIScreen.screens.enumerated() {
3291 let image = XCTAttachment(screenshot: screen.screenshot())
3292 image.name = "Marketing-live-waveform-a-screen-\(index)"; image.lifetime = .keepAlways; add(image)
3293 }
3294 Thread.sleep(forTimeInterval: 0.4)
3295 XCTAssertNotEqual(first, waveform.screenshot().pngRepresentation, "Measured speech must move the native waveform, not leave a flat line")
3296 for (index, screen) in XCUIScreen.screens.enumerated() {
3297 let image = XCTAttachment(screenshot: screen.screenshot())
3298 image.name = "Marketing-live-waveform-b-screen-\(index)"; image.lifetime = .keepAlways; add(image)
3299 }
3300 app.buttons["transcriptionStopButton"].tap()
3301 app.terminate()
3302 }
3303
3304 @MainActor func testMarketingLayoutCaptures() throws {
3305 let app = XCUIApplication()
3306 app.launchEnvironment["JOTLEY_SCREENSHOT_CHAT_READY"] = "1"
3307 app.launchEnvironment["JOTLEY_SCREENSHOT_DATA"] = ###"""
3308[
3309 {
3310 "title": "Friday Launch Plan",
3311 "folder": "Work",
3312 "tags": [
3313 "Design",
3314 "Product",
3315 "Planning"
3316 ],
3317 "transcript": "Maya: Let’s keep Friday’s launch focused. The new welcome flow should show people how to start a transcription, find a summary and ask their notes a question.\n\nAlex: I’ll finish the accessibility checks by Thursday afternoon. We should test the compact layout as carefully as the larger one.\n\nSam: I’ll share the launch checklist and gather feedback from the team. Let’s review the final screenshots tomorrow.\n\nMaya: Agreed. We’ll meet Friday at ten, review the remaining questions and make the launch decision together.",
3318 "summary": "## Summary\nThe team agreed on a focused Friday launch, with clear onboarding, readable notes and a final accessibility review.\n\n## Key Points\n- Keep the welcome flow simple and useful.\n- Check both compact and larger layouts.\n- Review the final screenshots before launch.\n\n## Decisions\n- Meet Friday at 10:00 for the final launch review.\n\n## Action Items\n- Alex: finish accessibility checks by Thursday.\n- Sam: share the launch checklist and gather feedback.\n- Maya: lead the final review on Friday.",
3319 "timestampOffset": -3600,
3320 "messages": [
3321 {
3322 "role": "user",
3323 "content": "Who is doing what before Friday?"
3324 },
3325 {
3326 "role": "assistant",
3327 "content": "- **Alex:** finish the accessibility checks by Thursday.\n- **Sam:** share the launch checklist and gather feedback.\n- **Maya:** lead the final review on Friday at 10:00."
3328 }
3329 ]
3330 },
3331 {
3332 "title": "Lecture: Working Memory",
3333 "folder": "Study",
3334 "tags": [
3335 "Learning",
3336 "Psychology"
3337 ],
3338 "transcript": "Working memory holds information while we use it. Focus on one task, group related ideas and test recall without looking at your notes. Space your study sessions over several days.",
3339 "summary": "## Summary\nAttention and recall improve when study sessions focus on one task at a time.\n\n## Key Points\n- Group related ideas.\n- Explain concepts in your own words.\n- Review over several days.",
3340 "timestampOffset": -7200
3341 },
3342 {
3343 "title": "Ideas for the Weekend",
3344 "folder": "Personal",
3345 "tags": [
3346 "Ideas"
3347 ],
3348 "transcript": "Walk the river trail. Try a new recipe. Make time for a conversation with friends. Leave the rest of the afternoon open.",
3349 "summary": "## Summary\nA little time outside, something new to try and room for the people who matter.",
3350 "timestampOffset": -90000
3351 },
3352 {
3353 "title": "Design Review: A Clearer First Step",
3354 "folder": "Work",
3355 "tags": [
3356 "Design",
3357 "Research"
3358 ],
3359 "transcript": "The first screen should make the next step obvious. We agreed to simplify the labels, keep the primary action visible and check the contrast in light and dark mode.",
3360 "summary": "## Summary\nA clearer first step helps people start with confidence.\n\n## Key Points\n- Use short, familiar labels.\n- Keep the primary action visible.\n- Check contrast in both appearances.",
3361 "timestampOffset": -172800
3362 },
3363 {
3364 "title": "Book Club: Small Habits",
3365 "folder": "Personal",
3366 "tags": [
3367 "Reading",
3368 "Ideas"
3369 ],
3370 "transcript": "Make the habit small enough to start on a busy day. Keep the book where you will see it. Five pages each evening is a better starting point than a perfect plan.",
3371 "summary": "## Summary\nSmall, repeatable habits make room for more reading.\n\n## Action Items\n- Leave the next book beside the reading chair.\n- Read five pages each evening.",
3372 "timestampOffset": -180000
3373 },
3374 {
3375 "title": "Lecture: How We Learn",
3376 "folder": "Study",
3377 "tags": [
3378 "Learning"
3379 ],
3380 "transcript": "Practice remembering an idea before checking the answer. Mix short recall sessions with time between reviews. Explain the concept in your own words to spot what is still unclear.",
3381 "summary": "## Summary\nRecall, spacing and explanation help ideas stay useful.\n\n## Key Points\n- Try recall before rereading.\n- Leave time between reviews.\n- Explain the concept in your own words.",
3382 "timestampOffset": -259200
3383 },
3384 {
3385 "title": "Garden Plans for Spring",
3386 "folder": "Personal",
3387 "tags": [
3388 "Home",
3389 "Ideas"
3390 ],
3391 "transcript": "Grow herbs near the kitchen window and start tomatoes when the weather warms. Check which planters get the most sunlight. Keep the first season simple.",
3392 "summary": "## Summary\nStart a small garden with useful herbs and a sunny spot for tomatoes.",
3393 "timestampOffset": -345600
3394 }
3395]
3396"""###
3397 app.launchEnvironment["JOTLEY_TEST_TRANSCRIPTION_LIFECYCLE"] = "1"
3398 app.launchEnvironment["JOTLEY_SCREENSHOT_LIVE_TEXT"] = "Let’s keep Friday’s launch focused. One clear welcome, readable notes and a final review. Alex will finish the accessibility checks by Thursday. Sam will share the launch checklist."
3399 func launch(_ theme: String = "Purple", _ appearance: String = "Light") {
3400 app.terminate()
3401 app.launchEnvironment["JOTLEY_SCREENSHOT_APPEARANCE"] = appearance
3402 app.launchArguments = ["-selectedThemeColor", theme, "-jotleyWelcomeCompleted.v1", "YES", "-jotley.summaryDisplayStyle", "cards"]
3403 app.launch()
3404 XCTAssertTrue(app.staticTexts["noteDetailTitle"].waitForExistence(timeout: 20))
3405 }
3406 func capture(_ name: String) {
3407 Thread.sleep(forTimeInterval: 0.4) // Capture the settled segmented-control animation.
3408 for (index, screen) in XCUIScreen.screens.enumerated() {
3409 let image = XCTAttachment(screenshot: screen.screenshot())
3410 image.name = "Marketing-\(name)-screen-\(index)"; image.lifetime = .keepAlways; add(image)
3411 }
3412 }
3413 func library() {
3414 let settings = app.buttons["notesListSettingsButton"]
3415 if settings.exists && settings.isHittable { return }
3416 let back = app.buttons["BackButton"]
3417 if back.exists && back.isHittable { back.tap() }
3418 else {
3419 let sidebar = app.navigationBars.buttons.matching(NSPredicate(format: "label CONTAINS[c] 'sidebar'")).firstMatch
3420 XCTAssertTrue(sidebar.waitForExistence(timeout: 5)); sidebar.tap()
3421 }
3422 XCTAssertTrue(settings.waitForExistence(timeout: 5))
3423 }
3424 XCUIDevice.shared.orientation = .portrait
3425 if ProcessInfo.processInfo.environment["JOTLEY_CAPTURE_WEBSITE"] == "1" {
3426 if UIDevice.current.userInterfaceIdiom == .pad {
3427 XCUIDevice.shared.orientation = .landscapeLeft
3428 launch(); capture("website-ipad-summary")
3429 app.terminate()
3430 return
3431 }
3432 launch("Purple", "Dark"); capture("website-summary")
3433 app.buttons["noteDetailShareButton"].tap()
3434 let exportOptions = app.buttons["More Export Options"]
3435 XCTAssertTrue(exportOptions.waitForExistence(timeout: 5))
3436 exportOptions.tap()
3437 let formatted = app.buttons.matching(NSPredicate(format: "identifier == %@ OR label == %@", "exportMarkdownButton", "Full Note (Formatted)")).firstMatch
3438 XCTAssertTrue(formatted.waitForExistence(timeout: 5))
3439 capture("website-export")
3440 launch("Purple", "Dark"); library()
3441 let search = app.textFields["notesListSearchField"]
3442 XCTAssertTrue(search.waitForExistence(timeout: 5))
3443 search.tap()
3444 search.typeText("launch")
3445 capture("website-search")
3446 app.launchEnvironment["JOTLEY_SCREENSHOT_AUDIO_LEVELS"] =
3447 ProcessInfo.processInfo.environment["JOTLEY_MARKETING_AUDIO_LEVELS"]
3448 launch("Purple", "Dark")
3449 app.buttons["notesListNewNoteButton"].firstMatch.tap()
3450 XCTAssertTrue(app.buttons["transcriptionPauseButton"].waitForExistence(timeout: 10))
3451 Thread.sleep(forTimeInterval: 4) // Let the waveform and transcript fill in.
3452 capture("website-live")
3453 capture("website-live-alternate")
3454 app.buttons["transcriptionStopButton"].tap()
3455 app.terminate()
3456 return
3457 }
3458 if ProcessInfo.processInfo.environment["JOTLEY_CAPTURE_NEUTRAL_ONLY"] == "1" {
3459 launch("Neutral"); capture("neutral")
3460 library(); capture("neutral-library")
3461 launch("Neutral", "Dark"); capture("neutral-dark")
3462 app.terminate()
3463 return
3464 }
3465 launch()
3466 capture("summary")
3467 app.scrollViews.firstMatch.swipeUp(); capture("actions")
3468 launch(); app.buttons["noteDetailTranscriptTab"].tap(); capture("transcript")
3469 if XCUIScreen.screens.count > 1 {
3470 XCUIDevice.shared.orientation = .landscapeLeft
3471 XCTAssertTrue(app.buttons["noteDetailTranscriptTab"].waitForExistence(timeout: 5)); capture("landscape-transcript")
3472 app.buttons["noteDetailSummaryTab"].tap(); capture("landscape-summary")
3473 XCUIDevice.shared.orientation = .portrait
3474 }
3475 launch(); app.buttons["noteDetailSummaryAskAIButton"].tap()
3476 XCTAssertTrue(app.buttons["askAIDoneButton"].waitForExistence(timeout: 10)); capture("chat")
3477 app.buttons["askAIDoneButton"].tap(); library(); capture("library")
3478 app.buttons["notesListFolderDrawerButton"].tap()
3479 XCTAssertTrue(app.buttons["folderDrawerDoneButton"].waitForExistence(timeout: 5)); capture("folders")
3480 launch("Orange"); capture("orange")
3481 launch("Light Blue"); capture("blue")
3482 launch("Purple", "Dark"); capture("dark")
3483 launch("Neutral"); capture("neutral")
3484 launch("Neutral", "Dark"); capture("neutral-dark")
3485 launch(); app.buttons["notesListNewNoteButton"].firstMatch.tap()
3486 XCTAssertTrue(app.buttons["transcriptionPauseButton"].waitForExistence(timeout: 10)); capture("live")
3487 app.buttons["transcriptionStopButton"].tap()
3488 app.terminate()
3489 app.launchEnvironment["JOTLEY_TEST_ONBOARDING"] = "1"
3490 app.launchEnvironment["JOTLEY_TEST_RESET_ONBOARDING"] = "1"
3491 app.launchEnvironment["JOTLEY_TEST_STOREFRONT"] = "USA"
3492 app.launchArguments = ["-selectedThemeColor", "Purple"]
3493 app.launch()
3494 XCTAssertTrue(app.buttons["onboardingContinue"].waitForExistence(timeout: 15)); capture("onboarding")
3495 app.buttons["onboardingContinue"].tap()
3496 app.buttons["onboardingContinue"].tap()
3497 XCTAssertTrue(app.staticTexts["onboardingLanguageHint"].waitForExistence(timeout: 60)); capture("language")
3498 app.terminate()
3499 }
3500 // END LOCAL MARKETING CAPTURE
3501
3502 @MainActor func testAppStoreScreenshots() throws {
3503 let identifier = ProcessInfo.processInfo.environment["SIMULATOR_MODEL_IDENTIFIER"] ?? ""
3504 guard (identifier.hasPrefix("iPhone18,") || identifier.hasPrefix("iPhone19,")) || identifier.hasPrefix("iPad17,") else { throw XCTSkip("Use an eligible iPhone or iPad screenshot simulator") }
3505 XCUIDevice.shared.orientation = .portrait
3506 let app = XCUIApplication()
3507 app.launchEnvironment["JOTLEY_SCREENSHOT_DATA"] = #"""
3508[{"title":"Weekly Design Review","folder":"Work","tags":["meeting","design"],"transcript":"Let\u2019s focus on making the first transcription feel simple. We agreed to keep one clear transcription action and show the transcript as the conversation unfolds. The team liked the side-by-side note list on iPad because it makes it easy to compare meeting notes.\n\nFor the next check-in, Maya will test the transcription flow, Alex will review the summary templates, and Sam will organize feedback into a shared checklist. We\u2019ll keep the first release focused on reliable transcription, readable notes, and clear next steps.\n\nOur next review is Friday at ten. Bring one example of a useful meeting summary and one thing that could feel simpler.","summary":"## Key Decisions\n- Keep live transcription simple and show the live transcript.\n- Use the iPad split view to browse notes side by side.\n\n## Next Steps\n- Maya: test the transcription flow.\n- Alex: review the summary templates.\n- Sam: organize the feedback checklist.\n\n## Next Check-in\nFriday at 10:00. Bring one useful summary and one idea to simplify the experience."},{"title":"Lecture: Working Memory","folder":"Study","tags":["lecture","psychology"],"transcript":"Working memory helps us hold information briefly while we use it. Attention is limited, so splitting our focus between too many tasks makes learning harder. We can reduce that load by grouping related ideas and writing down the next step.\n\nFor the study session, explain each concept in your own words, connect it to something you already know, and test yourself without looking at the notes. Space the next review over several days rather than doing everything at once.","summary":"## Main Ideas\n- Working memory holds information while we use it.\n- Focus on one task to reduce mental load.\n- Group related ideas and write down the next step.\n\n## Study Plan\nExplain the ideas in your own words, test recall without notes, and space reviews across several days."},{"title":"Garden Plans for Spring","folder":"Personal","tags":["ideas"],"transcript":"Start with herbs by the kitchen window, then plant tomatoes where they get the most sun. Keep a small notebook for watering, planting dates, and what works well. This weekend, measure the raised bed and make a short seed list.","summary":"## Spring Garden\n- Grow herbs near the kitchen window.\n- Plant tomatoes in the sunniest spot.\n- Track watering and planting dates.\n\n## This Weekend\nMeasure the raised bed and choose seeds."},{"title":"Weekend Ideas","folder":"Personal","tags":["ideas"],"transcript":"Walk the river trail.\nTry a new recipe.\nSketch a few ideas for the garden.\nLeave some time open.","summary":""}]
3509"""#
3510 func launch(_ appearance: String) {
3511 app.terminate()
3512 app.launchEnvironment["JOTLEY_SCREENSHOT_APPEARANCE"] = appearance
3513 app.launch()
3514 XCTAssertTrue(app.buttons["notesListNewNoteButton"].waitForExistence(timeout: 15))
3515 XCTAssertLessThanOrEqual(app.textFields["notesListSearchField"].frame.height, 45)
3516 }
3517 func capture(_ name: String) {
3518 XCTAssertFalse(app.alerts.firstMatch.exists, app.debugDescription)
3519 let image = XCTAttachment(screenshot: XCUIScreen.main.screenshot())
3520 image.name = name; image.lifetime = .keepAlways; add(image)
3521 }
3522 func openMeeting() {
3523 let row = app.buttons.containing(.staticText, identifier: "Weekly Design Review").firstMatch
3524 XCTAssertTrue(row.waitForExistence(timeout: 5), app.debugDescription)
3525 row.tap()
3526 XCTAssertTrue(app.staticTexts["noteDetailTitle"].waitForExistence(timeout: 5))
3527 }
3528 launch("Dark")
3529 openMeeting()
3530 XCTAssertTrue(app.buttons["Summary"].waitForExistence(timeout: 5))
3531 capture("01-summary-dark")
3532 app.buttons["noteDetailMoreActionsButton"].tap()
3533 app.buttons["noteDetailSummaryTemplateMenu"].tap()
3534 app.buttons["Auto"].tap()
3535 XCTAssertTrue(app.descendants(matching: .any)["noteDetailSummaryContent"].exists,
3536 "Template choice must keep the rendered summary visible")
3537 XCTAssertFalse(app.buttons["noteDetailGenerateSummaryButton"].exists)
3538 XCTAssertTrue(app.descendants(matching: .any)["noteDetailSummaryContent"].exists)
3539 launch("Light")
3540 openMeeting()
3541 app.buttons["Transcript"].tap()
3542 XCTAssertTrue(app.descendants(matching: .any)["noteDetailTranscriptContent"].waitForExistence(timeout: 5))
3543 capture("02-transcript-light")
3544 launch("Light")
3545 capture("03-notes-light")
3546 launch("Dark")
3547 app.buttons["notesListFolderDrawerButton"].tap()
3548 XCTAssertTrue(app.buttons["folderDrawerManageButton"].waitForExistence(timeout: 5))
3549 capture("04-folders-dark")
3550 launch("Dark")
3551 app.buttons["notesListNewNoteButton"].tap()
3552 stopNewTranscriptionAndOpenNote(app)
3553 capture("05-new-note-dark")
3554 app.terminate()
3555 }
3556
3557}