* chore(merge): resolve conflicts, fix mockWs error, and apply refactor standards * Potential fix for pull request finding 'CodeQL / Incomplete URL substring sanitization' Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> * Potential fix for pull request finding 'CodeQL / Incomplete URL substring sanitization' Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> * Potential fix for pull request finding 'CodeQL / Incomplete URL substring sanitization' Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> * fix(ci): Stabilize github actions and resolve test failures - fix(tests): update WsClient mock to use standard function for Vitest constructor compatibility - fix(db): correct PrismaClient import path to use generated output directory - fix(e2e): add predev database boot step to playwright CI workflow - chore: sync pnpm-lock.yaml after merge conflict resolution * refactor(plugins): decouple GeoJSON plugin and implement data bus lifecycle - feat(sdk): [Minor] Added dynamicPluginCreate, dynamicPluginRemove, and pluginUnregistered to DataBusEvents. - feat(core): [Minor] Implemented unregisterPlugin in PluginManager.ts for automated IndexedDB caching cleanup and polling teardown. - feat(core): [Minor] Added removeLayer to layersSlice.ts to support safe removal of plugin states. - refactor(plugins): [Patch] Refactored useGeoJsonImport.ts and ImportedLayerList.tsx to decouple from direct manager imports, utilizing DataBus for lifecycle events. - refactor(core): [Patch] Added pluginUnregistered listener to DataBusSubscriber.tsx to handle state and cache cleanup synchronously via event. * fix(types): resolve PluginManager type errors * refactor(core): decouple PluginManager and fix rendering invariants - refactor(core): Replace Zustand mutations in PluginManager with DataBus events (Patch) - refactor(sdk): Add layerLoadingChanged, pluginError, pluginUnregistered to DataBusEvents (Patch) - refactor(ui): Subscribe to new DataBus events in DataBusSubscriber (Patch) - fix(plugins): Remove size from BaseAviationPlugin to fix model rendering clipping (Patch) - fix(plugins): Migrate BaseIncidentPlugin from size to iconScale to fix billboard clipping (Patch) * chore: resolve lockfile conflict --------- Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
57 lines
1.9 KiB
TypeScript
57 lines
1.9 KiB
TypeScript
import {
|
|
describe, it, expect, vi, afterEach
|
|
} from "vitest";
|
|
import { dataBus } from "./DataBus";
|
|
|
|
/**
|
|
* DataBus is a typed singleton event bus used by every plugin and most
|
|
* of the UI for cross-component communication. A regression here would
|
|
* be silent and immediate — events stop arriving, layers go blank, the
|
|
* agent bus stops responding — so it's worth pinning down the basics.
|
|
*
|
|
* Each test removes the listeners it adds in `afterEach` so the
|
|
* singleton state doesn't leak between tests.
|
|
*/
|
|
|
|
afterEach(() => {
|
|
dataBus.removeAllListeners();
|
|
});
|
|
|
|
describe("DataBus", () => {
|
|
it("dispatches emit() payloads to subscribers of the matching event", () => {
|
|
const handler = vi.fn();
|
|
dataBus.on("dataUpdated", handler);
|
|
|
|
dataBus.emit("dataUpdated", { pluginId: "test", entities: [] });
|
|
|
|
expect(handler).toHaveBeenCalledTimes(1);
|
|
expect(handler).toHaveBeenCalledWith({ pluginId: "test", entities: [] });
|
|
});
|
|
|
|
it("returns an unsubscribe function from on() that detaches the handler", () => {
|
|
const handler = vi.fn();
|
|
const unsubscribe = dataBus.on("dataUpdated", handler);
|
|
|
|
unsubscribe();
|
|
dataBus.emit("dataUpdated", { pluginId: "test", entities: [] });
|
|
|
|
expect(handler).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("isolates handler failures so one throw doesn't block other subscribers", () => {
|
|
const errorSpy = vi.spyOn(console, "error").mockImplementation(() => {});
|
|
const throwing = vi.fn(() => {
|
|
throw new Error("intentional");
|
|
});
|
|
const surviving = vi.fn();
|
|
dataBus.on("layerToggled", throwing);
|
|
dataBus.on("layerToggled", surviving);
|
|
|
|
dataBus.emit("layerToggled", { pluginId: "test", enabled: true });
|
|
|
|
expect(throwing).toHaveBeenCalledTimes(1);
|
|
expect(surviving).toHaveBeenCalledTimes(1);
|
|
errorSpy.mockRestore();
|
|
});
|
|
});
|