Skip to content

Commit f545f1c

Browse files
author
am
committed
test: exercise thread profile noise through bound name service
Co-authored-by: Kalvin Chau <[email protected]> Signed-off-by: Kalvin Chau <[email protected]> Signed-off-by: am <6e30cd56c30e030cd31bb0939b94a7c257c9a09d5ba2d92cf2735da45629f248@buzz.block.builderlab.xyz>
1 parent ea234c1 commit f545f1c

1 file changed

Lines changed: 26 additions & 48 deletions

File tree

‎src/features/messages/ThreadPanel.identity.test.tsx‎

Lines changed: 26 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,16 @@ import {
1010
} from "@testing-library/react";
1111
import { StrictMode } from "react";
1212
import { afterAll, afterEach, expect, it, vi } from "vitest";
13-
import type { ChannelMessage, Profile } from "../relay/contracts";
14-
import type { ProfileQueries } from "../relay/profile-directory";
13+
import type { ChannelMessage } from "../relay/contracts";
1514
import { createRelaySession } from "../relay/session";
1615
import type { LiveCallbacks } from "../relay/live";
17-
import { keypair, message, scriptedTransport, signed } from "../relay/testing";
16+
import {
17+
keypair,
18+
message,
19+
profile,
20+
scriptedTransport,
21+
signed,
22+
} from "../relay/testing";
1823
import { ThreadPanel } from "./ThreadPanel";
1924

2025
const bodyRender = vi.fn();
@@ -46,26 +51,6 @@ afterEach(() => {
4651
vi.clearAllMocks();
4752
});
4853

49-
function mutableProfiles(initial: ReadonlyMap<string, Profile>) {
50-
let snapshot = initial;
51-
const listeners = new Set<() => void>();
52-
const queries: ProfileQueries = {
53-
snapshot: () => snapshot,
54-
subscribe(listener) {
55-
listeners.add(listener);
56-
return () => listeners.delete(listener);
57-
},
58-
async ensure() {},
59-
};
60-
return {
61-
queries,
62-
publish(next: ReadonlyMap<string, Profile>) {
63-
snapshot = next;
64-
for (const listener of listeners) listener();
65-
},
66-
};
67-
}
68-
6954
it("retains mounted rows through a deferred real-session page and profile noise", async () => {
7055
const relay = keypair();
7156
const viewer = keypair();
@@ -87,17 +72,13 @@ it("retains mounted rows through a deferred real-session page and profile noise"
8772
["e", root.id, "", "root"],
8873
["e", root.id, "", "reply"],
8974
]);
90-
traffic.receive([root, reply]);
91-
92-
const alice: Profile = Object.freeze({ name: "Alice" });
93-
const bob: Profile = Object.freeze({ name: "Bob" });
94-
const profiles = mutableProfiles(
95-
new Map([
96-
[aliceKey.pubkey, alice],
97-
[bobKey.pubkey, bob],
98-
]),
99-
);
100-
const session = { ...owner.session, profiles: profiles.queries };
75+
traffic.receive([
76+
root,
77+
reply,
78+
profile(aliceKey, { name: "Alice" }),
79+
profile(bobKey, { name: "Bob" }),
80+
]);
81+
const session = owner.session;
10182

10283
render(
10384
<StrictMode>
@@ -135,16 +116,18 @@ it("retains mounted rows through a deferred real-session page and profile noise"
135116
if (!page) throw new Error("Deferred thread page was not requested");
136117
bodyRender.mockClear();
137118

119+
// An unrelated signed profile preserves the selected map, but the shared
120+
// name service still invalidates every mounted row. Do not claim zero renders.
138121
await act(async () => {
139-
profiles.publish(
140-
new Map([
141-
[aliceKey.pubkey, alice],
142-
[bobKey.pubkey, bob],
143-
[keypair().pubkey, { name: "Other" }],
144-
]),
145-
);
122+
traffic.receive([profile(keypair(), { name: "Other" })]);
146123
});
147-
expect(bodyRender).not.toHaveBeenCalled();
124+
expect(bodyRender.mock.calls).toEqual([
125+
["Root body"],
126+
["Root body"],
127+
["Reply body"],
128+
["Reply body"],
129+
]);
130+
bodyRender.mockClear();
148131

149132
const appended = message(bobKey, "a", "Appended reply body", 3, [
150133
["e", root.id, "", "root"],
@@ -174,12 +157,7 @@ it("retains mounted rows through a deferred real-session page and profile noise"
174157
bodyRender.mockClear();
175158

176159
await act(async () => {
177-
profiles.publish(
178-
new Map([
179-
[aliceKey.pubkey, alice],
180-
[bobKey.pubkey, { name: "Robert" }],
181-
]),
182-
);
160+
traffic.receive([profile(bobKey, { name: "Robert" }, 1_700_000_001)]);
183161
});
184162
expect(await screen.findAllByText("Robert")).toHaveLength(2);
185163
expect(bodyRender).toHaveBeenCalled();

0 commit comments

Comments
 (0)