Files
LocalMind/__tests__/ChatInput.test.tsx
evandro b441339bb4 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.
2026-10-10 04:29:33 -03:00

40 lines
1.6 KiB
TypeScript

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('');
});
});