import Foundation import XCTest @testable import CottonUI /// The opened fan draws a command's named object (`shell.opened`'s `icon`, /// `act-`), never its verb or kind. Every command a kit offers on a /// held card names one and Loom bundles it: no tile is words alone (362 /// walk: Drop, Archive, Sign out and Share ink were blank cream tiles, /// because this sweep let a command with no object stand as words). @MainActor final class CommandPicturesTests: XCTestCase { func testEveryBundledCommandHasItsPicture() throws { let catalogue = SourceSweep.source("CottonPaper/Media.xcassets") var checked = 0 for url in try SourceSweep.kitTables() { let json = try JSONSerialization.jsonObject(with: Data(contentsOf: url)) let tables = (json as? [[String: Any]]) ?? [(json as? [String: Any]) ?? [:]] for table in tables { for raw in table["commands"] as? [[String: Any]] ?? [] { // A field card's slip, a list's act and a form's stand on no tile. guard raw["sheet"] == nil, raw["list"] == nil, raw["form"] as? Bool != true else { continue } let data = try JSONSerialization.data(withJSONObject: raw) let command = try JSONDecoder().decode(RecordCommand.self, from: data) let picture = try XCTUnwrap(command.object.map { "act-" + $0 }, "\(url.lastPathComponent) \(command.label) names no object") XCTAssertTrue(FileManager.default.fileExists(atPath: catalogue.appendingPathComponent("\(picture).imageset").path), "\(url.lastPathComponent) \(command.label): \(picture)") checked += 1 } } } XCTAssertGreaterThan(checked, 0, "the sweep read no commands") } }