import CottonValues import Foundation import SwiftUI import XCTest @testable import CottonUI /// What a record's page draws and what it leaves to its "Add" line — the /// reading rules that keep a page from being a form of names over dashes. @MainActor final class PageFormRulesTests: XCTestCase { private func decode(extra: String = "", titleColumn: String = #", "required":true"#) throws -> TableDefinition { try TableDefinition.decode(Data(""" {"id":"example","name":"Example","plural":"Examples","builtin":false, "columns":[{"key":"title","type":"text"\(titleColumn)},{"key":"body","type":"longtext"}, {"key":"due_at","type":"date"},{"key":"notes","type":"longtext"}, {"key":"state","type":"choice","choices":["open","bank_statement"]}, {"key":"all_day","type":"bool"},{"key":"needed","type":"text","required":true}, {"key":"made_at","type":"date","readonly":true}], "title":"title","slip":{"title":"title"},"tile":{"face":"slip-list"}, "page":[{"columns":["title","body","due_at","state","all_day","needed","made_at"]}, {"heading":"Details","columns":["notes"]}]\(extra)} """.utf8)) } /// RULE: A column with no name of its own reads as its key in words without the store's endings, and a choice with no label reads as words too; neither is ever shown as stored. func testKeysAndChoicesReadAsWordsNeverAsStored() throws { let state = try XCTUnwrap(decode().column("state")) XCTAssertEqual(FaceText.line(.text("bank_statement"), column: state), "Bank statement") } }