From c185ac439f71567311136e45c2c2b8513744ce0a Mon Sep 17 00:00:00 2001
From: "M. Reza Qorib" <rezaqorib96@gmail.com>
Date: Sat, 15 Apr 2017 16:43:04 +0700
Subject: [PATCH] [#140652771] #18 Refactor test codes

---
 .../__test__/components/ApplyModal-test.jsx   |  6 +--
 .../components/CompanyVacancy-test.js         | 54 ++++++++++++++++---
 .../js/__test__/components/Vacancy-test.jsx   |  8 +--
 .../__test__/components/VacancyList-test.jsx  | 29 +++++++---
 assets/js/components/VacancyList.jsx          |  2 +-
 debug.log                                     |  1 +
 6 files changed, 77 insertions(+), 23 deletions(-)
 create mode 100644 debug.log

diff --git a/assets/js/__test__/components/ApplyModal-test.jsx b/assets/js/__test__/components/ApplyModal-test.jsx
index 58baa31d..f805b8db 100644
--- a/assets/js/__test__/components/ApplyModal-test.jsx
+++ b/assets/js/__test__/components/ApplyModal-test.jsx
@@ -4,11 +4,11 @@ import ReactTestUtils from 'react-addons-test-utils';
 import ApplyModal from '../../components/ApplyModal';
 
 describe('ApplyModal', () => {
- it('renders without problem', () => {
+  it('renders without problem', () => {
     const modalPendaftaran = ReactTestUtils.renderIntoDocument(
-      <ApplyModal id={4} data={{key: 'value'}} buttonTitle="submit" />);
+      <ApplyModal id={4} data={{ key: 'value' }} buttonTitle="submit" />);
     expect(modalPendaftaran).to.exist;
- });
+  });
 
   it('open without problem', () => {
     const modalPendaftaran = ReactTestUtils.renderIntoDocument(
diff --git a/assets/js/__test__/components/CompanyVacancy-test.js b/assets/js/__test__/components/CompanyVacancy-test.js
index 5ae7ef92..df7bc4db 100644
--- a/assets/js/__test__/components/CompanyVacancy-test.js
+++ b/assets/js/__test__/components/CompanyVacancy-test.js
@@ -1,14 +1,52 @@
-/**
- * Created by baisa on 09/04/2017.
- */
 import React from 'react';
 import ReactTestUtils from 'react-addons-test-utils';
 import CompanyVacancy from '../../components/CompanyVacancy';
 
-describe('ApplyModal', () => {
- it('renders without problem', () => {
+describe('CompanyVacancy', () => {
+  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,
+  };
+
+  const response2 = {
+    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,
+  };
+
+  it('renders with logo without problem', () => {
+     const companyVacancy = ReactTestUtils.renderIntoDocument(
+       <CompanyVacancy data={response2} />);
+     expect(companyVacancy).to.exist;
+  });
+
+  it('renders without logo without problem', () => {
     const companyVacancy = ReactTestUtils.renderIntoDocument(
-      <CompanyVacancy header="header"/>);
+      <CompanyVacancy data={response} />);
     expect(companyVacancy).to.exist;
- });
-}
+  });
+
+});
diff --git a/assets/js/__test__/components/Vacancy-test.jsx b/assets/js/__test__/components/Vacancy-test.jsx
index a98d5565..8a08783e 100644
--- a/assets/js/__test__/components/Vacancy-test.jsx
+++ b/assets/js/__test__/components/Vacancy-test.jsx
@@ -8,11 +8,11 @@ describe('Vacancy', () => {
   const fetchMock = require('fetch-mock');
   const response ={
     close_time: '2019-03-28T05:55:42Z',
-      company: {
+    company: {
       address: 'kebayoran baru',
-        id: 1,
-        logo: null,
-        name: 'tutup lapak',
+      id: 1,
+      logo: null,
+      name: 'tutup lapak',
     },
     created: '2017-03-28T07:05:47.128672Z',
       description: 'Lorem ipsum dolbh.',
diff --git a/assets/js/__test__/components/VacancyList-test.jsx b/assets/js/__test__/components/VacancyList-test.jsx
index b94249c1..3663c129 100644
--- a/assets/js/__test__/components/VacancyList-test.jsx
+++ b/assets/js/__test__/components/VacancyList-test.jsx
@@ -22,19 +22,26 @@ describe('VacancyList', () => {
     updated: '2017-03-28T07:34:13.122093Z',
     verified: true,
   }];
-  // const response2 = { hello: 'not-world' };
 
   it('renders without problem', () => {
     fetchMock.get('*', response);
     const vacancyList = ReactTestUtils.renderIntoDocument(
-      <VacancyList studentId={1} url="test" />);
+      <VacancyList userId={1} url="test" />);
     expect(vacancyList).to.exist;
   });
 
+  it('renders without problem for company', () => {
+    fetchMock.get('*', response);
+    const vacancyList = ReactTestUtils.renderIntoDocument(
+      <VacancyList type='company' userId={1} url="test" />);
+    vacancyList.state.vacancies = response;
+    expect(vacancyList.generateVacancies()).to.exist;
+  });
+
   it('update bookmarks without problem', () => {
     fetchMock.get('*', response);
     const vacancyList = ReactTestUtils.renderIntoDocument(
-      <VacancyList studentId={1} url="test" />);
+      <VacancyList userId={1} url="test" />);
     vacancyList.updateBookmarkList();
     expect(JSON.stringify(vacancyList.state.bookmarkList)).to.be.defined;
   });
@@ -42,19 +49,27 @@ describe('VacancyList', () => {
   it('renders marked bookmarked vacancies without problem', () => {
     fetchMock.get('*', response);
     const vacancyList = ReactTestUtils.renderIntoDocument(
-      <VacancyList studentId={1} url="test" />);
+      <VacancyList userId={1} url="test" />);
     vacancyList.state.vacancies = response;
-    vacancyList.state.bookmarkList = [{id: 5}, {id: 3}];
+    vacancyList.state.bookmarkList = [{id: 5}, {id: 3}, {id: 1}];
+    expect(vacancyList.generateVacancies()).to.exist;
+  });
+
+  it('renders not marked vacancies without problem', () => {
+    fetchMock.get('*', response);
+    const vacancyList = ReactTestUtils.renderIntoDocument(
+      <VacancyList userId={1} url="test" />);
+    vacancyList.state.vacancies = response;
+    vacancyList.state.bookmarkList = [{id: 6}, {id: 4}, {id: 2}];
     expect(vacancyList.generateVacancies()).to.exist;
   });
 
   it('success calling API', () => {
     fetchMock.get('*', response);
     const vacancyList = ReactTestUtils.renderIntoDocument(
-      <VacancyList studentId={1} url="test" />);
+      <VacancyList userId={1} url="test" />);
     vacancyList.state.vacancies = response;
     expect(JSON.stringify(vacancyList.state.vacancies)).to.equal(JSON.stringify(response));
-    expect(vacancyList.generateVacancies()).to.exist;
     });
   });
 
diff --git a/assets/js/components/VacancyList.jsx b/assets/js/components/VacancyList.jsx
index d14c126d..37295929 100644
--- a/assets/js/components/VacancyList.jsx
+++ b/assets/js/components/VacancyList.jsx
@@ -24,10 +24,10 @@ export default class VacancyList extends React.Component {
     if (this.props.type === 'student') {
       this.updateBookmarkList();
     }
+    this.state = { vacancies: [], bookmarkList: [] };
     Server.get(this.props.url, false).then((data) => {
       this.setState({ vacancies: data });
     });
-    this.state = { vacancies: [], bookmarkList: [] };
     this.updateBookmarkList = this.updateBookmarkList.bind(this);
     this.generateVacancies = this.generateVacancies.bind(this);
     this.checkBookmark = this.checkBookmark.bind(this);
diff --git a/debug.log b/debug.log
new file mode 100644
index 00000000..48169a2e
--- /dev/null
+++ b/debug.log
@@ -0,0 +1 @@
+[0415/162748.577:ERROR:prune_crash_reports.cc(35)] PruneCrashReportDatabase: Failed to get pending reports
-- 
GitLab