22 lines
848 B
TypeScript
22 lines
848 B
TypeScript
|
|
import { describe, test, expect } from 'vitest';
|
||
|
|
import { TextareaField } from './TextareaField';
|
||
|
|
|
||
|
|
const toHtml = (TextareaField as any).toHtml;
|
||
|
|
|
||
|
|
describe('TextareaField.toHtml accessibility (F2.1)', () => {
|
||
|
|
test('label for= matches textarea id=', () => {
|
||
|
|
const { html } = toHtml({ label: 'Message', name: 'message' }, '');
|
||
|
|
const forMatch = html.match(/<label for="([^"]+)"/);
|
||
|
|
const idMatch = html.match(/<textarea id="([^"]+)"/);
|
||
|
|
expect(forMatch).toBeTruthy();
|
||
|
|
expect(idMatch).toBeTruthy();
|
||
|
|
expect(forMatch![1]).toBe(idMatch![1]);
|
||
|
|
});
|
||
|
|
|
||
|
|
test('no visible label: textarea gets aria-label from placeholder', () => {
|
||
|
|
const { html } = toHtml({ label: '', name: 'notes', placeholder: 'Anything else?' }, '');
|
||
|
|
expect(html).not.toContain('<label');
|
||
|
|
expect(html).toContain('aria-label="Anything else?"');
|
||
|
|
});
|
||
|
|
});
|