A list of timestamps in both file menus paid for itself only on the day something went wrong, and it was in the way on every other. The entries are gone; loadDocument now offers the versions where the browser copy has actually failed the reader — newest first, one question each, and the one taken up starts under the boot flag like any other document. The store loses its reactive singleton with them.
28 lines
1.1 KiB
TypeScript
28 lines
1.1 KiB
TypeScript
import { describe, it, expect, vi } from 'vitest';
|
|
import { fakeIndexedDb } from '../fakeIdb';
|
|
|
|
describe('the autosave keeps a few earlier versions', () => {
|
|
it('takes one every few minutes and holds on to the newest three', async () => {
|
|
const idb = fakeIndexedDb();
|
|
vi.stubGlobal('indexedDB', { open: idb.open });
|
|
const { keepSnapshot, listSnapshots, readSnapshot } = await import('../../src/lib/storage/snapshots');
|
|
const now = vi.spyOn(Date, 'now');
|
|
const at = (min: number) => 1_800_000_000_000 + min * 60_000;
|
|
|
|
now.mockReturnValue(at(0));
|
|
await keepSnapshot({ type: 'doc', v: 1 });
|
|
now.mockReturnValue(at(1));
|
|
await keepSnapshot({ type: 'doc', v: 2 }); // a minute on: still the same version
|
|
expect(await listSnapshots()).toEqual([at(0)]);
|
|
|
|
for (const m of [6, 12, 18]) {
|
|
now.mockReturnValue(at(m));
|
|
await keepSnapshot({ type: 'doc', v: m });
|
|
}
|
|
expect(await listSnapshots()).toEqual([at(18), at(12), at(6)]);
|
|
expect(idb.data.size).toBe(3);
|
|
expect(await readSnapshot(at(12))).toEqual({ type: 'doc', v: 12 });
|
|
expect(await readSnapshot(at(0))).toBeNull();
|
|
});
|
|
});
|