Fakultas Ilmu Komputer UI

ApplicantList-test.jsx 2.49 KB
Newer Older
1
2
3
4
5
6
7
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
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import React from 'react';
import ReactTestUtils from 'react-addons-test-utils';
import fetchMock from 'fetch-mock';
import ApplicantList from '../../components/ApplicantList';
import Applicant from '../../components/Applicant';

describe('ApplicantList', () => {

  const vacancy = {
    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,
  }

  const student = {
    role: 'student',
    data: {
      url: 'http://localhost:8000/api/users/9/',
      username: 'muhammad.reza42',
      email: 'muhammad.reza42@ui.ac.id',
      is_staff: false,
      company: null,
      supervisor: null,
      student: {
        id: 3,
        user: {
          url: 'http://localhost:8000/api/users/9/',
          username: 'muhammad.reza42',
          email: 'muhammad.reza42@ui.ac.id',
          is_staff: false,
        },
        name: 'Muhammad R.',
        created: '2017-03-28T13:33:46.147241Z',
        updated: '2017-03-28T13:33:46.148248Z',
        npm: 1406543593,
        resume: null,
        phone_number: null,
        bookmarked_vacancies: [
          3,
        ],
        applied_vacancies: [
          3,
          1,
        ],
      },
    },
  };

  const response = [
    { id: 1, status: Applicant.APPLICATION_STATUS.ACCEPTED, student, vacancy },
    { id: 2, status: Applicant.APPLICATION_STATUS.BOOKMARKED, student, vacancy },
    { id: 3, status: Applicant.APPLICATION_STATUS.NEW, student, vacancy },
    { id: 4, status: Applicant.APPLICATION_STATUS.REJECTED, student, vacancy },
  ];

  fetchMock.restore();
  fetchMock.get('*', response);

  it('renders without problem', () => {
    const applicantList = ReactTestUtils.renderIntoDocument(
      <ApplicantList status={Applicant.APPLICATION_STATUS.ACCEPTED} url="test" />);
    expect(applicantList).to.exist;
  });

  it('can update status', () => {
    const applicantList = ReactTestUtils.renderIntoDocument(
      <ApplicantList status={Applicant.APPLICATION_STATUS.ACCEPTED} url="test" />);
    applicantList.setState({applications : response });

    expect(applicantList.state).to.not.equal(response);
    applicantList.updateStatus(1, Applicant.APPLICATION_STATUS.BOOKMARKED);
    expect(applicantList.state).to.not.equal(response);
  });
});