Skip to content

Commit 8a90574

Browse files
author
Nika Kolesnikova
committed
test: update List test to be able to click on a New Item button
1 parent e8d4d27 commit 8a90574

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

tests/List.test.jsx

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { render, screen } from '@testing-library/react';
22
import { MemoryRouter } from 'react-router-dom';
3+
import { userEvent } from '@testing-library/user-event';
34
import { List } from '../src/views/List';
45
import { mockShoppingListData } from '../src/mocks/__fixtures__/shoppingListData';
56
import { useStateWithStorage, useEnsureListPath } from '../src/hooks';
@@ -58,6 +59,23 @@ beforeEach(() => {
5859
});
5960

6061
describe('List Component', () => {
62+
test('shows AddItems component with existing items', async () => {
63+
render(
64+
<MemoryRouter>
65+
<List data={mockShoppingListData} listPath={'/groceries'} />
66+
</MemoryRouter>,
67+
);
68+
69+
const dropDownIcon = await screen.findByTestId('new-item-button');
70+
await userEvent.click(dropDownIcon);
71+
72+
expect(screen.getByLabelText('Add item:')).toBeInTheDocument();
73+
expect(screen.getByLabelText('Soon')).toBeInTheDocument();
74+
expect(screen.getByLabelText('Kind of soon')).toBeInTheDocument();
75+
expect(screen.getByLabelText('Not soon')).toBeInTheDocument();
76+
expect(screen.getByText('Submit')).toBeInTheDocument();
77+
});
78+
6179
test('renders the shopping list name, search field, and all list items from the data prop', () => {
6280
render(
6381
<MemoryRouter>
@@ -108,18 +126,4 @@ describe('List Component', () => {
108126
'It seems like you landed here without first creating a list or selecting an existing one. Please select or create a new list first. Redirecting to Home.',
109127
);
110128
});
111-
112-
test('shows AddItems component with existing items', () => {
113-
render(
114-
<MemoryRouter>
115-
<List data={mockShoppingListData} listPath={'/groceries'} />
116-
</MemoryRouter>,
117-
);
118-
119-
expect(screen.getByLabelText('Item Name:')).toBeInTheDocument();
120-
expect(screen.getByLabelText('Soon')).toBeInTheDocument();
121-
expect(screen.getByLabelText('Kind of soon')).toBeInTheDocument();
122-
expect(screen.getByLabelText('Not soon')).toBeInTheDocument();
123-
expect(screen.getByText('Submit')).toBeInTheDocument();
124-
});
125129
});

0 commit comments

Comments
 (0)