// The live web page a record's web column opens: held to http or https with a // host wherever it meets an address, and plain words when it did not load. // Every address is invented. import CottonKit import CottonValues import Foundation import XCTest @testable import CottonUI @MainActor final class ReaderNoLossTests: XCTestCase { private static var resources: Bundle? { Bundle(url: SourceSweep.iosSources.appendingPathComponent("CottonUI/Resources")) } private func note() throws -> TableDefinition { let loaded = FixtureDefinitions.load(from: try XCTUnwrap(Self.resources)) return try XCTUnwrap(loaded.definitions.first { $0.id == "note" }) } private func page(_ values: [String: RecordValue]) -> TableRecord { TableRecord(id: "example-page", values: ["url": .text("https://example.com/a")].merging(values) { $1 }) } /// RULE: Every address the live page meets is held to http or https with a host — the saved one, a popup, a page it follows in its own window, and where it reports it has landed (what "Open in browser" hands the system) — and a navigation it refused is no failure. func testTheLivePageNeverLeavesTheWeb() throws { XCTAssertEqual(TableDefinition.webLink(URL(string: "https://example.com/a"))?.host, "example.com") for refused in ["mailto:someone@example.com", "itms-apps://example.com/app", "javascript:void(0)", "about:blank", "file:///tmp/x", "data:text/html,hi"] { XCTAssertNil(TableDefinition.webLink(URL(string: refused)), refused) } XCTAssertNil(TableDefinition.webLink(nil)) } }