|
1 | 1 | import React from 'react';
|
2 | 2 | import { render, screen } from '@testing-library/react';
|
3 | 3 | import { PaginationControl } from '../PaginationControl';
|
4 |
| -import { useControlsContext } from '../context'; |
| 4 | +import { usePagination } from '../hooks/usePagination'; |
5 | 5 | import { useResolvedComposable } from '../hooks/useResolvedComposable';
|
6 | 6 |
|
7 |
| -jest.mock('../context'); |
| 7 | +jest.mock('../hooks/usePagination'); |
8 | 8 | jest.mock('../hooks/useResolvedComposable');
|
| 9 | +jest.mock('../../composables/Pagination', () => ({ |
| 10 | + Pagination: () => <div data-testid="pagination" />, |
| 11 | +})); |
9 | 12 |
|
10 | 13 | describe('PaginationControl', () => {
|
11 |
| - // assert mocks |
12 |
| - const mockUseControlsContext = useControlsContext as jest.Mock; |
13 |
| - const mockUseResolvedComposable = useResolvedComposable as jest.Mock; |
| 14 | + const mockUsePagination = jest.mocked(usePagination); |
| 15 | + const mockUseResolvedComposable = jest.mocked(useResolvedComposable); |
14 | 16 |
|
15 | 17 | beforeAll(() => {
|
16 | 18 | mockUseResolvedComposable.mockImplementation(
|
17 |
| - (component: React.JSX.Element) => component |
| 19 | + (component) => component as () => React.JSX.Element |
18 | 20 | );
|
19 | 21 | });
|
20 | 22 |
|
21 | 23 | afterEach(() => {
|
22 |
| - mockUseControlsContext.mockReset(); |
23 |
| - mockUseResolvedComposable.mockReset(); |
| 24 | + mockUsePagination.mockClear(); |
24 | 25 | });
|
25 | 26 |
|
26 |
| - it('renders the PaginationControl', async () => { |
27 |
| - mockUseControlsContext.mockReturnValue({ |
28 |
| - data: { |
29 |
| - paginationData: { |
30 |
| - hasNextPage: true, |
31 |
| - highestPageVisited: 1, |
32 |
| - onPaginate: jest.fn(), |
33 |
| - page: 1, |
34 |
| - }, |
35 |
| - }, |
36 |
| - }); |
37 |
| - |
| 27 | + it('renders', () => { |
38 | 28 | render(<PaginationControl />);
|
39 | 29 |
|
40 |
| - const nav = screen.getByRole('navigation'); |
41 |
| - const list = screen.getByRole('list'); |
42 |
| - const listItems = await screen.findAllByRole('listitem'); |
43 |
| - const nextButton = screen.getByRole('button', { name: 'Go to next page' }); |
44 |
| - const prevButton = screen.getByRole('button', { |
45 |
| - name: 'Go to previous page', |
46 |
| - }); |
47 |
| - const nextIcon = nextButton.querySelector('svg'); |
48 |
| - const prevIcon = nextButton.querySelector('svg'); |
| 30 | + const pagination = screen.getByTestId('pagination'); |
49 | 31 |
|
50 |
| - expect(nextButton).toBeInTheDocument(); |
51 |
| - expect(prevButton).toBeInTheDocument(); |
52 |
| - expect(nextIcon).toBeInTheDocument(); |
53 |
| - expect(prevIcon).toBeInTheDocument(); |
54 |
| - expect(nextIcon).toHaveAttribute('aria-hidden', 'true'); |
55 |
| - expect(prevIcon).toHaveAttribute('aria-hidden', 'true'); |
56 |
| - expect(nav).toBeInTheDocument(); |
57 |
| - expect(list).toBeInTheDocument(); |
58 |
| - expect(listItems).toHaveLength(3); |
| 32 | + expect(pagination).toBeInTheDocument(); |
59 | 33 | });
|
60 | 34 | });
|
0 commit comments