import Foundation import OrgCore import OrgDocument import OrgMathJax import PDFKit import Testing @testable import OrgApp /// What Print… sends to the printer: the page PDF export makes of the file, the subtree or the /// selection, and the agenda as shown. @MainActor struct PrintingTests { init() { PDFExport.mathJaxURL = OrgMathJax.script } static let text = "#+TITLE: Notes\n* One\nFirst body.\n** Inner\nInner body.\n* Two\nSecond body.\n" func page(_ scope: PrintScope, text: String = Self.text) -> String? { Printing.page(text, path: "/notes/a.org", scope: scope, settings: .default, codeStyle: nil, language: "en") } func offset(of needle: String, in text: String = Self.text) -> Int { (text as NSString).range(of: needle).location } @Test func eachScope() throws { let file = try #require(page(.file)) #expect(file.contains("
work
")) #expect(html.contains("Today · Thursday, November 26, 2026") && html.contains("Tomorrow · Friday, November 27, 2026")) #expect(html.contains("TODO Call the bank")) #expect(html.contains("09:00") && html.contains("work · :phone:")) #expect(html.contains("Overdue 1
") && html.contains("[#A] Send the report")) // Escaped, not markup. #expect(html.contains("Read <b>this</b>")) // Folded overdue entries stay folded; a filter leaves out what it hides. let folded = page(agenda, overdueShown: false) #expect(folded.contains("Overdue 1") && !folded.contains("Send the report")) var filter = AgendaFilter() filter.tags = ["-phone"] #expect(!page(agenda, filter: filter).contains("Call the bank")) } @Test func agendaListsAndEmptyDays() async throws { let (list, notes) = try await agenda(.todo(keywords: nil)) _ = notes let html = page(list) #expect(html.contains("Call the bank") && html.contains("Send the report") && !html.contains("Filed")) #expect(!html.contains("class=\"gutter\"")) var none = AgendaFilter() none.tags = ["+nothing"] #expect(page(list, filter: none).contains("No entries")) let (days, more) = try await agenda(.agenda(span: 1, startOffset: 3)) _ = more #expect(!page(days).contains("Nothing scheduled
")) } /// The agenda's page goes through the same pages as a file's. @Test func agendaPrintsAsPages() async throws { let (agenda, notes) = try await agenda(.agenda(span: 2, startOffset: nil)) _ = notes let text = try #require(PDFDocument(data: try await Printing.pages(html: page(agenda), directory: nil))).string ?? "" #expect(text.contains("Call the bank") && text.contains("Send the report")) } }