1import { assertEquals } from "@std/assert";23import {4 getInitialStackIndex,5 resolveDayStackState,6} from "@/lib/shikaku/day_stack_state.ts";78Deno.test("resolveDayStackState allows play on today's unlocked stack", () => {9 assertEquals(10 resolveDayStackState({11 date: "2026-04-16",12 today: "2026-04-16",13 stackIndex: 2,14 playableStackIndex: 2,15 mostRecentStackIndex: 2,16 isReplay: false,17 }),18 { mode: "playable", message: "Drag. One clue.", canReset: true },19 );20});2122Deno.test("resolveDayStackState keeps earlier stacks read-only on today", () => {23 assertEquals(24 resolveDayStackState({25 date: "2026-04-16",26 today: "2026-04-16",27 stackIndex: 1,28 playableStackIndex: 3,29 mostRecentStackIndex: 3,30 isReplay: false,31 }),32 { mode: "readonly", message: "Earlier stack. View only.", canReset: false },33 );34});3536Deno.test("resolveDayStackState locks future days", () => {37 assertEquals(38 resolveDayStackState({39 date: "2026-04-17",40 today: "2026-04-16",41 stackIndex: 0,42 playableStackIndex: 0,43 mostRecentStackIndex: 0,44 isReplay: false,45 }),46 { mode: "locked", message: "Locked until this day.", canReset: false },47 );48});4950Deno.test("resolveDayStackState keeps past days readonly until replay is requested", () => {51 assertEquals(52 resolveDayStackState({53 date: "2026-04-15",54 today: "2026-04-16",55 stackIndex: 2,56 playableStackIndex: 0,57 mostRecentStackIndex: 2,58 isReplay: false,59 }),60 { mode: "readonly", message: "Past day. View only.", canReset: true },61 );62});6364Deno.test("resolveDayStackState allows replay after reset on a past day", () => {65 assertEquals(66 resolveDayStackState({67 date: "2026-04-15",68 today: "2026-04-16",69 stackIndex: 2,70 playableStackIndex: 0,71 mostRecentStackIndex: 2,72 isReplay: true,73 }),74 { mode: "playable", message: "Replay mode.", canReset: true },75 );76});7778Deno.test("getInitialStackIndex loads the unlocked top stack for today", () => {79 assertEquals(80 getInitialStackIndex({81 date: "2026-04-17",82 today: "2026-04-17",83 selectedStackIndex: 0,84 playableStackIndex: 2,85 }),86 2,87 );88});8990Deno.test("getInitialStackIndex keeps the saved top stack for past days", () => {91 assertEquals(92 getInitialStackIndex({93 date: "2026-04-16",94 today: "2026-04-17",95 selectedStackIndex: 2,96 playableStackIndex: 0,97 }),98 2,99 );100});