// The episode's lobby card: the caption is the core's mark and the title, // taken down before it wraps; the length is said from its minutes; the strip // is filled as far as the resume point is of the length, full once watched, // its place typed on a player's clock; a watched episode wears the stub; a // stillless one shows its number on the dark; the parts tagged; every word a // line or the card's; the card hangs on the velvet and cuts. The marquee // over the player sets the same caption on its plate. The empty Films // deck's doors carry their painted pictures as act pictures. @testable import CottonFaces import CottonPaper import CottonSpecimens import CottonValues import SwiftUI import XCTest /// The parts a drawn face tagged. private final class LobbyPartsTagged { var parts: Set = [] } @MainActor final class EpisodeLobbyTests: XCTestCase { private typealias Catalogue = EpisodeLobbyFaceCatalogue private typealias Knobs = EpisodeLobbyFaceKnobs private let join = ShellLines.line("cards", "join") private func episode(_ fields: [String: RecordValue], _ status: String = "watching") -> DeckCard { Catalogue.episode(status, fields) } /// RULE: The caption is the card's subtitle (the core's mark for the season and number) then its title, joined as the cards join words, on one line at its own size when it fits; the face composes no mark of its own. func testTheCaptionIsTheCardsMarkAndTitle() { XCTAssertEqual(ShellLines.line("cards", "field.episode_mark", ["said": "2", "number": "5"]), "S2 E5") XCTAssertEqual(EpisodeLobbySetting.caption(Catalogue.still), "S2 E5" + join + "The Long Night") let (lines, size) = EpisodeLobbySetting.captionLines(Catalogue.still) XCTAssertEqual(lines, ["S2 E5" + join + "The Long Night"]) XCTAssertEqual(size, Knobs.captionSize, "a caption that fits is set at its own size") XCTAssertEqual(EpisodeLobbySetting.caption(episode(["title": .text("Fog")])), "Fog", "no mark kept: the title alone") XCTAssertEqual(EpisodeLobbySetting.caption(episode(["subtitle": .text("S1 E1")])), "S1 E1") XCTAssertNil(EpisodeLobbySetting.caption(episode([:]))) XCTAssertEqual(EpisodeLobbySetting.captionLines(episode([:])).lines, []) // The number typed on a stillless card is the card's number. XCTAssertEqual(EpisodeLobbySetting.numeral(Catalogue.noStill), "3") XCTAssertNil(EpisodeLobbySetting.numeral(episode([:]))) } /// RULE: A caption too long is taken down before it wraps; past the least size it takes two lines, the second cut with an ellipsis, both inside the caption's room. func testTheCaptionShrinksBeforeItWraps() { let (lines, size) = EpisodeLobbySetting.captionLines(Catalogue.longestTitle) XCTAssertEqual(lines.count, 2) XCTAssertNotEqual(lines.last?.last, "\u{2026}", "two lines hold the longest specimen whole") let cut = EpisodeLobbySetting.captionLines(episode(["subtitle": .text("S1 E1"), "title": .text(Array(repeating: "The Long Night", count: 9).joined(separator: " "))])) XCTAssertEqual(cut.lines.count, 2) XCTAssertEqual(cut.lines.last?.last, "\u{2026}", "too long even at the least size: cut") XCTAssertGreaterThanOrEqual(cut.size, Knobs.captionLeast) XCTAssertGreaterThanOrEqual(size, Knobs.captionLeast) XCTAssertLessThanOrEqual(CGFloat(lines.count) * size * Knobs.captionStep, Knobs.caption.height + 0.5) for line in lines { XCTAssertLessThanOrEqual(HighlightPassageSetting.wide(line, EpisodeLobbySetting.type(size)), Knobs.caption.width + 0.5) } let shrunk = EpisodeLobbySetting.captionLines(episode(["subtitle": .text("S2 E5"), "title": .text("The Long Night at the Harbour Lamp, Part Two")])) XCTAssertEqual(shrunk.lines.count, 1, "a caption a little long is only taken down") XCTAssertLessThan(shrunk.size, Knobs.captionSize) } /// RULE: The strip is filled as far as the resume point (seconds) is of the length (minutes), its place typed on a player's clock in the film's line; a watched episode's is full, its place at the end; one not begun, or with no length, wears none. func testTheStripIsFilledByThePosition() throws { XCTAssertEqual(try XCTUnwrap(EpisodeLobbySetting.share(Catalogue.halfWatched)), 0.5, accuracy: 0.0001) XCTAssertEqual(EpisodeLobbySetting.place(Catalogue.halfWatched), ShellLines.line("cards", "film.position", ["at": "24:00", "of": "48:00"])) XCTAssertEqual(EpisodeLobbySetting.place(Catalogue.halfWatched), "24:00 of 48:00") XCTAssertEqual(EpisodeLobbySetting.share(Catalogue.watched), 1) XCTAssertEqual(EpisodeLobbySetting.place(Catalogue.watched), "48:00 of 48:00") XCTAssertEqual(EpisodeLobbySetting.share(episode(["used": .number(9000), "limit": .number(48)])), 1, "past the end, full") XCTAssertEqual(EpisodeLobbySetting.place(episode(["used": .number(9000), "limit": .number(48)])), "48:00 of 48:00") XCTAssertNil(EpisodeLobbySetting.share(Catalogue.still), "not begun") XCTAssertNil(EpisodeLobbySetting.place(Catalogue.still)) XCTAssertNil(EpisodeLobbySetting.share(episode(["used": .number(600)])), "no length, no share") XCTAssertNil(EpisodeLobbySetting.place(episode(["used": .number(600)]))) XCTAssertEqual(EpisodeLobbySetting.clock(330), "5:30") XCTAssertEqual(EpisodeLobbySetting.clock(6720), "1:52:00") XCTAssertEqual(EpisodeLobbySetting.clock(3600), "1:00:00") // The length, from its minutes, as a film's is said. XCTAssertEqual(EpisodeLobbySetting.length(Catalogue.still), ShellLines.line("cards", "film.length_minutes", ["minutes": "48"])) XCTAssertEqual(EpisodeLobbySetting.length(Catalogue.still), "48 min") XCTAssertNil(EpisodeLobbySetting.length(episode([:]))) } /// RULE: An episode watched by its status wears the stub, stamped in the film's line and typed with the day it was watched, bare of its weekday; any other status, none. func testTheStubIsByWatched() throws { let stub = try XCTUnwrap(EpisodeLobbySetting.stub(Catalogue.watched)) XCTAssertEqual(stub.stamp, ShellLines.line("cards", "film.stub").uppercased()) XCTAssertEqual(stub.day, "4 NOV") XCTAssertNil(try XCTUnwrap(EpisodeLobbySetting.stub(episode(["date": .text(ShellLines.line("cards", "date.add"))], "watched"))).day, "watched with no day kept: stamped, not dated") for status in ["want_to_watch", "watching", "stopped"] { XCTAssertNil(EpisodeLobbySetting.stub(episode(["date": .text("Wed 4 Nov")], status)), status) } } /// RULE (Cinemas gaps, 5 Nov 2026): An episode still converting on the Mac wears the stub stamped CONVERTING, with no day, before any tap. func testAnEpisodeConvertingOnTheMacWearsTheConvertingStub() throws { let stub = try XCTUnwrap(EpisodeLobbySetting.stub(episode(["date": .text("Wed 4 Nov")], "needs_mac"))) XCTAssertEqual(stub.stamp, "CONVERTING") XCTAssertNil(stub.day) } /// RULE: Every word the lobby card, the marquee and the Cinemas parts say is a line or the card's: the mark the core's, the length, the place and the stub the film's lines, never a literal typed or said. func testItsWordsAreLines() throws { for key in ["film.position", "film.length_minutes", "film.length_hours", "film.stub", "join"] { XCTAssertNotEqual(ShellLines.line("cards", key), "cards.\(key)", "the kit ships cards.\(key)") } XCTAssertNotEqual(ShellLines.line("cards", "field.episode_mark"), "cards.field.episode_mark") let faces = URL(fileURLWithPath: #filePath).deletingLastPathComponent().deletingLastPathComponent().deletingLastPathComponent() .appendingPathComponent("Sources/CottonFaces/Cotton") for file in ["EpisodeLobbyFace.swift", "CinemaMarquee.swift", "CinemaParts.swift"] { let source = try String(contentsOf: faces.appendingPathComponent(file), encoding: .utf8) let face = source.components(separatedBy: "public enum EpisodeLobbyFaceCatalogue")[0] XCTAssertNil(face.range(of: #"Text\(""#, options: .regularExpression), "\(file) types no literal") XCTAssertNil(face.range(of: #"accessibilityLabel\(""#, options: .regularExpression), "\(file) says no literal") } } /// RULE: The face tags the still as its picture and the caption as its title; a part-watched or watched episode its strip as its state, a watched one its stub as done. func testTheCardTagsItsParts() { let still = FixturePictures.image("kelmoor-lake") XCTAssertNotNil(still) func parts(_ card: DeckCard, still: Image?) -> Set { let tagged = LobbyPartsTagged() let drawn = EpisodeLobbyFace(card: card, still: still) .frame(width: 340, height: 451) .backgroundPreferenceValue(FacePartsKey.self) { regions in let _ = tagged.parts.formUnion(regions.map(\.part)) Color.clear } XCTAssertNotNil(ImageRenderer(content: drawn).cgImage) return tagged.parts } XCTAssertEqual(parts(Catalogue.still, still: still), [.picture, .title]) XCTAssertEqual(parts(Catalogue.noStill, still: nil), [.picture, .title]) XCTAssertEqual(parts(Catalogue.halfWatched, still: still), [.picture, .title, .state]) XCTAssertEqual(parts(Catalogue.watched, still: still), [.picture, .title, .state, .done]) } /// RULE: The card, its shadow and its stub stay inside the card's room; the strip is laid inside its rect, clear of the length and the place. func testTheCardKeepsInsideItsRoom() throws { XCTAssertTrue(Knobs.shadow.contains(Knobs.stub), "the stub is inside the shadow's reach") XCTAssertTrue(CGRect(origin: .zero, size: Knobs.box).contains(Knobs.stub), "the stub stays on the card") let font = EpisodeLobbySetting.type(Knobs.footSize) let length = try XCTUnwrap(EpisodeLobbySetting.length(Catalogue.halfWatched)) let place = try XCTUnwrap(EpisodeLobbySetting.place(Catalogue.halfWatched)) XCTAssertLessThan(Knobs.lengthFrom + HighlightPassageSetting.wide(length, font) + Knobs.stripGap, Knobs.progress.minX + 1, "the length ends before the strip's own start") XCTAssertGreaterThan(Knobs.placeTo - HighlightPassageSetting.wide(place, font) - Knobs.stripGap, Knobs.progress.maxX - 1, "the place begins after the strip's own end") } /// RULE: The lobby card hangs bare on the cinema's velvet under its house light, draws its own sheet and is stepped by a cut; its specimens show an episode with a still and without, half watched, watched, the longest title and the fullest; every material it lays is in the catalogue. func testTheCardHangsOnTheVelvetAndCuts() { XCTAssertEqual(FaceRegistry.ground("episode.lobby"), .velvet) XCTAssertEqual(FaceRegistry.stock("episode.lobby"), .own) XCTAssertEqual(Catalogue.face.steps, .cut) XCTAssertEqual(Catalogue.face.specimens.map(\.name), ["still", "no-still", "half-watched", "watched", "longest-title", "largest"]) XCTAssertNil(Catalogue.face.specimens.first { $0.name == "no-still" }?.picture) for name in ["lobby-card", "lobby-card-shadow", "progress-strip", "stub", "stub-shadow", "velvet", "house-light", "marquee-plate"] { XCTAssertNotNil(CottonMedia.image(name, scale: 3), "\(name) is not in the catalogue") } } /// RULE: The empty Films deck's three doors (Add files, Add a folder, Find a film) carry their painted pictures as act pictures: the string-tie envelope, the red cloth folder and the small lobby frame, named for the core's act objects pouch, portfolio and frame. func testTheDoorsCarryTheirPictures() { for name in ["act-pouch", "act-portfolio", "act-frame"] { XCTAssertNotNil(CottonMedia.image(name, scale: 3), "\(name) is not in the catalogue") } } /// RULE: The marquee over the player sets the caption on one line, at its own size when it fits, taken down to the least, past it cut with an ellipsis; nothing for no words. func testTheMarqueeSetsTheCaption() { let caption = EpisodeLobbySetting.caption(Catalogue.still) ?? "" let (line, size) = CinemaMarqueeSetting.line(caption) XCTAssertEqual(line, caption) XCTAssertEqual(size, CinemaMarqueeKnobs.size) let long = CinemaMarqueeSetting.line(EpisodeLobbySetting.caption(Catalogue.longestTitle) ?? "") XCTAssertEqual(long.line?.last, "\u{2026}") XCTAssertGreaterThanOrEqual(long.size, CinemaMarqueeKnobs.least) XCTAssertLessThanOrEqual(HighlightPassageSetting.wide(long.line ?? "", EpisodeLobbySetting.type(long.size)), CinemaMarqueeKnobs.words.width + 0.5) XCTAssertNil(CinemaMarqueeSetting.line(" ").line) XCTAssertEqual(CinemaMarqueeKnobs.stands, 3) XCTAssertNotNil(ImageRenderer(content: CinemaMarqueePlate(caption: caption, width: 360)).cgImage) } }