Fakultas Ilmu Komputer UI

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

[#140652771] #18 Refactor VacancyPage for company

parent 4c4a2a30
...@@ -6,38 +6,78 @@ import VacancyList from './components/VacancyList'; ...@@ -6,38 +6,78 @@ import VacancyList from './components/VacancyList';
export default class VacancyPage extends React.Component { 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' };
}
return { id: '0', type: 'error' };
}
constructor(props) { constructor(props) {
super(props); super(props);
/* istanbul ignore next */ /* istanbul ignore next */
const role = VacancyPage.getRole();
this.state = { this.state = {
email: '',
password: '',
errorFlag: false,
vacancies: [], vacancies: [],
id: role.type,
role: role.type,
}; };
this.handleItemClick = this.handleItemClick.bind(this);
} }
handleItemClick = (e, { name }) => this.setState({ activeItem: name }); generateVacancies() {
if (this.state.role === 'student') {
return (
<Tabs selected={0}>
<Pane label="Semua Lowongan" >
<VacancyList
key={1}
studentId={this.state.id}
url="/vacancies/"
/>
</Pane>
<Pane label="Lamaran saya" >
<VacancyList
key={2}
status="Batal"
studentId={this.state.id}
url={`/students/${this.state.id}/applied-vacancies/`}
/>
</Pane>
<Pane label="Lamaran Ditandai" >
<VacancyList
key={3}
studentId={this.state.id}
url={`/students/${this.state.id}/bookmarked-vacancies/`}
/>
</Pane>
</Tabs>
);
} else if (this.state.role === 'company') {
return (
<VacancyList key={1} studentId={this.state.id} url="/vacancies/" />
);
}
console.log(this.state);
return (
<div>
<h3>
Anda tidak terautentifikasi. Harap logout dan login
kembali dengan akun yang benar
</h3>
</div>
);
}
render() { render() {
const student = Storage.get('user-data').student;
return ( return (
<div className="halamanLowongan"> <div className="applicant">
<Tabs selected={0}> { this.generateVacancies() }
<Pane label="Semua Lowongan" > </div>
<VacancyList key={1} studentId={student.id} url="/vacancies/" />
</Pane>
<Pane label="Lamaran saya" >
<VacancyList key={2} status="Batal" studentId={student.id} url={`/students/${student.id}/applied-vacancies/`} />
</Pane>
<Pane label="Lamaran Ditandai" >
<VacancyList key={3} studentId={student.id} url={`/students/${student.id}/bookmarked-vacancies/`} />
</Pane>
</Tabs>
</div>
); );
} }
} }
...@@ -61,6 +61,17 @@ describe('VacancyList', () => { ...@@ -61,6 +61,17 @@ describe('VacancyList', () => {
supervisor: null, supervisor: null,
student: null, student: null,
}; };
const errorSession = {
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', () => { it('renders for companies without problem', () => {
Storage.set('user-data', companySession); Storage.set('user-data', companySession);
const vacancyPage = ReactTestUtils.renderIntoDocument( const vacancyPage = ReactTestUtils.renderIntoDocument(
...@@ -74,7 +85,15 @@ describe('VacancyList', () => { ...@@ -74,7 +85,15 @@ describe('VacancyList', () => {
const vacancyPage = ReactTestUtils.renderIntoDocument( const vacancyPage = ReactTestUtils.renderIntoDocument(
<VacancyPage studentId={1} url="test" />); <VacancyPage studentId={1} url="test" />);
expect(vacancyPage).to.exist; expect(vacancyPage).to.exist;
expect(vacancyPage.state.role).to.equal('company'); 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" />);
expect(vacancyPage).to.exist;
expect(vacancyPage.state.role).to.equal('error');
}); });
}); });
...@@ -22,7 +22,7 @@ describe('VacancyList', () => { ...@@ -22,7 +22,7 @@ describe('VacancyList', () => {
updated: '2017-03-28T07:34:13.122093Z', updated: '2017-03-28T07:34:13.122093Z',
verified: true, verified: true,
}]; }];
const response2 = { hello: 'not-world' }; // const response2 = { hello: 'not-world' };
it('renders without problem', () => { it('renders without problem', () => {
fetchMock.get('*', response); fetchMock.get('*', response);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment