Fakultas Ilmu Komputer UI

Commit 9c5db625 authored by Zamil Majdy's avatar Zamil Majdy
Browse files

[Test] Add new testcases on Create Vacancy test

parent f922213e
import React from 'react';
import { Segment, Button, Form, TextArea, Header, Icon, Image } from 'semantic-ui-react';
export default class CreateLowongan extends React.Component {
render() {
return (
<div className="create-lowongan" >
<Segment className="form-segment">
<Header as='h2' icon textAlign='center'>
<Icon name='briefcase' circular />
<Header.Content>
Lowongan KP
</Header.Content>
</Header>
<Form>
<Form.Field>
<label>Posisi Lowongan</label>
<input placeholder="Posisi" />
</Form.Field>
<Form.Field label='Alamat Kantor' control='select'>
<option value='alamat1'>Alamat 1</option>
<option value='alamat2'>Alamat 2</option>
<input placeholder="Alamat" />
</Form.Field>
<Form.TextArea label="Deskripsi" placeholder="Deskripsi Lowongan..." row />
<Button type="submit" primary floated="right">Submit</Button>
</Form>
</Segment>
</div>
);
}
}
import React from 'react';
import ReactTestUtils from 'react-addons-test-utils';
import CreateLowongan from '../CreateLowongan';
import fetchMock from 'fetch-mock';
import CreateVacancy from '../CreateVacancy';
import Storage from '../lib/Storage';
describe('CreateLowongan', () => {
describe('CreateVacancy', () => {
const companySession = {
url: 'http://localhost:8001/api/users/8/',
username: 'Tutuplapak',
......@@ -41,16 +42,72 @@ describe('CreateLowongan', () => {
it('renders for companies without problem', () => {
Storage.set('user-data', companySession);
const createLowongan = ReactTestUtils.renderIntoDocument(
<CreateLowongan />);
expect(createLowongan).to.exist;
const createVacancy = ReactTestUtils.renderIntoDocument(
<CreateVacancy />,
);
expect(createVacancy).to.exist;
});
it('renders without problem for error case', () => {
Storage.set('user-data', errorSession);
const createLowongan = ReactTestUtils.renderIntoDocument(
<CreateLowongan />);
expect(createLowongan).to.exist;
const createVacancy = ReactTestUtils.renderIntoDocument(
<CreateVacancy />,
);
expect(createVacancy).to.exist;
});
it('support handle change', () => {
Storage.set('user-data', companySession);
const createVacancy = ReactTestUtils.renderIntoDocument(
<CreateVacancy />,
);
createVacancy.setState({
name: 'stub',
description: 'stub',
});
createVacancy.handleChange({ target: { name: 'test', value: 'hue' } });
expect(createVacancy.state.test).to.equal('hue');
});
it('submit vacancy properly (loading)', () => {
fetchMock.post('*', 404);
Storage.set('user-data', companySession);
const createVacancy = ReactTestUtils.renderIntoDocument(
<CreateVacancy />,
);
createVacancy.setState({
name: 'stub',
description: 'stub',
});
const openField = ReactTestUtils.findRenderedDOMComponentWithClass(createVacancy, 'open-time-field');
const closeField = ReactTestUtils.findRenderedDOMComponentWithClass(createVacancy, 'close-time-field');
ReactTestUtils.Simulate.click(openField);
ReactTestUtils.Simulate.keyDown(openField, { key: 'Enter', keyCode: 13, which: 13 });
ReactTestUtils.Simulate.click(closeField);
ReactTestUtils.Simulate.keyDown(closeField, { key: 'Enter', keyCode: 13, which: 13 });
expect(createVacancy.state.formLoading).to.equal(false);
createVacancy.handleSubmit(new Event('click'));
expect(createVacancy.state.formLoading).to.equal(true);
fetchMock.restore();
});
it('submit vacancy properly (success)', () => {
fetchMock.post('*', { data: 'value' });
Storage.set('user-data', companySession);
const createVacancy = ReactTestUtils.renderIntoDocument(
<CreateVacancy />,
);
createVacancy.setState({
name: 'stub',
description: 'stub',
});
expect(createVacancy.state.formLoading).to.equal(false);
createVacancy.handleSubmit(new Event('click'));
expect(createVacancy.state.formLoading).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