Files
worldwideview/src/core/state/dataSlice.test.ts
SilvertakanaandCopilot Autofix powered by AI fc7dd02ee2 refactor(core): harden typescript and fix linting violations (#146)
* 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

* fix: restore BottomPanelManager in AppShell and fix vitest config

* fix(layout): restore bottom panel positioning and transition styling

This commit corrects the missing bottom panel issue by resolving CSS aggregation errors and fixing transition logic. The version is bumped to 2.15.5.

* refactor(core): harden typescript and fix linting violations

This commit addresses the remaining any types and linting errors across the core engine.

* fix(eslint): resolve react-hook immutability and cascading render violations

---------

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
2026-05-17 17:36:33 +12:00

87 lines
3.3 KiB
TypeScript

/* eslint-disable @typescript-eslint/no-explicit-any */
import {
describe, it, expect, beforeEach, vi
} from 'vitest';
import { createStore, type StoreApi } from 'zustand/vanilla';
import type { GeoEntity } from '@/core/plugins/PluginTypes';
import { createDataSlice, DataSlice } from './dataSlice';
// We need a mock store that includes selectedEntity to test the cross-slice update behavior
interface MockAppStore extends DataSlice {
selectedEntity: GeoEntity | null;
}
describe('dataSlice', () => {
let store: StoreApi<MockAppStore>;
beforeEach(() => {
store = createStore<MockAppStore>((set, get, api) => {
const dataSlice = createDataSlice(set as any, get as any, api as any);
return {
...dataSlice,
selectedEntity: null,
};
});
});
it('initializes with empty entities', () => {
expect(store.getState().entitiesByPlugin).toEqual({});
});
it('sets entities for a plugin', () => {
const mockEntities = [{ id: 'e1', pluginId: 'plugin-a' } as GeoEntity];
store.getState().setEntities('plugin-a', mockEntities);
expect(store.getState().entitiesByPlugin['plugin-a']).toEqual(mockEntities);
});
it('updates selectedEntity if new data for the same entity arrives', () => {
// Initial selected entity
const oldEntity = { id: 'e1', pluginId: 'plugin-a', name: 'Old Name' } as any as GeoEntity;
store.setState({ selectedEntity: oldEntity });
// New data arrives with updated name
const freshEntity = { id: 'e1', pluginId: 'plugin-a', name: 'New Name' } as any as GeoEntity;
store.getState().setEntities('plugin-a', [freshEntity]);
expect(store.getState().selectedEntity).toEqual(freshEntity);
});
it('does not update selectedEntity if new data does not contain it', () => {
const oldEntity = { id: 'e1', pluginId: 'plugin-a', name: 'Old Name' } as any as GeoEntity;
store.setState({ selectedEntity: oldEntity });
// New data arrives but the entity is missing
store.getState().setEntities('plugin-a', [{ id: 'e2', pluginId: 'plugin-a' } as GeoEntity]);
expect(store.getState().selectedEntity).toEqual(oldEntity);
});
it('clears entities for a specific plugin', () => {
const mockEntitiesA = [{ id: 'e1', pluginId: 'plugin-a' } as GeoEntity];
const mockEntitiesB = [{ id: 'e2', pluginId: 'plugin-b' } as GeoEntity];
store.getState().setEntities('plugin-a', mockEntitiesA);
store.getState().setEntities('plugin-b', mockEntitiesB);
store.getState().clearEntities('plugin-a');
expect(store.getState().entitiesByPlugin['plugin-a']).toBeUndefined();
expect(store.getState().entitiesByPlugin['plugin-b']).toEqual(mockEntitiesB);
});
it('gets all entities across plugins flattened', () => {
const mockEntitiesA = [{ id: 'e1', pluginId: 'plugin-a' } as GeoEntity];
const mockEntitiesB = [{ id: 'e2', pluginId: 'plugin-b' } as GeoEntity];
store.getState().setEntities('plugin-a', mockEntitiesA);
store.getState().setEntities('plugin-b', mockEntitiesB);
const all = store.getState().getAllEntities();
expect(all).toHaveLength(2);
expect(all).toContainEqual(mockEntitiesA[0]);
expect(all).toContainEqual(mockEntitiesB[0]);
});
});