// A group call's shapes as the core answers them (chat/CONTRACT.md "Group calls"): the line's Join, the banner's // answer, and the call screen's tiles, grid and privacy line, read from the core's own fixture. import CottonKit import Foundation import XCTest @testable import CottonUI final class ChatGroupCallShapesTests: XCTestCase { // RULE: a group's call going on carries its room and Join on its line; a line without it reads as before. func testTheLineCarriesJoin() throws { let json = #"{"item":"event","message":"m1","text":"Asha started a voice call","groupCall":{"room":"r1","video":false,"join":"Join"}}"# let item = try JSONDecoder().decode(ChatThreadItem.self, from: Data(json.utf8)) guard case .event(_, let text, nil, nil, let line?) = item else { return XCTFail("the line carries its group call") } XCTAssertEqual(text, "Asha started a voice call") XCTAssertEqual(line, ChatGroupCallLine(room: "r1", video: false, join: "Join")) let plain = try JSONDecoder().decode(ChatThreadItem.self, from: Data(#"{"item":"event","message":"m2","text":"Ravi joined"}"#.utf8)) guard case .event(_, _, nil, nil, nil) = plain else { return XCTFail("a plain line has no group call") } let again = try JSONDecoder().decode(ChatThreadItem.self, from: JSONEncoder().encode(item)) XCTAssertEqual(again, item, "it survives the warm cache") } // RULE: the banner reads live with Join, here with the core's words, and offline as not known. func testTheBannerReadsEachAnswer() throws { let live = try JSONDecoder().decode(ChatGroupCallState.self, from: Data(#"{"live":true,"room":"r1","video":true,"here":false,"banner":"Video call going on","in":"Asha, Ravi in the call","people":["Asha","Ravi"],"count":3,"join":"Join"}"#.utf8)) XCTAssertEqual(live.banner, "Video call going on") XCTAssertEqual(live.in, "Asha, Ravi in the call") XCTAssertEqual(live.join, "Join") let offline = try JSONDecoder().decode(ChatGroupCallState.self, from: Data(#"{"live":false,"room":"r1","unknown":true}"#.utf8)) XCTAssertEqual(offline.unknown, true) XCTAssertFalse(offline.live) } // RULE: the core's group screens read whole: a tile each in its grid, the privacy line, Leave, the notes mark. func testTheCoresGroupScreensRead() throws { // The fixture as the core wrote it, from the source tree (the simulator reads the Mac's files). let url = URL(fileURLWithPath: #filePath).deletingLastPathComponent() .appendingPathComponent("../../../Sources/CottonUI/Resources/Fixtures/chat-group-call.json").standardized let all = try JSONDecoder().decode([String: JSONValue].self, from: Data(contentsOf: url)) func screen(_ key: String) throws -> ChatCallScreen { try JSONDecoder().decode(ChatCallScreen.self, from: JSONEncoder().encode(try XCTUnwrap(all[key], key))) } let four = try screen("group") XCTAssertEqual(four.group, true) XCTAssertEqual(four.tiles?.count, 4) XCTAssertEqual(four.tiles?.last?.you, true) XCTAssertEqual(four.grid, ChatCallGrid(columns: 2, rows: 2)) XCTAssertEqual(four.privacy, "Protected in transit") XCTAssertNotNil(four.privacyDetail) XCTAssertEqual(four.controls.last?.label, "Leave") XCTAssertEqual(try screen("group8").grid, ChatCallGrid(columns: 2, rows: 4)) XCTAssertEqual(try screen("group-notes").notes?.line, "Asha Example is taking notes") XCTAssertNil(ChatCallScreen.hidden.group, "a one-to-one call reads no group") } }