Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
193 changes: 0 additions & 193 deletions src/components/Pagination.tsx
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file was broken into three modules which are in the (new) Pagination directory. This file became index.tsx, with pieces extracted to be utils.ts and hooks.ts

This file was deleted.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There were a couple of branches of code that were not getting test coverage. They do now.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { render } from '@testing-library/react';
import { Pagination, LinkForPage } from "./Pagination";
import { Pagination, LinkForPage } from ".";
import { range } from './utils';

describe('Pagination', () => {
let root: HTMLElement;
Expand All @@ -10,11 +11,11 @@ describe('Pagination', () => {
document.body.append(root);
});

it('matches snapshot', () => {
it('matches snapshot; default href is "#"', () => {
render(<Pagination
currentPage={1} totalPages={10}
Page={({ page, current }) =>
<LinkForPage page={page} current={current} href="#" />
<LinkForPage page={page} current={current} href="" />
}
/>, {container: root});
expect(document.body).toMatchSnapshot();
Expand All @@ -30,6 +31,17 @@ describe('Pagination', () => {
expect(document.body).toMatchSnapshot();
});

it('Shows paginationinfo', () => {
render(<Pagination
currentPage={5} totalPages={15} showFromEnd={1} showFromCurrent={1}
pageSize={5} totalItems={75}
Page={({ page, current }) =>
<LinkForPage page={page} current={current} href="#" />
}
/>, {container: root});
expect(document.querySelector('.pagination-info')?.textContent).toBe('21-25 of 75');
});

it('grows to min size', () => {
render(<Pagination
currentPage={1} totalPages={10} showFromEnd={1} showFromCurrent={1}
Expand Down Expand Up @@ -59,4 +71,20 @@ describe('Pagination', () => {
/>, {container: root});
expect(document.body).toMatchSnapshot();
});

// This is a special case in adjustRangesToMeetMinimum
it('expands middle range to the left', () => {
render(<Pagination
currentPage={4} totalPages={10}
Page={({ page, current }) =>
<LinkForPage page={page} current={current} href="#" />
}
/>, {container: root});
});
});

describe('Pagination/utils', () => {
it('bounds-checks range', () => {
expect(range(10, 5)).toEqual([]);
});
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import { Pagination, LinkForPage } from "./Pagination";
import { Pagination, LinkForPage } from ".";

export const Examples = () => {
const [currentPage, setCurrentPage] = React.useState(1);
Expand Down
Loading
Loading