From 9979eddbcdfabad4ebc8c2063145a078ac49adbb Mon Sep 17 00:00:00 2001 From: Jake McDermott Date: Sun, 18 Nov 2018 21:56:08 -0500 Subject: [PATCH] add basic component test for pagination --- __tests__/components/Pagination.test.jsx | 72 ++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 __tests__/components/Pagination.test.jsx diff --git a/__tests__/components/Pagination.test.jsx b/__tests__/components/Pagination.test.jsx new file mode 100644 index 0000000000..7158c04471 --- /dev/null +++ b/__tests__/components/Pagination.test.jsx @@ -0,0 +1,72 @@ +import React from 'react'; +import { mount } from 'enzyme'; +import Pagination from '../../src/components/Pagination'; + +describe('', () => { + const noop = () => {}; + + let pagination; + + afterEach(() => { + if (toolbar) { + 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( + + ); + + 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( + + ); + + 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); + }); +});