Fakultas Ilmu Komputer UI

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

[#140655219] [REFACTOR] #25 Improve test

parent 2edfea00
......@@ -34,7 +34,6 @@ export default class ProfilePage extends React.Component {
resume: '',
show_transcript: '',
},
needRefresh: 0,
bagikanTranskrip: '',
};
this.getProfile = this.getProfile.bind(this);
......@@ -42,7 +41,6 @@ export default class ProfilePage extends React.Component {
this.handleCheckbox = this.handleCheckbox.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
this.handleFile = this.handleFile.bind(this);
this.refresh = this.refresh.bind(this);
this.getProfile();
}
......@@ -82,15 +80,12 @@ export default class ProfilePage extends React.Component {
});
console.log(submitForm);
Server.submit(`/profiles/students/${this.state.id}/`, submitForm, 'PATCH').then(() => {
this.modalAlert.open('Profil berhasil diperbaharui', 'Silakan periksa kembali profil anda', this.refresh );
this.modalAlert.open('Profil berhasil diperbaharui', 'Silakan periksa kembali profil anda' );
}, error => error.then((r) => {
this.modalAlert.open('Pembaharuan profil gagal', r.error);
}));
};
refresh = () => {
this.setState({ needRefresh: (this.state.needRefresh + 1) });
}
handleFile = (e) => {
const form = this.state.form;
......@@ -173,7 +168,7 @@ export default class ProfilePage extends React.Component {
</div>
<div className="button-profile">
<a href={this.state.resume ? this.state.resume : '#'} ><Button primary size="small">Resume</Button></a>
{ this.state.show_transcript && (this.state.needRefresh > 0) &&
{ this.state.show_transcript &&
<Button primary size="small">Transkrip</Button>
}
</div>
......
......@@ -84,16 +84,37 @@ describe('ProfilePage', () => {
phone_number: null,
birth_place: null,
birth_date: null,
photo: 'dor',
major: null,
batch: null,
show_transcript: false,
};
const response2 = {
id: 3,
name: 'Muhammad R.',
user: {
url: 'http://localhost:8000/api/users/9/',
username: 'muhammad.reza42',
email: 'muhammad.reza42@ui.ac.id',
is_staff: false,
},
npm: 1406543593,
resume: null,
phone_number: null,
birth_place: null,
birth_date: null,
major: null,
batch: null,
show_transcript: true,
};
it('renders without problem', () => {
fetchMock.get('*', response);
const profile = ReactTestUtils.renderIntoDocument(
<ProfilePage route={{ own: true, data: studentSession }} user={{ data: studentSession }} params={{}} />);
profile.getProfile().then(()=> expect(profile.state.name).to.equal(response.name));
profile.updateForm(true);
fetchMock.restore();
});
......@@ -105,6 +126,29 @@ describe('ProfilePage', () => {
fetchMock.restore();
});
it('get profile for company without problem', () => {
fetchMock.get('*', response2);
const profile = ReactTestUtils.renderIntoDocument(
<ProfilePage route={{ own: false, data: studentSession }} user={{ data: companyUser }} params={{ id: 3 }} />);
profile.getProfile().then(()=> expect(profile.state.name).to.equal(response2.name));
fetchMock.restore();
});
it('show/hide transcript without problem', () => {
fetchMock.get('*', response2);
const profile = ReactTestUtils.renderIntoDocument(
<ProfilePage route={{ own: true, data: studentSession }} user={{ data: studentSession }} params={{ id: 3 }} />);
const checkboxNode = ReactTestUtils.scryRenderedDOMComponentsWithTag(profile, 'Input')[4];
const checkbox = false;
checkboxNode.value = checkbox;
profile.getProfile().then(()=> expect(profile.state.show_transcript).to.equal(true));
profile.handleCheckbox({name: 'show_transcript', value: checkbox}, {name: 'show_transcript', checked: false});
// ReactTestUtils.Simulate.change(checkboxNode, { target: {name: 'show_transcript', value: checkbox} }, {name: 'show_transcript', checked: false});
expect(profile.state.form.show_transcript).to.equal(false);
fetchMock.restore();
});
it('renders without problem when error getting data', () => {
fetchMock.get('*', 400);
const profile = ReactTestUtils.renderIntoDocument(
......@@ -155,4 +199,18 @@ describe('ProfilePage', () => {
ReactTestUtils.Simulate.change(emailNode, { target: { value: password } });
expect(emailNode.value).to.equal(password);
});
it('handle file input without problem', () => {
fetchMock.patch('*', { data: 'value' });
fetchMock.get('*', response);
const profile = ReactTestUtils.renderIntoDocument(
<ProfilePage route={{ own: true, data: studentSession }} user={{ data: studentSession }} params={{ id: 3 }} />);
const emailNode = ReactTestUtils.scryRenderedDOMComponentsWithTag(profile, 'Input')[0];
// const passwordNode = ReactDOM.findDOMNode(formLogin.refs.password);
profile.handleFile({ target: { name: 'photo', files: ['abc', 'def'] } });
expect(profile.state.form.photo).to.equal('abc');
});
});
......@@ -20,6 +20,21 @@ describe('VacancyList', () => {
open_time: '2017-03-28T05:55:38Z',
updated: '2017-03-28T07:34:13.122093Z',
verified: true,
}, {
close_time: '2019-03-28T05:55:42Z',
company: {
address: 'kebayoran baru',
id: 2,
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',
verified: true,
}];
const response2 = [{
......@@ -57,6 +72,16 @@ describe('VacancyList', () => {
});
it('update bookmarks without problem', () => {
fetchMock.get('*', response);
const vacancyList = ReactTestUtils.renderIntoDocument(
<VacancyList userId={1} url="test" />);
vacancyList.state.appliedList = [{id:1},{id:3}];
vacancyList.updateStatusList();
expect(JSON.stringify(vacancyList.state.bookmarkList)).to.be.defined;
fetchMock.restore();
});
it('check applied vacancies without problem', () => {
fetchMock.get('*', response);
const vacancyList = ReactTestUtils.renderIntoDocument(
<VacancyList userId={1} url="test" />);
......
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