feat(a11y): label icon-only buttons and inputs for screen readers
Header, message action, send/stop, history, model selector and dark-mode controls had no accessible name (icon-only buttons). Adds roles/labels and selected/disabled state; no visual change.
This commit is contained in:
1 parent
0e5b38fd15
commit
b441339bb4
8 files changed
+84
-7
No files matched your search
@@ -0,0 +1,39 @@
|
||||
import { fireEvent, render, screen } from '@testing-library/react-native';
|
||||
import React from 'react';
|
||||
import { ChatInput } from '../components/chat/ChatInput';
|
||||
|
||||
describe('ChatInput', () => {
|
||||
it('sends trimmed text, clears the field and disables send while empty', () => {
|
||||
const onSend = jest.fn();
|
||||
render(<ChatInput onSend={onSend} />);
|
||||
|
||||
expect(screen.getByLabelText('Send message').props.accessibilityState.disabled).toBe(true);
|
||||
|
||||
fireEvent.changeText(screen.getByLabelText('Message'), ' hello ');
|
||||
fireEvent.press(screen.getByLabelText('Send message'));
|
||||
|
||||
expect(onSend).toHaveBeenCalledWith('hello');
|
||||
expect(screen.getByLabelText('Message').props.value).toBe('');
|
||||
});
|
||||
|
||||
it('shows a stop button instead of send while loading', () => {
|
||||
const onStop = jest.fn();
|
||||
render(<ChatInput onSend={jest.fn()} onStop={onStop} isLoading />);
|
||||
|
||||
expect(screen.queryByLabelText('Send message')).toBeNull();
|
||||
fireEvent.press(screen.getByLabelText('Stop generating'));
|
||||
expect(onStop).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('fills the field when editing and lets the user cancel', () => {
|
||||
const onCancelEdit = jest.fn();
|
||||
render(<ChatInput onSend={jest.fn()} editingText="old text" onCancelEdit={onCancelEdit} />);
|
||||
|
||||
expect(screen.getByText('Editing message')).toBeTruthy();
|
||||
expect(screen.getByLabelText('Message').props.value).toBe('old text');
|
||||
|
||||
fireEvent.press(screen.getByLabelText('Cancel editing'));
|
||||
expect(onCancelEdit).toHaveBeenCalledTimes(1);
|
||||
expect(screen.getByLabelText('Message').props.value).toBe('');
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user