|
| 1 | +import React from 'react'; |
| 2 | +import { render, screen, fireEvent } from '@testing-library/react'; |
| 3 | +import { describe, it, expect, vi } from 'vitest'; |
| 4 | +import { CollaborativeEditingTools } from '../CollaborativeEditingTools'; |
| 5 | +import { MediaEmbedder } from '../MediaEmbedder'; |
| 6 | +import { ContentTemplateLibrary } from '../ContentTemplateLibrary'; |
| 7 | + |
| 8 | +// ─── CollaborativeEditingTools ──────────────────────────────────────────────── |
| 9 | + |
| 10 | +describe('CollaborativeEditingTools accessibility', () => { |
| 11 | + it('renders collaborator list with role=list and aria-label', () => { |
| 12 | + render(<CollaborativeEditingTools />); |
| 13 | + const list = screen.getByRole('list', { name: /active collaborators/i }); |
| 14 | + expect(list).toBeInTheDocument(); |
| 15 | + }); |
| 16 | + |
| 17 | + it('renders each collaborator avatar as a listitem with descriptive alt', () => { |
| 18 | + render(<CollaborativeEditingTools />); |
| 19 | + const items = screen.getAllByRole('listitem'); |
| 20 | + expect(items.length).toBeGreaterThan(0); |
| 21 | + items.forEach((item) => { |
| 22 | + expect(item).toHaveAttribute('alt', expect.stringMatching(/is editing/i)); |
| 23 | + }); |
| 24 | + }); |
| 25 | + |
| 26 | + it('status badge has aria-label with collaborator count', () => { |
| 27 | + render(<CollaborativeEditingTools />); |
| 28 | + const badge = screen.getByLabelText(/3 active collaborators/i); |
| 29 | + expect(badge).toBeInTheDocument(); |
| 30 | + }); |
| 31 | +}); |
| 32 | + |
| 33 | +// ─── MediaEmbedder ──────────────────────────────────────────────────────────── |
| 34 | + |
| 35 | +describe('MediaEmbedder accessibility', () => { |
| 36 | + const noop = vi.fn(); |
| 37 | + |
| 38 | + it('image trigger button has aria-label', () => { |
| 39 | + render(<MediaEmbedder onAddImage={noop} onAddYoutube={noop} />); |
| 40 | + expect(screen.getByRole('button', { name: /add image/i })).toBeInTheDocument(); |
| 41 | + }); |
| 42 | + |
| 43 | + it('youtube trigger button has aria-label', () => { |
| 44 | + render(<MediaEmbedder onAddImage={noop} onAddYoutube={noop} />); |
| 45 | + expect(screen.getByRole('button', { name: /add youtube video/i })).toBeInTheDocument(); |
| 46 | + }); |
| 47 | + |
| 48 | + it('dialog has role=dialog, aria-modal, and aria-labelledby when open', () => { |
| 49 | + render(<MediaEmbedder onAddImage={noop} onAddYoutube={noop} />); |
| 50 | + fireEvent.click(screen.getByRole('button', { name: /add image/i })); |
| 51 | + |
| 52 | + const dialog = screen.getByRole('dialog'); |
| 53 | + expect(dialog).toHaveAttribute('aria-modal', 'true'); |
| 54 | + expect(dialog).toHaveAttribute('aria-labelledby'); |
| 55 | + |
| 56 | + const titleId = dialog.getAttribute('aria-labelledby')!; |
| 57 | + expect(document.getElementById(titleId)).toBeInTheDocument(); |
| 58 | + }); |
| 59 | + |
| 60 | + it('URL input has an accessible label', () => { |
| 61 | + render(<MediaEmbedder onAddImage={noop} onAddYoutube={noop} />); |
| 62 | + fireEvent.click(screen.getByRole('button', { name: /add image/i })); |
| 63 | + expect(screen.getByLabelText(/image url/i)).toBeInTheDocument(); |
| 64 | + }); |
| 65 | + |
| 66 | + it('error paragraph has role=alert and aria-live=assertive', () => { |
| 67 | + render(<MediaEmbedder onAddImage={noop} onAddYoutube={noop} />); |
| 68 | + fireEvent.click(screen.getByRole('button', { name: /add image/i })); |
| 69 | + |
| 70 | + const errorEl = screen.getByRole('alert'); |
| 71 | + expect(errorEl).toHaveAttribute('aria-live', 'assertive'); |
| 72 | + }); |
| 73 | + |
| 74 | + it('input is described by the error element', () => { |
| 75 | + render(<MediaEmbedder onAddImage={noop} onAddYoutube={noop} />); |
| 76 | + fireEvent.click(screen.getByRole('button', { name: /add image/i })); |
| 77 | + |
| 78 | + const input = screen.getByLabelText(/image url/i); |
| 79 | + const errorEl = screen.getByRole('alert'); |
| 80 | + expect(input).toHaveAttribute('aria-describedby', errorEl.id); |
| 81 | + }); |
| 82 | +}); |
| 83 | + |
| 84 | +// ─── ContentTemplateLibrary ─────────────────────────────────────────────────── |
| 85 | + |
| 86 | +describe('ContentTemplateLibrary accessibility', () => { |
| 87 | + const mockEditor = { |
| 88 | + chain: () => ({ focus: () => ({ insertContent: () => ({ run: vi.fn() }) }) }), |
| 89 | + } as unknown as import('@tiptap/react').Editor; |
| 90 | + |
| 91 | + it('renders as an aside with aria-label', () => { |
| 92 | + render(<ContentTemplateLibrary editor={mockEditor} />); |
| 93 | + const sidebar = screen.getByRole('complementary', { name: /content templates/i }); |
| 94 | + expect(sidebar).toBeInTheDocument(); |
| 95 | + }); |
| 96 | + |
| 97 | + it('each template button has a descriptive aria-label', () => { |
| 98 | + render(<ContentTemplateLibrary editor={mockEditor} />); |
| 99 | + const buttons = screen.getAllByRole('button'); |
| 100 | + buttons.forEach((btn) => { |
| 101 | + const label = btn.getAttribute('aria-label') ?? ''; |
| 102 | + expect(label.length).toBeGreaterThan(0); |
| 103 | + expect(label.toLowerCase()).toContain('insert'); |
| 104 | + }); |
| 105 | + }); |
| 106 | + |
| 107 | + it('template icons are hidden from assistive technology', () => { |
| 108 | + render(<ContentTemplateLibrary editor={mockEditor} />); |
| 109 | + // Icon wrappers should carry aria-hidden="true" |
| 110 | + const hiddenEls = document |
| 111 | + .querySelectorAll('[aria-hidden="true"]'); |
| 112 | + expect(hiddenEls.length).toBeGreaterThan(0); |
| 113 | + }); |
| 114 | +}); |
0 commit comments