* card-interactions.test.js: group delete tests used `.dialog-ok` (class selector) but the button has `id="dialog-ok"`. querySelector returned null, the click was skipped, the dialog stayed open and blocked every downstream test. Fixed to getElementById. * runner.js closeAll(): added #dialog, #bucket-super-popover (remove), and #gitea-overlay to the cleanup list. A failed test that leaves any of these open no longer poisons the rest of the suite. * runner.js copy handler: when there are failures or flaky tests, the "copy" button now builds the clipboard text from lastResults — only failed + flaky lines (suite name, test name, timing, error, original error for retried). When everything passed, copies the full output as before. lastResults is set in renderResults(). * bucket-context.test.js: move-left test used `[data-bucket]` to find user bucket tabs, which misses super-bucket tiles (they carry `data-bucket-super`). Changed to `[data-bucket-drag]` which is on both regular and super-bucket tiles but not on fixed filters. * context-menu.test.js: make-ticket pre-fill assertion now polls up to 2s for the title input to be populated (async openCreateForm repo-fetch was racing against the immediate assertion). * card-join.test.js: clickJoin sleep bumped from 400ms → 800ms. joinSelectedCards does 3+ serial API calls (fetch bodies, PATCH winner, N×DELETE losers, _reloadAll) which sometimes exceeded the old 400ms window on slow runs. * Runner cache: RUNNER_V bumped from ?v=2 → ?v=3 in loader.js + all 42 test files so the browser picks up the new runner.js content (copy handler, closeAll, retry progress bar) without a hard reload. super-buckets: remember last selection per group * buckets.js: module-scope lastSuperSelection Map tracks the last active member per super-bucket parent. Updated in renderBar() whenever activeBucket matches a group member. tileFor() uses it as a fallback when the user is on a different bucket — the tile shows the last-picked child's name and color instead of reverting to the parent. The dropdown popover also highlights the last selection when no member is currently active. chore: bump version to 0.9.11 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
142 lines
6.2 KiB
JavaScript
142 lines
6.2 KiB
JavaScript
import { describe, it, expect, csrf } from './runner.js?v=3';
|
|
|
|
describe('Export: JSON ZIP', () => {
|
|
it('export endpoint returns ZIP', async () => {
|
|
const res = await fetch('api/export');
|
|
expect(res.status).toBe(200);
|
|
expect(res.headers.get('content-type')).toContain('zip');
|
|
});
|
|
|
|
it('export with ids returns ZIP', async () => {
|
|
const cards = await fetch('api/cards').then(r => r.json());
|
|
if (!cards.length) return;
|
|
const res = await fetch(`api/export?ids=${cards[0].id}`);
|
|
expect(res.status).toBe(200);
|
|
expect(res.headers.get('content-type')).toContain('zip');
|
|
});
|
|
|
|
it('export contains data.json', async () => {
|
|
const res = await fetch('api/export');
|
|
const blob = await res.blob();
|
|
// ZIP magic number: PK (0x50 0x4b)
|
|
const bytes = new Uint8Array(await blob.slice(0, 2).arrayBuffer());
|
|
expect(bytes[0]).toBe(0x50);
|
|
expect(bytes[1]).toBe(0x4b);
|
|
});
|
|
});
|
|
|
|
describe('Export: Markdown Vault', () => {
|
|
it('vault export returns ZIP', async () => {
|
|
const res = await fetch('api/export-md');
|
|
expect(res.status).toBe(200);
|
|
expect(res.headers.get('content-type')).toContain('zip');
|
|
});
|
|
|
|
it('vault export with ids returns ZIP', async () => {
|
|
const cards = await fetch('api/cards').then(r => r.json());
|
|
if (!cards.length) return;
|
|
const res = await fetch(`api/export-md?ids=${cards[0].id}`);
|
|
expect(res.status).toBe(200);
|
|
});
|
|
});
|
|
|
|
describe('Export: Backup Integrity', () => {
|
|
it('export→import round-trip preserves card and bucket count', async () => {
|
|
// Snapshot current state
|
|
const cardsBefore = await fetch('api/cards').then(r => r.json());
|
|
const bucketsBefore = await fetch('api/buckets').then(r => r.json());
|
|
|
|
// Export current state
|
|
const blob = await fetch('api/export').then(r => r.blob());
|
|
|
|
// Create some extra cards that should be wiped on replace-import
|
|
await fetch('api/cards', {
|
|
method: 'POST', headers: { 'Content-Type': 'application/json', 'X-CSRF-Token': csrf() },
|
|
body: JSON.stringify({ title: '__extra_should_vanish__', body: '', color: '#38bdf8' }),
|
|
});
|
|
|
|
// Import (replace mode) — should restore exact state from export
|
|
const form = new FormData();
|
|
form.append('file', blob, 'roundtrip.zip');
|
|
await fetch('api/import', { method: 'POST', body: form, headers: { 'X-CSRF-Token': csrf() } });
|
|
|
|
const cardsAfter = await fetch('api/cards').then(r => r.json());
|
|
const bucketsAfter = await fetch('api/buckets').then(r => r.json());
|
|
expect(cardsAfter.length).toBe(cardsBefore.length);
|
|
expect(bucketsAfter.length).toBe(bucketsBefore.length);
|
|
// Extra card should be gone
|
|
expect(cardsAfter.some(c => c.title === '__extra_should_vanish__')).toBe(false);
|
|
});
|
|
|
|
it('export→import preserves caldav_uid', async () => {
|
|
const cardsBefore = await fetch('api/cards').then(r => r.json());
|
|
const withCaldav = cardsBefore.filter(c => c.caldav_uid);
|
|
if (!withCaldav.length) return; // skip if no synced cards
|
|
|
|
// Export
|
|
const blob = await fetch('api/export').then(r => r.blob());
|
|
|
|
// Import
|
|
const form = new FormData();
|
|
form.append('file', blob, 'roundtrip.zip');
|
|
await fetch('api/import', { method: 'POST', body: form, headers: { 'X-CSRF-Token': csrf() } });
|
|
|
|
// Verify caldav_uid preserved
|
|
const cardsAfter = await fetch('api/cards').then(r => r.json());
|
|
const withCaldavAfter = cardsAfter.filter(c => c.caldav_uid);
|
|
expect(withCaldavAfter.length).toBe(withCaldav.length);
|
|
});
|
|
|
|
it('export→import preserves tags and due_dates', async () => {
|
|
// Create a card with tags and due date
|
|
const card = await fetch('api/cards', {
|
|
method: 'POST', headers: { 'Content-Type': 'application/json', 'X-CSRF-Token': csrf() },
|
|
body: JSON.stringify({ title: '__test_roundtrip__', body: '#alpha #beta', color: '#38bdf8' }),
|
|
}).then(r => r.json());
|
|
await fetch(`api/cards/${card.id}`, {
|
|
method: 'PATCH', headers: { 'Content-Type': 'application/json', 'X-CSRF-Token': csrf() },
|
|
body: JSON.stringify({ due_date: '2099-12-31' }),
|
|
});
|
|
|
|
// Export
|
|
const blob = await fetch('api/export').then(r => r.blob());
|
|
|
|
// Import (replace)
|
|
const form = new FormData();
|
|
form.append('file', blob, 'roundtrip.zip');
|
|
await fetch('api/import', { method: 'POST', body: form, headers: { 'X-CSRF-Token': csrf() } });
|
|
|
|
// Find the card
|
|
const cards = await fetch('api/cards').then(r => r.json());
|
|
const found = cards.find(c => c.title === '__test_roundtrip__');
|
|
expect(found).toExist();
|
|
expect(found.tags).toContain('alpha');
|
|
expect(found.tags).toContain('beta');
|
|
expect(found.due_date).toBe('2099-12-31');
|
|
});
|
|
|
|
it('export→import preserves bucket color', async () => {
|
|
// Create a bucket with a recognizable name and patch a custom color onto it
|
|
const b = await fetch('api/buckets', {
|
|
method: 'POST', headers: { 'Content-Type': 'application/json', 'X-CSRF-Token': csrf() },
|
|
body: JSON.stringify({ name: '__test_bucket_color__' }),
|
|
}).then(r => r.json());
|
|
await fetch(`api/buckets/${b.id}`, {
|
|
method: 'PATCH', headers: { 'Content-Type': 'application/json', 'X-CSRF-Token': csrf() },
|
|
body: JSON.stringify({ color: '#fb7185' }),
|
|
});
|
|
|
|
// Round-trip through export → replace-import
|
|
const blob = await fetch('api/export').then(r => r.blob());
|
|
const form = new FormData();
|
|
form.append('file', blob, 'roundtrip.zip');
|
|
await fetch('api/import', { method: 'POST', body: form, headers: { 'X-CSRF-Token': csrf() } });
|
|
|
|
// The bucket must reappear with the same custom color (not the schema default)
|
|
const buckets = await fetch('api/buckets').then(r => r.json());
|
|
const found = buckets.find(x => x.name === '__test_bucket_color__');
|
|
expect(found).toExist();
|
|
expect(found.color).toBe('#fb7185');
|
|
});
|
|
});
|