Files
worldwideview/src/core/data/CacheLayer.test.ts
T
SilvertakanaandCopilot Autofix powered by AI 16c82c9184 refactor(lint): address React 19 hook purity and immutability violations (#136)
* 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>
2026-05-16 13:03:05 +12:00

60 lines
1.7 KiB
TypeScript

import {
describe, it, expect, beforeEach, afterEach, vi
} from "vitest";
import type { GeoEntity } from "@/core/plugins/PluginTypes";
import { cacheLayer } from "./CacheLayer";
/**
* In-memory cache contract. The persistent (IndexedDB) layer needs a
* real browser and isn't exercised here — these tests cover only the
* Map-backed first tier that every plugin enable/disable cycle hits.
*
* We `clear()` between tests because cacheLayer is a process-wide
* singleton; without it, residual entries from one test would mask
* failures in another.
*/
function entity(id: string): GeoEntity {
return {
id,
pluginId: "test",
latitude: 0,
longitude: 0,
timestamp: new Date(),
properties: {},
};
}
beforeEach(() => {
cacheLayer.clear();
vi.useRealTimers();
});
afterEach(() => {
vi.useRealTimers();
});
describe("CacheLayer (memory tier)", () => {
it("round-trips entities by pluginId within the TTL window", () => {
const entities = [entity("a"), entity("b")];
cacheLayer.set("aviation", entities, 60_000);
expect(cacheLayer.get("aviation")).toEqual(entities);
});
it("returns null and evicts the entry once the TTL expires", () => {
vi.useFakeTimers();
vi.setSystemTime(new Date("2026-01-01T00:00:00Z"));
cacheLayer.set("aviation", [entity("a")], 5_000);
expect(cacheLayer.get("aviation")).not.toBeNull();
vi.advanceTimersByTime(5_001);
expect(cacheLayer.get("aviation")).toBeNull();
// Second get confirms the eviction happened — the entry is gone
// from the underlying Map, not just rejected on lookup.
expect(cacheLayer.get("aviation")).toBeNull();
});
});