oficina / docs Public

Clone
git clone https://amadan.net/oficina/docs

Plain git — no account needed to clone.

Download

Download this file

1import Foundation
2import XCTest
3@testable import DocsKit
4
5/// The apps' Colophon (Help → Colophon on the Mac, the library's menu on
6/// iPhone) is Resources/Colophon.json, which internal/shipped generates
7/// from what the apps ship and holds to estilo's catalog. These hold the
8/// app's reading of it: every section and entry is shown, every bundled
9/// typeface's full licence is the file the web serves, and the Mac's
10/// Sparkle is the Mac's alone.
11final class DocsColophonTests: XCTestCase {
12 func testEveryBundledFamilyHasItsEntryAndFullLicence() throws {
13 let data = try Data(contentsOf: DocsFontsTests.repository.appendingPathComponent("internal/fonts/fonts.json"))
14 let families = try XCTUnwrap((try JSONSerialization.jsonObject(with: data) as? [String: Any])?["families"] as? [[String: Any]])
15 let typefaces = try XCTUnwrap(DocsColophon.sections.first { $0.id == "typefaces" })
16 XCTAssertEqual(typefaces.entries.count, families.count, "one typeface entry per bundled family")
17 for family in families {
18 let name = try XCTUnwrap(family["name"] as? String)
19 let entry = try XCTUnwrap(typefaces.entries.first { $0.name == name }, name)
20 XCTAssertEqual(entry.licence.name, "SIL Open Font License 1.1", name)
21 XCTAssertFalse(entry.author.isEmpty, name)
22 let served = try String(contentsOf: DocsFontsTests.repository.appendingPathComponent("internal/fonts/files/\(family["dir"]!)/\(family["licence"]!)"), encoding: .utf8)
23 XCTAssertEqual(entry.packages.first?.notices.first?.text, served, "\(name) shows the licence the web serves")
24 }
25 }
26
27 func testEveryEntryIsWholeAndEveryShippedPackageCarriesItsText() throws {
28 let entries = DocsColophon.sections.flatMap(\.entries)
29 XCTAssertGreaterThan(entries.count, 50)
30 for entry in entries {
31 XCTAssertFalse(entry.blurb.isEmpty || entry.usage.isEmpty || entry.author.isEmpty || entry.licence.name.isEmpty, entry.id)
32 XCTAssertNotNil(entry.homeURL, entry.id)
33 XCTAssertNotNil(entry.sourceURL, entry.id)
34 for package in entry.packages where package.tool != true && entry.licence.spdx != "NOASSERTION" {
35 XCTAssertFalse(package.notices.isEmpty, "\(entry.id): \(package.name)")
36 }
37 }
38 XCTAssertEqual(Set(DocsColophon.sections.map(\.id)).isSubset(of: DocsColophon.sectionOrder), true)
39 for section in DocsColophon.sections {
40 XCTAssertNotEqual(DocsColophon.heading(section.id), "native.colophon.section.\(section.id)", "\(section.id) has no heading")
41 }
42 }
43
44 func testSparkleIsTheMacsAlone() {
45 let ids = Set(DocsColophon.sections.flatMap(\.entries).map(\.id))
46 #if os(macOS)
47 XCTAssertTrue(ids.contains("sparkle"))
48 #else
49 XCTAssertFalse(ids.contains("sparkle"), "the iPhone app does not link Sparkle")
50 #endif
51 XCTAssertTrue(ids.contains("rastrillo-native"))
52 XCTAssertTrue(ids.contains("wasmi"))
53 XCTAssertTrue(ids.contains("yrs"))
54 }
55
56 #if os(iOS)
57 /// Each entry's page grows with Dynamic Type: at the largest
58 /// accessibility size its text wraps to a taller page instead of
59 /// truncating. iOS only; macOS has no Dynamic Type.
60 @MainActor func testEntryPagesFollowDynamicType() throws {
61 for entry in DocsColophon.sections.flatMap(\.entries).prefix(20) {
62 func height(_ size: DynamicTypeSize) -> CGFloat {
63 UIHostingController(rootView: DocsColophonDetailContent(entry: entry).dynamicTypeSize(size))
64 .sizeThatFits(in: CGSize(width: 390, height: CGFloat.greatestFiniteMagnitude)).height
65 }
66 XCTAssertGreaterThan(height(.accessibility5), height(.large) * 1.5, entry.name)
67 }
68 }
69 #endif
70}
71