Files
webmail/components/settings/__tests__/settings-section-links.test.tsx
T
Linus Rath 8008393e59 feat: add an Accessibility page to Settings
Settings get a page of their own for accessibility, with presets on top
(screen reader, low vision, dyslexia, focus, keyboard and motor, motion
and seizure safe, deaf and hard of hearing) that change several options
at once and can be undone, then the options by topic, and a reset.

Text size used to be a fixed 14/16/18px on the root, which threw away
the size people set in their browser. It is now a percentage of the
browser's size, from 87.5% to 200%. Motion, contrast and transparency
follow the system by default and can be overridden either way; the
old Animations switch becomes Reduce motion. The visual options are
applied before the first paint, so the page no longer flashes at the
wrong size.

- `lib/accessibility-settings.ts`: the new settings, their allowed
  values, and the code that writes them onto `<html>`
- `app/accessibility.css`: bundled fonts (Atkinson Hyperlegible Next,
  Lexend, OpenDyslexic), text spacing, a focus outline that survives
  Windows contrast themes, more-contrast colours on any theme, reduced
  transparency, a large pointer
- admins can preset every new option but lock only shortcuts, send
  confirmation and the notification duration; a lock on text size or
  another reading aid works as a default
- always-light mail and toolbar labels now sync, and imports drop
  values the page doesn't know
- font size and animations move off Appearance, the plain text font
  off Reading; everyday settings such as conversation view and undo
  send show on both their own page and Accessibility
2026-10-29 17:53:32 +01:00

145 lines
6.7 KiB
TypeScript

