oficina / meet Public

Clone
git clone https://amadan.net/oficina/meet

Plain git — no account needed to clone.

Download

Download this file

1import XCTest
2
3@testable import CallsKit
4
5/// Spec §15.19 on the native side: the core puts each peer's reported
6/// media on the roster snapshot, and the tiles read it through Call. What
7/// is held here is the part that can be wrong without a call running —
8/// the wire shape, and unknown never reading as muted or off.
9final class PeerMediaTests: XCTestCase {
10 private func state(_ json: String) throws -> RoomState {
11 try JSONDecoder().decode(RoomState.self, from: Data(json.utf8))
12 }
13
14 func testARosterCarriesReportedMediaAndLeavesTheRestUnknown() throws {
15 let s = try state(
16 #"""
17 {"phase":"admitted","peer":"me","boot":"b","waiting":[],"peers":[
18 {"peer":"me","name":"Me","kind":"member","media":{"muted":false,"cameraOff":false}},
19 {"peer":"bea","name":"Bea","kind":"member","gen":1,"media":{"muted":true,"cameraOff":true}},
20 {"peer":"old","name":"Old","kind":"guest","gen":1}
21 ]}
22 """#)
23 XCTAssertEqual(Call.peerMedia("bea", in: s), PeerMedia(muted: true, cameraOff: true))
24 // A client from before §15.19 never reports: the snapshot says
25 // nothing, and nothing is guessed.
26 XCTAssertNil(Call.peerMedia("old", in: s))
27 XCTAssertNil(Call.peerMedia("nobody", in: s))
28 XCTAssertNil(Call.peerMedia("bea", in: nil))
29 }
30
31 func testAMalformedReportDoesNotCostTheWholeState() throws {
32 // The core only ever forwards two booleans, but a snapshot the app
33 // cannot decode is a call that stops updating, so the shape is pinned.
34 XCTAssertThrowsError(
35 try state(
36 #"{"phase":"admitted","peer":"me","boot":"b","waiting":[],"peers":[{"peer":"x","name":"X","kind":"member","media":{"muted":"yes","cameraOff":false}}]}"#
37 ))
38 }
39
40 @MainActor func testUnknownIsNeitherMutedNorOff() {
41 let call = Call(playAudio: false)
42 XCTAssertFalse(call.isMuted("anyone"))
43 XCTAssertFalse(call.isCameraOff("anyone"))
44 XCTAssertNil(call.peerMedia("anyone"))
45 }
46
47 func testTheTileSaysMutedInWordsForVoiceOver() {
48 XCTAssertEqual(tileAccessibilityLabel("Bea", muted: true), "Bea, muted")
49 XCTAssertEqual(tileAccessibilityLabel("Bea", muted: false), "Bea")
50 }
51}
52