Files
hyprcrd/public/plugins/tests/editor.test.js
T
thandClaude Opus 4.6 b08bdbaeb2 tests: assert new appointments don't inherit the active bucket
Opens the editor twice against a real bucket as activeBucket: once
with a #termin-seeded body (should stay empty in inp-bucket) and
once with a plain body (should pick up the active bucket id).
Skipped on fresh DBs that have no buckets to inherit from.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 22:06:10 +02:00

113 lines
4.1 KiB
JavaScript

import { describe, it, afterEach, expect, $, click, pressKey, sleep, closeAll, csrf } from './runner.js?v=4';
describe('Editor: Structure', () => {
it('has all elements', () => {
for (const id of ['modal', 'inp-title', 'editor-body', 'editor-preview', 'color-presets']) {
expect($(`#${id}`)).toExist();
}
});
it('has save buttons', () => {
for (const id of ['modal-save', 'modal-save-close', 'modal-cancel']) {
expect($(`#${id}`)).toExist();
}
});
it('has due date and done toggle', () => {
expect($('#inp-due-date')).toExist();
expect($('#inp-done-toggle')).toExist();
});
});
describe('Editor: Open/Close', () => {
afterEach(() => closeAll());
it('opens on add button', async () => {
click('#add-btn');
await sleep(200);
expect($('#modal')).toBeVisible();
});
it('title field focused on open', async () => {
click('#add-btn');
await sleep(200);
expect(document.activeElement).toBe($('#inp-title'));
});
it('closes on cancel', async () => {
click('#add-btn');
await sleep(100);
click('#modal-cancel');
await sleep(150);
expect($('#modal')).toBeHidden();
});
it('closes on ESC', async () => {
click('#add-btn');
await sleep(100);
pressKey('Escape');
await sleep(150);
expect($('#modal')).toBeHidden();
});
it('opens on board right-click (new card)', async () => {
const board = $('#board');
board.dispatchEvent(new MouseEvent('contextmenu', { bubbles: true, clientX: 100, clientY: 300 }));
await sleep(200);
expect($('#modal')).toBeVisible();
});
});
describe('Editor: Card Create', () => {
afterEach(() => closeAll());
it('creates card via API and shows on board', async () => {
const res = await fetch('api/cards', {
method: 'POST', headers: { 'Content-Type': 'application/json', 'X-CSRF-Token': csrf() },
body: JSON.stringify({ title: '__test_editor__', body: 'body text', color: '#fb7185' }),
}).then(r => r.json());
expect(res.id).toBeGreaterThan(0);
await window._reloadAll?.();
await sleep(200);
expect(document.querySelector(`[data-id="${res.id}"]`)).toExist();
});
});
describe('Editor: new-appointment bucket default', () => {
// New appointments (body pre-seeded with #termin / #geburtstag from
// the calendar day-popup template) must not inherit the currently
// active real bucket — they belong to a calendar. Regular new
// cards keep inheriting so the user doesn't have to re-pick.
afterEach(async () => {
// Close any open modal and restore the runner's baseline bucket.
document.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape', bubbles: true }));
await sleep(80);
window.state.activeBucket = 'all';
});
it('#termin body forces empty bucket; plain body inherits active', async () => {
const buckets = await fetch('api/buckets').then(r => r.json());
if (!Array.isArray(buckets) || !buckets.length) return; // nothing to inherit from
const b = buckets[0];
window.state.activeBucket = b.id;
// Appointment-flavoured body → inp-bucket stays empty.
window._openModal({ id: null, title: '9999-01-01 — probe', body: '#termin', color: '#fb923c', bucket_id: null });
await sleep(80);
const apptBucket = $('#inp-bucket').value;
document.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape', bubbles: true }));
await sleep(120);
// Plain body → inp-bucket inherits the active bucket id.
window._openModal({ id: null, title: '__test_inherit__', body: '', color: '#38bdf8', bucket_id: null });
await sleep(80);
const regBucket = $('#inp-bucket').value;
document.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape', bubbles: true }));
await sleep(120);
expect(apptBucket).toBe('');
expect(regBucket).toBe(String(b.id));
});
});