// The journal page as a diary lying open: the mood pressed as its seal (its // own wax, or a bare disc for none), the weather a glyph, the star the ribbon // pulled out; every word the core's, tagged; it lies on the journal's bedside // table and is stepped by a cut. @testable import CottonFaces import CottonPaper import CottonValues import SwiftUI import XCTest @MainActor final class JournalDiaryTests: XCTestCase { typealias Catalogue = JournalDiaryFaceCatalogue /// RULE: The seal is pressed in the mood's own wax — great gold, good green, okay blue-grey, low indigo, awful oxblood — and a page with no mood, or a word the diary keeps no wax for, has a plain unpressed disc. func testTheSealIsTheMoodsWax() { XCTAssertEqual(DiarySetting.seal(Catalogue.starred), "diary-seal-great") XCTAssertEqual(DiarySetting.seal(Catalogue.evening), "diary-seal-good") XCTAssertEqual(DiarySetting.seal(Catalogue.old), "diary-seal-okay") XCTAssertEqual(DiarySetting.seal(Catalogue.low), "diary-seal-low") XCTAssertEqual(DiarySetting.seal(Catalogue.untitled), "diary-seal-awful") XCTAssertEqual(DiarySetting.seal(Catalogue.blank), "diary-seal-bare") XCTAssertEqual(DiarySetting.seal(Catalogue.page(["seal": .text("ecstatic")])), "diary-seal-bare") for mood in DiarySetting.moods + ["bare"] { XCTAssertNotNil(CottonMedia.image("diary-seal-\(mood)", scale: 3), "the \(mood) seal is not in the catalogue") } XCTAssertEqual(DiarySeal.wax("diary-seal-great"), JournalMaterial.great.colour) XCTAssertEqual(DiarySeal.wax("diary-seal-bare"), JournalMaterial.bare.colour) } /// RULE: The weather is a small glyph by its stored value, none for a day with no weather; the ribbon is pulled out only for a starred page. func testTheWeatherIsAGlyphAndTheStarTheRibbon() { XCTAssertEqual(DiarySetting.weather(Catalogue.evening), "sun.max") XCTAssertEqual(DiarySetting.weather(Catalogue.low), "cloud.rain") XCTAssertEqual(DiarySetting.weather(Catalogue.untitled), "cloud.bolt.rain") XCTAssertEqual(DiarySetting.weather(Catalogue.old), "cloud.fog") XCTAssertNil(DiarySetting.weather(Catalogue.blank)) let size = CGSize(width: 300, height: 446) XCTAssertTrue(DiarySetting.set(Catalogue.starred, size: size, theme: .paper).starred) XCTAssertFalse(DiarySetting.set(Catalogue.evening, size: size, theme: .paper).starred) for name in ["diary-book", "diary-ribbon-in", "diary-ribbon-out"] { XCTAssertNotNil(CottonMedia.image(name, scale: 3), "\(name) is not in the catalogue") } } /// RULE: The title takes the first rules, one line or two, a page with no title its first sentence; the words follow on the next rule and stop at the page's last; a blank page writes nothing but its date. func testTheWordsAreWrittenOnTheRules() { let size = CGSize(width: 300, height: 446) let evening = DiarySetting.set(Catalogue.evening, size: size, theme: .paper) XCTAssertFalse(evening.title.isEmpty) XCTAssertLessThanOrEqual(evening.title.count, JournalDiaryFaceKnobs.titleLines) XCTAssertEqual(evening.wordsRule, evening.title.count) XCTAssertLessThanOrEqual(evening.wordsRules.upperBound, JournalDiaryFaceKnobs.rules.count) XCTAssertEqual(evening.date, "Thu 12 Nov") XCTAssertEqual(evening.place, "Invented hills above the town") let untitled = DiarySetting.set(Catalogue.untitled, size: size, theme: .paper) XCTAssertEqual(untitled.title.map(\.words).joined(separator: " "), "The storm took the big branch off the neem in the night") let blank = DiarySetting.set(Catalogue.blank, size: size, theme: .paper) XCTAssertTrue(blank.title.isEmpty && blank.words.isEmpty) XCTAssertNil(blank.place) XCTAssertEqual(blank.date, "Thu 12 Nov") } /// RULE: The date, the place, the title, the words, the seal and the weather are each their part; a blank page tags its date and its bare seal. func testEveryWordIsTheCoresAndTagged() { XCTAssertEqual(tagged(Catalogue.evening), [.when, .weather, .place, .title, .body, .seal]) XCTAssertEqual(tagged(Catalogue.blank), [.when, .seal]) } /// RULE: The diary lies bare on the journal's bedside table, draws its own object, and is stepped by a cut. func testTheDiaryLiesOnTheBedsideTableAndCuts() { XCTAssertEqual(FaceRegistry.ground("journal.diary"), .bedsideTable) XCTAssertEqual(FaceRegistry.stock("journal.diary"), .own) XCTAssertEqual(Catalogue.face.steps, .cut) XCTAssertEqual(Catalogue.face.specimens.map(\.name), ["evening", "starred", "low", "untitled", "blank", "old"]) XCTAssertTrue(FaceGround.bedsideTable.dark) XCTAssertEqual(FaceGround.bedsideTable.tile, "journal-bedside") XCTAssertEqual(FaceGround.bedsideTable.lamp?.name, "bedside-lamp") XCTAssertNotNil(CottonMedia.image("journal-bedside", scale: 3), "the table's tile is not in the catalogue") XCTAssertNotNil(CottonMedia.image("bedside-lamp", scale: 3), "the lamp's pool is not in the catalogue") } private func tagged(_ card: DeckCard) -> Set { final class Tagged { var parts: Set = [] } let tagged = Tagged() let drawn = JournalDiaryFace(card: card) .frame(width: 340, height: 480) .backgroundPreferenceValue(FacePartsKey.self) { regions in let _ = tagged.parts.formUnion(regions.map(\.part)) Color.clear } XCTAssertNotNil(ImageRenderer(content: drawn).cgImage) return tagged.parts } }