Fakultas Ilmu Komputer UI

Pagination-test.jsx 3.23 KB
Newer Older
1
2
3
4
/* eslint-disable no-unused-expressions */
import React from 'react';
import ReactTestUtils from 'react-addons-test-utils';
import fetchMock from 'fetch-mock';
5
import Pagination from '../../components/Pagination';
6
7

describe('Pagination', () => {
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
  const response = {
    items: [{
            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,
          },
          ],
    next:'/next',
  };
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72

  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" />);
73
74
75
76
77
78
79
80
81
82
    pagination.getItemsData().then(() =>
      expect(JSON.stringify(pagination.state.items)).to.equal(JSON.stringify(response.items)));
    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;
83
84
85
    fetchMock.restore();
  });

86
  it('can go prev without problem', () => {
87
88
    fetchMock.get('*', response);
    const pagination = ReactTestUtils.renderIntoDocument(
89
90
91
      <Pagination child={<div />} url="test" />);
    const prev = ReactTestUtils.scryRenderedDOMComponentsWithTag(pagination, 'a')[0];
    ReactTestUtils.Simulate.click(prev);
92
93
94
    fetchMock.restore();
  });

95
96
  it('can go next without problem', () => {
    fetchMock.get('*', response);
97
98
    const pagination = ReactTestUtils.renderIntoDocument(
      <Pagination child={<div />} url="test" />);
99
100
    const next = ReactTestUtils.scryRenderedDOMComponentsWithTag(pagination, 'a')[2];
    ReactTestUtils.Simulate.click(next);
101
102
103
104
    fetchMock.restore();
  });
});