@eureca/eureca-ui
Version:
UI component library of Eureca's user and admin apps
50 lines (41 loc) • 2.05 kB
JavaScript
import React from 'react';
import { List } from '..';
import { render, fireEvent } from '@testing-library/react';
const mockFunction = jest.fn().mockImplementation(value => value);
function renderList(props) {
return render(<List {...props} />);
}
describe('List component', () => {
it('create a new question', () => {
const { getByTestId } = renderList({ updateList: mockFunction });
const addNewQuestionInput = getByTestId('add-question-testid');
fireEvent.click(addNewQuestionInput);
expect(mockFunction).toReturnWith(['', '']);
});
it('update the question in the right index', () => {
const { getByTestId, getAllByTestId } = renderList({ updateList: mockFunction });
const addNewQuestionInput = getByTestId('add-question-testid');
fireEvent.change(getAllByTestId('input-testid')[0], { target: { value: 'Edward' } });
expect(mockFunction).toReturnWith(['Edward']);
fireEvent.click(addNewQuestionInput);
fireEvent.change(getAllByTestId('input-testid')[1], { target: { value: 'Alphonse' } });
expect(mockFunction).toReturnWith(['Edward', 'Alphonse']);
});
it('show the close button when hovered', () => {
const { getAllByTestId } = renderList({ updateList: mockFunction });
const [input] = getAllByTestId('input-testid');
fireEvent.mouseOver(input);
expect(getAllByTestId('close-testid')[0]).toBeDefined();
});
it('remove a item of the list', () => {
const { getByTestId, getAllByTestId } = renderList({ updateList: mockFunction });
fireEvent.change(getAllByTestId('input-testid')[0], { target: { value: 'Edward' } });
expect(mockFunction).toReturnWith(['Edward']);
fireEvent.click(getByTestId('add-question-testid'));
fireEvent.change(getAllByTestId('input-testid')[1], { target: { value: 'Alphonse' } });
expect(mockFunction).toReturnWith(['Edward', 'Alphonse']);
fireEvent.mouseOver(getAllByTestId('input-testid')[0]);
fireEvent.click(getByTestId('close-testid'));
expect(mockFunction).toReturnWith(['Alphonse']);
});
});