mirror of
https://github.com/bulwarkmail/webmail.git
synced 2026-10-31 08:13:50 +00:00
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
95 lines
4.1 KiB
TypeScript
95 lines
4.1 KiB
TypeScript
import { afterEach, describe, expect, it } from 'vitest';
|
|
import {
|
|
ACCESSIBILITY_DEFAULTS,
|
|
accessibilityBootScript,
|
|
applyAccessibilityTo,
|
|
isAllowedAccessibilityValue,
|
|
toastDurationAtLeast,
|
|
} from '../accessibility-settings';
|
|
|
|
const root = () => document.documentElement;
|
|
|
|
afterEach(() => {
|
|
for (const name of root().getAttributeNames()) if (name.startsWith('data-')) root().removeAttribute(name);
|
|
root().style.removeProperty('--font-size-base');
|
|
localStorage.clear();
|
|
});
|
|
|
|
describe('applyAccessibilityTo', () => {
|
|
it('sets the text size as a percentage of the browser default, not in pixels', () => {
|
|
applyAccessibilityTo(root(), { fontSize: 'medium' });
|
|
expect(root().style.getPropertyValue('--font-size-base')).toBe('100%');
|
|
applyAccessibilityTo(root(), { fontSize: 'huge' });
|
|
expect(root().style.getPropertyValue('--font-size-base')).toBe('200%');
|
|
applyAccessibilityTo(root(), { fontSize: 'small' });
|
|
expect(root().style.getPropertyValue('--font-size-base')).toBe('87.5%');
|
|
});
|
|
|
|
it('writes nothing for "follow the system", so the media queries decide', () => {
|
|
applyAccessibilityTo(root(), { ...ACCESSIBILITY_DEFAULTS, fontSize: 'medium' });
|
|
expect(root().getAttributeNames().filter((n) => n.startsWith('data-'))).toEqual([]);
|
|
});
|
|
|
|
it('marks explicit overrides either way', () => {
|
|
applyAccessibilityTo(root(), { reduceMotion: 'on', contrast: 'more', reduceTransparency: 'off' });
|
|
expect(root().dataset.motion).toBe('reduce');
|
|
expect(root().dataset.animations).toBe('off');
|
|
expect(root().dataset.contrast).toBe('more');
|
|
expect(root().dataset.transparency).toBe('full');
|
|
|
|
applyAccessibilityTo(root(), { reduceMotion: 'off', contrast: 'normal' });
|
|
expect(root().dataset.motion).toBe('full');
|
|
expect(root().dataset.animations).toBeUndefined();
|
|
expect(root().dataset.contrast).toBe('normal');
|
|
expect(root().dataset.transparency).toBeUndefined();
|
|
});
|
|
|
|
it('removes an attribute again when the option goes back to its default', () => {
|
|
applyAccessibilityTo(root(), { appFont: 'lexend', focusRing: 'extra', underlineLinks: true });
|
|
expect(root().dataset.appFont).toBe('lexend');
|
|
expect(root().dataset.focusRing).toBe('extra');
|
|
expect(root().dataset.underlineLinks).toBe('on');
|
|
applyAccessibilityTo(root(), { appFont: 'default', focusRing: 'normal', underlineLinks: false });
|
|
expect(root().dataset.appFont).toBeUndefined();
|
|
expect(root().dataset.focusRing).toBeUndefined();
|
|
expect(root().dataset.underlineLinks).toBeUndefined();
|
|
});
|
|
});
|
|
|
|
describe('accessibilityBootScript', () => {
|
|
it('runs on its own before React and applies the persisted settings', () => {
|
|
localStorage.setItem('settings-storage', JSON.stringify({
|
|
state: { fontSize: 'xx-large', contrast: 'more', reduceMotion: 'on' },
|
|
version: 9,
|
|
}));
|
|
// Indirect eval runs in global scope: anything the function borrowed
|
|
// from its module would be undefined here and throw (caught silently,
|
|
// so the attributes would stay unset).
|
|
(0, eval)(accessibilityBootScript());
|
|
expect(root().style.getPropertyValue('--font-size-base')).toBe('150%');
|
|
expect(root().dataset.contrast).toBe('more');
|
|
expect(root().dataset.motion).toBe('reduce');
|
|
});
|
|
|
|
it('does nothing without stored settings', () => {
|
|
(0, eval)(accessibilityBootScript());
|
|
expect(root().style.getPropertyValue('--font-size-base')).toBe('');
|
|
});
|
|
});
|
|
|
|
describe('allowed values', () => {
|
|
it('rejects values the stylesheet does not know', () => {
|
|
expect(isAllowedAccessibilityValue('fontSize', 'huge')).toBe(true);
|
|
expect(isAllowedAccessibilityValue('fontSize', 'enormous')).toBe(false);
|
|
expect(isAllowedAccessibilityValue('reduceMotion', true)).toBe(false);
|
|
expect(isAllowedAccessibilityValue('toastDuration', 7)).toBe(false);
|
|
expect(isAllowedAccessibilityValue('readAloudVoice', 'Anna')).toBe(true);
|
|
});
|
|
|
|
it('counts "until closed" as meeting any toast minimum', () => {
|
|
expect(toastDurationAtLeast(0, 20)).toBe(true);
|
|
expect(toastDurationAtLeast(10, 20)).toBe(false);
|
|
expect(toastDurationAtLeast(20, 20)).toBe(true);
|
|
});
|
|
});
|