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); p.markCleared('1-1'); assert.equal(p.isUnlocked(ids, 1), true); 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.equal(STORAGE_KEY, 'mode:03-hex-walls'); assert.ok(store.get(STORAGE_KEY)); const p2 = new Progress(store); assert.equal(p2.isCleared('1-1'), true); assert.equal(p2.currentId, '1-2'); assert.equal(p2.prefs.sound, false); assert.equal(p2.prefs.haptics, true); p2.resetAll(); assert.equal(new Progress(store).clearedCount(), 0); }); test('坏存档不炸', () => { const store = new MemoryStore(); store.set(STORAGE_KEY, '{not json'); const p = new Progress(store); assert.equal(p.clearedCount(), 0); });