Fakultas Ilmu Komputer UI

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

[#140655219] [REFACTOR] #25 Refactor test code for ProfilePage

parent d2914308
......@@ -29,7 +29,7 @@ export default class ProfilePage extends React.Component {
photo: '',
form: {
picture: '',
name: '',
email: '',
phone_number: '',
resume: '',
show_transcript: '',
......
......@@ -42,14 +42,32 @@ describe('ProfilePage', () => {
},
};
const brokenSession = {
url: 'http://localhost:8000/api/users/9/',
username: 'muhammad.reza42',
email: 'muhammad.reza42@ui.ac.id',
is_staff: false,
company: null,
supervisor: null,
student: null,
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',
},
supervisor: null,
student: null,
},
};
const response = {
......@@ -72,15 +90,17 @@ describe('ProfilePage', () => {
};
it('renders without problem', () => {
fetchMock.get('*', response);
const profile = ReactTestUtils.renderIntoDocument(
<ProfilePage route={{ own: true, data: studentSession }} params={{}} />);
expect(profile.state.name).to.equal(studentSession.student.name);
<ProfilePage route={{ own: true, data: studentSession }} user={{ data: studentSession }} params={{}} />);
profile.getProfile().then(()=> expect(profile.state.name).to.equal(response.name));
fetchMock.restore();
});
it('get profile for company without problem', () => {
fetchMock.get('*', response);
const profile = ReactTestUtils.renderIntoDocument(
<ProfilePage route={{ own: false, data: studentSession }} params={{ id: 3 }} />);
<ProfilePage route={{ own: false, data: studentSession }} user={{ data: companyUser }} params={{ id: 3 }} />);
profile.getProfile().then(()=> expect(profile.state.name).to.equal(response.name));
fetchMock.restore();
});
......@@ -88,7 +108,51 @@ describe('ProfilePage', () => {
it('renders without problem when error getting data', () => {
fetchMock.get('*', 400);
const profile = ReactTestUtils.renderIntoDocument(
<ProfilePage route={{ own: false, data: studentSession }} params={{ id: 3 }} />);
<ProfilePage route={{ own: false, data: studentSession }} user={{ data: studentSession }} params={{ id: 3 }} />);
profile.getProfile().then(()=> expect(profile.state.name).to.equal('Gagal mendapatkan informasi'));
});
it('submit form without problem', () => {
fetchMock.patch('*', { data: 'value' });
const profile = ReactTestUtils.renderIntoDocument(
<ProfilePage route={{ own: true, data: studentSession }} user={{ data: studentSession }} params={{ id: 3 }} />);
profile.state.form = {name: 'abra', email:''};
const submitButton = ReactTestUtils.scryRenderedDOMComponentsWithTag(profile, 'Input')[1];
ReactTestUtils.Simulate.click(submitButton);
const form = ReactTestUtils.findRenderedDOMComponentWithTag(profile, 'Form');
ReactTestUtils.Simulate.submit(form);
fetchMock.restore();
});
it('render without problem when submit file error', () => {
fetchMock.patch('*', 400);
fetchMock.get('*', response);
const profile = ReactTestUtils.renderIntoDocument(
<ProfilePage route={{ own: true, data: studentSession }} user={{ data: studentSession }} params={{ id: 3 }} />);
profile.state.form = {name: 'abra', email:''};
const submitButton = ReactTestUtils.scryRenderedDOMComponentsWithTag(profile, 'Input')[1];
ReactTestUtils.Simulate.click(submitButton);
const form = ReactTestUtils.findRenderedDOMComponentWithTag(profile, 'Form');
ReactTestUtils.Simulate.submit(form);
fetchMock.restore();
});
it('handle email 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')[1];
// const passwordNode = ReactDOM.findDOMNode(formLogin.refs.password);
const password = 'passwd';
emailNode.value = password;
expect(profile.state.form.email).to.equal('');
ReactTestUtils.Simulate.change(emailNode, { target: { value: password } });
expect(emailNode.value).to.equal(password);
});
});
......@@ -37,6 +37,23 @@ describe('CompanyVacancy', () => {
verified: true,
};
const response3 = {
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: false,
};
it('renders with logo without problem', () => {
const companyVacancy = ReactTestUtils.renderIntoDocument(
<CompanyVacancy data={response2} />);
......@@ -49,6 +66,12 @@ describe('CompanyVacancy', () => {
expect(companyVacancy).to.exist;
});
it('renders without logo for unverified company without problem', () => {
const companyVacancy = ReactTestUtils.renderIntoDocument(
<CompanyVacancy data={response3} />);
expect(companyVacancy).to.exist;
});
it('loads when delete button clicked', () => {
const companyVacancy = ReactTestUtils.renderIntoDocument(
<CompanyVacancy data={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