mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-09-10 02:25:56 +00:00
test(web): preserve toast announcement and focus semantics
Recovery feedback must remain available without stealing keyboard focus. Cover existing error/warning and success/info live-region distinctions, atomic contextual text and retained focus through the public toast entry point. This protects accessibility behaviour without adding product scope; DOM assertions do not establish screen-reader acceptance. Change-source: pulse-maintainer
This commit is contained in:
@@ -11,6 +11,27 @@ describe('Toast', () => {
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
it.each([
|
||||
['error', 'alert', 'assertive'],
|
||||
['warning', 'alert', 'assertive'],
|
||||
['success', 'status', 'polite'],
|
||||
['info', 'status', 'polite'],
|
||||
] as const)('preserves %s announcement semantics without moving focus', (type, role, live) => {
|
||||
render(() => <><button>Recovery action</button><ToastContainer /></>);
|
||||
const action = screen.getByRole('button', { name: 'Recovery action' });
|
||||
action.focus();
|
||||
|
||||
window.showToast(type, 'Recovery result', 'Action context');
|
||||
|
||||
const announcement = screen.getByRole(role);
|
||||
expect(announcement).toHaveAttribute('aria-live', live);
|
||||
expect(announcement).toHaveAttribute('aria-atomic', 'true');
|
||||
expect(announcement).toHaveTextContent('Recovery result');
|
||||
expect(announcement).toHaveTextContent('Action context');
|
||||
expect(action).toHaveFocus();
|
||||
expect(screen.queryByRole(role === 'alert' ? 'status' : 'alert')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('keeps all toasts created within a batch', () => {
|
||||
render(() => <ToastContainer />);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user