Skip to content

Commit 9726593

Browse files
author
Nika Kolesnikova
committed
test: introduce ListItem test that ensures that additional information is being displayed upon clicking More Information button
1 parent 27664fc commit 9726593

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

tests/ListItem.test.jsx

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { render, screen } from '@testing-library/react';
2+
import { MemoryRouter } from 'react-router-dom';
3+
import { userEvent } from '@testing-library/user-event';
4+
import { ListItem } from '../src/components/ListItem';
5+
import { mockShoppingListData } from '../src/mocks/__fixtures__/shoppingListData';
6+
7+
describe('ListItem Component', () => {
8+
test('displays additional item information if More Information button is clicked', async () => {
9+
render(
10+
<MemoryRouter>
11+
<ListItem
12+
item={mockShoppingListData[1]}
13+
listPath={'/groceries'}
14+
itemUrgencyStatus="overdue"
15+
/>
16+
</MemoryRouter>,
17+
);
18+
19+
const moreInformationIcon = screen.getByTestId('MoreHorizIcon');
20+
await userEvent.click(moreInformationIcon);
21+
22+
expect(screen.getByText(mockShoppingListData[1].name)).toBeInTheDocument();
23+
expect(
24+
screen.getByText(
25+
`Item added on: ${mockShoppingListData[1].dateCreated.toDate().toLocaleString()}`,
26+
),
27+
).toBeInTheDocument();
28+
expect(
29+
screen.getByText(
30+
`Last bought on: ${mockShoppingListData[1].dateLastPurchased.toDate().toLocaleString()}`,
31+
),
32+
).toBeInTheDocument();
33+
expect(
34+
screen.getByText(
35+
`Expected to buy again by: ${mockShoppingListData[1].dateNextPurchased.toDate().toLocaleString()}`,
36+
),
37+
).toBeInTheDocument();
38+
});
39+
});

0 commit comments

Comments
 (0)