import React from 'react';
import { act, fireEvent, render, screen, waitFor } from '@testing-library/react';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
// Section deep links: `/settings/<tab>/<section>` and the ids of retired tabs
// land on the page and section that hold the setting now. The jump row at the
// top of a page lists its sections.
vi.mock('next-intl', () => ({
useTranslations: (ns?: string) => (key: string) => (ns ? `${ns}.${key}` : key),
useMessages: () => ({}),
useLocale: () => 'en',
useFormatter: () => ({ dateTime: String, relativeTime: String, number: String }),
}));
vi.mock('@/hooks/use-media-query', () => ({
useIsDesktop: () => true,
useIsMobile: () => false,
useMediaQuery: () => false,
useDeviceDetection: () => ({ isMobile: false, isTablet: false, isDesktop: true }),
}));
vi.mock('@/hooks/use-config', () => ({ useConfig: () => ({ appName: 'Mail', stalwartFeaturesEnabled: false }) }));
vi.mock('@/components/layout/navigation-rail', () => ({ NavigationRail: () => null }));
vi.mock('@/components/layout/sidebar-apps-modal', () => ({ SidebarAppsModal: () => null }));
vi.mock('@/components/plugins/app-top-banner-slot', () => ({ AppTopBannerSlot: () => null }));
vi.mock('@/components/settings/about-data-settings', () => ({
AboutDataSettings: () => null,
AboutFooter: () => <div data-testid="about-footer" />,
}));
vi.mock('@/components/settings/appearance-settings',() => ({ AppearanceSettings: () => <div>appearance pane</div> }));
vi.mock('@/components/settings/accessibility-settings', () => ({ AccessibilitySettings: () => <div>accessibility pane</div> }));
vi.mock('@/components/settings/organize-settings', () => ({
OrganizeSettings: () => (
<div>
<div data-settings-section="folders"><h3>Folders</h3></div>
<div data-settings-section="tags"><h3>Tags</h3></div>
</div>
),
}));
vi.mock('@/components/settings/account-settings', () => ({
AccountSettings: () => (
<div>
<div data-settings-section="profile"><h3>Profile</h3></div>
<div data-settings-section="addresses"><h3>Email addresses</h3></div>
</div>
),
}));
const { SettingsApp } = await import('../settings-app');
const { useAuthStore } = await import('@/stores/auth-store');
const { usePluginStore } = await import('@/stores/plugin-store');
const { useThemeStore } = await import('@/stores/theme-store');
const { useSettingsStore } = await import('@/stores/settings-store');
const { SettingsSection } = await import('../settings-section');
const scrolled: string[] = [];
beforeEach(() => {
scrolled.length = 0;
Element.prototype.scrollIntoView = function (this: Element) {
scrolled.push((this as HTMLElement).dataset.settingsSection ?? this.tagName);
};
vi.stubGlobal('fetch', vi.fn().mockRejectedValue(new Error('Unexpected network request')));
try { localStorage.setItem('settings-active-tab', 'appearance'); } catch { /* ignore */ }
const client = new Proxy({}, {
get: (_t, prop) => (prop === 'then' ? undefined : (prop === 'getAccountId' ? () => 'acc' : () => null)),
});
useAuthStore.setState({ isAuthenticated: true, isLoading: false, client: client as never });
usePluginStore.setState({ initializePlugins: vi.fn().mockResolvedValue(undefined) });
useThemeStore.setState({ syncServerThemes: vi.fn().mockResolvedValue(undefined) } as never);
act(() => { useSettingsStore.setState({ showAdvancedSettings: false }); });
});
afterEach(() => {
vi.unstubAllGlobals();
});
describe('settings section links', () => {
it('lands an old /settings/keywords link on the tags section of Folders & tags', async () => {
render(<SettingsApp linkSegments={['keywords']} />);
expect(screen.getByTestId('settings-tab-organize')).toHaveAttribute('aria-current', 'page');
await waitFor(() => expect(scrolled).toContain('tags'));
});
it('lands /settings/organize/folders on that section', async () => {
render(<SettingsApp linkSegments={['organize', 'folders']} />);
await waitFor(() => expect(scrolled).toContain('folders'));
expect(scrolled).not.toContain('tags');
});
it('lists the sections of the open page in the jump row', async () => {
render(<SettingsApp linkSegments={['organize']} />);
const nav = screen.getByTestId('settings-section-nav');
await waitFor(() => expect(nav).not.toHaveAttribute('hidden'));
fireEvent.click(screen.getByRole('button', { name: 'Tags' }));
expect(scrolled).toContain('tags');
});
it('flashes the section a jump-row button scrolls to', async () => {
const { container } = render(<SettingsApp linkSegments={['organize']} />);
const nav = screen.getByTestId('settings-section-nav');
await waitFor(() => expect(nav).not.toHaveAttribute('hidden'));
vi.useFakeTimers();
try {
fireEvent.click(screen.getByRole('button', { name: 'Tags' }));
const tags = container.querySelector('[data-settings-section="tags"]')!;
const folders = container.querySelector('[data-settings-section="folders"]')!;
expect(tags).toHaveClass('settings-search-highlight');
expect(folders).not.toHaveClass('settings-search-highlight');
act(() => { vi.advanceTimersByTime(1800); });
expect(tags).not.toHaveClass('settings-search-highlight');
} finally {
vi.useRealTimers();
}
});
it('follows a tab-change event that names a retired tab to its new section', async () => {
render(<SettingsApp linkSegments={[]} />);
act(() => { window.dispatchEvent(new CustomEvent('settings-tab-change', { detail: 'identities' })); });
expect(screen.getByTestId('settings-tab-account')).toHaveAttribute('aria-current', 'page');
await waitFor(() => expect(scrolled).toContain('addresses'));
});
it('turns the Advanced switch on when a link names a section it hides', async () => {
function AdvancedPage() {
return (
<SettingsSection id="downloads" title="Downloads" advanced>
<span>rows</span>
</SettingsSection>
);
}
vi.doMock('@/components/settings/reading-settings', () => ({ ReadingSettings: AdvancedPage }));
const { SettingsApp: App } = await import('../settings-app');
render(<App linkSegments={['downloads']} />);
expect(screen.getByTestId('settings-tab-reading')).toHaveAttribute('aria-current', 'page');
await waitFor(() => expect(useSettingsStore.getState().showAdvancedSettings).toBe(true), { timeout: 3000 });
await waitFor(() => expect(scrolled).toContain('downloads'));
});
it('shows the version footer in the sidebar only with Advanced on', () => {
render(<SettingsApp />);
expect(screen.queryByTestId('about-footer')).toBeNull();
fireEvent.click(screen.getByTestId('settings-advanced-switch'));
expect(screen.getByTestId('about-footer')).toBeInTheDocument();
});
});