Fakultas Ilmu Komputer UI

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

#140654507 #13 improve testing and component for vacancy js consumer

parent 7b2905fd
// /* eslint-disable no-unused-expressions */
// import React from 'react';
// import ReactTestUtils from 'react-addons-test-utils';
// import Lowongan from '../components/ComponentRegister';
// import Vacancy from '../components/ComponentRegister';
//
// describe('Lowongan', () => {
// describe('Vacancy', () => {
// it('renders without problem', () => {
// let companyRegister = ReactTestUtils.renderIntoDocument(
// <CompanyRegister />);
......
/* eslint-disable no-unused-expressions */
import React from 'react';
import ReactTestUtils from 'react-addons-test-utils';
import Lowongan from '../../components/Lowongan';
describe('Lowongan', () => {
it('renders without problem', () => {
let lowongan = ReactTestUtils.renderIntoDocument(
<Lowongan />);
expect(lowongan).to.exist;
lowongan = ReactTestUtils.renderIntoDocument(
<Lowongan image="img" header="header" content="content" paragraph="paragraph"/>);
expect(lowongan).to.exist;
});
});
\ No newline at end of file
import React from 'react';
import ReactTestUtils from 'react-addons-test-utils';
import ModalAlert from '../../components/ModalAlert';
describe('ModalAlert', () => {
it('renders without problem', () => {
const modalAlert = ReactTestUtils.renderIntoDocument(
<ModalAlert id={4} coverLetter="letter" onChangeValue={() => {}}/>);
expect(modalAlert).to.exist;
});
});
\ No newline at end of file
......@@ -5,8 +5,17 @@ import ModalPendaftaran from '../../components/ModalPendaftaran';
describe('ModalPendaftaran', () => {
it('renders without problem', () => {
const ModalPendaftaran = ReactTestUtils.renderIntoDocument(
<ModalPendaftaran header="header" buttontTitle="buttonTitle" content="content"/>);
expect(ModalPendaftaran).to.exist;
const modalPendaftaran = ReactTestUtils.renderIntoDocument(
<ModalPendaftaran id={4} data={{key: 'value'}} buttonTitle="submit" />);
expect(modalPendaftaran).to.exist;
});
it('open without problem', () => {
const modalPendaftaran = ReactTestUtils.renderIntoDocument(
<ModalPendaftaran id={4} data={{ key: 'value' }} buttonTitle="submit" />);
const modal = ReactTestUtils.findRenderedDOMComponentWithTag(modalPendaftaran, 'Button');
ReactTestUtils.Simulate.click(modal);
});
});
\ No newline at end of file
});
/* eslint-disable no-unused-expressions */
import React from 'react';
import ReactTestUtils from 'react-addons-test-utils';
import Vacancy from '../../components/Vacancy';
describe('Vacancy', () => {
const response ={
close_time: '2019-03-28T05:55:42Z',
company: {
address: 'kebayoran baru',
id: 1,
logo: null,
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: true,
};
const response2 ={
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: true,
};
it('renders null picture without problem', () => {
const lowongan = ReactTestUtils.renderIntoDocument(
<Vacancy data={response} />);
expect(lowongan).to.exist;
});
it('renders with picture without problem', () => {
const lowongan = ReactTestUtils.renderIntoDocument(
<Vacancy data={response2} />);
expect(lowongan).to.exist;
});
});
......@@ -2,21 +2,41 @@
import React from 'react';
import ReactTestUtils from 'react-addons-test-utils';
import VacancyList from '../../components/VacancyList';
import Lowongan from '../../components/Lowongan';
import Server from '../../lib/Server';
describe('VacancyList', () => {
it('created without problem', () => {
const vacancyList = new VacancyList();
expect(vacancyList).to.be.an.instanceof(VacancyList);
});
const fetchMock = require('fetch-mock');
const response = [{
close_time: '2019-03-28T05:55:42Z',
company: {
address: 'kebayoran baru',
id: 1,
logo: null,
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: true,
}];
const response2 = { hello: 'not-world' };
it('renders without problem', () => {
const vacancyList = ReactTestUtils.renderIntoDocument(
<VacancyList vacancies={[{ key: 'value' }, { key2: 'value2' }]} />);
<VacancyList url="test" />);
expect(vacancyList).to.exist;
});
React.Children.forEach(vacancyList.props.children, (child) => {
expect(child).to.be.an.instanceof(Lowongan);
it('success calling API', () => {
fetchMock.get('*', response);
const vacancyList = ReactTestUtils.renderIntoDocument(
<VacancyList url="test" />);
vacancyList.state.vacancies = response;
expect(JSON.stringify(vacancyList.state.vacancies)).to.equal(JSON.stringify(response));
expect(vacancyList.generateVacancies()).to.exist;
});
});
});
......@@ -24,7 +24,22 @@ import Server from './../../lib/Server';
describe('Server get test', () => {
const fetchMock = require('fetch-mock');
const response = { hello: 'world' };
const response = {
close_time: '2019-03-28T05:55:42Z',
company: {
address: 'kebayoran baru',
id: 1,
logo: null,
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: true,
};
it('Check Server get right response', () => {
fetchMock.get('*', response);
......@@ -85,6 +100,6 @@ describe('Server get test', () => {
it('Check getcookie method', () => {
document.cookie = ';test=test;';
expect(Server.getCookie('test')).to.not.exist;
expect(Server.getCookie('test')).to.exist;
});
});
import React from 'react';
import { Modal, Button, Icon } from 'semantic-ui-react';
import Server from '../lib/Server';
import Logger from '../lib/Logger';
export default class ModalAlert extends React.Component {
static propTypes = {
......@@ -25,7 +24,6 @@ export default class ModalAlert extends React.Component {
close = () => this.setState({ open: false });
handleOpen() {
Logger.log(this.state);
const requestData = { coverLetter: this.props.coverLetter };
Server.post(`/students/${this.props.id}/application`, requestData).then((data) => {
this.setState({
......
......@@ -26,7 +26,7 @@ export default class ModalPendaftaran extends React.Component {
}
handleChange(event) {
// this.setState({ coverLetter: event.target.value });
this.setState({ coverLetter: event.target.value });
}
handleOpen() {
......@@ -39,7 +39,7 @@ export default class ModalPendaftaran extends React.Component {
render = () => (
<Modal
trigger={<Button onClick={this.handleOpen} floated='right'>{this.props.buttonTitle}</Button>}
trigger={<Button onClick={this.handleOpen} floated="right">{this.props.buttonTitle}</Button>}
closeIcon="close"
open={this.state.modalOpen}
onClose={this.handleClose}
......
......@@ -10,25 +10,22 @@ export default class Lowongan extends React.Component {
};
render() {
console.log(this.props.data);
console.log(this.props.data.company);
return (
<Item >
<Item.Image size="small" src={this.props.data.company.logo ? this.props.data.company.logo: defaultImage} />
<Item.Content verticalAlign="middle">
<Item.Extra>
<h3>{ this.props.data.name }</h3>
<h4>{ this.props.data.company.name }</h4>
<h5>{ this.props.data.company.address }</h5>
<Item >
<Item.Image size="small" src={this.props.data.company.logo ? this.props.data.company.logo: defaultImage} />
<Item.Content verticalAlign="middle">
<Item.Extra>
<h3>{ this.props.data.name }</h3>
<h4>{ this.props.data.company.name }</h4>
<h5>{ this.props.data.company.address }</h5>
<ModalPendaftaran id={this.props.data.id} data={{ header: this.props.data.name,
description: this.props.data.description }} buttonTitle="Daftar" />
</Item.Extra>
</Item.Content>
</Item>
<ModalPendaftaran
id={this.props.data.id} data={{ header: this.props.data.name,
description: this.props.data.description }} buttonTitle="Daftar" />
</Item.Extra>
</Item.Content>
</Item>
);
}
}
\ No newline at end of file
import React from 'react';
import { Item } from 'semantic-ui-react';
import Lowongan from './Lowongan';
import Lowongan from './Vacancy';
import Server from '../lib/Server';
export default class VacancyList extends React.Component {
......@@ -11,9 +11,9 @@ export default class VacancyList extends React.Component {
constructor(props) {
super(props);
/* istanbul ignore next */
this.state = { vacancies: [] };
Server.get(this.props.url, false).then((data) => {
console.log(data);
this.setState({ vacancies: data });
}, () => {
});
......@@ -29,9 +29,7 @@ export default class VacancyList extends React.Component {
render = () => {
return (
<Item.Group relaxed>
{/*<Item.Group relaxed>*/}
{ this.generateVacancies() }
{/*</Item.Group>*/}
</Item.Group>
);
}
......
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