// The files a note carries open read-only in Words (the owner, 22 Nov 2026, // WORDS-DRAWER.md; CONTRACT.md section 15, as Android). An invented note // carries an invented web page, Markdown file, PDF, picture and an archive // Words cannot show (`-notes-open files`, notes-files-seed.json, attached by // developer.inventNoteFiles). They stand as rows under the note's top bar, two // and "3 more files"; a tap opens each: the page sealed (its script, which // would rewrite it, does not run), the Markdown drawn as a note that takes no // keyboard, the PDF's pages, the picture whole; the archive asks before // another app opens it. Shots words-attach-* (WORDS_SHOTS, passed as // TEST_RUNNER_WORDS_SHOTS). import XCTest final class NotesFileTests: NotesUITestCase { private func keep(_ name: String) { let screen = XCUIScreen.main.screenshot() let shot = XCTAttachment(screenshot: screen) shot.name = name shot.lifetime = .keepAlways add(shot) if let dir = ProcessInfo.processInfo.environment["WORDS_SHOTS"], !dir.isEmpty { try? screen.pngRepresentation.write(to: URL(fileURLWithPath: dir).appendingPathComponent(name + ".png")) } } @MainActor private func opened(_ app: XCUIApplication, _ shown: String, named: String) { XCTAssertTrue(NotesUI.id(app, "notes-file-viewer").waitForExistence(timeout: 8), "\(named) opened") XCTAssertTrue(NotesUI.id(app, shown).waitForExistence(timeout: 10), "\(named) is drawn as \(shown)") XCTAssertEqual(NotesUI.id(app, "file-viewer-title").label, named) } @MainActor private func back(_ app: XCUIApplication) { NotesUI.id(app, "file-viewer-back").tap() XCTAssertTrue(NotesUI.id(app, "notes-file-viewer").waitForNonExistence(timeout: 5), "Back closed the file") } @MainActor private func fromTheSheet(_ app: XCUIApplication, _ name: String) { NotesUI.id(app, "note-files-more").tap() let row = NotesUI.button(app, name) XCTAssertTrue(row.waitForExistence(timeout: 5), "the sheet of all the files offers \(name)") row.tap() } // RULE: a note's web page, Markdown file, PDF and picture each open read-only from its rows; the page's script does not run; a file Words cannot show is asked first. @MainActor func testANotesFilesOpenReadOnly() throws { let app = XCUIApplication() app.launchArguments += ["-notes-open", "files"] app.launch() XCTAssertTrue(NotesUI.writer(app).waitForExistence(timeout: 90), "the invented note with files opened") try skipUnderTheShellsCard(app) let first = NotesUI.id(app, "note-file-0") XCTAssertTrue(first.waitForExistence(timeout: 10), "the note's files stand under its top bar") XCTAssertTrue(NotesUI.id(app, "note-file-1").exists) XCTAssertTrue(NotesUI.id(app, "note-files-more").label.contains("3 more files"), "five files: two, and 3 more") XCTAssertFalse(NotesUI.id(app, "note-file-2").exists, "at most three rows") keep("words-attach-note") first.tap() opened(app, "file-viewer-page", named: "Invented lake plan.html") let web = app.webViews.firstMatch XCTAssertTrue(web.staticTexts["Invented lake plan"].waitForExistence(timeout: 10), "the page is drawn") XCTAssertTrue(web.staticTexts["Three days by the lakes, written as a page."].exists, "the page's words stand as written") XCTAssertFalse(web.staticTexts["Scripts ran in this page."].exists, "the page's script did not run") keep("words-attach-page") back(app) NotesUI.id(app, "note-file-1").tap() opened(app, "file-viewer-note", named: "Invented packing list.md") let words = NotesUI.id(app, "file-viewer-note") XCTAssertTrue((words.value as? String ?? "").contains("Stove and gas"), "the Markdown's own words, drawn as a note") words.tap() XCTAssertFalse(app.keyboards.firstMatch.waitForExistence(timeout: 2), "it takes no keyboard: read only") keep("words-attach-markdown") back(app) fromTheSheet(app, "Invented ferry ticket.pdf") opened(app, "file-viewer-pdf", named: "Invented ferry ticket.pdf") settle(1) keep("words-attach-pdf") back(app) fromTheSheet(app, "invented-shore.png") opened(app, "file-viewer-picture", named: "invented-shore.png") settle(1) keep("words-attach-picture") back(app) fromTheSheet(app, "Invented shore photos.zip") XCTAssertTrue(app.staticTexts["Words cannot show this kind of file. Open it in another app?"].waitForExistence(timeout: 5), "a file Words cannot show is asked before another app opens it") keep("words-attach-elsewhere") } }