Fakultas Ilmu Komputer UI

VacancyList-test.jsx 1.99 KB
Newer Older
1
2
3
4
/* eslint-disable no-unused-expressions */
import React from 'react';
import ReactTestUtils from 'react-addons-test-utils';
import VacancyList from '../../components/VacancyList';
5
import Server from '../../lib/Server';
6

7
describe('VacancyList', () => {
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
  const fetchMock = require('fetch-mock');
  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: 3,
    name: 'Software Engineer',
    open_time: '2017-03-28T05:55:38Z',
    updated: '2017-03-28T07:34:13.122093Z',
    verified: true,
  }];
25
  // const response2 = { hello: 'not-world' };
26
27

  it('renders without problem', () => {
28
    fetchMock.get('*', response);
29
    const vacancyList = ReactTestUtils.renderIntoDocument(
30
      <VacancyList studentId={1} url="test" />);
31
    expect(vacancyList).to.exist;
32
  });
33

34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
  it('update bookmarks without problem', () => {
    fetchMock.get('*', response);
    const vacancyList = ReactTestUtils.renderIntoDocument(
      <VacancyList studentId={1} url="test" />);
    vacancyList.updateBookmarkList();
    expect(JSON.stringify(vacancyList.state.bookmarkList)).to.be.defined;
  });

  it('renders marked bookmarked vacancies without problem', () => {
    fetchMock.get('*', response);
    const vacancyList = ReactTestUtils.renderIntoDocument(
      <VacancyList studentId={1} url="test" />);
    vacancyList.state.vacancies = response;
    vacancyList.state.bookmarkList = [{id: 5}, {id: 3}];
    expect(vacancyList.generateVacancies()).to.exist;
  });

51
52
53
  it('success calling API', () => {
    fetchMock.get('*', response);
    const vacancyList = ReactTestUtils.renderIntoDocument(
54
      <VacancyList studentId={1} url="test" />);
55
56
57
    vacancyList.state.vacancies = response;
    expect(JSON.stringify(vacancyList.state.vacancies)).to.equal(JSON.stringify(response));
    expect(vacancyList.generateVacancies()).to.exist;
58
59
    });
  });
60