import { readFileSync } from 'node:fs'; import { join } from 'node:path'; import { render, screen } from '@testing-library/react'; import { describe, it, expect } from 'vitest'; import { SettingItem, ToggleSwitch, RadioGroup, Select, SectionNav, SettingsSection } from '../settings-section'; describe('SettingItem controls', () => { it('names a toggle after the row label and reports its state', () => { render( {}} /> ); const toggle = screen.getByRole('switch', { name: 'Conversation view' }); expect(toggle).toHaveAttribute('aria-checked', 'true'); }); it('puts a glossary info button beside the label without changing the toggle name', () => { render( {}} /> ); // The mocked translator returns keys: the button is named by glossary.what_is. const info = screen.getByRole('button', { name: 'what_is' }); expect(info).toHaveAttribute('data-glossary-term', 'app_password'); expect(info.closest('label')).toBeNull(); expect(screen.getByRole('switch', { name: 'App passwords' })).toBeInTheDocument(); }); it('adds a glossary info button to a section title', () => { render(

rows

); const heading = screen.getByRole('heading', { name: 'Delegates' }); expect(heading.parentElement?.querySelector('[data-glossary-term="delegation"]')).not.toBeNull(); }); it('lets an explicit ariaLabel win over the row label', () => { render( {}} ariaLabel="Group by thread" /> ); expect(screen.getByRole('switch', { name: 'Group by thread' })).toHaveAttribute('aria-checked', 'false'); }); it('reports which option of a segmented control is active', () => { render( {}} options={[ { value: 'compact', label: 'Compact' }, { value: 'cosy', label: 'Cosy' }, ]} /> ); expect(screen.getByRole('button', { name: 'Cosy' })).toHaveAttribute('aria-pressed', 'true'); expect(screen.getByRole('button', { name: 'Compact' })).toHaveAttribute('aria-pressed', 'false'); expect(screen.getByRole('group', { name: 'Density' })).toBeTruthy(); }); it('names a select after the row label', () => { render(