Skip to content

Where people and agents ship software together. The open-source git platform for the whole job: issues, agents, checks and deploys to the edge.

30 linesCodeBlameRaw
1import assert from "node:assert/strict";
2import { test } from "node:test";
3
4import { readNow, showConversation, shownConversations } from "./read-when-shown.ts";
5
6const moment = { visible: true, onScreen: true, newestId: "msg_2", lastRead: null };
7
8test("messages are read only while the page is visible and they are on screen", () => {
9 assert.equal(readNow(moment), "msg_2");
10 assert.equal(readNow({ ...moment, visible: false }), null, "a hidden tab reads nothing");
11 assert.equal(readNow({ ...moment, onScreen: false }), null, "the panel closed, the card scrolled away");
12 assert.equal(readNow({ ...moment, newestId: null }), null, "nothing there yet");
13});
14
15test("each newest id is read once, and only forward", () => {
16 assert.equal(readNow({ ...moment, lastRead: "msg_2" }), null);
17 assert.equal(readNow({ ...moment, lastRead: "msg_3" }), null);
18 assert.equal(readNow({ ...moment, newestId: "msg_3", lastRead: "msg_2" }), "msg_3");
19});
20
21test("a conversation is shown while any surface shows it", () => {
22 const panel = showConversation("chn_dm");
23 const card = showConversation("chn_dm");
24 assert.ok(shownConversations().has("chn_dm"));
25 panel();
26 panel();
27 assert.ok(shownConversations().has("chn_dm"), "the card still shows it; letting go twice counts once");
28 card();
29 assert.ok(!shownConversations().has("chn_dm"));
30});