import Foundation import XCTest @testable import DocsKit /// The apps' Colophon (Help → Colophon on the Mac, the library's menu on /// iPhone) is Resources/Colophon.json, which internal/shipped generates /// from what the apps ship and holds to estilo's catalog. These hold the /// app's reading of it: every section and entry is shown, every bundled /// typeface's full licence is the file the web serves, and the Mac's /// Sparkle is the Mac's alone. final class DocsColophonTests: XCTestCase { func testEveryBundledFamilyHasItsEntryAndFullLicence() throws { let data = try Data(contentsOf: DocsFontsTests.repository.appendingPathComponent("internal/fonts/fonts.json")) let families = try XCTUnwrap((try JSONSerialization.jsonObject(with: data) as? [String: Any])?["families"] as? [[String: Any]]) let typefaces = try XCTUnwrap(DocsColophon.sections.first { $0.id == "typefaces" }) XCTAssertEqual(typefaces.entries.count, families.count, "one typeface entry per bundled family") for family in families { let name = try XCTUnwrap(family["name"] as? String) let entry = try XCTUnwrap(typefaces.entries.first { $0.name == name }, name) XCTAssertEqual(entry.licence.name, "SIL Open Font License 1.1", name) XCTAssertFalse(entry.author.isEmpty, name) let served = try String(contentsOf: DocsFontsTests.repository.appendingPathComponent("internal/fonts/files/\(family["dir"]!)/\(family["licence"]!)"), encoding: .utf8) XCTAssertEqual(entry.packages.first?.notices.first?.text, served, "\(name) shows the licence the web serves") } } func testEveryEntryIsWholeAndEveryShippedPackageCarriesItsText() throws { let entries = DocsColophon.sections.flatMap(\.entries) XCTAssertGreaterThan(entries.count, 50) for entry in entries { XCTAssertFalse(entry.blurb.isEmpty || entry.usage.isEmpty || entry.author.isEmpty || entry.licence.name.isEmpty, entry.id) XCTAssertNotNil(entry.homeURL, entry.id) XCTAssertNotNil(entry.sourceURL, entry.id) for package in entry.packages where package.tool != true && entry.licence.spdx != "NOASSERTION" { XCTAssertFalse(package.notices.isEmpty, "\(entry.id): \(package.name)") } } XCTAssertEqual(Set(DocsColophon.sections.map(\.id)).isSubset(of: DocsColophon.sectionOrder), true) for section in DocsColophon.sections { XCTAssertNotEqual(DocsColophon.heading(section.id), "native.colophon.section.\(section.id)", "\(section.id) has no heading") } } func testSparkleIsTheMacsAlone() { let ids = Set(DocsColophon.sections.flatMap(\.entries).map(\.id)) #if os(macOS) XCTAssertTrue(ids.contains("sparkle")) #else XCTAssertFalse(ids.contains("sparkle"), "the iPhone app does not link Sparkle") #endif XCTAssertTrue(ids.contains("rastrillo-native")) XCTAssertTrue(ids.contains("wasmi")) XCTAssertTrue(ids.contains("yrs")) } #if os(iOS) /// Each entry's page grows with Dynamic Type: at the largest /// accessibility size its text wraps to a taller page instead of /// truncating. iOS only; macOS has no Dynamic Type. @MainActor func testEntryPagesFollowDynamicType() throws { for entry in DocsColophon.sections.flatMap(\.entries).prefix(20) { func height(_ size: DynamicTypeSize) -> CGFloat { UIHostingController(rootView: DocsColophonDetailContent(entry: entry).dynamicTypeSize(size)) .sizeThatFits(in: CGSize(width: 390, height: CGFloat.greatestFiniteMagnitude)).height } XCTAssertGreaterThan(height(.accessibility5), height(.large) * 1.5, entry.name) } } #endif }