app

Local-first trade for farms and co-ops
git clone https://radroots.dev/git/app.git
Log | Files | Refs | README | LICENSE

notices.test.ts (1339B)


      1 import { render } from 'svelte/server';
      2 import { describe, it, expect } from 'vitest';
      3 import Notice from '../../../src/lib/components/Notice.svelte';
      4 import ErrorSummary from '../../../src/lib/components/ErrorSummary.svelte';
      5 import Harness from './NoticeHarness.svelte';
      6 describe('persistent accessible status and form summary SSR', () => {
      7   it('escapes plain text and politely announces without focus/dismissal', () => {
      8     const html = render(Notice, {
      9       props: { tone: 'error', text: '<img src=x>' }
     10     }).body;
     11     expect(html).toContain('&lt;img src=x>');
     12     expect(html).toContain('aria-live="polite"');
     13     expect(html).not.toMatch(/autofocus|onclick|setTimeout|<button/);
     14   });
     15   it('links only safe same-page fields and associates a heading', () => {
     16     const html = render(Harness).body;
     17     expect(html).toContain('href="#food"');
     18     expect(html).not.toMatch(/href="https:|href="javascript:/);
     19     expect(html).toContain('Unsafe destination');
     20     expect(html).toContain('aria-labelledby=');
     21     expect(html).toContain('sender archive');
     22     expect(html).toContain('event-A');
     23     expect(html).toContain('target-A');
     24   });
     25   it('does not flag fields before any errors exist', () => {
     26     expect(render(ErrorSummary, { props: { errors: [] } }).body).not.toContain(
     27       'Check the following fields'
     28     );
     29   });
     30 });