| ... | ... | @@ -21,7 +21,7 @@ import { render } from "vitest-browser-react"; |
| 21 | 21 | import { useComposerDraftStore } from "../composerDraftStore"; |
| 22 | 22 | import { __resetLocalApiForTests } from "../localApi"; |
| 23 | 23 | import { AppAtomRegistryProvider } from "../rpc/atomRegistry"; |
| 24 | | import { getServerConfig } from "../rpc/serverState"; |
| 24 | import { getServerConfig, getServerConfigUpdatedNotification } from "../rpc/serverState"; |
| 25 | 25 | import { getWsConnectionStatus } from "../rpc/wsConnectionState"; |
| 26 | 26 | import { getRouter } from "../router"; |
| 27 | 27 | import { useStore } from "../store"; |
| ... | ... | @@ -303,11 +303,6 @@ async function waitForNoToasts(): Promise<void> { |
| 303 | 303 | ); |
| 304 | 304 | } |
| 305 | 305 | |
| 306 | | async function warmServerConfigUpdateStream(): Promise<void> { |
| 307 | | sendServerConfigUpdatedPush([]); |
| 308 | | await new Promise((resolve) => setTimeout(resolve, 50)); |
| 309 | | } |
| 310 | | |
| 311 | 306 | async function waitForInitialWsSubscriptions(): Promise<void> { |
| 312 | 307 | await vi.waitFor( |
| 313 | 308 | () => { |
| ... | ... | @@ -331,6 +326,33 @@ async function waitForServerConfigSnapshot(): Promise<void> { |
| 331 | 326 | ); |
| 332 | 327 | } |
| 333 | 328 | |
| 329 | async 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 | |
| 334 | 356 | async function mountApp(): Promise<{ cleanup: () => Promise<void> }> { |
| 335 | 357 | const host = document.createElement("div"); |
| 336 | 358 | host.style.position = "fixed"; |
| ... | ... | @@ -356,6 +378,7 @@ async function mountApp(): Promise<{ cleanup: () => Promise<void> }> { |
| 356 | 378 | await waitForInitialWsSubscriptions(); |
| 357 | 379 | await waitForWsConnection(); |
| 358 | 380 | await waitForServerConfigSnapshot(); |
| 381 | await waitForServerConfigStreamReady(); |
| 359 | 382 | await waitForNoToasts(); |
| 360 | 383 | |
| 361 | 384 | return { |
| ... | ... | @@ -429,8 +452,6 @@ describe("Keybindings update toast", () => { |
| 429 | 452 | const mounted = await mountApp(); |
| 430 | 453 | |
| 431 | 454 | try { |
| 432 | | await warmServerConfigUpdateStream(); |
| 433 | | |
| 434 | 455 | sendServerConfigUpdatedPush([]); |
| 435 | 456 | await waitForToast("Keybindings updated", 1); |
| 436 | 457 | |