From 93537587ca115853eb2d5fd064e14aa9899a1756 Mon Sep 17 00:00:00 2001 From: "M. Reza Qorib" <rezaqorib96@gmail.com> Date: Wed, 3 May 2017 22:32:50 +0700 Subject: [PATCH] [#144502159] [Red] #37 create test for Pagination component --- .../__test__/components/Pagination-test.jsx | 93 +++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 assets/js/__test__/components/Pagination-test.jsx diff --git a/assets/js/__test__/components/Pagination-test.jsx b/assets/js/__test__/components/Pagination-test.jsx new file mode 100644 index 00000000..54804bfd --- /dev/null +++ b/assets/js/__test__/components/Pagination-test.jsx @@ -0,0 +1,93 @@ +/* eslint-disable no-unused-expressions */ +import React from 'react'; +import ReactTestUtils from 'react-addons-test-utils'; +import fetchMock from 'fetch-mock'; +import List from '../../components/Pagination' +import VacancyList from '../../components/VacancyList' + +describe('Pagination', () => { + const response = [{ + close_time: '2019-03-28T05:55:42Z', + company: { + address: 'kebayoran baru', + id: 1, + logo: null, + name: 'tutup lapak', + }, + created: '2017-03-28T07:05:47.128672Z', + description: 'Lorem ipsum dolbh.', + id: 1, + name: 'Software Engineer', + open_time: '2017-03-28T05:55:38Z', + updated: '2017-03-28T07:34:13.122093Z', + verified: true, + }, { + close_time: '2019-03-28T05:55:42Z', + company: { + address: 'kebayoran baru', + id: 2, + logo: null, + name: 'tutup lapak', + }, + created: '2017-03-28T07:05:47.128672Z', + description: 'Lorem ipsum dolbh.', + id: 2, + name: 'Software Engineer', + open_time: '2017-03-28T05:55:38Z', + updated: '2017-03-28T07:34:13.122093Z', + verified: true, + }]; + + const response2 = [{ + close_time: '2019-03-28T05:55:42Z', + company: { + address: 'kebayoran baru', + id: 1, + logo: null, + name: 'tutup lapak', + }, + created: '2017-03-28T07:05:47.128672Z', + description: 'Lorem ipsum dolbh.', + id: 2, + name: 'Software Engineer', + open_time: '2017-03-28T05:55:38Z', + updated: '2017-03-28T07:34:13.122093Z', + verified: true, + }]; + + it('renders without problem', () => { + fetchMock.get('*', response); + const pagination = ReactTestUtils.renderIntoDocument( + <Pagination child={<div />} url="test" />); + expect(pagination).to.exist; + fetchMock.restore(); + }); + + it('get items without problem', () => { + fetchMock.get('*', response); + const pagination = ReactTestUtils.renderIntoDocument( + <Pagination child={<div />} url="test" />); + pagination.getItemsData(); + expect(pagination.state.items).to.equal(response); + fetchMock.restore(); + }); + + it('generate child components without problem', () => { + fetchMock.get('*', response); + const child = <VacancyList url="" userId=""/> + const pagination = ReactTestUtils.renderIntoDocument( + <Pagination child={child} url="test" />); + const childRendered = ReactTestUtils.findRenderedDOMComponentWithTag(pagination, child); + expect(childRendered).to,exist; + fetchMock.restore(); + }); + + it('renders without problem when failed getting data', () => { + fetchMock.get('*', 400); + const pagination = ReactTestUtils.renderIntoDocument( + <Pagination child={<div />} url="test" />); + expect(pagination).to.exist; + fetchMock.restore(); + }); +}); + -- GitLab