Fakultas Ilmu Komputer UI

Commit 999b9635 authored by Zamil Majdy's avatar Zamil Majdy
Browse files

Merge branch 'UserStory2' of https://gitlab.com/PPL2017csui/PPLA1 into UserStory2

# Conflicts:
#	assets/js/VacancyPage.jsx
parents 366417b0 dafdd8b5
......@@ -22,21 +22,22 @@ export default class VacancyPage extends React.Component {
render() {
const student = Storage.get('user-data').student;
return (
<div className="halamanLowongan">
<Tabs selected={0}>
<Pane label="Semua Lowongan" >
<VacancyList key={1} url="/vacancies/" />
</Pane>
<Pane label="Lamaran saya" >
<VacancyList key={2} url={`/students/${student.id}/applied-vacancies/`} />
</Pane>
<Pane label="Lamaran Ditandai" >
<VacancyList key={3} url={`/students/${student.id}/bookmarked-vacancies/`} />
</Pane>
</Tabs>
</div>
<div className="halamanLowongan">
<Tabs selected={0}>
<Pane label="Semua Lowongan" >
<VacancyList key={1} studentId={student.id} url="/vacancies/" />
</Pane>
<Pane label="Lamaran saya" >
<VacancyList key={2} studentId={student.id} url={`/students/${student.id}/applied-vacancies/`} />
</Pane>
<Pane label="Lamaran Ditandai" >
<VacancyList key={3} studentId={student.id} url={`/students/${student.id}/bookmarked-vacancies/`} />
</Pane>
</Tabs>
</div>
);
}
}
/* eslint-disable no-unused-expressions */
import React from 'react';
import ReactTestUtils from 'react-addons-test-utils';
import ModalPendaftaran from '../../components/ModalPendaftaran';
import ApplyModal from '../../components/ApplyModal';
describe('ModalPendaftaran', () => {
describe('ApplyModal', () => {
it('renders without problem', () => {
const modalPendaftaran = ReactTestUtils.renderIntoDocument(
<ModalPendaftaran id={4} data={{key: 'value'}} buttonTitle="submit" />);
<ApplyModal 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" />);
<ApplyModal id={4} data={{ key: 'value' }} buttonTitle="submit" />);
const modal = ReactTestUtils.findRenderedDOMComponentWithTag(modalPendaftaran, 'Button');
ReactTestUtils.Simulate.click(modal);
......
......@@ -2,6 +2,7 @@
import React from 'react';
import ReactTestUtils from 'react-addons-test-utils';
import Vacancy from '../../components/Vacancy';
import Storage from '../../lib/Storage'
describe('Vacancy', () => {
const response ={
......@@ -21,7 +22,7 @@ describe('Vacancy', () => {
verified: true,
};
const response2 ={
const response2 = {
close_time: '2019-03-28T05:55:42Z',
company: {
address: 'kebayoran baru',
......@@ -49,4 +50,13 @@ describe('Vacancy', () => {
<Vacancy data={response2} />);
expect(lowongan).to.exist;
});
it('bookmarks without problem', () => {
const lowongan = ReactTestUtils.renderIntoDocument(
<Vacancy data={response2} />);
const response3 = { student: { id: 1, name: 2 } };
expect(lowongan.props.data.id).to.equal(3);
Storage.set('user-data', response3);
expect(lowongan.bookmark()).to.be.undefined;
});
});
......@@ -2,7 +2,7 @@ import React from 'react';
import { Modal, Button, Icon, TextArea, Form } from 'semantic-ui-react';
import ModalAlert from './ModalAlert';
export default class ModalPendaftaran extends React.Component {
export default class ApplyModal extends React.Component {
static propTypes = {
data: React.PropTypes.object.isRequired,
id: React.PropTypes.number.isRequired,
......
......@@ -57,14 +57,14 @@ export default class LoginForm extends React.Component {
<Image src={`./assets/img/${this.props.imgSrc}`} size={this.props.imgSize} verticalAlign="middle" /> <span>{ this.props.header }</span>
</div>
<Form.Group widths="equal">
<Form.Field required>
<Form.Field>
<label htmlFor="id"> Username </label>
<Input type="text" id="username" icon="user" iconPosition="left" placeholder="username" onChange={e => this.handleChange(e, 'username')} required />
</Form.Field>
</Form.Group>
<Form.Group widths="equal">
<Form.Field required>
<Form.Field>
<label htmlFor="password"> Password </label>
<Input type="password" id="password" icon="key" iconPosition="left" placeholder="password" onChange={e => this.handleChange(e, 'password')} required />
</Form.Field>
......
import React from 'react';
import { Button, Image as ImageComponent, Item, Rating, Icon } from 'semantic-ui-react'
import ModalPendaftaran from './ModalPendaftaran';
import ModalPendaftaran from './ApplyModal';
const paragraph = <ImageComponent src="http://semantic-ui.com/images/wireframe/short-paragraph.png" />;
......@@ -26,7 +26,7 @@ export default class Lowongan extends React.Component {
<h4>PT. Koding Kuat </h4>
<h5> JL.Kali deres utara no.1 Jakarta Barat, DKI Jakarta</h5>
<ModalPendaftaran id={1} data={ { header: 'Deskripsi Lowongan', description: 'Lorem ipsum dolor sit amet'} } buttonTitle="Daftar" />
<ApplicancyModal id={1} data={ { header: 'Deskripsi Lowongan', description: 'Lorem ipsum dolor sit amet'} } buttonTitle="Daftar" />
</Item.Content>
</Item.Content>
......
import React from 'react';
import { Button, Image as ImageComponent, Item, Rating } from 'semantic-ui-react';
import ModalPendaftaran from './ModalPendaftaran';
import ApplyModal from './ApplyModal';
import Storage from '../lib/Storage';
import Server from '../lib/Server';
const defaultImage = 'http://semantic-ui.com/images/wireframe/image.png';
export default class Lowongan extends React.Component {
export default class Vacancy extends React.Component {
static propTypes = {
data: React.PropTypes.object.isRequired,
bookmarked: React.PropTypes.number,
};
static defaultProps = {
bookmarked: 0,
};
constructor(props) {
super(props);
/* istanbul ignore next */
this.state = { bookmarked: this.props.bookmarked };
this.bookmark = this.bookmark.bind(this);
}
bookmark() {
const studentId = Storage.get('user-data').student.id;
const data = { vacancy_id: this.props.data.id };
Server.post(`/students/${studentId}/bookmarked-vacancies/`, data).then((response) => {
console.log(JSON.stringify(response));
}, (error) => {
console.log(JSON.stringify(error));
});
if (this.state.bookmarked < 1){
Server.post(`/students/${studentId}/bookmarked-vacancies/`, data);
} else {
Server.delete(`/students/${studentId}/bookmarked-vacancies/${this.props.data.id}/`);
}
this.state.bookmarked = 1 - this.state.bookmarked;
}
render() {
......@@ -36,12 +43,12 @@ export default class Lowongan extends React.Component {
<h3>{ this.props.data.name }</h3>
<div className="bookmark">
<Rating icon="star" onRate={this.bookmark} size="massive" defaultRating={0} maxRating={1} />
<Rating icon="star" onRate={this.bookmark} size="massive" defaultRating={this.props.bookmarked} maxRating={1} />
</div>
<h4>{ this.props.data.company.name }</h4>
<h5>{ this.props.data.company.address }</h5>
<ModalPendaftaran
<ApplyModal
id={this.props.data.id} data={{ header: this.props.data.name,
description: this.props.data.description }} buttonTitle="Daftar"
/>
......
import React from 'react';
import { Item } from 'semantic-ui-react';
import Lowongan from './Vacancy';
import Vacancy from './Vacancy';
import Server from '../lib/Server';
export default class VacancyList extends React.Component {
static propTypes = {
url: React.PropTypes.string.isRequired,
studentId: React.PropTypes.number.isRequired,
};
static defaultProps = {
bookmarkList: false,
};
constructor(props) {
super(props);
/* istanbul ignore next */
this.updateBookmarkList();
Server.get(this.props.url, false).then((data) => {
this.setState({ vacancies: data });
});
/* istanbul ignore next */
this.state = { vacancies: [] };
this.state = { vacancies: [], bookmarkList: [] };
this.updateBookmarkList = this.updateBookmarkList.bind(this);
this.generateVacancies = this.generateVacancies.bind(this);
this.checkBookmark = this.checkBookmark.bind(this);
}
checkBookmark(id) {
for (let i = 0; i < this.state.bookmarkList.length; i++) {
if (id == this.state.bookmarkList[i].id) { return 1; }
}
return 0;
}
updateBookmarkList() {
Server.get(`/students/${this.props.studentId}/bookmarked-vacancies/`, false).then((data) => {
this.setState({ bookmarkList: data });
});
}
generateVacancies() {
return this.state.vacancies.map(vacancy =>
<Lowongan key={vacancy.id} data={vacancy} />,
<Vacancy key={vacancy.id} bookmarked={this.checkBookmark(vacancy.id)} data={vacancy} />,
);
}
......@@ -32,4 +52,4 @@ export default class VacancyList extends React.Component {
{ this.generateVacancies() }
</Item.Group>
);
}
\ No newline at end of file
}
......@@ -35,6 +35,7 @@ module.exports = {
exclude: [
path.resolve('node_modules/'),
path.resolve('assets/js/__test__/'),
path.resolve('assets/js/components/ModalAlert.jsx'),
],
loader: 'istanbul-instrumenter-loader' }],
},
......
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