Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Fix act errors in CollectionControl test #21421

Merged
merged 1 commit into from
Sep 10, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -85,49 +85,58 @@ const createProps = () => ({
value: [{ key: 'hrYAZ5iBH' }],
});

test('Should render', () => {
test('Should render', async () => {
const props = createProps();
render(<CollectionControl {...props} />);
expect(screen.getByTestId('CollectionControl')).toBeInTheDocument();
expect(await screen.findByTestId('CollectionControl')).toBeInTheDocument();
});

test('Should show the button with the label', () => {
test('Should show the button with the label', async () => {
const props = createProps();
render(<CollectionControl {...props} />);
expect(screen.getByRole('button', { name: props.label })).toBeInTheDocument();
expect(
await screen.findByRole('button', { name: props.label }),
).toBeInTheDocument();
expect(screen.getByRole('button', { name: props.label })).toHaveTextContent(
props.label,
);
});

test('Should have add button', () => {
test('Should have add button', async () => {
const props = createProps();
render(<CollectionControl {...props} />);

expect(
await screen.findByRole('button', { name: 'plus-large' }),
).toBeInTheDocument();
expect(props.onChange).toBeCalledTimes(0);
userEvent.click(screen.getByRole('button', { name: 'plus-large' }));
expect(props.onChange).toBeCalledWith([{ key: 'hrYAZ5iBH' }, undefined]);
});

test('Should have remove button', () => {
test('Should have remove button', async () => {
const props = createProps();
render(<CollectionControl {...props} />);

expect(
await screen.findByRole('button', { name: 'remove-item' }),
).toBeInTheDocument();
expect(props.onChange).toBeCalledTimes(0);
userEvent.click(screen.getByRole('button', { name: 'remove-item' }));
expect(props.onChange).toBeCalledWith([]);
});

test('Should have SortableDragger icon', () => {
test('Should have SortableDragger icon', async () => {
const props = createProps();
render(<CollectionControl {...props} />);
expect(screen.getByLabelText('drag')).toBeVisible();
expect(await screen.findByLabelText('drag')).toBeVisible();
});

test('Should call Control component', () => {
test('Should call Control component', async () => {
const props = createProps();
render(<CollectionControl {...props} />);

expect(await screen.findByTestId('TestControl')).toBeInTheDocument();
expect(props.onChange).toBeCalledTimes(0);
userEvent.click(screen.getByTestId('TestControl'));
expect(props.onChange).toBeCalledWith([{ key: 'hrYAZ5iBH' }]);
Expand Down