Fakultas Ilmu Komputer UI

Commit e51ee2c8 authored by Zamil Majdy's avatar Zamil Majdy
Browse files

[#140656091] [#33] [Red] Add applicant and approve test

parent 21f7d414
import React from 'react';
import ReactTestUtils from 'react-addons-test-utils';
import Applicant from '../../components/Applicant';
import fetchMock from 'fetch-mock';
describe('Applicant', () => {
const stub = {
data: {
vacancy: { name: 'name' },
student: { major: 'hue' },
status: 2,
},
updateStatus: () => {},
};
const stub2 = {
data: {
vacancy: { name: 'name' },
student: { major: 'hue' },
status: 3,
},
updateStatus: () => {},
};
it('renders without problem', () => {
fetchMock.get('*', stub);
const applicant = ReactTestUtils.renderIntoDocument(
<Applicant data={stub.data} updateStatus={stub.updateStatus} />,
);
expect(applicant).to.exist;
fetchMock.restore();
});
it('bookmarks without problem', () => {
fetchMock.get('*', stub);
fetchMock.patch('*', {});
const applicant = ReactTestUtils.renderIntoDocument(
<Applicant data={stub2.data} updateStatus={stub.updateStatus} />,
);
applicant.bookmark();
expect(applicant).to.exist;
fetchMock.restore();
});
it('bookmarks with problem', () => {
fetchMock.get('*', stub);
fetchMock.patch('*', {});
const applicant = ReactTestUtils.renderIntoDocument(
<Applicant data={stub.data} updateStatus={stub.updateStatus} />,
);
applicant.bookmark();
expect(applicant).to.exist;
fetchMock.restore();
});
// it('test apply without problem', () => {
// const applyModal = ReactTestUtils.renderIntoDocument(
// <Applicant />,
// );
// const response = { student: { id: 1, name: 2 } };
//
// Storage.set('user-data', response);
// fetchMock.post('*', { data: 'value' });
// 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(
// <Applicant />,
// );
// const response = { student: { id: 1, name: 2 } };
//
// Storage.set('user-data', response);
// fetchMock.post('*', 404);
// applyModal.open('Menghubungkan ke Server', '', '', () => {});
// applyModal.handleYes();
// expect(applyModal.state.header).to.equal('Menghubungkan ke Server');
// fetchMock.restore();
// });
});
/* eslint-disable no-unused-expressions */
import React from 'react';
import ReactTestUtils from 'react-addons-test-utils';
import fetchMock from 'fetch-mock';
import ApproveModal from '../../components/ApproveModal';
describe('ApproveModal', () => {
it('renders without problem', () => {
const modalApproval = ReactTestUtils.renderIntoDocument(
<ApproveModal id={4} data={{ key: 'value' }} buttonTitle="approve" />);
<ApproveModal updateStatus={() => {}} data={{ key: 'value' }} />);
expect(modalApproval).to.exist;
});
it('open without problem', () => {
const modalApproval = ReactTestUtils.renderIntoDocument(
<ApproveModal id={4} data={{ key: 'value' }} buttonTitle="approve" />);
<ApproveModal updateStatus={() => {}} data={{ key: 'value' }} />);
const modal = ReactTestUtils.findRenderedDOMComponentWithTag(modalApproval, 'Button');
ReactTestUtils.Simulate.click(modal);
......@@ -21,10 +22,33 @@ describe('ApproveModal', () => {
it('close without problem', () => {
const modalApproval = ReactTestUtils.renderIntoDocument(
<ApproveModal id={4} data={{ key: 'value' }} buttonTitle="submit" />);
<ApproveModal updateStatus={() => {}} data={{ key: 'value' }} />);
modalApproval.handleClose();
expect(modalApproval.state.modalOpen).to.equal(false);
});
});
\ No newline at end of file
it('reject without problem', () => {
fetchMock.get('*', { });
fetchMock.patch('*', { });
const modalApproval = ReactTestUtils.renderIntoDocument(
<ApproveModal updateStatus={() => {}} data={{ key: 'value' }} />);
modalApproval.modal = { open: () => {} };
modalApproval.reject();
modalApproval.rejectApplication();
expect(modalApproval.state.rejectLoading).to.equal(true);
fetchMock.restore();
});
it('apply without problem', () => {
fetchMock.get('*', { });
fetchMock.patch('*', { });
const modalApproval = ReactTestUtils.renderIntoDocument(
<ApproveModal updateStatus={() => {}} data={{ key: 'value' }} />);
modalApproval.modal = { open: () => {} };
modalApproval.accept();
modalApproval.acceptApplication();
expect(modalApproval.state.acceptLoading).to.equal(true);
fetchMock.restore();
});
});
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