import assert from 'node:assert/strict'; import { test } from 'node:test'; import { MemoryStore, Progress, STORAGE_KEY } from '../src/progress'; const ids = ['1-1', '1-2', '1-3']; test('线性解锁与首个未通关', () => { const p = new Progress(new MemoryStore()); assert.equal(p.isUnlocked(ids, 0), true); assert.equal(p.isUnlocked(ids, 1), false); assert.equal(p.firstUncleared(ids), '1-1'); p.markCleared('1-1'); assert.equal(p.isUnlocked(ids, 1), true); assert.equal(p.isUnlocked(ids, 2), false); assert.equal(p.firstUncleared(ids), '1-2'); p.markCleared('1-2'); p.markCleared('1-3'); assert.equal(p.firstUncleared(ids), '1-3'); }); test('存档落在本玩法的桶里并可恢复', () => { const store = new MemoryStore(); const p = new Progress(store); p.markCleared('1-1'); p.setCurrent('1-2'); p.setPrefs({ sound: false }); assert.ok(store.get(STORAGE_KEY)); const q = new Progress(store); assert.equal(q.isCleared('1-1'), true); assert.equal(q.currentId, '1-2'); assert.equal(q.prefs.sound, false); assert.equal(q.prefs.haptics, true); q.resetAll(); assert.equal(new Progress(store).clearedCount(), 0); }); test('跨包链式解锁:2-1 要先过 1-10', () => { const chained = ['1-1', '1-2', '2-1', '2-2']; const p = new Progress(new MemoryStore()); assert.equal(p.isUnlocked(chained, 2), false); p.markCleared('1-1'); p.markCleared('1-2'); assert.equal(p.isUnlocked(chained, 2), true); assert.equal(p.isUnlocked(chained, 3), false); }); test('损坏的存档不炸', () => { const store = new MemoryStore(); store.set(STORAGE_KEY, '{not json'); assert.doesNotThrow(() => new Progress(store)); });