From 0a070be0116751acb06fe17386d317ba8f45e035 Mon Sep 17 00:00:00 2001
From: Zamil Majdy <z.majdy1996@gmail.com>
Date: Tue, 2 May 2017 00:27:03 +0700
Subject: [PATCH] [#144502159] [#35] [Refactor] Update correlated testcases and
 main component to fix bug

---
 assets/js/ApplicantPage.jsx                   | 20 ++++----------
 assets/js/Dashboard.jsx                       |  2 +-
 assets/js/ProfilePage.jsx                     |  2 +-
 .../__test__/components/ApplyModal-test.jsx   | 14 ++++++++++
 .../__test__/components/ApproveModal-test.jsx |  6 +++--
 .../js/__test__/components/Vacancy-test.jsx   | 26 -------------------
 6 files changed, 25 insertions(+), 45 deletions(-)

diff --git a/assets/js/ApplicantPage.jsx b/assets/js/ApplicantPage.jsx
index 2931c861..adf39901 100644
--- a/assets/js/ApplicantPage.jsx
+++ b/assets/js/ApplicantPage.jsx
@@ -29,21 +29,11 @@ export default class ApplicantPage extends React.Component {
     const company = this.props.user.data.company;
     return (
       <Tabs selected={0}>
-        <Pane label="Lamaran Baru" >
-          <ApplicantList key={1} companyId={company.id} url={`/companies/${company.id}/applications/?status=${Applicant.APPLICATION_STATUS.NEW}`} status={Applicant.APPLICATION_STATUS.NEW} />
-        </Pane>
-        <Pane label="Lamaran Dibaca" >
-          <ApplicantList key={2} companyId={company.id} url={`/companies/${company.id}/applications/?status=${Applicant.APPLICATION_STATUS.READ}`} status={Applicant.APPLICATION_STATUS.READ} />
-        </Pane>
-        <Pane label="Lamaran Ditandai" >
-          <ApplicantList key={3} companyId={company.id} url={`/companies/${company.id}/applications/?status=${Applicant.APPLICATION_STATUS.BOOKMARKED}`} status={Applicant.APPLICATION_STATUS.BOOKMARKED} />
-        </Pane>
-        <Pane label="Lamaran Diterima" >
-          <ApplicantList key={4} companyId={company.id} url={`/companies/${company.id}/applications/?status=${Applicant.APPLICATION_STATUS.ACCEPTED}`} status={Applicant.APPLICATION_STATUS.ACCEPTED} />
-        </Pane>
-        <Pane label="Lamaran Ditolak" >
-          <ApplicantList key={5} companyId={company.id} url={`/companies/${company.id}/applications/?status=${Applicant.APPLICATION_STATUS.REJECTED}`} status={Applicant.APPLICATION_STATUS.REJECTED} />
-        </Pane>
+        <ApplicantList label="Lamaran Baru" key={1} companyId={company.id} url={`/companies/${company.id}/applications/?status=${Applicant.APPLICATION_STATUS.NEW}`} status={Applicant.APPLICATION_STATUS.NEW} />
+        <ApplicantList label="Lamaran Dibaca" key={2} companyId={company.id} url={`/companies/${company.id}/applications/?status=${Applicant.APPLICATION_STATUS.READ}`} status={Applicant.APPLICATION_STATUS.READ} />
+        <ApplicantList label="Lamaran Ditandai" key={3} companyId={company.id} url={`/companies/${company.id}/applications/?status=${Applicant.APPLICATION_STATUS.BOOKMARKED}`} status={Applicant.APPLICATION_STATUS.BOOKMARKED} />
+        <ApplicantList label="Lamaran Diterima" key={4} companyId={company.id} url={`/companies/${company.id}/applications/?status=${Applicant.APPLICATION_STATUS.ACCEPTED}`} status={Applicant.APPLICATION_STATUS.ACCEPTED} />
+        <ApplicantList label="Lamaran Ditolak" key={5} companyId={company.id} url={`/companies/${company.id}/applications/?status=${Applicant.APPLICATION_STATUS.REJECTED}`} status={Applicant.APPLICATION_STATUS.REJECTED} />
       </Tabs>
     );
   }
diff --git a/assets/js/Dashboard.jsx b/assets/js/Dashboard.jsx
index c317fa5a..83fe6ec2 100755
--- a/assets/js/Dashboard.jsx
+++ b/assets/js/Dashboard.jsx
@@ -1,6 +1,6 @@
 import React from 'react';
 import TopMenu from './components/TopMenu';
-import Footer from './components/Footer'
+import Footer from './components/Footer';
 
 export default class Dashboard extends React.Component {
   static propTypes = {
diff --git a/assets/js/ProfilePage.jsx b/assets/js/ProfilePage.jsx
index f3a512b6..fb1fe596 100644
--- a/assets/js/ProfilePage.jsx
+++ b/assets/js/ProfilePage.jsx
@@ -89,7 +89,7 @@ export default class ProfilePage extends React.Component {
     const form = this.state.form;
     form[e.target.name] = e.target.files[0];
     this.setState({ form });
-  }
+  };
 
   handleChange = (e) => {
     const form = this.state.form;
diff --git a/assets/js/__test__/components/ApplyModal-test.jsx b/assets/js/__test__/components/ApplyModal-test.jsx
index f06675e1..1119ff7c 100644
--- a/assets/js/__test__/components/ApplyModal-test.jsx
+++ b/assets/js/__test__/components/ApplyModal-test.jsx
@@ -2,6 +2,7 @@
 import React from 'react';
 import ReactTestUtils from 'react-addons-test-utils';
 import ApplyModal from '../../components/ApplyModal';
+import fetchMock from 'fetch-mock';
 
 describe('ApplyModal', () => {
   it('renders without problem', () => {
@@ -11,12 +12,25 @@ describe('ApplyModal', () => {
   });
 
   it('open without problem', () => {
+    fetchMock.post('*', {});
     const modalPendaftaran = ReactTestUtils.renderIntoDocument(
       <ApplyModal id={4} data={{ key: 'value' }} buttonTitle="submit" apply={() => {}}/>);
     const modal = ReactTestUtils.findRenderedDOMComponentWithTag(modalPendaftaran, 'Button');
     modalPendaftaran.handleApply();
     ReactTestUtils.Simulate.click(modal);
     expect(modalPendaftaran).to.exist;
+    fetchMock.restore();
+  });
+
+  it('open with problem', () => {
+    fetchMock.post('*', 404);
+    const modalPendaftaran = ReactTestUtils.renderIntoDocument(
+      <ApplyModal id={4} data={{ key: 'value' }} buttonTitle="submit" apply={() => {}}/>);
+    const modal = ReactTestUtils.findRenderedDOMComponentWithTag(modalPendaftaran, 'Button');
+    modalPendaftaran.handleApply();
+    ReactTestUtils.Simulate.click(modal);
+    expect(modalPendaftaran).to.exist;
+    fetchMock.restore();
   });
 
   it('change without problem', () => {
diff --git a/assets/js/__test__/components/ApproveModal-test.jsx b/assets/js/__test__/components/ApproveModal-test.jsx
index 739192af..255581c5 100644
--- a/assets/js/__test__/components/ApproveModal-test.jsx
+++ b/assets/js/__test__/components/ApproveModal-test.jsx
@@ -3,6 +3,7 @@ import React from 'react';
 import ReactTestUtils from 'react-addons-test-utils';
 import fetchMock from 'fetch-mock';
 import ApproveModal from '../../components/ApproveModal';
+import Applicant from '../../components/Applicant';
 
 describe('ApproveModal', () => {
   it('renders without problem', () => {
@@ -14,7 +15,7 @@ describe('ApproveModal', () => {
   it('open without problem', () => {
     fetchMock.get('*', { student: { resume: 'asdasd' } });
     const modalApproval = ReactTestUtils.renderIntoDocument(
-      <ApproveModal updateStatus={() => {}} data={{ key: 'value', student: { resume: 'asdasd' } }} />);
+      <ApproveModal updateStatus={() => {}} data={{ key: 'value', student: { resume: 'asdasd' }, status: Applicant.APPLICATION_STATUS.NEW }} />);
 
     const modal = ReactTestUtils.findRenderedDOMComponentWithTag(modalApproval, 'Button');
     ReactTestUtils.Simulate.click(modal);
@@ -24,8 +25,9 @@ describe('ApproveModal', () => {
 
   it('close without problem', () => {
     fetchMock.get('*', { student: { resume: 'asdasd' } });
+    fetchMock.patch('*', { student: { resume: 'asdasd' } });
     const modalApproval = ReactTestUtils.renderIntoDocument(
-      <ApproveModal updateStatus={() => {}} data={{ key: 'value', student: { resume: 'asdasd' } }} />);
+      <ApproveModal updateStatus={() => {}} data={{ key: 'value', student: { resume: 'asdasd' }, status: Applicant.APPLICATION_STATUS.NEW  }} />);
 
     modalApproval.handleClose();
     expect(modalApproval.state.modalOpen).to.equal(false);
diff --git a/assets/js/__test__/components/Vacancy-test.jsx b/assets/js/__test__/components/Vacancy-test.jsx
index 7d99368d..65222b3d 100644
--- a/assets/js/__test__/components/Vacancy-test.jsx
+++ b/assets/js/__test__/components/Vacancy-test.jsx
@@ -99,30 +99,4 @@ describe('Vacancy', () => {
     expect(lowongan.bookmark()).to.be.undefined;
     fetchMock.restore();
   });
-
-  it('apply without problem', () => {
-    fetchMock.post('*', response);
-    fetchMock.delete('*', response);
-    const lowongan = ReactTestUtils.renderIntoDocument(
-      <Vacancy status="Daftar" data={response2} bookmarked={1}/>);
-    const response3 = { student: { id: 1, name: 2 } };
-    lowongan.apply(1);
-    expect(lowongan.props.data.id).to.equal(3);
-    Storage.set('user-data', response3);
-    expect(lowongan.bookmark()).to.be.undefined;
-    fetchMock.restore();
-  });
-
-  it('apply with problem', () => {
-    fetchMock.post('*', 404);
-    fetchMock.delete('*', response);
-    const lowongan = ReactTestUtils.renderIntoDocument(
-      <Vacancy status="Daftar" data={response2} bookmarked={1}/>);
-    const response3 = { student: { id: 1, name: 2 } };
-    lowongan.apply(1);
-    expect(lowongan.props.data.id).to.equal(3);
-    Storage.set('user-data', response3);
-    expect(lowongan.bookmark()).to.be.undefined;
-    fetchMock.restore();
-  });
 });
-- 
GitLab