Fakultas Ilmu Komputer UI

Commit adc85050 authored by M. Reza Qorib's avatar M. Reza Qorib
Browse files

Merge branch 'UserStory3' of https://gitlab.com/PPL2017csui/PPLA1 into...

Merge branch 'UserStory3' of https://gitlab.com/PPL2017csui/PPLA1 into Features/CompanyVacancyApplicationList
parents 5fe653a4 5dd947d2
......@@ -11,6 +11,7 @@
"func-names": ["error", "never"],
"react/prefer-stateless-function": [0, { "ignorePureComponents": true }],
"react/forbid-prop-types": [0],
"react/no-multi-comp": [0, { "ignoreStateless": 1 }],
"import/extensions": ["off", "never"],
"import/no-unresolved": 0,
"no-underscore-dangle" : 0,
......
......@@ -8,11 +8,6 @@
-moz-box-sizing: border-box;
}
.applicant{
margin-left: 150px;
margin-right: 150px;
}
.ui.inverted.segment.header{
background-color: #EEEEEE;
color:black;
......
import React from 'react';
import CompanyVacancy from './components/CompanyVacancy';
import { Segment } from 'semantic-ui-react';
export default class ApplicantPage extends React.Component {
render() {
return (
<CompanyVacancy header="Software Engineer" />
);
}
}
import React from 'react';
import Tabs from './components/Tabs';
import Pane from './components/Pane';
import Storage from './lib/Storage';
import VacancyList from './components/VacancyList';
export default class VacancyPage extends React.Component {
static getRole() {
const student = Storage.get('user-data').student;
const company = Storage.get('user-data').company;
if (student) {
return { id: student.id, type: 'student' };
} else if (company) {
return { id: company.id, type: 'company' };
static propTypes = {
user: React.PropTypes.object.isRequired,
};
static getId(user) {
const role = user.role;
if (role === 'student') {
return user.data.student.id;
} else if (role === 'company') {
return user.data.company.id;
}
return { id: '0', type: 'error' };
return 0;
}
constructor(props) {
super(props);
/* istanbul ignore next */
const role = VacancyPage.getRole();
this.state = {
vacancies: [],
id: role.id,
role: role.type,
id: VacancyPage.getId(this.props.user),
};
}
generateVacancies() {
if (this.state.role === 'student') {
if (this.props.user.role === 'student') {
return (
<Tabs selected={0}>
<Pane label="Semua Lowongan" >
......@@ -43,7 +43,6 @@ export default class VacancyPage extends React.Component {
<Pane label="Lamaran saya" >
<VacancyList
key={2}
status="Batal"
userId={this.state.id}
url={`/students/${this.state.id}/applied-vacancies/`}
/>
......@@ -57,7 +56,7 @@ export default class VacancyPage extends React.Component {
</Pane>
</Tabs>
);
} else if (this.state.role === 'company') {
} else if (this.props.user.role === 'company') {
return (
<VacancyList key={1} userId={this.state.id} url={`/companies/${this.state.id}/vacancies/`} type="company" />
);
......
......@@ -8,94 +8,97 @@ import Storage from '../lib/Storage';
describe('VacancyPage', () => {
fetchMock.get('*', { data: 'value' });
const studentSession = {
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,
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,
],
},
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 companySession = {
url: 'http://localhost:8001/api/users/8/',
username: 'Tutuplapak',
email: '',
is_staff: false,
company: {
id: 3,
user: {
url: 'http://localhost:8001/api/users/8/',
username: 'Tutuplapak',
email: '',
is_staff: false,
const companyUser = {
role: 'company',
data: {
url: 'http://localhost:8001/api/users/8/',
username: 'Tutuplapak',
email: '',
is_staff: false,
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',
},
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,
},
supervisor: null,
student: null,
};
const errorSession = {
url: 'http://localhost:8001/api/users/8/',
username: 'Tutuplapak',
email: '',
is_staff: false,
company: null,
supervisor: null,
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 companies without problem', () => {
Storage.set('user-data', companySession);
const vacancyPage = ReactTestUtils.renderIntoDocument(
<VacancyPage studentId={1} url="test" />);
<VacancyPage user={companyUser} />);
expect(vacancyPage).to.exist;
expect(vacancyPage.state.role).to.equal('company');
});
it('renders for students without problem', () => {
Storage.set('user-data', studentSession);
const vacancyPage = ReactTestUtils.renderIntoDocument(
<VacancyPage studentId={1} url="test" />);
<VacancyPage user={studentUser} />);
expect(vacancyPage).to.exist;
expect(vacancyPage.state.role).to.equal('student');
});
it('renders without problem for error case', () => {
Storage.set('user-data', errorSession);
const vacancyPage = ReactTestUtils.renderIntoDocument(
<VacancyPage studentId={1} url="test" />);
<VacancyPage user={errorUser} />);
expect(vacancyPage).to.exist;
expect(vacancyPage.state.role).to.equal('error');
});
});
......@@ -12,10 +12,11 @@ describe('ApplyModal', () => {
it('open without problem', () => {
const modalPendaftaran = ReactTestUtils.renderIntoDocument(
<ApplyModal id={4} data={{ key: 'value' }} buttonTitle="submit" />);
<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;
});
it('change without problem', () => {
......
/* eslint-disable no-unused-expressions */
import React from 'react';
import ReactTestUtils from 'react-addons-test-utils';
import fetchMock from 'fetch-mock';
import CancelModal from '../../components/CancelModal';
import Storage from '../../lib/Storage';
describe('CancelModal', () => {
it('renders without problem', () => {
const modalPendaftaran = ReactTestUtils.renderIntoDocument(
<CancelModal id={4} />);
expect(modalPendaftaran).to.exist;
});
it('open without problem', () => {
const modalPendaftaran = ReactTestUtils.renderIntoDocument(
<CancelModal id={4} />);
const modal = ReactTestUtils.findRenderedDOMComponentWithTag(modalPendaftaran, 'Button');
ReactTestUtils.Simulate.click(modal);
expect(modalPendaftaran.state.modalOpen).to.equal(true);
});
it('close without problem', () => {
const modalPendaftaran = ReactTestUtils.renderIntoDocument(
<CancelModal id={4} />);
modalPendaftaran.handleClose();
expect(modalPendaftaran.state.modalOpen).to.equal(false);
});
it('remove vacancy without problem', () => {
fetchMock.delete('*', { data: 'value' });
const modalPendaftaran = ReactTestUtils.renderIntoDocument(
<CancelModal id={4} />);
const response3 = { student: { id: 1, name: 2 } };
Storage.set('user-data', response3);
modalPendaftaran.removeVacancy();
expect(modalPendaftaran.state.header).to.exist;
fetchMock.restore();
});
it('remove vacancy with problem', () => {
fetchMock.delete('*', 404);
const modalPendaftaran = ReactTestUtils.renderIntoDocument(
<CancelModal id={4} />);
const response3 = { student: { id: 1, name: 2 } };
Storage.set('user-data', response3);
modalPendaftaran.removeVacancy();
expect(modalPendaftaran.state.header).to.exist;
fetchMock.restore();
});
it('confirm with problem', () => {
fetchMock.delete('*', 404);
const modalPendaftaran = ReactTestUtils.renderIntoDocument(
<CancelModal id={4} />);
modalPendaftaran.confirm();
expect(modalPendaftaran.state.header).to.equal('Permintaan gagal');
fetchMock.restore();
});
it('render next modal without problem', () => {
const modalPendaftaran = ReactTestUtils.renderIntoDocument(
<CancelModal id={4} />);
modalPendaftaran.state.confirmed = true;
modalPendaftaran.forceUpdate()
expect(modalPendaftaran).to.exist;
});
});
// /* eslint-disable no-unused-expressions */
// import React from 'react';
// import ReactTestUtils from 'react-addons-test-utils';
// import fetchMock from 'fetch-mock';
// import ConfirmationModal from '../../components/ConfirmationModal';
// import Storage from '../../lib/Storage';
//
// describe('ConfirmationModal', () => {
// it('renders without problem', () => {
// const modalPendaftaran = ReactTestUtils.renderIntoDocument(
// <ConfirmationModal id={4} />);
// expect(modalPendaftaran).to.exist;
// });
//
// it('open without problem', () => {
// const modalPendaftaran = ReactTestUtils.renderIntoDocument(
// <ConfirmationModal id={4} />);
//
// const modal = ReactTestUtils.findRenderedDOMComponentWithTag(modalPendaftaran, 'Button');
// ReactTestUtils.Simulate.click(modal);
// expect(modalPendaftaran.state.modalOpen).to.equal(true);
// });
//
// it('close without problem', () => {
// const modalPendaftaran = ReactTestUtils.renderIntoDocument(
// <ConfirmationModal id={4} />);
//
// modalPendaftaran.handleClose();
// expect(modalPendaftaran.state.modalOpen).to.equal(false);
// });
//
// it('remove vacancy without problem', () => {
// fetchMock.delete('*', { data: 'value' });
// const modalPendaftaran = ReactTestUtils.renderIntoDocument(
// <ConfirmationModal id={4} />);
//
// const response3 = { student: { id: 1, name: 2 } };
// Storage.set('user-data', response3);
// modalPendaftaran.removeVacancy();
// expect(modalPendaftaran.state.header).to.exist;
// fetchMock.restore();
// });
//
// it('remove vacancy with problem', () => {
// fetchMock.delete('*', 404);
// const modalPendaftaran = ReactTestUtils.renderIntoDocument(
// <ConfirmationModal id={4} />);
//
// const response3 = { student: { id: 1, name: 2 } };
// Storage.set('user-data', response3);
// modalPendaftaran.removeVacancy();
// expect(modalPendaftaran.state.header).to.exist;
// fetchMock.restore();
// });
//
// it('confirm with problem', () => {
// fetchMock.delete('*', 404);
// const modalPendaftaran = ReactTestUtils.renderIntoDocument(
// <ConfirmationModal id={4} />);
//
// modalPendaftaran.confirm();
// expect(modalPendaftaran.state.header).to.equal('Permintaan gagal');
// fetchMock.restore();
// });
//
// it('render next modal without problem', () => {
// const modalPendaftaran = ReactTestUtils.renderIntoDocument(
// <ConfirmationModal id={4} />);
//
// modalPendaftaran.state.confirmed = true;
// modalPendaftaran.forceUpdate()
// expect(modalPendaftaran).to.exist;
// });
// });
import React from 'react';
import ReactTestUtils from 'react-addons-test-utils';
import ApplyConfirmationModal from '../../components/ApplyConfirmationModal';
import ConfirmationModal from '../../components/ConfirmationModal';
import fetchMock from 'fetch-mock';
import Storage from '../../lib/Storage';
import Server from '../../lib/Server';
describe('ApplyConfirmationModal', () => {
describe('ConfirmationModal', () => {
it('renders without problem', () => {
const applyModal = ReactTestUtils.renderIntoDocument(
<ApplyConfirmationModal id={4} coverLetter="letter" onChangeValue={() => {}} />,
<ConfirmationModal />,
);
expect(applyModal).to.exist;
});
it('test apply without problem', () => {
const applyModal = ReactTestUtils.renderIntoDocument(
<ApplyConfirmationModal id={4} coverLetter="letter" onChangeValue={() => {}} />,
<ConfirmationModal />,
);
const response = { student: { id: 1, name: 2 } };
Storage.set('user-data', response);
fetchMock.post('*', { data: 'value' });
applyModal.open();
applyModal.handleOpen();
applyModal.close();
applyModal.open('Menghubungkan ke Server');
expect(applyModal.state.header).to.equal('Menghubungkan ke Server');
fetchMock.restore();
});
it('test apply with problem', () => {
const applyModal = ReactTestUtils.renderIntoDocument(
<ApplyConfirmationModal id={4} coverLetter="letter" onChangeValue={() => {}} />,
<ConfirmationModal />,
);
const response = { student: { id: 1, name: 2 } };
Storage.set('user-data', response);
fetchMock.post('*', 404);
applyModal.open();
applyModal.handleOpen();
applyModal.close();
applyModal.open('Menghubungkan ke Server', '', '', () => {});
applyModal.handleYes();
expect(applyModal.state.header).to.equal('Menghubungkan ke Server');
fetchMock.restore();
});
});
\ No newline at end of file
});
......@@ -72,6 +72,7 @@ describe('Vacancy', () => {
expect(lowongan.props.data.id).to.equal(3);
Storage.set('user-data', response3);
expect(lowongan.bookmark()).to.be.undefined;
fetchMock.restore();
});
it('cancel bookmarks without problem', () => {
......@@ -79,8 +80,49 @@ describe('Vacancy', () => {
const lowongan = ReactTestUtils.renderIntoDocument(
<Vacancy status="Daftar" data={response2} bookmarked={1}/>);
const response3 = { student: { id: 1, name: 2 } };
lowongan.removeVacancyApplication();
lowongan.openConfirmationModal();
expect(lowongan.props.data.id).to.equal(3);
Storage.set('user-data', response3);
expect(lowongan.bookmark()).to.be.undefined;
fetchMock.restore();
});
it('cancel bookmarks with problem', () => {
fetchMock.delete('*', 404);
const lowongan = ReactTestUtils.renderIntoDocument(
<Vacancy status="Daftar" data={response2} bookmarked={1}/>);
const response3 = { student: { id: 1, name: 2 } };
lowongan.removeVacancyApplication();
expect(lowongan.props.data.id).to.equal(3);
Storage.set('user-data', response3);
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();
});
});
......@@ -15,7 +15,24 @@ describe('VacancyList', () => {
},
created: '2017-03-28T07:05:47.128672Z',
description: 'Lorem ipsum dolbh.',
id: 3,
id: 1,
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: null,
name: 'tutup lapak',
},
created: '2017-03-28T07:05:47.128672Z',
description: 'Lorem ipsum dolbh.',
id: 2,
name: 'Software Engineer',
open_time: '2017-03-28T05:55:38Z',
updated: '2017-03-28T07:34:13.122093Z',
......@@ -43,7 +60,7 @@ describe('VacancyList', () => {
fetchMock.get('*', response);
const vacancyList = ReactTestUtils.renderIntoDocument(
<VacancyList userId={1} url="test" />);
vacancyList.updateBookmarkList();
vacancyList.updateStatusList();
expect(JSON.stringify(vacancyList.state.bookmarkList)).to.be.defined;
fetchMock.restore();
});
......@@ -54,6 +71,7 @@ describe('VacancyList', () => {
<VacancyList userId={1} url="test" />);
vacancyList.state.vacancies = response;
vacancyList.state.bookmarkList = [{ id: 5 }, { id: 3 }, { id: 1 }];
vacancyList.updateStatusList();