From b08bdbaeb24a77e65aa6aa04a410881285e2ac96 Mon Sep 17 00:00:00 2001 From: th Date: Wed, 15 Apr 2026 22:06:10 +0200 Subject: [PATCH] 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) --- public/plugins/tests/editor.test.js | 38 +++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/public/plugins/tests/editor.test.js b/public/plugins/tests/editor.test.js index 078d060..ecfbf00 100644 --- a/public/plugins/tests/editor.test.js +++ b/public/plugins/tests/editor.test.js @@ -72,3 +72,41 @@ describe('Editor: Card Create', () => { 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)); + }); +});