fix: disable deleting moves while a game is in progress (#874)
This commit is contained in:
1 parent
654f884a5c
commit
2e25128e73
4 files changed
+49
-2
No files matched your search
@@ -0,0 +1,40 @@
|
||||
import { createStore } from "jotai";
|
||||
import { expect, test } from "vitest";
|
||||
import {
|
||||
activeTabAtom,
|
||||
currentGameInProgressAtom,
|
||||
currentGameStateAtom,
|
||||
tabsAtom,
|
||||
} from "@/state/atoms";
|
||||
import type { Tab } from "@/utils/tabs";
|
||||
|
||||
function storeWithTab(type: Tab["type"]) {
|
||||
const store = createStore();
|
||||
store.set(tabsAtom, [{ name: "Tab", value: "tab", type, gameOrigin: { kind: "none" } }]);
|
||||
store.set(activeTabAtom, "tab");
|
||||
return store;
|
||||
}
|
||||
|
||||
test("a play tab is in progress only while the game is playing", () => {
|
||||
const store = storeWithTab("play");
|
||||
expect(store.get(currentGameInProgressAtom)).toBe(false);
|
||||
|
||||
store.set(currentGameStateAtom, "playing");
|
||||
expect(store.get(currentGameInProgressAtom)).toBe(true);
|
||||
|
||||
store.set(currentGameStateAtom, "gameOver");
|
||||
expect(store.get(currentGameInProgressAtom)).toBe(false);
|
||||
});
|
||||
|
||||
test("an analysis tab is never in progress", () => {
|
||||
const store = storeWithTab("analysis");
|
||||
store.set(currentGameStateAtom, "playing");
|
||||
expect(store.get(currentGameInProgressAtom)).toBe(false);
|
||||
});
|
||||
|
||||
test("no tab selected is not in progress", () => {
|
||||
const store = createStore();
|
||||
store.set(tabsAtom, []);
|
||||
store.set(activeTabAtom, null);
|
||||
expect(store.get(currentGameInProgressAtom)).toBe(false);
|
||||
});
|
||||
Reference in new issue
Block a user