Branchwell

Inkspring / app · inkspring.ai / native-mac / UITests / XPostEditingUITests.swift

Raw 50.5 KB on 332c2458022ae8f6648ea05f3c733b528a595172
1import XCTest
2
3final class WalkthroughTests: XCTestCase {
4 func testColdLaunchWaitsForLibraryBeforeShowingReview() {
5 let app = XCUIApplication()
6 app.launchArguments = ["--library-fixture", "--initial-load-fixture"]
7 app.launch()
8 let loader = app.descendants(matching: .any)["library.initialLoad"].firstMatch
9 XCTAssertTrue(loader.waitForExistence(timeout: 3))
10 XCTAssertFalse(app.buttons["Write an idea"].exists)
11 XCTAssertFalse(app.tabBars.firstMatch.exists)
12 capture("Initial iCloud check", app)
13 let draft = app.descendants(matching: .any).matching(NSPredicate(format: "label CONTAINS[c] %@", "A quieter way to draft")).firstMatch
14 XCTAssertTrue(draft.waitForExistence(timeout: 12))
15 XCTAssertFalse(loader.exists)
16 }
17
18 func testReviewCardsShowLatestSavedDatesAndOrderIdeasByUpdate() {
19 continueAfterFailure = false
20 let app = XCUIApplication()
21 app.launchArguments = ["--library-fixture", "--review-timestamps-fixture", "-inkspring.mobile.theme", "graphite"]
22 app.launchEnvironment["INKSPRING_FIXTURE_ID"] = UUID().uuidString
23 app.launch()
24 let draft = app.staticTexts["A quieter way to draft"].firstMatch
25 if !draft.waitForExistence(timeout: 2), app.buttons["ToggleSidebar"].exists {
26 app.buttons["ToggleSidebar"].tap()
27 }
28 XCTAssertTrue(draft.waitForExistence(timeout: 8), app.debugDescription)
29 let timestamps = app.staticTexts.matching(NSPredicate(format: "label BEGINSWITH %@", "Updated "))
30 XCTAssertTrue(timestamps.firstMatch.exists)
31 capture("Draft cards show last update", app)
32
33 app.buttons["Ideas"].firstMatch.tap()
34 let recent = app.staticTexts["Start with the smallest useful thing"].firstMatch
35 let previous = app.staticTexts["Show the unfinished work"].firstMatch
36 XCTAssertTrue(recent.waitForExistence(timeout: 5), app.debugDescription)
37 XCTAssertTrue(previous.exists)
38 XCTAssertLessThan(recent.frame.minY, previous.frame.minY)
39 XCTAssertFalse(app.staticTexts.containing(NSPredicate(format: "label CONTAINS %@", "Open idea")).firstMatch.exists)
40 XCTAssertEqual(timestamps.count, 2)
41 capture("Idea cards show project and last update", app)
42 }
43
44 func testDisconnectedAgentStaysHiddenWithAvailableWritingProviders() {
45 let app = openIdea(theme: "warm-paper", extraArguments: ["--writing-model-fixture", "--no-mcp-fixture"])
46 let skip = app.buttons["Skip idea"].firstMatch
47 for _ in 0..<4 where !skip.isHittable { app.swipeUp() }
48 XCTAssertTrue(skip.isHittable)
49 XCTAssertFalse(app.buttons["idea.draft.open"].exists)
50 XCTAssertFalse(app.buttons["review.addRevisionRequest"].exists)
51 }
52
53 func testMobileWritingUsesMacDefaultsAndAllowsAOneTimeOverride() {
54 continueAfterFailure = false
55 let app = openIdea(theme: "warm-paper", extraArguments: ["--writing-model-fixture", "--idea-draft-result-fixture"])
56 let draft = app.buttons["idea.draft.open"].firstMatch
57 for _ in 0..<4 where !draft.isHittable { app.swipeUp() }
58 XCTAssertTrue(draft.isHittable)
59 draft.tap()
60
61 let claude = app.buttons["writing.provider.claude"]
62 let codex = app.buttons["writing.provider.codex"]
63 let model = app.buttons["writing.model.open"]
64 XCTAssertTrue(codex.waitForExistence(timeout: 5))
65 XCTAssertTrue(codex.isSelected)
66 XCTAssertTrue(model.label.contains("Mac default (GPT-6.2 Sol)"))
67 capture("Mac default on iPhone", app)
68
69 claude.tap()
70 XCTAssertTrue(claude.isSelected)
71 model.tap()
72 let fable = app.buttons["writing.model.claude-fable-5-2"]
73 XCTAssertTrue(fable.isHittable)
74 capture("Claude model choices on iPhone", app)
75 fable.tap()
76 XCTAssertTrue(model.label.contains("Fable 5.2"))
77 XCTAssertEqual(app.buttons["idea.draft.send"].label, "Send to Claude")
78 app.buttons["writing.reset"].tap()
79 XCTAssertTrue(codex.isSelected)
80 XCTAssertTrue(model.label.contains("Mac default (GPT-6.2 Sol)"))
81
82 model.tap()
83 let astra = app.buttons["writing.model.gpt-6.2-astra"]
84 XCTAssertTrue(astra.isHittable)
85 capture("Codex model choices on iPhone", app)
86 astra.tap()
87 XCTAssertTrue(model.label.contains("GPT-6.2 Astra"))
88 let x = app.buttons["idea.draft.platform.x"]
89 for _ in 0..<3 where !x.isHittable { app.swipeUp() }
90 x.tap()
91 let send = app.buttons["idea.draft.send"]
92 XCTAssertTrue(send.isEnabled)
93 capture("GPT-6.2 Astra selected on iPhone", app)
94 send.tap()
95 XCTAssertTrue(app.staticTexts["Sent to Codex"].waitForExistence(timeout: 5))
96 capture("Sent to Codex on iPhone", app)
97 }
98
99 func testIdeaDraftButtonSelectsPlatformsAndClosesAfterSendingToClaude() {
100 continueAfterFailure = false
101 let app = openIdea(theme: "warm-paper")
102 let draft = app.buttons["idea.draft.open"].firstMatch
103 for _ in 0..<4 where !draft.isHittable { app.swipeUp() }
104 XCTAssertTrue(draft.isHittable, app.debugDescription)
105 XCTAssertTrue(app.buttons["Skip idea"].exists)
106 capture("Draft button above Skip idea", app)
107 draft.tap()
108 let x = app.buttons["idea.draft.platform.x"].firstMatch
109 XCTAssertTrue(x.waitForExistence(timeout: 5), app.debugDescription)
110 x.tap()
111 XCTAssertEqual(x.label, "X post")
112 XCTAssertFalse(app.descendants(matching: .any)["idea.draft.xFormat"].exists)
113 for platform in ["linkedin-article", "substack"] {
114 let option = app.buttons["idea.draft.platform.\(platform)"].firstMatch
115 for _ in 0..<4 where !option.isHittable { app.swipeUp() }
116 XCTAssertTrue(option.isHittable, app.debugDescription)
117 option.tap()
118 }
119 XCTAssertFalse(app.buttons["idea.draft.platform.instagram"].exists)
120 XCTAssertFalse(app.buttons["idea.draft.platform.tiktok"].exists)
121 capture("Platforms selected for Claude", app)
122 let send = app.buttons["idea.draft.send"].firstMatch
123 for _ in 0..<5 where !send.isHittable { app.swipeUp() }
124 XCTAssertTrue(send.isHittable && send.isEnabled, app.debugDescription)
125 send.tap()
126 let viewPost = app.buttons["idea.draft.viewPost"].firstMatch
127 XCTAssertTrue(viewPost.waitForExistence(timeout: 5), app.debugDescription)
128 XCTAssertTrue(app.staticTexts["Sent to Claude"].exists)
129 XCTAssertFalse(send.exists)
130 capture("Sent to Claude with View Post", app)
131 viewPost.tap()
132 let queued = app.staticTexts["Queued for Claude on your Mac."].firstMatch
133 XCTAssertTrue(queued.waitForExistence(timeout: 5) && queued.isHittable, app.debugDescription)
134 XCTAssertTrue(app.buttons["idea.detail.title"].firstMatch.isHittable)
135 capture("View Post returns to the queued idea", app)
136 }
137
138 func testIdeaImageOffersPhotoDraftsAndQueuesGeneration() {
139 continueAfterFailure = false
140 let app = openIdea(theme: "warm-paper", extraArguments: ["--idea-image-fixture"])
141 let image = app.images["idea.image.preview"].firstMatch
142 XCTAssertTrue(image.waitForExistence(timeout: 5), app.debugDescription)
143 capture("Idea image preview", app)
144 let draft = app.buttons["idea.draft.open"].firstMatch
145 for _ in 0..<8 where !draft.isHittable { app.swipeUp() }
146 XCTAssertTrue(draft.isHittable)
147 draft.tap()
148 let instagram = app.buttons["idea.draft.platform.instagram"].firstMatch
149 let tiktok = app.buttons["idea.draft.platform.tiktok"].firstMatch
150 XCTAssertTrue(instagram.waitForExistence(timeout: 5))
151 XCTAssertTrue(tiktok.exists)
152 capture("Photo draft destinations", app)
153 app.buttons["Done"].firstMatch.tap()
154 let edit = app.buttons["idea.image.open"].firstMatch
155 for _ in 0..<8 where !edit.isHittable { app.swipeDown() }
156 XCTAssertTrue(edit.isHittable)
157 edit.tap()
158 let generate = app.buttons["idea.image.generate"].firstMatch
159 XCTAssertTrue(generate.waitForExistence(timeout: 5))
160 capture("Generate image on your Mac", app)
161 generate.tap()
162 XCTAssertTrue(app.staticTexts["Queued for image generation on your Mac."].firstMatch.waitForExistence(timeout: 5))
163 capture("Idea image generation queued", app)
164 }
165
166 func testOrdinaryDraftScheduledAndPublishedImagePreviews() {
167 continueAfterFailure = false
168 let app = openReview(theme: "warm-paper", arguments: ["--post-images-fixture", "--schedule-fixture"])
169 let draft = app.staticTexts["A quieter way to draft"].firstMatch
170 XCTAssertTrue(draft.waitForExistence(timeout: 8), app.debugDescription)
171 capture("Review with a post image", app)
172 draft.tap()
173 XCTAssertTrue(app.images["draft.image.preview"].firstMatch.waitForExistence(timeout: 6), app.debugDescription)
174 capture("Image in an ordinary draft", app)
175 app.buttons["Schedule"].firstMatch.tap()
176 XCTAssertTrue(app.images["schedule.image.fixture-1"].firstMatch.waitForExistence(timeout: 6), app.debugDescription)
177 capture("Scheduled post with image", app)
178 app.buttons["Published"].firstMatch.tap()
179 XCTAssertTrue(app.images["published.image.fixture-published"].firstMatch.waitForExistence(timeout: 6), app.debugDescription)
180 XCTAssertTrue(app.descendants(matching: .any)["published.open.fixture-published.0"].firstMatch.exists)
181 capture("Published post with image", app)
182 }
183
184 func testViewPostOpensTheSyncedDraftForManualFollowUps() {
185 continueAfterFailure = false
186 let app = openIdea(theme: "graphite", extraArguments: ["--idea-draft-result-fixture"])
187 let draft = app.buttons["idea.draft.open"].firstMatch
188 for _ in 0..<4 where !draft.isHittable { app.swipeUp() }
189 draft.tap()
190 app.buttons["idea.draft.platform.x"].firstMatch.tap()
191 let send = app.buttons["idea.draft.send"].firstMatch
192 XCTAssertTrue(send.isHittable && send.isEnabled)
193 send.tap()
194 let viewPost = app.buttons["idea.draft.viewPost"].firstMatch
195 XCTAssertTrue(viewPost.waitForExistence(timeout: 5))
196 for _ in 0..<4 where !app.buttons["idea.draft.link.x"].firstMatch.isHittable { app.swipeDown() }
197 XCTAssertTrue(app.buttons["idea.draft.link.x"].firstMatch.waitForExistence(timeout: 5))
198 viewPost.tap()
199 let openingPost = app.buttons["x.editPost.0"].firstMatch
200 XCTAssertTrue(openingPost.waitForExistence(timeout: 5), app.debugDescription)
201 XCTAssertTrue(openingPost.label.contains("Show one trade-off"))
202 XCTAssertFalse(app.buttons["x.editPost.1"].exists)
203 capture("View Post opens the generated X draft", app)
204 app.buttons["x.addReply"].firstMatch.tap()
205 XCTAssertTrue(app.buttons["x.editPost.1"].firstMatch.exists)
206 XCTAssertFalse(app.buttons["x.editPost.2"].exists)
207 capture("First follow-up added manually in the draft", app)
208 }
209
210 func testIdeaDraftActionsInAllThemes() {
211 continueAfterFailure = false
212 for theme in ["graphite", "warm-paper", "native-light"] {
213 verifyIdeaDraftActions(theme: theme)
214 }
215 }
216
217 func testIdeaDraftActionsMatchSystem() {
218 continueAfterFailure = false
219 verifyIdeaDraftActions(theme: "system")
220 }
221
222 func testWithdrawPendingRevisionAndKeepAppliedRequest() {
223 continueAfterFailure = false
224 let app = openIdea(theme: "warm-paper", extraArguments: ["--script-fixture", "--withdraw-revision-fixture"])
225 let withdraw = app.buttons["revision.withdraw.7ac22da9-1ef6-4dbd-8913-9b9caa03ec64"].firstMatch
226 for _ in 0..<6 where !withdraw.isHittable { app.swipeUp() }
227 XCTAssertTrue(withdraw.isHittable, app.debugDescription)
228 XCTAssertGreaterThanOrEqual(withdraw.frame.height, 44)
229 XCTAssertFalse(app.buttons["revision.withdraw.6b5734c1-bc62-49d3-99c6-94829fd30008"].exists)
230 capture("Pending revision ready to withdraw", app)
231 withdraw.tap()
232 let removed = app.staticTexts["Shorten the introduction."].firstMatch
233 XCTAssertTrue(removed.waitForNonExistence(timeout: 15), app.debugDescription)
234 XCTAssertTrue(app.staticTexts["Keep the research citations."].firstMatch.exists)
235 capture("Withdrawal completed and applied request retained", app)
236 }
237
238 func testIdeaRevisionRequestUsesTheMacWritingConnection() {
239 continueAfterFailure = false
240 let app = openIdea(theme: "graphite", extraArguments: ["--script-fixture", "--revision-requests-fixture"])
241 let addRequest = app.buttons["review.addRevisionRequest"].firstMatch
242 let input = app.descendants(matching: .any).matching(identifier: "review.revisionRequest").firstMatch
243 let send = app.buttons["Send revision request"].firstMatch
244 let requests = ["Focus on one practical example.", "Keep the original source links."]
245 for (index, text) in requests.enumerated() {
246 for _ in 0..<4 where !addRequest.isHittable { app.swipeUp() }
247 XCTAssertTrue(addRequest.isHittable)
248 XCTAssertFalse(input.exists)
249 addRequest.tap()
250 XCTAssertTrue(input.waitForExistence(timeout: 5))
251 if index == 0 { capture("Idea revision request and example", app) }
252 input.tap()
253 input.typeText(text)
254 for _ in 0..<4 where !send.isHittable { app.swipeUp() }
255 XCTAssertTrue(send.isHittable)
256 send.tap()
257 XCTAssertTrue(app.staticTexts[text].firstMatch.waitForExistence(timeout: 8))
258 }
259 XCTAssertTrue(app.staticTexts["Acted on"].firstMatch.waitForExistence(timeout: 8))
260 XCTAssertEqual(app.staticTexts.matching(identifier: "Acted on").count, 2)
261 for text in requests { XCTAssertEqual(app.staticTexts.matching(identifier: text).count, 1) }
262 capture("Both Inkspring revision requests marked acted on", app)
263 }
264
265 private func verifyIdeaDraftActions(theme: String) {
266 let app = openIdea(theme: theme)
267 defer { app.terminate() }
268 let draft = app.buttons["idea.draft.open"].firstMatch
269 let skip = app.buttons["Skip idea"].firstMatch
270 for _ in 0..<4 where !draft.isHittable || !skip.isHittable { app.swipeUp() }
271 XCTAssertTrue(draft.isHittable && draft.isEnabled)
272 XCTAssertTrue(skip.isHittable)
273 XCTAssertGreaterThanOrEqual(draft.frame.height, 44)
274 XCTAssertLessThan(draft.frame.midY, skip.frame.midY)
275 capture("Idea detail - \(theme)", app)
276 draft.tap()
277
278 let send = app.buttons["idea.draft.send"].firstMatch
279 let x = app.buttons["idea.draft.platform.x"].firstMatch
280 XCTAssertTrue(x.waitForExistence(timeout: 5))
281 XCTAssertTrue(send.isHittable)
282 XCTAssertFalse(send.isEnabled)
283 capture("Chooser without selection - \(theme)", app)
284 x.tap()
285 XCTAssertTrue(send.isHittable && send.isEnabled)
286 XCTAssertGreaterThanOrEqual(send.frame.height, 44)
287 capture("Chooser with selection - \(theme)", app)
288 }
289
290 private func openIdea(theme: String, extraArguments: [String] = []) -> XCUIApplication {
291 let app = XCUIApplication()
292 app.launchArguments = ["--library-fixture", "-inkspring.mobile.theme", theme] + extraArguments
293 app.launchEnvironment["INKSPRING_FIXTURE_ID"] = UUID().uuidString
294 app.launch()
295 let review = app.buttons["Review"].firstMatch
296 if !review.waitForExistence(timeout: 3), app.buttons["ToggleSidebar"].exists { app.buttons["ToggleSidebar"].tap() }
297 XCTAssertTrue(review.waitForExistence(timeout: 10))
298 review.tap()
299 let filter = app.buttons["Ideas"].firstMatch
300 let idea = app.staticTexts["Show the unfinished work"].firstMatch
301 if !idea.exists { filter.tap() }
302 if !idea.waitForExistence(timeout: 3), filter.isHittable { filter.tap() }
303 XCTAssertTrue(idea.waitForExistence(timeout: 8), app.debugDescription)
304 idea.tap()
305 return app
306 }
307
308 func testMediaDraftsStartWithMediaAndCaption() {
309 continueAfterFailure = false
310 let app = openIdea(theme: "warm-paper")
311 for (title, picker) in [("TikTok video", "Choose a video"), ("Instagram post", "Choose a photo or video")] {
312 let media = app.buttons["idea.media.open"].firstMatch
313 for _ in 0..<4 where !media.isHittable { app.swipeUp() }
314 media.coordinate(withNormalizedOffset: CGVector(dx: 0.2, dy: 0.5)).tap()
315 let choice = app.descendants(matching: .any).matching(NSPredicate(format: "label == %@", title)).firstMatch
316 XCTAssertTrue(choice.waitForExistence(timeout: 5), app.debugDescription)
317 choice.tap()
318 XCTAssertTrue(app.buttons[picker].firstMatch.waitForExistence(timeout: 5), app.debugDescription)
319 XCTAssertTrue(app.descendants(matching: .any).matching(identifier: "Caption (optional)").firstMatch.exists)
320 XCTAssertFalse(app.staticTexts["Hashtags"].exists)
321 capture(title, app)
322 app.buttons["Done"].firstMatch.tap()
323 }
324 }
325
326 func testPlanPreviewEditSaveAndAssistant() {
327 continueAfterFailure = false
328 let app = XCUIApplication()
329 app.launchArguments = ["--library-fixture", "--newsletter-fixture", "-inkspring.mobile.theme", "warm-paper"]
330 app.launchEnvironment["INKSPRING_FIXTURE_ID"] = UUID().uuidString
331 app.launch()
332 let row = app.staticTexts["A better first paragraph"].firstMatch
333 if !row.waitForExistence(timeout: 3), app.buttons["ToggleSidebar"].exists { app.buttons["ToggleSidebar"].tap() }
334 XCTAssertTrue(row.waitForExistence(timeout: 10))
335 row.tap()
336 XCTAssertFalse(app.buttons["outline.view"].exists)
337 XCTAssertFalse(app.buttons["Create plan"].exists)
338 app.buttons["newsletter.more"].firstMatch.tap()
339 let add = app.buttons["outline.menu"].firstMatch
340 XCTAssertEqual(add.label, "Add outline")
341 add.tap()
342 let markdown = app.buttons["Markdown"].firstMatch
343 XCTAssertTrue(markdown.waitForExistence(timeout: 5)); markdown.tap()
344 let editor = app.textViews["plan.markdown"].firstMatch
345 XCTAssertTrue(editor.waitForExistence(timeout: 5)); editor.tap()
346 editor.typeText("# Launch plan\n\n- [ ] Check the links\n- [ ] Review the opening\n\n[Inkspring](https://inkspring.ai/)")
347 capture("Inline Plan Markdown editor", app)
348 let save = app.buttons["plan.save"].firstMatch
349 for _ in 0..<5 where !save.isHittable { app.swipeUp() }
350 XCTAssertTrue(save.isHittable); save.tap()
351 let view = app.buttons["outline.view"].firstMatch
352 XCTAssertTrue(view.waitForExistence(timeout: 8))
353 view.tap()
354 XCTAssertTrue(app.staticTexts["Launch plan"].firstMatch.waitForExistence(timeout: 5))
355 capture("Plan saved locally and queued for Mac", app)
356 }
357 func testAskInkspringScreen() {
358 let app = XCUIApplication()
359 app.launchArguments = ["--library-fixture", "-inkspring.mobile.theme", "warm-paper"]
360 app.launchEnvironment["INKSPRING_FIXTURE_ID"] = UUID().uuidString
361 app.launch()
362 let ask = app.buttons["assistant.open"].firstMatch
363 if !ask.waitForExistence(timeout: 2), app.buttons["ToggleSidebar"].exists { app.buttons["ToggleSidebar"].tap() }
364 XCTAssertTrue(ask.waitForExistence(timeout: 15)); ask.tap()
365 XCTAssertTrue(app.textFields["assistant.message"].waitForExistence(timeout: 5) || app.textViews["assistant.message"].exists)
366 capture("Ask Inkspring on-device assistant", app)
367 }
368
369 func testPublishedIsATopLevelTabWithOriginalPostLinks() {
370 let app = XCUIApplication()
371 app.launchArguments = ["--library-fixture", "--schedule-fixture", "-inkspring.mobile.theme", "warm-paper"]
372 app.launchEnvironment["INKSPRING_FIXTURE_ID"] = UUID().uuidString
373 app.launch()
374 let upcoming = app.staticTexts["A quieter way to draft"]
375 XCTAssertTrue(upcoming.waitForExistence(timeout: 10))
376 let updated = app.staticTexts.matching(NSPredicate(format: "label BEGINSWITH %@", "Updated ")).firstMatch
377 XCTAssertTrue(updated.exists)
378 XCTAssertTrue(app.staticTexts.matching(NSPredicate(format: "label BEGINSWITH %@", "Scheduled for ")).firstMatch.exists)
379 XCTAssertFalse(app.segmentedControls["Schedule view"].exists)
380 let publication = app.staticTexts["A quieter way to publish"]
381 XCTAssertFalse(publication.exists)
382 let publishedTab = app.buttons["Published"].firstMatch
383 XCTAssertTrue(publishedTab.isHittable, app.debugDescription)
384 capture("Schedule with Published in main navigation", app)
385 publishedTab.tap()
386 XCTAssertTrue(publication.waitForExistence(timeout: 5))
387 XCTAssertTrue(updated.exists)
388 XCTAssertTrue(app.staticTexts.matching(NSPredicate(format: "label BEGINSWITH %@", "Published ")).firstMatch.exists)
389 XCTAssertFalse(upcoming.exists)
390 let link = app.descendants(matching: .any).matching(identifier: "published.open.fixture-published.0").firstMatch
391 XCTAssertTrue(link.exists)
392 XCTAssertEqual(link.label, "Open on Substack")
393 capture("Mobile Published feed and original post link", app)
394 app.buttons["Schedule"].firstMatch.tap()
395 XCTAssertTrue(upcoming.waitForExistence(timeout: 5))
396 XCTAssertFalse(publication.exists)
397 }
398
399 func testXArticleReviewsAccountAndPublishesFullTextThroughMac() {
400 continueAfterFailure = false
401 let app = openExistingWriting("Untitled X article")
402 let more = app.buttons["newsletter.more"].firstMatch
403 XCTAssertTrue(more.waitForExistence(timeout: 8)); more.tap()
404 app.buttons["Edit Markdown"].firstMatch.tap()
405 let editor = app.textViews["newsletter.markdown"].firstMatch
406 XCTAssertTrue(editor.waitForExistence(timeout: 5)); editor.tap()
407 editor.typeText("# Our mission\n\nWe build real skills with AI and automation.\n\n[Visit our site](https://protomota.com)\n\n" + String(repeating: "Full article text. ", count: 30))
408 app.buttons["Done"].firstMatch.tap()
409 let review = app.buttons["article.reviewPublish"].firstMatch
410 XCTAssertTrue(review.waitForExistence(timeout: 10)); XCTAssertTrue(review.isEnabled)
411 capture("Full X Article preview and publishing controls", app)
412 review.tap()
413 let publish = app.buttons["Publish article now"].firstMatch
414 XCTAssertTrue(publish.waitForExistence(timeout: 5))
415 XCTAssertTrue(app.staticTexts.containing(NSPredicate(format: "label CONTAINS %@", "@fixture")).firstMatch.exists)
416 capture("Review the X account before publishing", app)
417 publish.tap()
418 let link = app.links["View published X article"].firstMatch
419 XCTAssertTrue(link.waitForExistence(timeout: 12), app.debugDescription)
420 XCTAssertTrue(app.staticTexts["Our mission"].firstMatch.exists)
421 XCTAssertFalse(app.buttons["article.reviewPublish"].exists)
422 capture("Confirmed X Article link and complete article", app)
423 more.tap()
424 XCTAssertFalse(app.buttons["Edit Markdown"].exists)
425 }
426
427 func testRoundNewIdeaButtonAcrossThemesAndOpensSavedIdea() {
428 continueAfterFailure = false
429 for theme in ["warm-paper", "graphite", "native-light", "system"] {
430 let app = openReview(theme: theme, arguments: ["--idea-first-fixture"])
431 let plus = app.buttons["idea.new"].firstMatch
432 XCTAssertTrue(plus.waitForExistence(timeout: 8), app.debugDescription)
433 XCTAssertEqual(plus.label, "Draft a new idea")
434 XCTAssertEqual(plus.frame.width, plus.frame.height, accuracy: 2)
435 capture("Round new idea button – " + theme, app)
436 XCTAssertTrue(app.buttons["quickX.open"].exists)
437 guard theme == "graphite" else {
438 app.terminate()
439 continue
440 }
441 plus.tap()
442 let title = app.textFields["idea.new.title"].firstMatch
443 XCTAssertTrue(title.waitForExistence(timeout: 5), app.debugDescription)
444 title.tap()
445 title.typeText("Make time for careful work")
446 let angle = app.textFields["idea.new.angle"].firstMatch
447 title.typeText("\n")
448 if !angle.hasFocus { angle.tap() }
449 angle.typeText("Share one detail worth someone’s time.")
450 let save = app.buttons["Save idea"].firstMatch
451 for _ in 0..<3 where !save.isHittable { app.swipeUp() }
452 XCTAssertTrue(save.isEnabled, app.debugDescription)
453 save.tap()
454 let draft = app.buttons["idea.draft.open"].firstMatch
455 XCTAssertTrue(draft.waitForExistence(timeout: 10), app.debugDescription)
456 let savedTitle = app.buttons["idea.detail.title"].firstMatch
457 XCTAssertTrue(savedTitle.exists, app.debugDescription)
458 XCTAssertEqual(savedTitle.label, "Make time for careful work")
459 capture("Saved idea opens – " + theme, app)
460 app.terminate()
461 }
462 }
463
464 func testGenerateSelectAndSaveIdeaFromBothEntryPoints() {
465 continueAfterFailure = false
466 let notes = "Private Facebook chats went to the wrong users. Classic Facebook."
467 let suggestionTitle = "Private chats sent to the wrong people"
468
469 for fromReview in [false, true] {
470 let arguments = ["--idea-first-fixture", "--idea-suggestions-fixture"]
471 let app: XCUIApplication
472 if fromReview {
473 app = openReview(theme: "graphite", arguments: arguments)
474 app.buttons["idea.new"].firstMatch.tap()
475 } else {
476 app = XCUIApplication()
477 app.launchArguments = ["--library-fixture", "--ideas-fixture", "-inkspring.mobile.theme", "graphite"] + arguments
478 app.launchEnvironment["INKSPRING_FIXTURE_ID"] = UUID().uuidString
479 app.launch()
480 }
481
482 let title = app.textFields["idea.new.title"].firstMatch
483 let angle = app.textFields["idea.new.angle"].firstMatch
484 XCTAssertTrue(angle.waitForExistence(timeout: 8), app.debugDescription)
485 angle.tap()
486 angle.typeText(notes)
487 XCTAssertEqual(angle.value as? String, notes, app.debugDescription)
488 let generate = app.buttons["Generate ideas"].firstMatch
489 for _ in 0..<3 where !generate.isHittable { app.swipeUp() }
490 XCTAssertTrue(generate.isEnabled && generate.isHittable, app.debugDescription)
491 generate.coordinate(withNormalizedOffset: CGVector(dx: 0.18, dy: 0.5)).tap()
492
493 let result = app.buttons.matching(identifier: "idea.suggestion")
494 .matching(NSPredicate(format: "label CONTAINS %@", suggestionTitle)).firstMatch
495 for _ in 0..<3 where !result.isHittable { app.swipeUp() }
496 XCTAssertTrue(result.waitForExistence(timeout: 5) && result.isHittable, app.debugDescription)
497 XCTAssertTrue(result.label.contains(notes))
498 capture("Generated suggestions – " + (fromReview ? "composer" : "New ideas"), app)
499 result.coordinate(withNormalizedOffset: CGVector(dx: 0.92, dy: 0.5)).tap()
500
501 XCTAssertTrue(title.isHittable, app.debugDescription)
502 XCTAssertEqual(title.value as? String, suggestionTitle)
503 XCTAssertEqual(angle.value as? String, notes)
504 XCTAssertFalse(result.exists)
505 capture("Selected idea is ready to edit – " + (fromReview ? "composer" : "New ideas"), app)
506 let save = app.buttons["Save idea"].firstMatch
507 XCTAssertTrue(save.isEnabled && save.isHittable, app.debugDescription)
508 save.tap()
509
510 let savedTitle = app.buttons["idea.detail.title"].firstMatch
511 XCTAssertTrue(savedTitle.waitForExistence(timeout: 10), app.debugDescription)
512 XCTAssertEqual(savedTitle.label, suggestionTitle)
513 XCTAssertTrue(app.buttons[notes].firstMatch.exists, app.debugDescription)
514 capture("Saved idea keeps the original point – " + (fromReview ? "composer" : "New ideas"), app)
515 app.terminate()
516 }
517 }
518
519 func testQuickXProofreadReviewAndPublishConfirmation() {
520 continueAfterFailure = false
521 let app = openReview(theme: "graphite", arguments: ["--quick-x-fixture"])
522 let quick = app.buttons["quickX.open"].firstMatch
523 XCTAssertTrue(quick.waitForExistence(timeout: 8))
524 quick.tap()
525 let field = app.descendants(matching: .any)["quickX.text"].firstMatch
526 XCTAssertTrue(field.waitForExistence(timeout: 5))
527 field.tap()
528 field.typeText("Share teh work.")
529 let hide = app.keyboards.buttons["Hide keyboard"].firstMatch
530 if hide.isHittable { hide.tap() }
531 let proofread = app.buttons["proofread.start"].firstMatch
532 XCTAssertTrue(proofread.isHittable && proofread.isEnabled, app.debugDescription)
533 proofread.tap()
534 let apply = app.buttons["proofread.apply"].firstMatch
535 XCTAssertTrue(apply.waitForExistence(timeout: 5), app.debugDescription)
536 XCTAssertTrue(app.staticTexts["Before: teh"].exists)
537 XCTAssertTrue(app.staticTexts["After: the"].exists)
538 capture("Review Apple Intelligence proofreading suggestions", app)
539 apply.tap()
540 XCTAssertTrue((field.value as? String ?? "").contains("Share the work."))
541 app.buttons["quickX.review"].firstMatch.tap()
542 let publish = app.buttons["Publish to X"].firstMatch
543 XCTAssertTrue(publish.waitForExistence(timeout: 5), app.debugDescription)
544 capture("Quick X confirmation includes account and final copy", app)
545 publish.tap()
546 let result = app.descendants(matching: .any)["quickX.published"].firstMatch
547 XCTAssertTrue(result.waitForExistence(timeout: 10), app.debugDescription)
548 }
549
550 private func openReview(theme: String, arguments: [String]) -> XCUIApplication {
551 let app = XCUIApplication()
552 app.launchArguments = ["--library-fixture", "-inkspring.mobile.theme", theme] + arguments
553 app.launchEnvironment["INKSPRING_FIXTURE_ID"] = UUID().uuidString
554 app.launch()
555 let review = app.buttons["Review"].firstMatch
556 if !review.waitForExistence(timeout: 3), app.buttons["ToggleSidebar"].exists { app.buttons["ToggleSidebar"].tap() }
557 XCTAssertTrue(review.waitForExistence(timeout: 8))
558 review.tap()
559 return app
560 }
561
562 private func openExistingWriting(_ title: String, arguments: [String] = []) -> XCUIApplication {
563 let app = openReview(theme: "warm-paper", arguments: ["--script-fixture", "--existing-writing-fixture"] + arguments)
564 let item = app.staticTexts[title].firstMatch
565 XCTAssertTrue(item.waitForExistence(timeout: 8), app.debugDescription)
566 item.tap()
567 return app
568 }
569
570 func testNewsletterKeepsManualEditingWhenAgentIsDisconnected() {
571 let app = openExistingWriting("Untitled newsletter", arguments: ["--writing-model-fixture", "--no-mcp-fixture"])
572 app.buttons["newsletter.more"].firstMatch.tap()
573 let edit = app.buttons["Edit Markdown"].firstMatch
574 XCTAssertTrue(edit.waitForExistence(timeout: 5))
575 XCTAssertFalse(app.buttons["Ask AI…"].exists)
576 edit.tap()
577 XCTAssertTrue(app.textViews["newsletter.markdown"].firstMatch.waitForExistence(timeout: 5))
578 XCTAssertFalse(app.buttons["writing.tools"].exists)
579 }
580
581 func testNewsletterCreationAndAskAIApplyBriefWithoutLeavingEditor() {
582 continueAfterFailure = false
583 let app = openExistingWriting("Untitled newsletter", arguments: ["--history-fixture"])
584 let more = app.buttons["newsletter.more"].firstMatch
585 XCTAssertTrue(more.waitForExistence(timeout: 8)); more.tap()
586 app.buttons["Ask AI…"].firstMatch.tap()
587 let addRequest = app.buttons["writing.addRevisionRequest"].firstMatch
588 XCTAssertTrue(addRequest.waitForExistence(timeout: 8))
589 addRequest.tap()
590 let prompt = app.textFields["writing.prompt"].firstMatch
591 XCTAssertTrue(prompt.waitForExistence(timeout: 8), app.debugDescription)
592 prompt.tap(); prompt.typeText("Write a quick brief about local AI models.")
593 capture("Ask the Mac writing agent for a brief", app)
594 let send = app.buttons["writing.send"].firstMatch
595 XCTAssertTrue(send.isEnabled); send.tap()
596 let reply = app.staticTexts["writing.reply"].firstMatch
597 XCTAssertTrue(reply.waitForExistence(timeout: 12), app.debugDescription)
598 XCTAssertTrue(reply.label.contains("Wrote a short brief"))
599 XCTAssertTrue(app.staticTexts["Acted on"].firstMatch.exists)
600 capture("Saved writing request and applied response", app)
601 app.buttons["writing.close"].tap()
602 let editor = app.textViews["newsletter.markdown"].firstMatch
603 XCTAssertTrue(editor.waitForExistence(timeout: 5))
604 XCTAssertTrue((editor.value as? String ?? "").contains("# Local AI models"))
605 let title = app.textFields["script.title"].firstMatch
606 title.coordinate(withNormalizedOffset: CGVector(dx: 0.98, dy: 0.5)).tap()
607 title.typeText(String(repeating: XCUIKeyboardKey.delete.rawValue, count: 19) + "Local models newsletter")
608 editor.tap()
609 editor.typeText("\n\nAn author addition.\n\n")
610 app.buttons["Done"].firstMatch.tap()
611 XCTAssertTrue(app.staticTexts["Local AI models"].firstMatch.waitForExistence(timeout: 8))
612 capture("Newsletter brief rendered with author changes", app)
613 more.tap(); app.buttons["Edit Markdown"].firstMatch.tap()
614 XCTAssertTrue((editor.value as? String ?? "").contains("An author addition."))
615 XCTAssertEqual(title.value as? String, "Local models newsletter")
616 app.buttons["writing.tools"].firstMatch.tap()
617 XCTAssertTrue(reply.waitForExistence(timeout: 5))
618 capture("Writing request history survives reopening", app)
619 }
620
621 func testFullHeightNewsletterEditingKeepsCursorAndFindsText() {
622 continueAfterFailure = false
623 let app = XCUIApplication()
624 app.launchArguments = ["--library-fixture", "--newsletter-fixture", "--history-fixture", "-inkspring.mobile.theme", "warm-paper"]
625 app.launchEnvironment["INKSPRING_FIXTURE_ID"] = UUID().uuidString
626 app.launch()
627 let row = app.staticTexts["A better first paragraph"].firstMatch
628 if !row.waitForExistence(timeout: 3), app.buttons["ToggleSidebar"].exists { app.buttons["ToggleSidebar"].tap() }
629 XCTAssertTrue(row.waitForExistence(timeout: 10)); row.tap()
630 app.buttons["newsletter.more"].firstMatch.tap()
631 app.buttons["Edit Markdown"].firstMatch.tap()
632 let editor = app.textViews["newsletter.markdown"].firstMatch
633 XCTAssertTrue(editor.waitForExistence(timeout: 5)); editor.tap()
634 XCTAssertGreaterThan(editor.frame.height, 200)
635 XCTAssertFalse(app.buttons["history.open"].exists)
636 editor.typeText("ANCHOR")
637 Thread.sleep(forTimeInterval: 2)
638 editor.typeText(" CONTINUED\n\nA real new paragraph.\n")
639 XCTAssertTrue((editor.value as? String ?? "").contains("ANCHOR CONTINUED\n\nA real new paragraph.\n"))
640 app.buttons["editor.find"].firstMatch.tap()
641 let search = app.searchFields.firstMatch
642 XCTAssertTrue(search.waitForExistence(timeout: 5), app.debugDescription)
643 search.typeText("paragraph")
644 let attachment = XCTAttachment(screenshot: app.screenshot()); attachment.name = "newsletter-find"; attachment.lifetime = .keepAlways; add(attachment)
645 }
646
647 func testYouTubeScriptsCreateEditAndReopenWithoutPublishing() {
648 continueAfterFailure = false
649 let app = openExistingWriting("Untitled YouTube script", arguments: ["--history-fixture"])
650 let more = app.buttons["newsletter.more"].firstMatch
651 XCTAssertTrue(more.waitForExistence(timeout: 8)); more.tap()
652 app.buttons["Edit Markdown"].firstMatch.tap()
653 let editor = app.textViews["newsletter.markdown"].firstMatch
654 XCTAssertTrue(editor.waitForExistence(timeout: 5))
655 let title = app.textFields["script.title"].firstMatch
656 XCTAssertTrue(title.exists)
657 title.coordinate(withNormalizedOffset: CGVector(dx: 0.98, dy: 0.5)).tap()
658 title.typeText(String(repeating: XCUIKeyboardKey.delete.rawValue, count: 23) + "Hallway brief")
659 editor.tap()
660 editor.typeText("We build useful skills.\n\nWe protect our signal.")
661 Thread.sleep(forTimeInterval: 2)
662 editor.typeText("\n\nWe keep learning.")
663 XCTAssertTrue((editor.value as? String ?? "").contains("We protect our signal.\n\nWe keep learning."))
664 app.buttons["Done"].firstMatch.tap()
665 XCTAssertTrue(app.staticTexts["We build useful skills."].firstMatch.waitForExistence(timeout: 10))
666 XCTAssertFalse(app.buttons["Schedule post…"].exists)
667 XCTAssertFalse(app.buttons["Publish"].exists)
668 more.tap(); app.buttons["Edit Markdown"].firstMatch.tap()
669 XCTAssertTrue((editor.value as? String ?? "").contains("We keep learning."))
670 editor.typeText("\n\nA second editing session.")
671 app.buttons["Done"].firstMatch.tap()
672 let attachment = XCTAttachment(screenshot: app.screenshot()); attachment.name = "youtube-script-preview"; attachment.lifetime = .keepAlways; add(attachment)
673 }
674
675 func testXArticleIsClearlyLabeledAndEditsAsLongForm() {
676 continueAfterFailure = false
677 let app = openExistingWriting("Untitled X article", arguments: ["--history-fixture"])
678 XCTAssertTrue(app.navigationBars["X article"].waitForExistence(timeout: 8))
679 let more = app.buttons["newsletter.more"].firstMatch
680 more.tap(); app.buttons["Edit Markdown"].firstMatch.tap()
681 let editor = app.textViews["newsletter.markdown"].firstMatch
682 XCTAssertTrue(editor.waitForExistence(timeout: 5)); editor.tap()
683 editor.typeText("# Our mission\n\nWe build real skills with AI and automation.\n\n" + String(repeating: "We protect our signal. ", count: 20))
684 app.buttons["Done"].firstMatch.tap()
685 XCTAssertTrue(app.staticTexts["Our mission"].firstMatch.waitForExistence(timeout: 8))
686 XCTAssertTrue(app.staticTexts["X article"].firstMatch.exists)
687 XCTAssertFalse(app.buttons["Schedule post…"].exists)
688 capture("X article badge and full long-form preview", app)
689 }
690
691 func testNewsletterHistoryRestoresEarlierMarkdown() {
692 continueAfterFailure = false
693 let app = XCUIApplication()
694 app.launchArguments = ["--library-fixture", "--newsletter-fixture", "--history-fixture", "-inkspring.mobile.theme", "warm-paper"]
695 app.launchEnvironment["INKSPRING_FIXTURE_ID"] = UUID().uuidString
696 app.launch()
697 let newsletter = app.staticTexts["A better first paragraph"].firstMatch
698 if !newsletter.waitForExistence(timeout: 3) {
699 let platforms = app.buttons["review.platformFilter"].firstMatch
700 if !platforms.exists, app.buttons["ToggleSidebar"].exists { app.buttons["ToggleSidebar"].tap() }
701 XCTAssertTrue(platforms.waitForExistence(timeout: 5)); platforms.tap()
702 let substack = app.buttons["Substack"].firstMatch
703 XCTAssertTrue(substack.waitForExistence(timeout: 5)); substack.tap()
704 }
705 XCTAssertTrue(newsletter.waitForExistence(timeout: 10)); newsletter.tap()
706 let more = app.buttons["newsletter.more"].firstMatch
707 XCTAssertTrue(more.waitForExistence(timeout: 5)); more.tap()
708 app.buttons["Edit Markdown"].firstMatch.tap()
709 let editor = app.textViews["newsletter.markdown"].firstMatch
710 XCTAssertTrue(editor.waitForExistence(timeout: 5)); editor.tap()
711 editor.typeText("\n\n[Revision link](https://example.com/history)\n\n")
712 XCTAssertTrue((editor.value as? String ?? "").contains("[Revision link](https://example.com/history)"))
713 app.buttons["Done"].firstMatch.tap()
714 let history = app.buttons["history.open"].firstMatch
715 XCTAssertTrue(history.waitForExistence(timeout: 5)); history.tap()
716 let older = app.buttons["history.version.1"].firstMatch
717 XCTAssertTrue(older.waitForExistence(timeout: 10))
718 capture("Newsletter saves retained in revision history", app)
719 older.tap()
720 let restore = app.buttons["history.restore"].firstMatch
721 XCTAssertTrue(restore.waitForExistence(timeout: 5))
722 for _ in 0..<5 where !restore.isHittable { app.swipeUp() }
723 XCTAssertTrue(restore.isEnabled)
724 restore.tap()
725 if app.buttons["history.version.0"].waitForExistence(timeout: 2) {
726 app.navigationBars.buttons.element(boundBy: 0).tap()
727 }
728 XCTAssertTrue(more.waitForExistence(timeout: 5))
729 more.tap(); app.buttons["Edit Markdown"].firstMatch.tap()
730 XCTAssertTrue(editor.waitForExistence(timeout: 5))
731 XCTAssertFalse((editor.value as? String ?? "").contains("Revision link"))
732 capture("Earlier newsletter Markdown restored inline", app)
733 }
734
735 func testHistoryRestoresAnOlderSaveAndKeepsTheNewerOne() {
736 continueAfterFailure = false
737 let app = XCUIApplication()
738 app.launchArguments = ["--library-fixture", "--x-thread-fixture", "--history-fixture", "-inkspring.mobile.theme", "warm-paper"]
739 app.launchEnvironment["INKSPRING_FIXTURE_ID"] = UUID().uuidString
740 app.launch()
741 let title = app.staticTexts["I opened the Lab"].firstMatch
742 if !title.waitForExistence(timeout: 3), app.buttons["ToggleSidebar"].exists { app.buttons["ToggleSidebar"].tap() }
743 XCTAssertTrue(title.waitForExistence(timeout: 10)); title.tap()
744 app.buttons["x.reply.0"].firstMatch.tap()
745 let opening = app.buttons["x.editPost.0"].firstMatch
746 XCTAssertTrue(opening.waitForExistence(timeout: 5)); opening.tap()
747 let editor = app.textViews["x.postText.0"].firstMatch
748 XCTAssertTrue(editor.waitForExistence(timeout: 5))
749 editor.coordinate(withNormalizedOffset: .zero).withOffset(CGVector(dx: editor.frame.width - 12, dy: 15)).tap()
750 editor.typeText("\n\nA later revision.")
751 XCTAssertEqual(editor.value as? String, "We build useful tools and give them away.\n\nA later revision.")
752 app.buttons["x.backToThread"].tap()
753 app.buttons["Done"].firstMatch.tap()
754 let history = app.buttons["history.open"].firstMatch
755 XCTAssertTrue(history.waitForExistence(timeout: 5)); history.tap()
756 let older = app.buttons["history.version.1"].firstMatch
757 XCTAssertTrue(older.waitForExistence(timeout: 10))
758 capture("History retains both saves with timestamps", app)
759 older.tap()
760 let restore = app.buttons["history.restore"].firstMatch
761 XCTAssertTrue(restore.waitForExistence(timeout: 5))
762 for _ in 0..<5 where !restore.isHittable { app.swipeUp() }
763 XCTAssertTrue(restore.isEnabled)
764 capture("Inspect the earlier version before restoring", app)
765 restore.tap()
766 if app.buttons["history.version.0"].waitForExistence(timeout: 2) {
767 capture("Restoring adds a version and keeps later saves", app)
768 app.navigationBars.buttons.element(boundBy: 0).tap()
769 }
770 let restored = app.buttons["x.reply.0"].firstMatch
771 XCTAssertTrue(restored.waitForExistence(timeout: 5))
772 XCTAssertFalse(restored.label.contains("A later revision."))
773 capture("Earlier text restored in the draft", app)
774 history.tap()
775 let newer = app.buttons["history.version.1"].firstMatch
776 XCTAssertTrue(newer.waitForExistence(timeout: 5))
777 XCTAssertTrue(newer.label.contains("A later revision."))
778 }
779
780 func testReturnCreatesParagraphsAndKeepsTwoSeparateReplies() {
781 continueAfterFailure = false
782 let app = XCUIApplication()
783 app.launchArguments = ["--library-fixture", "--x-thread-fixture", "-inkspring.mobile.theme", "warm-paper"]
784 app.launchEnvironment["INKSPRING_FIXTURE_ID"] = UUID().uuidString
785 app.launch()
786 let opening = app.buttons["x.reply.0"].firstMatch
787 if !opening.waitForExistence(timeout: 3) {
788 let draft = app.staticTexts["I opened the Lab"].firstMatch
789 if !draft.exists, app.buttons["ToggleSidebar"].exists { app.buttons["ToggleSidebar"].tap() }
790 XCTAssertTrue(draft.waitForExistence(timeout: 10)); draft.tap()
791 }
792 XCTAssertTrue(opening.waitForExistence(timeout: 10)); opening.tap()
793 let openEditor = app.buttons["x.editPost.0"].firstMatch
794 XCTAssertTrue(openEditor.waitForExistence(timeout: 10)); openEditor.tap()
795 let editor = app.textViews["x.postText.0"].firstMatch
796 XCTAssertTrue(editor.waitForExistence(timeout: 10))
797 editor.coordinate(withNormalizedOffset: .zero).withOffset(CGVector(dx: editor.frame.width - 12, dy: 15)).tap()
798 // Actual Return keys at the end and between words, not a final fixture assignment.
799 editor.typeText("\n")
800 XCTAssertEqual(editor.value as? String, "We build useful tools and give them away.\n")
801 editor.typeText("\nA second paragraph.")
802 let expected = "We build useful tools and give them away.\n\nA second paragraph."
803 XCTAssertEqual(editor.value as? String, expected)
804 editor.typeText("\nThird line.")
805 let savedText = expected + "\nThird line."
806 XCTAssertEqual(editor.value as? String, savedText)
807 capture("Return preserves blank lines and subsequent typing", app)
808 app.buttons["x.backToThread"].tap()
809 let secondReply = app.buttons["x.editPost.2"].firstMatch
810 for _ in 0..<4 where !secondReply.isHittable { app.swipeUp() }
811 XCTAssertTrue(secondReply.waitForExistence(timeout: 5))
812 capture("Newsletter and Discord remain two follow-up replies", app)
813 app.buttons["Done"].firstMatch.tap()
814 XCTAssertTrue(app.buttons["x.reply.0"].waitForExistence(timeout: 10))
815 XCTAssertTrue(app.buttons["x.reply.0"].label.contains("A second paragraph."))
816 XCTAssertTrue(app.buttons["x.reply.2"].exists)
817 capture("Saved draft retains paragraphs and three parts", app)
818 app.terminate()
819 app.launch()
820 let reopened = app.buttons["x.reply.0"].firstMatch
821 if !reopened.waitForExistence(timeout: 3) { app.staticTexts["I opened the Lab"].firstMatch.tap() }
822 XCTAssertTrue(reopened.waitForExistence(timeout: 10))
823 XCTAssertTrue(reopened.label.contains("A second paragraph."))
824 reopened.tap()
825 XCTAssertTrue(openEditor.waitForExistence(timeout: 10)); openEditor.tap()
826 XCTAssertTrue(editor.waitForExistence(timeout: 10))
827 XCTAssertEqual(editor.value as? String, savedText)
828 capture("Relaunch restores exact paragraph breaks", app)
829 }
830
831 func testLinkedReplyOpensTheEditableXArticle() {
832 continueAfterFailure = false
833 let app = XCUIApplication()
834 app.launchArguments = ["--library-fixture", "--x-thread-fixture", "--article-link-fixture"]
835 app.launchEnvironment["INKSPRING_FIXTURE_ID"] = UUID().uuidString
836 app.launch()
837 let draft = app.staticTexts["I opened the Lab"].firstMatch
838 XCTAssertTrue(draft.waitForExistence(timeout: 10))
839 draft.tap()
840 let article = app.buttons["X article · The manifesto"].firstMatch
841 for _ in 0..<4 where !article.isHittable { app.swipeUp() }
842 XCTAssertTrue(article.isHittable)
843 capture("Thread with linked X article", app)
844 article.tap()
845 XCTAssertTrue(app.navigationBars["X article"].waitForExistence(timeout: 6))
846 app.buttons["newsletter.more"].firstMatch.tap()
847 app.buttons["Edit Markdown"].firstMatch.tap()
848 XCTAssertTrue(app.textViews["newsletter.markdown"].firstMatch.waitForExistence(timeout: 6))
849 capture("Linked article open for editing", app)
850 }
851
852 func testReviewWriteIdeaOpensTheComposerBeforeMacSetup() {
853 continueAfterFailure = false
854 let app = XCUIApplication()
855 app.launchArguments = ["--unpaired-fixture", "-inkspring.mobile.theme", "warm-paper", "-inkspring.mobile.completedWelcome", "YES"]
856 app.launchEnvironment["INKSPRING_FIXTURE_ID"] = UUID().uuidString
857 app.launch()
858 XCTAssertTrue(app.staticTexts["Your writing workspace"].waitForExistence(timeout: 8))
859 let writeIdea = app.buttons["Write an idea"].firstMatch
860 XCTAssertTrue(writeIdea.isHittable)
861 XCTAssertGreaterThanOrEqual(writeIdea.frame.height, 44)
862 capture("Write an idea button", app)
863 writeIdea.tap()
864 XCTAssertTrue(app.textFields["idea.new.title"].firstMatch.waitForExistence(timeout: 5), app.debugDescription)
865 capture("New ideas composer", app)
866 }
867
868 func testFirstLaunchSavesAnIdeaBeforeMacSetup() {
869 continueAfterFailure = false
870 let app = XCUIApplication()
871 app.launchArguments = ["--unpaired-fixture"]
872 app.launchEnvironment["INKSPRING_FIXTURE_ID"] = UUID().uuidString
873 app.launch()
874 XCTAssertTrue(app.staticTexts["Welcome to Inkspring"].waitForExistence(timeout: 10))
875 capture("01 Welcome", app)
876 let proceed = app.buttons["welcome.primary"]
877 if !proceed.isHittable { app.swipeUp() }
878 proceed.tap()
879 let title = app.textFields["idea.new.title"].firstMatch
880 XCTAssertTrue(title.waitForExistence(timeout: 5))
881 capture("02 Capture an idea", app)
882 title.tap()
883 title.typeText("A field guide to native apps")
884 let notes = app.textFields["idea.new.angle"].firstMatch
885 notes.tap()
886 notes.typeText("Compare how the same draft feels on iPhone and Mac.")
887 app.buttons["Save idea"].tap()
888 let saved = app.staticTexts.matching(NSPredicate(format: "label BEGINSWITH %@", "Saved on this device")).firstMatch
889 XCTAssertTrue(saved.waitForExistence(timeout: 6), app.debugDescription)
890 capture("03 Saved on this device", app)
891 let back = app.navigationBars["Idea"].buttons.firstMatch
892 XCTAssertTrue(back.isHittable)
893 back.tap()
894 let updated = app.staticTexts.matching(NSPredicate(format: "label BEGINSWITH %@", "Updated ")).firstMatch
895 for _ in 0..<3 where !updated.isHittable { app.swipeUp() }
896 XCTAssertTrue(updated.isHittable, app.debugDescription)
897 capture("Recently saved idea shows its local timestamp", app)
898 app.terminate()
899 app.launch()
900 XCTAssertTrue(app.staticTexts["Your writing workspace"].waitForExistence(timeout: 8))
901 capture("04 Workspace", app)
902 app.buttons["Mac setup guide"].tap()
903 XCTAssertTrue(app.staticTexts["Welcome to Inkspring"].waitForExistence(timeout: 5))
904 let done = app.buttons["welcome.primary"]
905 if !done.isHittable { app.swipeUp() }
906 done.tap()
907 app.buttons["Write an idea"].tap()
908 XCTAssertTrue(app.staticTexts["A field guide to native apps"].firstMatch.waitForExistence(timeout: 5))
909 }
910
911 private func capture(_ name: String, _ app: XCUIApplication) {
912 let attachment = XCTAttachment(screenshot: app.screenshot())
913 attachment.name = name
914 attachment.lifetime = .keepAlways
915 add(attachment)
916 }
917}