fix(updates): sync driver store state after update center runs

This commit is contained in:
zipg authored and GitHub committed 2026-09-30 19:46:49 +08:00
1 parent 7745834955
commit 5017aa7bb9
5 files changed
+174 -3

No files matched your search

@@ -1,7 +1,7 @@
// @vitest-environment happy-dom
import { describe, expect, it, vi } from "vitest";
import { COMPONENT_PLUGINS_UPDATED_EVENT, COMPONENT_UPDATES_CHANGED_EVENT, notifyComponentPluginsUpdated, notifyComponentUpdatesChanged } from "@/lib/updates/componentUpdateEvents";
import { COMPONENT_DRIVER_UPDATES_CHANGED_EVENT, COMPONENT_PLUGINS_UPDATED_EVENT, COMPONENT_UPDATES_CHANGED_EVENT, notifyComponentDriverUpdatesChanged, notifyComponentPluginsUpdated, notifyComponentUpdatesChanged } from "@/lib/updates/componentUpdateEvents";
describe("component update events", () => {
it("notifies plugin surfaces after component-level plugin updates", () => {
@@ -24,10 +24,21 @@ describe("component update events", () => {
window.removeEventListener(COMPONENT_UPDATES_CHANGED_EVENT, listener);
});
it("notifies the driver store when component updates change driver state", () => {
const listener = vi.fn();
window.addEventListener(COMPONENT_DRIVER_UPDATES_CHANGED_EVENT, listener);
notifyComponentDriverUpdatesChanged();
expect(listener).toHaveBeenCalledOnce();
window.removeEventListener(COMPONENT_DRIVER_UPDATES_CHANGED_EVENT, listener);
});
it("is inert when the store runs outside a browser environment", () => {
vi.stubGlobal("window", undefined);
try {
expect(() => notifyComponentPluginsUpdated()).not.toThrow();
expect(() => notifyComponentDriverUpdatesChanged()).not.toThrow();
expect(() => notifyComponentUpdatesChanged()).not.toThrow();
} finally {
vi.unstubAllGlobals();
@@ -1,4 +1,5 @@
export const COMPONENT_PLUGINS_UPDATED_EVENT = "dbx:component-plugins-updated";
export const COMPONENT_DRIVER_UPDATES_CHANGED_EVENT = "dbx:component-driver-updates-changed";
export const COMPONENT_UPDATES_CHANGED_EVENT = "dbx:component-updates-changed";
export function notifyComponentPluginsUpdated(): void {
@@ -6,6 +7,11 @@ export function notifyComponentPluginsUpdated(): void {
window.dispatchEvent(new Event(COMPONENT_PLUGINS_UPDATED_EVENT));
}
export function notifyComponentDriverUpdatesChanged(): void {
if (typeof window === "undefined") return;
window.dispatchEvent(new Event(COMPONENT_DRIVER_UPDATES_CHANGED_EVENT));
}
export function notifyComponentUpdatesChanged(): void {
if (typeof window === "undefined") return;
window.dispatchEvent(new Event(COMPONENT_UPDATES_CHANGED_EVENT));