32 lines · 1.8 KB · SwiftRaw
// The keys in the keyboard's place as the kit lays them (writing.json// `keyboard`): a grid of rows, editing keys grey, a held key's offers, and// the slim row under it; a key held behind another is still found by its id.@testable import CottonWritingimport XCTestfinal class WritingKeysTests: XCTestCase { func testTheGridDecodesWithItsGreyKeysHeldOffersAndFoot() throws { let words = try JSONDecoder().decode(WritingWords.self, from: Data(""" { "bar": [ { "id": "undo", "label": "Undo" }, { "id": "gap", "label": "" }, { "id": "format", "label": "Format" } ], "panel": [], "grid": [ [ { "id": "move_up", "label": "Move up", "grey": true, "action": { "action": "move_up" } }, { "id": "heading_1", "label": "Heading 1", "glyph": "H1", "action": { "action": "heading", "level": 1 }, "hold": [ { "id": "heading_2", "label": "Heading 2", "action": { "action": "heading", "level": 2 } } ] } ] ], "foot": [ { "id": "copy", "label": "Copy" }, { "id": "paste", "label": "Paste" } ] } """.utf8)) XCTAssertEqual(words.grid.first?.first?.grey, true) XCTAssertNil(words.grid.first?.last?.grey) XCTAssertEqual(words.grid.first?.last?.hold?.map(\.id), ["heading_2"]) XCTAssertEqual(words.key("heading_2")?.action?.fields["level"]?.number, 2, "a held key is found by its id") XCTAssertEqual(words.foot.map(\.id), ["copy", "paste"]) XCTAssertEqual(words.key("paste")?.label, "Paste") } func testWordsWithNoGridStillDecode() throws { let words = try JSONDecoder().decode(WritingWords.self, from: Data(#"{ "bar": [], "panel": [ { "id": "bold", "label": "Bold" } ] }"#.utf8)) XCTAssertTrue(words.grid.isEmpty) XCTAssertTrue(words.foot.isEmpty) XCTAssertEqual(words.key("bold")?.label, "Bold") }}