Fakultas Ilmu Komputer UI

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

describe('Vacancy', () => {
8
  const fetchMock = require('fetch-mock');
9
  const response = {
10
    close_time: '2019-03-28T05:55:42Z',
11
    company: {
12
      address: 'kebayoran baru',
13
14
15
      id: 1,
      logo: null,
      name: 'tutup lapak',
16
17
    },
    created: '2017-03-28T07:05:47.128672Z',
18
19
20
21
22
23
    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,
24
25
  };

M. Reza Qorib's avatar
M. Reza Qorib committed
26
  const response2 = {
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
    close_time: '2019-03-28T05:55:42Z',
    company: {
      address: 'kebayoran baru',
      id: 1,
      logo: 'pictures',
      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,
  };

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
  const studentUser = {
    role: 'company',
    data: {
      url: 'http://localhost:8001/api/users/8/',
      username: 'Tutuplapak',
      email: '',
      is_staff: false,
      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,
        birth_place: null,
        birth_date: null,
        major: null,
        batch: null,
        show_resume: false,
        bookmarked_vacancies: [
          3,
          2,
        ],
        applied_vacancies: [
          3,
          1,
        ],
      },
    },
  };


82
  it('renders with null picture and apply button without problem', () => {
83
    const lowongan = ReactTestUtils.renderIntoDocument(
84
      <Vacancy status={0} user={studentUser} data={response} />);
85
86
87
    expect(lowongan).to.exist;
  });

88
  it('renders with null picture and cancel button without problem', () => {
89
    const lowongan = ReactTestUtils.renderIntoDocument(
90
      <Vacancy status={1} user={studentUser} data={response} />);
91
92
93
94
95
    expect(lowongan).to.exist;
  });

  it('renders with picture and apply button without problem', () => {
    const lowongan = ReactTestUtils.renderIntoDocument(
96
      <Vacancy status={0} user={studentUser} data={response2} />);
97
98
99
100
101
    expect(lowongan).to.exist;
  });

  it('renders with picture and cancel button without problem', () => {
    const lowongan = ReactTestUtils.renderIntoDocument(
102
103
104
105
106
107
108
109
110
111
112
113
114
      <Vacancy status={2} user={studentUser} data={response2} />);
    expect(lowongan).to.exist;
  });

  it('renders for accepted without problem', () => {
    const lowongan = ReactTestUtils.renderIntoDocument(
      <Vacancy status={4} user={studentUser} data={response2} />);
    expect(lowongan).to.exist;
  });

  it('renders for rejected without problem', () => {
    const lowongan = ReactTestUtils.renderIntoDocument(
      <Vacancy status={3} user={studentUser} data={response2} />);
115
116
    expect(lowongan).to.exist;
  });
M. Reza Qorib's avatar
M. Reza Qorib committed
117
118

  it('bookmarks without problem', () => {
119
120
    fetchMock.post('*', response);
    const lowongan = ReactTestUtils.renderIntoDocument(
121
      <Vacancy status="Daftar" user={studentUser} data={response2} />);
122
123
124
125
    const response3 = { student: { id: 1, name: 2 } };
    expect(lowongan.props.data.id).to.equal(3);
    Storage.set('user-data', response3);
    expect(lowongan.bookmark()).to.be.undefined;
126
    fetchMock.restore();
127
128
129
130
  });

  it('cancel bookmarks without problem', () => {
    fetchMock.delete('*', { data: 'value' });
M. Reza Qorib's avatar
M. Reza Qorib committed
131
    const lowongan = ReactTestUtils.renderIntoDocument(
132
      <Vacancy status="Daftar" user={studentUser} data={response2} bookmarked={1} />);
M. Reza Qorib's avatar
M. Reza Qorib committed
133
    const response3 = { student: { id: 1, name: 2 } };
134
135
    lowongan.removeVacancyApplication();
    lowongan.openConfirmationModal();
136
    lowongan.updateStatus();
M. Reza Qorib's avatar
M. Reza Qorib committed
137
138
139
    expect(lowongan.props.data.id).to.equal(3);
    Storage.set('user-data', response3);
    expect(lowongan.bookmark()).to.be.undefined;
140
141
142
143
144
145
    fetchMock.restore();
  });

  it('cancel bookmarks with problem', () => {
    fetchMock.delete('*', 404);
    const lowongan = ReactTestUtils.renderIntoDocument(
146
      <Vacancy status="Daftar" user={studentUser} data={response2} bookmarked={1} />);
147
148
149
150
    const response3 = { student: { id: 1, name: 2 } };
    lowongan.removeVacancyApplication();
    expect(lowongan.props.data.id).to.equal(3);
    Storage.set('user-data', response3);
151
    lowongan.updateStatus('failed');
152
153
154
    expect(lowongan.bookmark()).to.be.undefined;
    fetchMock.restore();
  });
155
});