Files
galaxy-game/ui/frontend/tests/selection-store.test.ts
T
Ilia Denisov 6364bba6fd ui/phase-13: planet inspector — read-only
Plumbs the map → inspector pathway: a click on a planet selects it
through the new SelectionStore, the sidebar Inspector tab swaps
its empty-state copy for a per-kind read-only field set, and a
mobile-only bottom-sheet mirrors the same content over the map.
Field projection in api/game-state.ts now surfaces every documented
planet field.
2026-05-09 08:29:03 +02:00

48 lines
1.3 KiB
TypeScript

// SelectionStore unit tests. The store is in-memory only and carries
// no async lifecycle, so the cases focus on the rune transitions and
// the post-`dispose` no-op contract.
import { describe, expect, test } from "vitest";
import { SelectionStore } from "../src/lib/selection.svelte";
describe("SelectionStore", () => {
test("initial state has no selection", () => {
const store = new SelectionStore();
expect(store.selected).toBeNull();
});
test("selectPlanet records the planet id", () => {
const store = new SelectionStore();
store.selectPlanet(42);
expect(store.selected).toEqual({ kind: "planet", id: 42 });
});
test("selectPlanet replaces the previous selection", () => {
const store = new SelectionStore();
store.selectPlanet(1);
store.selectPlanet(2);
expect(store.selected).toEqual({ kind: "planet", id: 2 });
});
test("clear resets the selection to null", () => {
const store = new SelectionStore();
store.selectPlanet(7);
store.clear();
expect(store.selected).toBeNull();
});
test("dispose blocks subsequent mutations", () => {
const store = new SelectionStore();
store.selectPlanet(3);
store.dispose();
expect(store.selected).toBeNull();
store.selectPlanet(4);
expect(store.selected).toBeNull();
store.clear();
expect(store.selected).toBeNull();
});
});