awx/__tests__/components/Pagination.test.jsx
2018-12-10 10:17:00 -05:00

76 lines
1.8 KiB
JavaScript

import React from 'react';
import { mount } from 'enzyme';
import { I18nProvider } from '@lingui/react';
import Pagination from '../../src/components/Pagination';
describe('<Pagination />', () => {
let pagination;
afterEach(() => {
if (pagination) {
pagination.unmount();
pagination = null;
}
});
test('it triggers the expected callbacks on next and last', () => {
const next = 'button[aria-label="Next"]';
const last = 'button[aria-label="Last"]';
const onSetPage = jest.fn();
pagination = mount(
<I18nProvider>
<Pagination
count={21}
page={1}
pageCount={5}
page_size={5}
pageSizeOptions={[5, 10, 25, 50]}
onSetPage={onSetPage}
/>
</I18nProvider>
);
pagination.find(next).simulate('click');
expect(onSetPage).toHaveBeenCalledTimes(1);
expect(onSetPage).toBeCalledWith(2, 5);
pagination.find(last).simulate('click');
expect(onSetPage).toHaveBeenCalledTimes(2);
expect(onSetPage).toBeCalledWith(5, 5);
});
test('it triggers the expected callback on previous and first', () => {
const previous = 'button[aria-label="Previous"]';
const first = 'button[aria-label="First"]';
const onSetPage = jest.fn();
pagination = mount(
<I18nProvider>
<Pagination
count={21}
page={5}
pageCount={5}
page_size={5}
pageSizeOptions={[5, 10, 25, 50]}
onSetPage={onSetPage}
/>
</I18nProvider>
);
pagination.find(previous).simulate('click');
expect(onSetPage).toHaveBeenCalledTimes(1);
expect(onSetPage).toBeCalledWith(4, 5);
pagination.find(first).simulate('click');
expect(onSetPage).toHaveBeenCalledTimes(2);
expect(onSetPage).toBeCalledWith(1, 5);
});
});