Files
booksorter/src/web/session.test.ts
T

30 lines
939 B
TypeScript

import { test } from 'node:test';
import assert from 'node:assert/strict';
import { emptySession, forget, touch } from './session.ts';
test('a book listed twice stays one row and moves to the top', () => {
let s = touch(emptySession, 1, false);
s = touch(s, 2, false);
s = touch(s, 1, true);
assert.deepEqual(s.order, [1, 2]);
assert.equal(s.touched[1], 2);
assert.equal(s.touched[2], 1);
});
test('"earlier" is decided when the book is first listed, not by later scans', () => {
let s = touch(emptySession, 1, false);
s = touch(s, 1, true);
assert.equal(s.earlier[1], undefined);
s = touch(s, 2, true);
s = touch(s, 2, false);
assert.equal(s.earlier[2], true);
});
test('forget removes a book everywhere', () => {
let s = touch(touch(emptySession, 1, true), 2, false);
s = forget(s, 1);
assert.deepEqual(s.order, [2]);
assert.equal(s.earlier[1], undefined);
assert.equal(s.touched[1], undefined);
});