diff --git a/src/components/Pagination/Pagination.test.tsx b/src/components/Pagination/Pagination.test.tsx new file mode 100644 index 00000000..222917f3 --- /dev/null +++ b/src/components/Pagination/Pagination.test.tsx @@ -0,0 +1,40 @@ +import '@testing-library/jest-dom'; +import { fireEvent, render, screen, waitFor } from '@testing-library/react'; +import { Pagination } from './Pagination'; + +describe('', () => { + it('displays pagination controls when provided', () => { + render(); + const next = screen.getByText('Next'); + expect(next).toBeInTheDocument(); + + const prev = screen.getByText('Previous'); + expect(prev).toBeInTheDocument(); + }); + + it('disables previous button on first page', () => { + render(); + const prev = screen.getByText('Previous'); + expect(prev.classList.contains('a-btn__disabled')).toBe(true); + }); + + it('disables next button on last page', () => { + render(); + const next = screen.getByText('Next'); + expect(next.classList.contains('a-btn__disabled')).toBe(true); + }); + + it('goes to page on submit', () => { + render(); + const next = screen.getByText('Next'); + const input = screen.getByDisplayValue('2'); + const go = screen.getByText('Go'); + + fireEvent.change(input, { target: { value: '3' } }); + fireEvent.click(go); + + waitFor(() => { + expect(next.classList.contains('a-btn__disabled')).toBe(true); + }); + }); +});