ZDDC/tests/toast.spec.js
ZDDC 921713d0a4 chore: clear tech debt — green the suite + delete dead code
The full Playwright suite had 5 pre-existing failures (stale assertions for
since-reworked behavior) and the classifier carried dead code from removed flows.

Stale tests refreshed to current behavior:
- toast.spec (×3): toast.js now STACKS (sticky/dismissible) rather than showing
  one at a time — assert stacking + the "Clear all" control, read the message
  from .zddc-toast__msg (the toast also holds a × button), and dismiss via the ×
  (clicking the body no longer dismisses, by design).
- browse.spec: "New folder/New file" moved from the toolbar into the context
  menu — drop the #newFolderBtn/#newFileBtn assertions (Sort + Show-hidden stay).
- tokens.spec XSS guard: rewritten to the current apiActions modal flow
  (#api-create-btn → .api-modal → #table-root) instead of the long-gone inline
  #desc form. The escaping assertion now actually runs and confirms it holds.

Dead code removed:
- classifier .mdl-overlay* CSS (orphaned when the "MDL from archive" instantiate
  flow moved to the tables tool).
- classify.js filesInNode() — defined + exported but called nowhere.
- "From a list" naming: refreshed a stale "catalog" comment and renamed the 3
  remaining "By existing:" test titles.

Full suite now 340 passed / 0 failed.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-13 12:02:51 -05:00

74 lines
3.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Tests for shared/toast.js — the cross-tool notification helper
// available as window.zddc.toast(msg, level, opts). Loaded into every
// tool's bundle by build.sh.
//
// Strategy: load any tool's dist HTML over file:// (browse is the
// smallest), trigger the helper, and assert DOM + ARIA shape.
import { test, expect } from '@playwright/test';
import * as path from 'path';
const HTML_PATH = path.resolve('browse/dist/browse.html');
test.describe('shared/toast.js', () => {
test.beforeEach(async ({ page }) => {
await page.goto(`file://${HTML_PATH}`, { waitUntil: 'load' });
});
test('exposes window.zddc.toast(msg, level)', async ({ page }) => {
const exposed = await page.evaluate(
() => typeof window.zddc?.toast === 'function'
);
expect(exposed).toBe(true);
});
test('renders a toast with the level class and ARIA role', async ({ page }) => {
const after = await page.evaluate(() => {
window.zddc.toast('Saved.', 'success');
const el = document.querySelector('.zddc-toast');
return el && {
// The message lives in its own span (the toast also holds a × button).
text: el.querySelector('.zddc-toast__msg').textContent,
level: [...el.classList].find(c => c.startsWith('zddc-toast--')),
role: el.getAttribute('role'),
live: el.getAttribute('aria-live'),
};
});
expect(after).toEqual({
text: 'Saved.',
level: 'zddc-toast--success',
role: 'status',
live: 'polite',
});
});
test('error level uses role=alert + aria-live=assertive', async ({ page }) => {
const probe = await page.evaluate(() => {
window.zddc.toast('Boom', 'error');
const el = document.querySelector('.zddc-toast');
return { role: el.getAttribute('role'), live: el.getAttribute('aria-live') };
});
expect(probe).toEqual({ role: 'alert', live: 'assertive' });
});
test('toasts stack, and a "Clear all" control appears at 2+', async ({ page }) => {
const r = await page.evaluate(() => {
window.zddc.toast('one', 'error'); // sticky so it stays for the count
window.zddc.toast('two', 'error');
return {
count: document.querySelectorAll('.zddc-toast').length,
clearAll: !!document.querySelector('.zddc-toasts__clear'),
};
});
expect(r.count).toBe(2); // stack, not replace
expect(r.clearAll).toBe(true); // "Clear all" surfaces when 2+ are stacked
});
test('the × button dismisses a toast; clicking the body does not', async ({ page }) => {
await page.evaluate(() => window.zddc.toast('keep me', 'error')); // sticky
await page.locator('.zddc-toast .zddc-toast__msg').click(); // selecting text ≠ dismiss
await expect(page.locator('.zddc-toast')).toHaveCount(1);
await page.locator('.zddc-toast .zddc-toast__close').click(); // × dismisses
await expect(page.locator('.zddc-toast')).toHaveCount(0);
});
});