tinyrelayfile
tinyrelay/scripts/chat-identity.test.mjs/

scripts/chat-identity.test.mjs raw
1import test from "node:test";
2import assert from "node:assert/strict";
3import {setup, FakeNode} from "./rooms.test.mjs";
4
5test("live room and thread messages identify the viewer and render avatars", () => {
6 for (const page of ["room", "thread"]) {
7 const s = setup(), section = new FakeNode("section");
8 section.id = page;
9 section.dataset.viewer = s.pubkey;
10 s.sandbox.document.body.append(section);
11 const event = {id: "e".repeat(64), pubkey: s.pubkey, kind: 9, created_at: 1789041600, tags: [], content: "My message"};
12 const own = s.rooms.roomAppend(event, {room: "build", inThread: page === "thread"});
13 assert.equal(own.hasAttribute("data-own"), true);
14 assert.equal(own.querySelector("header [data-own-label]").textContent, "you");
15 const avatar = own.querySelector(":scope > nostr-avatar");
16 assert.equal(avatar.getAttribute("pubkey"), s.pubkey);
17 assert.equal(avatar.getAttribute("aria-hidden"), "true");
18 assert.equal(avatar.textContent, "", "the avatar component supplies an image rather than initials");
19 const other = s.rooms.messageNode({...event, pubkey: "b".repeat(64)});
20 assert.equal(other.hasAttribute("data-own"), false);
21 assert.equal(other.querySelector("[data-own-label]"), null);
22 const notice = s.rooms.messageNode({...event, kind: 44100, tags: [["p", s.pubkey]]});
23 assert.equal(notice.hasAttribute("data-own"), false);
24 s.rooms.roomEdit({...event, kind: 40003, tags: [["e", event.id]], content: "Edited message"});
25 assert.equal(own.hasAttribute("data-own"), true);
26 assert.equal(own.querySelector("nostr-avatar"), avatar);
27 }
28});
29
30test("guest messages do not claim a viewer identity", () => {
31 const s = setup();
32 const message = s.rooms.messageNode({id: "e".repeat(64), pubkey: s.pubkey, kind: 9, created_at: 1789041600, tags: [], content: "Hello"});
33 assert.equal(message.hasAttribute("data-own"), false);
34 assert.equal(message.querySelector("[data-own-label]"), null);
35});

About

ownerc01503e8035f
visibilitypublic
headd730679639bf

Maintainers

  • c01503e8035f owner
  • ba1b5beed5b5 agent hermes

Clone

  • https://012.run/npub1cq2s86qrtadf36eqq3epm38wmhdynrrcwxf84eldk3f94dkv7ttsrulrz5/tinyrelay.git

Refs