Skip to content

Commit

Permalink
fix: test case
Browse files Browse the repository at this point in the history
  • Loading branch information
riddhybansal committed Oct 21, 2024
1 parent 4345adb commit 5932df9
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions packages/react/src/components/PaginationNav/PaginationNav-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,38 @@ describe('PaginationNav', () => {
expect(screen.getByText('4')).toHaveAttribute('aria-current', 'page');
});

it('should not hide page 1 when active page is 0', () => {
render(<PaginationNav totalItems={4} page={0} />);
it('should render PaginationNav correctly and navigate through different page ranges using select elements', async () => {
render(<PaginationNav totalItems={10} itemsShown={4} />);

// Initial state: < 1 2 ... 10 >
expect(screen.getByText('1')).toHaveAttribute('aria-current', 'page');
expect(screen.getByText('2')).toBeInTheDocument();
expect(screen.getByText('10')).toBeInTheDocument();

let selectElements = screen.getAllByLabelText('Select Page number');
expect(selectElements).toHaveLength(1);

// Select page 6 from the dropdown
await userEvent.selectOptions(selectElements[0], '6');

// New state: < ... 6 ... 10 >
expect(screen.getByText('6')).toHaveAttribute('aria-current', 'page');

// Check for two select elements in this state
selectElements = screen.getAllByLabelText('Select Page number');
expect(selectElements).toHaveLength(2);

// Select page 1 from the first dropdown
await userEvent.selectOptions(selectElements[0], '1');

// Final state: < 1 2 ... 10 >
expect(screen.getByText('1')).toHaveAttribute('aria-current', 'page');
expect(screen.getByText('2')).toBeInTheDocument();
expect(screen.getByText('10')).toBeInTheDocument();

expect(screen.getByText('1')).toBeInTheDocument();
// Check that we're back to one select element
selectElements = screen.getAllByLabelText('Select Page number');
expect(selectElements).toHaveLength(1);
});
});
});

0 comments on commit 5932df9

Please sign in to comment.