eleven / messenger Public

Clone
git clone https://amadan.net/eleven/messenger

Plain git — no account needed to clone.

Download

Download this file

1import XCTest
2@testable import LChatCore
3
4// Pure-rule twins of web/static/ui.js displayNameFor / renameNotice (#577) —
5// the same cases test/ui.test.mjs pins on the web side, so the two
6// implementations can't drift apart.
7final class NicknamesTests: XCTestCase {
8 func testDisplayNameMyNameWins() {
9 XCTAssertEqual(Nicknames.displayName(.init(name: "Dermo", seen: "Dermo"), label: "Dermot"), "Dermo")
10 XCTAssertEqual(Nicknames.displayName(nil, label: "Dermot"), "Dermot")
11 XCTAssertEqual(Nicknames.displayName(nil, label: nil), "")
12 // Empty nickname = no nickname.
13 XCTAssertEqual(Nicknames.displayName(.init(name: "", seen: ""), label: "Dermot"), "Dermot")
14 }
15
16 func testRenameNoticeFiresOncePerUnacknowledgedRename() {
17 // The #577 scenario: invited as Dermo, renames to Dermot → the choice.
18 let fresh = Nicknames.renameNotice(.init(name: "Dermo", seen: "Dermo"), label: "Dermot")
19 XCTAssertEqual(fresh?.from, "Dermo")
20 XCTAssertEqual(fresh?.to, "Dermot")
21 // Acknowledged (kept my name): seen catches up, no more prompting.
22 XCTAssertNil(Nicknames.renameNotice(.init(name: "Dermo", seen: "Dermot"), label: "Dermot"))
23 // …until they rename AGAIN.
24 let again = Nicknames.renameNotice(.init(name: "Dermo", seen: "Dermot"), label: "Diarmuid")
25 XCTAssertEqual(again?.to, "Diarmuid")
26 // They renamed to exactly what I call them — nothing to ask.
27 XCTAssertNil(Nicknames.renameNotice(.init(name: "Dermo", seen: "x"), label: "Dermo"))
28 // No nickname / no published name yet → never a notice.
29 XCTAssertNil(Nicknames.renameNotice(nil, label: "Dermot"))
30 XCTAssertNil(Nicknames.renameNotice(.init(name: "Dermo", seen: "Dermo"), label: ""))
31 }
32}
33