// 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();
	});
});
