Fakultas Ilmu Komputer UI

TopMenu-test.jsx 11.4 KB
Newer Older
1
2
/* eslint-disable no-unused-expressions */
import React from 'react';
Syahrul Findi's avatar
Syahrul Findi committed
3
import ReactTestUtils from 'react-dom/test-utils';
4
import fetchMock from 'fetch-mock';
5
import moment from 'moment';
Arga Ghulam Ahmad's avatar
Arga Ghulam Ahmad committed
6
import TopMenu from '../../components/TopMenu';
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122

describe('TopMenu', () => {
  fetchMock.restore();
  fetchMock.get('*', { data: 'value' });

  const studentUser = {
    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 companyUser = {
    role: 'company',
    data: {
      url: 'http://localhost:8001/api/users/8/',
      username: 'Tutuplapak',
      email: '',
      is_staff: true,
      company: {
        id: 3,
        user: {
          url: 'http://localhost:8001/api/users/8/',
          username: 'Tutuplapak',
          email: '',
          is_staff: false,
        },
        name: 'Tutuplapak',
        created: '2017-03-28T07:30:10.535000Z',
        updated: '2017-03-28T07:30:10.535000Z',
        description: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla aliquet semper neque a fermentum. Duis ac tellus vitae augue iaculis ultrices. Curabitur commodo et neque nec feugiat. Morbi ac diam vel nunc commodo cursus. Phasellus nulla sapien, hendrerit vitae bibendum at, sollicitudin eu ante. Maecenas maximus, ante eu sollicitudin convallis, mauris nunc posuere risus, eu porttitor diam lacus vitae enim. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Suspendisse at lectus a elit sollicitudin tempor. Nullam condimentum, justo nec tincidunt maximus, neque mi vulputate leo, sit amet lacinia massa ex eget sem. Duis ac erat facilisis, fringilla mauris in, consequat neque. In et neque consequat, vehicula magna at, efficitur ante. Mauris ac lacinia nibh.\r\n\r\nProin sagittis, lectus quis maximus varius, libero justo sollicitudin augue, non lacinia risus orci a enim. Curabitur iaculis enim quis ullamcorper commodo. Vivamus id nisi rhoncus, dignissim tellus quis, interdum est. Fusce sollicitudin eu libero ac feugiat. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Maecenas semper posuere ex, sed accumsan libero iaculis faucibus. Fusce laoreet ac ligula ut consectetur. Donec tortor mauris, rutrum at sodales et, viverra in dolor. Sed bibendum elit et maximus volutpat. Phasellus justo ipsum, laoreet sit amet faucibus eu, ultricies suscipit mauris. Nullam aliquam libero eu ante ultrices mattis. Donec non justo hendrerit neque volutpat placerat. Ut euismod est nec sem mollis, sit amet porttitor massa rhoncus. Aenean id erat sit amet nunc ultrices scelerisque non in ipsum. Curabitur sollicitudin nulla id mi accumsan venenatis.',
        verified: true,
        logo: 'http://localhost:8001/files/company-logo/8a258a48-3bce-4873-b5d1-538b360d0059.png',
        address: 'Jl. Kebayoran Baru nomor 13, Jakarta Barat',
      },
      supervisor: null,
      student: null,
    },
  };

  const adminUser1 = {
    role: 'admin',
    data: {
      url: 'http://localhost:8001/api/users/8/',
      username: 'Tutuplapak',
      email: '',
      is_staff: true,
      supervisor: null,
      student: null,
      company: {
        id: 3,
        user: {
          url: 'http://localhost:8001/api/users/8/',
          username: 'Tutuplapak',
          email: '',
          is_staff: false,
        },
        name: 'Tutuplapak',
        created: '2017-03-28T07:30:10.535000Z',
        updated: '2017-03-28T07:30:10.535000Z',
        description: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla aliquet semper neque a fermentum. Duis ac tellus vitae augue iaculis ultrices. Curabitur commodo et neque nec feugiat. Morbi ac diam vel nunc commodo cursus. Phasellus nulla sapien, hendrerit vitae bibendum at, sollicitudin eu ante. Maecenas maximus, ante eu sollicitudin convallis, mauris nunc posuere risus, eu porttitor diam lacus vitae enim. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Suspendisse at lectus a elit sollicitudin tempor. Nullam condimentum, justo nec tincidunt maximus, neque mi vulputate leo, sit amet lacinia massa ex eget sem. Duis ac erat facilisis, fringilla mauris in, consequat neque. In et neque consequat, vehicula magna at, efficitur ante. Mauris ac lacinia nibh.\r\n\r\nProin sagittis, lectus quis maximus varius, libero justo sollicitudin augue, non lacinia risus orci a enim. Curabitur iaculis enim quis ullamcorper commodo. Vivamus id nisi rhoncus, dignissim tellus quis, interdum est. Fusce sollicitudin eu libero ac feugiat. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Maecenas semper posuere ex, sed accumsan libero iaculis faucibus. Fusce laoreet ac ligula ut consectetur. Donec tortor mauris, rutrum at sodales et, viverra in dolor. Sed bibendum elit et maximus volutpat. Phasellus justo ipsum, laoreet sit amet faucibus eu, ultricies suscipit mauris. Nullam aliquam libero eu ante ultrices mattis. Donec non justo hendrerit neque volutpat placerat. Ut euismod est nec sem mollis, sit amet porttitor massa rhoncus. Aenean id erat sit amet nunc ultrices scelerisque non in ipsum. Curabitur sollicitudin nulla id mi accumsan venenatis.',
        verified: true,
        logo: 'http://localhost:8001/files/company-logo/8a258a48-3bce-4873-b5d1-538b360d0059.png',
        address: 'Jl. Kebayoran Baru nomor 13, Jakarta Barat',
      },
    },
  };

  const adminUser2 = {
    role: 'admin',
    data: {
      url: 'http://localhost:8001/api/users/8/',
      username: 'Tutuplapak',
      email: '',
      is_staff: false,
      company: null,
      supervisor: null,
      student: null,
    },
  };

  const supervisorUser = {
    role: 'supervisor',
    data: {
      url: 'http://localhost:8001/api/users/8/',
      username: 'Tutuplapak',
      email: '',
      is_staff: false,
      company: null,
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
      supervisor: {
        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,
        ],
      },
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
      student: null,
    },
  };

  const errorUser = {
    role: 'error',
    data: {
      url: 'http://localhost:8001/api/users/8/',
      username: 'Tutuplapak',
      email: '',
      is_staff: false,
      company: null,
      supervisor: null,
      student: null,
    },
  };

  it('renders for company without problem', () => {
    const topmenu = ReactTestUtils.renderIntoDocument(
Arga Ghulam Ahmad's avatar
Arga Ghulam Ahmad committed
164
165
      <TopMenu user={companyUser} />,
    );
166
167
168
169
170
171
172
    expect(topmenu).to.exist;
  });

  it('renders for supervisor without problem', () => {
    const topmenu = ReactTestUtils.renderIntoDocument(
      <TopMenu user={supervisorUser}>
        <div> test </div>
Arga Ghulam Ahmad's avatar
Arga Ghulam Ahmad committed
173
174
      </TopMenu>,
    );
175
176
177
178
179
180
181
    expect(topmenu).to.exist;
  });

  it('renders for admin without problem', () => {
    const topmenu = ReactTestUtils.renderIntoDocument(
      <TopMenu user={adminUser1}>
        <div> test </div>
Arga Ghulam Ahmad's avatar
Arga Ghulam Ahmad committed
182
183
      </TopMenu>,
    );
184
185
186
187
188
189
190
    expect(topmenu).to.exist;
  });

  it('renders for student without problem', () => {
    const topmenu = ReactTestUtils.renderIntoDocument(
      <TopMenu user={studentUser}>
        <div> test </div>
Arga Ghulam Ahmad's avatar
Arga Ghulam Ahmad committed
191
192
      </TopMenu>,
    );
193
194
195
196
197
198
199
    expect(topmenu).to.exist;
  });

  it('renders for error without problem', () => {
    const topmenu = ReactTestUtils.renderIntoDocument(
      <TopMenu user={errorUser}>
        <div> test </div>
Arga Ghulam Ahmad's avatar
Arga Ghulam Ahmad committed
200
201
      </TopMenu>,
    );
202
203
204
205
206
207
208
209
    expect(topmenu).to.exist;
  });

  it('renders for user to logout without problem', () => {
    fetchMock.get('*', { data: 'value' });
    const topmenu = ReactTestUtils.renderIntoDocument(
      <TopMenu user={adminUser1}>
        <div> test </div>
Arga Ghulam Ahmad's avatar
Arga Ghulam Ahmad committed
210
211
      </TopMenu>,
    );
212
213
214
215
216
217
218
219
    topmenu.logout(new Event('click'));
    expect(topmenu).to.exist;
  });

  it('changes the activeItem when item is clicked', () => {
    const topmenu = ReactTestUtils.renderIntoDocument(
      <TopMenu user={adminUser2}>
        <div> test </div>
Arga Ghulam Ahmad's avatar
Arga Ghulam Ahmad committed
220
221
      </TopMenu>,
    );
222
223
224
    topmenu.handleItemClick(new Event('click'), 'undefined');
    expect(topmenu.state.activeItem).to.equal(undefined);
  });
225

226
227
228
229
  it('check topmenu state containst today quotes', () => {
    const topmenu = ReactTestUtils.renderIntoDocument(
      <TopMenu user={adminUser2}>
        <div> test </div>
Arga Ghulam Ahmad's avatar
Arga Ghulam Ahmad committed
230
231
      </TopMenu>,
    );
232
    expect(topmenu.state.todayQuote).to.not.equal(undefined);
Arga Ghulam Ahmad's avatar
Arga Ghulam Ahmad committed
233
  });
234

Arga Ghulam Ahmad's avatar
Arga Ghulam Ahmad committed
235
  it('check popup is open', () => {
236
237
238
    const topmenu = ReactTestUtils.renderIntoDocument(
      <TopMenu user={adminUser2}>
        <div> test </div>
Arga Ghulam Ahmad's avatar
Arga Ghulam Ahmad committed
239
240
241
242
243
      </TopMenu>,
    );
    topmenu.handleOpen();
    expect(topmenu.state.isOpen).to.equal(true);
  });
244

Arga Ghulam Ahmad's avatar
Arga Ghulam Ahmad committed
245
  it('check popup is close', () => {
246
247
248
    const topmenu = ReactTestUtils.renderIntoDocument(
      <TopMenu user={adminUser2}>
        <div> test </div>
Arga Ghulam Ahmad's avatar
Arga Ghulam Ahmad committed
249
250
251
252
253
      </TopMenu>,
    );
    topmenu.handleClose();
    expect(topmenu.state.isOpen).to.equal(false);
  });
254

RAMA WIDRAGAMA PUTRA's avatar
RAMA WIDRAGAMA PUTRA committed
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
    it('check popup is open', () => {
    const topmenu = ReactTestUtils.renderIntoDocument(
      <TopMenu user={adminUser2}>
        <div> test </div>
      </TopMenu>);
      topmenu.handleOpen();
      expect(topmenu.state.isOpen).to.equal(true);
    });

    it('check popup is close', () => {
    const topmenu = ReactTestUtils.renderIntoDocument(
      <TopMenu user={adminUser2}>
        <div> test </div>
      </TopMenu>);
      topmenu.handleClose();
      expect(topmenu.state.isOpen).to.equal(false);
    });

273
274
275
  it('TopMenu state contain right current date time', () => {
    moment.locale('id');
    const date = new Date();
Arga Ghulam Ahmad's avatar
Arga Ghulam Ahmad committed
276
    const expectedDate = `${moment(date).format('dddd')}, ${moment(date).format('LL')}`;
277
278
279
    const topMenu = ReactTestUtils.renderIntoDocument(
      <TopMenu user={adminUser2}>
        <div> test </div>
Arga Ghulam Ahmad's avatar
Arga Ghulam Ahmad committed
280
281
      </TopMenu>,
    );
282
283
    expect(topMenu.state.currentDate).to.equal(expectedDate);
  });
Vitosavero Avila Wibisono's avatar
Vitosavero Avila Wibisono committed
284
285
286
287
288

  it('TopMenu state contain aplliance information', () => {
    const topMenu = ReactTestUtils.renderIntoDocument(
      <TopMenu user={studentUser}>
        <div> test </div>
Arga Ghulam Ahmad's avatar
Arga Ghulam Ahmad committed
289
      </TopMenu>,
Vitosavero Avila Wibisono's avatar
Vitosavero Avila Wibisono committed
290
291
292
293
    );
    expect(topMenu.state.applianceInformation).to.exist;
  });

294
295
296
297
  it('TopMenu state contain kape description', () => {
    const topMenu = ReactTestUtils.renderIntoDocument(
      <TopMenu user={studentUser}>
        <div> test </div>
Arga Ghulam Ahmad's avatar
Arga Ghulam Ahmad committed
298
      </TopMenu>,
299
300
301
    );
    expect(topMenu.state.kapeDescription).to.exist;
  });
302
303
304
305
306
307
308
309
310

  it('TopMenu state contain welcome student', () => {
    const topMenu = ReactTestUtils.renderIntoDocument(
      <TopMenu user={studentUser}>
        <div> test </div>
      </TopMenu>,
    );
    expect(topMenu.state.welcomeStudent).to.exist;
  });
311
});