Skip to content

Commit 2f80f87

Browse files
committed
test: avoid allocation-heavy case setup (#116837)
1 parent 2532460 commit 2f80f87

1 file changed

Lines changed: 44 additions & 49 deletions

File tree

‎ui/src/pages/chat/chat-pane-sharing.test.ts‎

Lines changed: 44 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -215,57 +215,52 @@ describe("chat pane sharing mutation phase ownership", () => {
215215
},
216216
);
217217

218-
it.each(
219-
mutations.flatMap((mutation) =>
220-
(["resolve", "reject"] as const).map((completion) => ({
221-
...mutation,
222-
completion,
223-
})),
224-
),
225-
)(
226-
"drops a stale $name sharing reload when it later $completion",
227-
async ({ completion, invoke, method, name }) => {
228-
const listed = createDeferred<SessionMembersListResult>();
229-
const request = vi.fn((requestMethod: string) => {
230-
if (requestMethod === method) {
231-
return Promise.resolve({});
232-
}
233-
if (requestMethod === "session.members.list") {
234-
return listed.promise;
235-
}
236-
throw new Error(`unexpected old-connection request: ${requestMethod}`);
237-
});
238-
const oldSessions = {
239-
refreshReplacement: vi.fn(async () => undefined),
240-
} as unknown as SessionCapability;
241-
const { pane: testPane, state } = createTestChatPane({
242-
client: { request } as unknown as GatewayBrowserClient,
243-
sessions: oldSessions,
244-
});
245-
const pane = testPane as SharingPane;
246-
const row = sessionRow();
247-
const pending = invoke(pane, row);
248-
await vi.waitFor(() => {
249-
expect(request).toHaveBeenCalledWith(
250-
"session.members.list",
251-
expect.objectContaining({ sessionKey: row.key }),
252-
);
253-
});
218+
describe.each(mutations)("$name sharing reload", ({ invoke, method, name }) => {
219+
it.each(["resolve", "reject"] as const)(
220+
"drops a stale sharing reload when it later %s",
221+
async (completion) => {
222+
const listed = createDeferred<SessionMembersListResult>();
223+
const request = vi.fn((requestMethod: string) => {
224+
if (requestMethod === method) {
225+
return Promise.resolve({});
226+
}
227+
if (requestMethod === "session.members.list") {
228+
return listed.promise;
229+
}
230+
throw new Error(`unexpected old-connection request: ${requestMethod}`);
231+
});
232+
const oldSessions = {
233+
refreshReplacement: vi.fn(async () => undefined),
234+
} as unknown as SessionCapability;
235+
const { pane: testPane, state } = createTestChatPane({
236+
client: { request } as unknown as GatewayBrowserClient,
237+
sessions: oldSessions,
238+
});
239+
const pane = testPane as SharingPane;
240+
const row = sessionRow();
241+
const pending = invoke(pane, row);
242+
await vi.waitFor(() => {
243+
expect(request).toHaveBeenCalledWith(
244+
"session.members.list",
245+
expect.objectContaining({ sessionKey: row.key }),
246+
);
247+
});
254248

255-
const replacement = installReplacementConnection(pane, state, row);
256-
if (completion === "resolve") {
257-
listed.resolve(sharingResult(row));
258-
} else {
259-
listed.reject(new Error(`old ${name} sharing reload failed`));
260-
}
261-
await pending;
249+
const replacement = installReplacementConnection(pane, state, row);
250+
if (completion === "resolve") {
251+
listed.resolve(sharingResult(row));
252+
} else {
253+
listed.reject(new Error(`old ${name} sharing reload failed`));
254+
}
255+
await pending;
262256

263-
expect(oldSessions.refreshReplacement).toHaveBeenCalledTimes(name === "visibility" ? 1 : 0);
264-
expect(replacement.request).not.toHaveBeenCalled();
265-
expect(replacement.sessions.refreshReplacement).not.toHaveBeenCalled();
266-
expect(pane.sessionSharingStates.get(replacement.cacheKey)).toBe(replacement.sharingState);
267-
},
268-
);
257+
expect(oldSessions.refreshReplacement).toHaveBeenCalledTimes(name === "visibility" ? 1 : 0);
258+
expect(replacement.request).not.toHaveBeenCalled();
259+
expect(replacement.sessions.refreshReplacement).not.toHaveBeenCalled();
260+
expect(pane.sessionSharingStates.get(replacement.cacheKey)).toBe(replacement.sharingState);
261+
},
262+
);
263+
});
269264

270265
it("drops a stale member session refresh failure", async () => {
271266
const refreshed = createDeferred<void>();

0 commit comments

Comments
 (0)