import { screen, render, fireEvent } from '@testing-library/react';
import MainSearch from '../main-search';
describe('MainSearch component', () => {
const handleSubmit = jest.fn();
const handleChange = jest.fn();
const props = {
onTextChange: handleChange,
onSubmit: handleSubmit,
};
const namespaces = { one: 'One', two: 'Two', three: 'Three' };
it('should render', () => {
const { asFragment } = render();
expect(asFragment()).toMatchSnapshot();
});
it('should render with namespaces selector', () => {
const { asFragment } = render(
);
expect(asFragment()).toMatchSnapshot();
});
it('should submit the search term', () => {
render();
fireEvent.submit(screen.getByRole('form'));
expect(handleSubmit).toHaveBeenCalled();
});
it('should detect the search term', () => {
render();
fireEvent.change(screen.getByRole('searchbox'), {
target: { value: 'foo' },
});
expect(handleChange).toHaveBeenCalledWith('foo');
});
it('should set searchTerm', () => {
render();
expect((screen.getByRole('searchbox') as HTMLInputElement).value).toBe(
'blah'
);
});
});