|
1 | 1 | import { render, screen } from '@testing-library/react'; |
2 | 2 | import { MemoryRouter } from 'react-router-dom'; |
| 3 | +import { userEvent } from '@testing-library/user-event'; |
3 | 4 | import { List } from '../src/views/List'; |
4 | 5 | import { mockShoppingListData } from '../src/mocks/__fixtures__/shoppingListData'; |
5 | 6 | import { useStateWithStorage, useEnsureListPath } from '../src/hooks'; |
@@ -58,6 +59,23 @@ beforeEach(() => { |
58 | 59 | }); |
59 | 60 |
|
60 | 61 | 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 | + |
61 | 79 | test('renders the shopping list name, search field, and all list items from the data prop', () => { |
62 | 80 | render( |
63 | 81 | <MemoryRouter> |
@@ -108,18 +126,4 @@ describe('List Component', () => { |
108 | 126 | '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.', |
109 | 127 | ); |
110 | 128 | }); |
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 | | - }); |
125 | 129 | }); |
0 commit comments