2020-08-28 21:05:01 +03:00
|
|
|
import { shallow, ShallowWrapper } from 'enzyme';
|
2019-09-22 12:14:08 +03:00
|
|
|
import { identity } from 'ramda';
|
|
|
|
import { PaginationItem } from 'reactstrap';
|
2020-03-28 19:25:12 +03:00
|
|
|
import SimplePaginator from '../../src/common/SimplePaginator';
|
2020-03-28 19:33:23 +03:00
|
|
|
import { ELLIPSIS } from '../../src/utils/helpers/pagination';
|
2019-09-22 12:14:08 +03:00
|
|
|
|
|
|
|
describe('<SimplePaginator />', () => {
|
2020-08-28 21:05:01 +03:00
|
|
|
let wrapper: ShallowWrapper;
|
|
|
|
const createWrapper = (pagesCount: number, currentPage = 1) => {
|
2019-09-22 12:14:08 +03:00
|
|
|
wrapper = shallow(<SimplePaginator pagesCount={pagesCount} currentPage={currentPage} setCurrentPage={identity} />);
|
|
|
|
|
|
|
|
return wrapper;
|
|
|
|
};
|
|
|
|
|
2020-08-28 21:05:01 +03:00
|
|
|
afterEach(() => wrapper?.unmount());
|
2019-09-22 12:14:08 +03:00
|
|
|
|
2020-02-17 20:21:52 +03:00
|
|
|
it.each([ -3, -2, 0, 1 ])('renders empty when the amount of pages is smaller than 2', (pagesCount) => {
|
2019-09-22 12:14:08 +03:00
|
|
|
expect(createWrapper(pagesCount).text()).toEqual('');
|
|
|
|
});
|
|
|
|
|
2020-03-28 19:19:33 +03:00
|
|
|
describe('ELLIPSIS are rendered where expected', () => {
|
2020-08-28 21:05:01 +03:00
|
|
|
const getItemsForPages = (pagesCount: number, currentPage: number) => {
|
2019-09-22 12:14:08 +03:00
|
|
|
const paginator = createWrapper(pagesCount, currentPage);
|
|
|
|
const items = paginator.find(PaginationItem);
|
2020-08-28 21:05:01 +03:00
|
|
|
const itemsWithEllipsis = items.filterWhere((item) => item?.key()?.includes(ELLIPSIS));
|
2019-09-22 12:14:08 +03:00
|
|
|
|
|
|
|
return { items, itemsWithEllipsis };
|
|
|
|
};
|
|
|
|
|
2020-03-28 19:19:33 +03:00
|
|
|
it('renders first ELLIPSIS', () => {
|
2019-09-22 12:14:08 +03:00
|
|
|
const { items, itemsWithEllipsis } = getItemsForPages(9, 7);
|
|
|
|
|
2020-03-28 19:19:33 +03:00
|
|
|
expect(items.at(2).html()).toContain(ELLIPSIS);
|
2019-09-22 12:14:08 +03:00
|
|
|
expect(itemsWithEllipsis).toHaveLength(1);
|
|
|
|
});
|
|
|
|
|
2020-03-28 19:19:33 +03:00
|
|
|
it('renders last ELLIPSIS', () => {
|
2019-09-22 12:14:08 +03:00
|
|
|
const { items, itemsWithEllipsis } = getItemsForPages(9, 2);
|
|
|
|
|
2020-03-28 19:19:33 +03:00
|
|
|
expect(items.at(items.length - 3).html()).toContain(ELLIPSIS);
|
2019-09-22 12:14:08 +03:00
|
|
|
expect(itemsWithEllipsis).toHaveLength(1);
|
|
|
|
});
|
|
|
|
|
2020-03-28 19:19:33 +03:00
|
|
|
it('renders both ELLIPSIS', () => {
|
2019-09-22 12:14:08 +03:00
|
|
|
const { items, itemsWithEllipsis } = getItemsForPages(20, 9);
|
|
|
|
|
2020-03-28 19:19:33 +03:00
|
|
|
expect(items.at(2).html()).toContain(ELLIPSIS);
|
|
|
|
expect(items.at(items.length - 3).html()).toContain(ELLIPSIS);
|
2019-09-22 12:14:08 +03:00
|
|
|
expect(itemsWithEllipsis).toHaveLength(2);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|