From b1600adec47a04f60e1da07d94a3ed3906ff5aee Mon Sep 17 00:00:00 2001 From: Wes Bos Date: Thu, 14 Jun 2018 16:44:21 -0400 Subject: starter files --- .../frontend/__tests__/Pagination.test.js | 94 ++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 finished-application/frontend/__tests__/Pagination.test.js (limited to 'finished-application/frontend/__tests__/Pagination.test.js') diff --git a/finished-application/frontend/__tests__/Pagination.test.js b/finished-application/frontend/__tests__/Pagination.test.js new file mode 100644 index 0000000..29a57f9 --- /dev/null +++ b/finished-application/frontend/__tests__/Pagination.test.js @@ -0,0 +1,94 @@ +import React from 'react'; +import { shallow, mount } from 'enzyme'; +import toJSON from 'enzyme-to-json'; +import Pagination, { PAGINATION_QUERY } from '../components/Pagination'; +import { MockedProvider } from 'react-apollo/test-utils'; +import wait from 'waait'; +import { fakeItem } from '../lib/testUtils'; + +import Router from 'next/router'; + +// mock the router because there isn't really a router instance +Router.router = { push() {}, prefetch() {} }; + +function makeMocksFor(length) { + return [ + { + request: { query: PAGINATION_QUERY, variables: { skip: 0, first: 4 } }, + result: { + data: { + itemsConnection: { + __typename: 'aggregate', + aggregate: { + count: length, + __typename: 'count', + }, + }, + }, + }, + }, + ]; +} + +describe('', () => { + it('displays loading message', async () => { + const wrapper = mount( + + + + ); + await wait(); + wrapper.update(); + expect(toJSON(wrapper.find('div[data-test="pagination"]'))).toMatchSnapshot(); + }); + + it('renders pagination for 18 items', async () => { + const wrapper = mount( + + + + ); + await wait(); + wrapper.update(); + expect(wrapper.find('.totalPages').text()).toEqual('5'); + }); + + it('disables prev button on first page', async () => { + const wrapper = mount( + + + + ); + await wait(); + wrapper.update(); + // first page + expect(wrapper.find('a.prev').prop('aria-disabled')).toEqual(true); + expect(wrapper.find('a.next').prop('aria-disabled')).toEqual(false); + }); + + it('disables next button on last page', async () => { + const wrapper = mount( + + + + ); + await wait(); + wrapper.update(); + // first page + expect(wrapper.find('a.prev').prop('aria-disabled')).toEqual(false); + expect(wrapper.find('a.next').prop('aria-disabled')).toEqual(true); + }); + + it('enables all buttons on a middle page', async () => { + const wrapper = mount( + + + + ); + await wait(); + wrapper.update(); + // first page + expect(wrapper.find('a.prev').prop('aria-disabled')).toEqual(false); + expect(wrapper.find('a.next').prop('aria-disabled')).toEqual(false); + }); +}); -- cgit v1.3