authorgravatar for julius0216@outlook.comJulius Marminge <julius0216@outlook.com> 2026-04-09 14:26:28-07:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2026-04-09 14:26:28-07:00
log70f5dfcef78a8e153ab698c0b83661974a4fc033
treea0b7a282eab3757e3ada68d80b18e92241c9cbe1
parent9847e9b6211df61bd6d3d1142538ec4df77e0013
signature Signed by PGP key B5690EEEBB952194

Stabilize keybindings toast stream setup (#1860)

Co-authored-by: Julius Marminge <julius@macmini.local>

1 files changed, 29 insertions(+), 8 deletions(-)

apps/web/src/components/KeybindingsToast.browser.tsx+29-8
......@@ -21,7 +21,7 @@ import { render } from "vitest-browser-react";
2121import { useComposerDraftStore } from "../composerDraftStore";
2222import { __resetLocalApiForTests } from "../localApi";
2323import { AppAtomRegistryProvider } from "../rpc/atomRegistry";
24import { getServerConfig } from "../rpc/serverState";
24import { getServerConfig, getServerConfigUpdatedNotification } from "../rpc/serverState";
2525import { getWsConnectionStatus } from "../rpc/wsConnectionState";
2626import { getRouter } from "../router";
2727import { useStore } from "../store";
......@@ -303,11 +303,6 @@ async function waitForNoToasts(): Promise<void> {
303303 );
304304}
305305
306async function warmServerConfigUpdateStream(): Promise<void> {
307 sendServerConfigUpdatedPush([]);
308 await new Promise((resolve) => setTimeout(resolve, 50));
309}
310
311306async function waitForInitialWsSubscriptions(): Promise<void> {
312307 await vi.waitFor(
313308 () => {
......@@ -331,6 +326,33 @@ async function waitForServerConfigSnapshot(): Promise<void> {
331326 );
332327}
333328
329async function waitForServerConfigStreamReady(): Promise<void> {
330 const previousNotificationId = getServerConfigUpdatedNotification()?.id ?? 0;
331 for (let attempt = 0; attempt < 20; attempt += 1) {
332 rpcHarness.emitStreamValue(WS_METHODS.subscribeServerConfig, {
333 version: 1,
334 type: "settingsUpdated",
335 payload: { settings: fixture.serverConfig.settings },
336 });
337
338 try {
339 await vi.waitFor(
340 () => {
341 const notification = getServerConfigUpdatedNotification();
342 expect(notification?.id).toBeGreaterThan(previousNotificationId);
343 expect(notification?.source).toBe("settingsUpdated");
344 },
345 { timeout: 200, interval: 16 },
346 );
347 return;
348 } catch {
349 await new Promise((resolve) => setTimeout(resolve, 25));
350 }
351 }
352
353 throw new Error("Timed out waiting for the server config stream to deliver updates.");
354}
355
334356async function mountApp(): Promise<{ cleanup: () => Promise<void> }> {
335357 const host = document.createElement("div");
336358 host.style.position = "fixed";
......@@ -356,6 +378,7 @@ async function mountApp(): Promise<{ cleanup: () => Promise<void> }> {
356378 await waitForInitialWsSubscriptions();
357379 await waitForWsConnection();
358380 await waitForServerConfigSnapshot();
381 await waitForServerConfigStreamReady();
359382 await waitForNoToasts();
360383
361384 return {
......@@ -429,8 +452,6 @@ describe("Keybindings update toast", () => {
429452 const mounted = await mountApp();
430453
431454 try {
432 await warmServerConfigUpdateStream();
433
434455 sendServerConfigUpdatedPush([]);
435456 await waitForToast("Keybindings updated", 1);
436457