Fakultas Ilmu Komputer UI

Commit d79c880a authored by sirinbaisa's avatar sirinbaisa
Browse files

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

# Conflicts:
#	assets/js/components/TopMenu.jsx
parents 7c7d7699 83ea6c3d
......@@ -7,7 +7,6 @@ import Login from './Login';
import VacancyPage from './VacancyPage';
import CompanyRegister from './CompanyRegister';
import Server from './lib/Server';
// import Register from './CompanyRegister'
export const Profile = () => (
<Segment>
......@@ -22,12 +21,17 @@ export default class App extends React.Component {
super(props);
/* istanbul ignore next */
this.handleAuth = this.handleAuth.bind(this);
this.handleHome = this.handleHome.bind(this);
}
handleAuth = (nextState, replace) => (
Server.isLoggedIn() || replace({ pathname: '/login' })
);
handleHome= (nextState, replace) => (
Server.isLoggedIn() ? replace({ pathname: '/lowongan' }) : replace({ pathname: '/login' })
);
render = () => (
<Router history={browserHistory}>
......@@ -35,11 +39,12 @@ export default class App extends React.Component {
<Route path="/register" component={CompanyRegister} />
<Route component={Dashboard} onEnter={this.handleAuth}>
<Route path="/" component={Profile} />
<Route path="profile" component={Profile} />
<Route path="lowongan" component={VacancyPage} />
<Route path="users" component={Profile} />
<Route path="/profile" component={Profile} />
<Route path="/lowongan" component={VacancyPage} />
<Route path="/users" component={Profile} />
</Route>
<Redirect from="*" to="/login" />
<Route path="/home" onEnter={this.handleHome} />
<Redirect from="*" to="/home" />
</Router>
);
}
......
// /* 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;
});
});
......@@ -2,6 +2,7 @@ import React from 'react';
import { Form, Input, Button, Message, Image, Card } from 'semantic-ui-react';
import { browserHistory } from 'react-router';
import Server from '../lib/Server';
import Storage from '../lib/Storage';
export default class LoginForm extends React.Component {
......@@ -21,7 +22,7 @@ export default class LoginForm extends React.Component {
constructor(props) {
super(props);
/* istanbul ignore next */
this.state = { email: '', password: '', errorFlag: false };
this.state = { username: '', password: '', errorFlag: false };
this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}
......@@ -33,11 +34,13 @@ export default class LoginForm extends React.Component {
handleSubmit(event) {
event.preventDefault();
const data = {
type: this.props.type,
email: this.state.email,
'login-type': this.props.type,
username: this.state.username,
password: this.state.password,
};
Server.post('api/login/', data).then(() => {
Server.post('/login/', data).then((response) => {
Storage.set('user-data', response);
browserHistory.push('/home');
}, () => {
this.setState({ errorFlag: true });
......@@ -55,8 +58,8 @@ export default class LoginForm extends React.Component {
</div>
<Form.Group widths="equal">
<Form.Field required>
<label htmlFor="id"> Email </label>
<Input type="text" id="email" icon="user" iconPosition="left" placeholder="email" onChange={e => this.handleChange(e, 'email')} required />
<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>
......@@ -70,7 +73,7 @@ export default class LoginForm extends React.Component {
<Button type="submit" fluid color="blue">Login</Button>
<Message
error
content="Login gagal: email atau password salah."
content="Login gagal: username atau password salah."
/>
</Form>
......
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}
......
import React from 'react';
import { Menu, Image } from 'semantic-ui-react';
import { Link } from 'react-router';
import { Link, browserHistory } from 'react-router';
import Server from '../lib/Server';
import Storage from '../lib/Storage';
export default class TopMenu extends React.Component {
<<<<<<< HEAD
state = { activeItem: 'home' };
handleItemClick = (e, { name }) => this.setState({ activeItem: name })
render() {
const { activeItem } = this.state;
=======
constructor(props) {
super(props);
/* istanbul ignore next */
this.logout = this.logout.bind(this);
}
logout = () => {
Server.get('/api-auth/logout/?next=/', true).then(() => {
Storage.clear();
browserHistory.push('/login');
});
};
>>>>>>> 83ea6c3d4376e9644af1ae3104de3d496ee20b98
render() {
return (
<Menu color='blue' pointing secondary>
<Menu color="blue" pointing secondary>
<Image as="a" size="small" src="/assets/img/logo.png" href="/" />
<Menu.Menu position="right">
<Menu.Item as={Link} to="/lowongan" name='home' active={activeItem === 'home'} onClick={this.handleItemClick} />
<Menu.Item as={Link} to="/profile" name='profil' active={activeItem === 'profil'} onClick={this.handleItemClick}/>
{Server.isLoggedIn() ?
<Menu.Item as={Link} href="/api/api-auth/logout/?next=/" name='logout' active={activeItem === 'logout'} onClick={this.handleItemClick}/> :
<Menu.Item as={Link} to="/login" name='login' active={activeItem === 'login'} onClick={this.handleItemClick} />
}
<Menu.Item as={Link} to="/lowongan" name="home" onClick={this.handleItemClick} />
<Menu.Item as={Link} to="/profile" name="profil" onClick={this.handleItemClick} />
<Menu.Item as={Link} onClick={this.logout} name="logout" />
</Menu.Menu>
</Menu>
);
......
import React from 'react';
import { Button, Image as ImageComponent, Item, Rating } from 'semantic-ui-react'
import ModalPendaftaran from './ModalPendaftaran';
const defaultImage = "http://semantic-ui.com/images/wireframe/image.png";
export default class Lowongan extends React.Component {
static propTypes = {
data: React.PropTypes.object.isRequired,
};
render() {
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>
<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,10 +11,9 @@ export default class VacancyList extends React.Component {
constructor(props) {
super(props);
/* istanbul ignore next */
this.state = { vacancies: [] };
console.log(Server.isLoggedIn());
Server.get(this.props.url).then((data) => {
console.log(data);
Server.get(this.props.url, false).then((data) => {
this.setState({ vacancies: data });
}, () => {
});
......@@ -31,9 +30,7 @@ export default class VacancyList extends React.Component {
render = () => {
return (
<Item.Group relaxed>
{/*<Item.Group relaxed>*/}
{ this.generateVacancies() }
{/*</Item.Group>*/}
</Item.Group>
);
}
......
......@@ -44,7 +44,8 @@ export default class Server {
if (response.status === 204) {
return response;
}
return response.json();
const contentType = response.headers.get("content-type");
return contentType && contentType.indexOf("application/json") !== -1 ? response.json() : response.text();
});
/* istanbul ignore next */
......
# __init__.py
from core.tests.test_login import LoginTests
from core.tests.test_accounts import LoginTests
from core.tests.test_vacancies import ApplicationTests, BookmarkApplicationTests
import requests_mock
from rest_framework import status
from rest_framework.test import APITestCase
from django.contrib.auth.models import User
from core.models.accounts import Company
class LoginTests(APITestCase):
@requests_mock.Mocker()
def test_login(self, m):
def test_succesful_student_login_relogin(self, m):
"""
Ensure we can login
"""
m.post('https://api.cs.ui.ac.id/authentication/ldap/v2/', [{'json': {
m.post('https://api.cs.ui.ac.id/authentication/ldap/v2/', json={
"username": "dummy.mahasiswa",
"nama": "Dummy Mahasiswa",
"state": 1,
"kode_org": "01.00.12.01:mahasiswa",
"kodeidentitas": "1234567890",
"nama_role": "mahasiswa"
}, 'status_code': 200}, {'json': {
"username": "dummy.mahasiswa",
"nama": "Dummy Mahasiswa",
"state": 1,
"kode_org": "01.00.12.01:mahasiswa",
"kodeidentitas": "1234567890",
"nama_role": "mahasiswa"
}, 'status_code': 200}, {'json': {
"username": "dummy.dosen",
"nama": "Dummy Dosen",
"state": 1,
"kode_org": "01.00.12.01:dosen",
"kodeidentitas": "1234567820",
"nama_role": "dosen"
}, 'status_code': 200}, {'json': {
"state": 0
}, 'status_code': 200}])
}, status_code=200)
url = '/api/login/'
response = self.client.post(url, { 'username' : 'dummy.mahasiswa', 'password' : 'lalala', 'login-type' : 'sso-ui'}, format='json')
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
response = self.client.post(url, {'username': 'dummy.mahasiswa', 'password': 'lalala', 'login-type': 'sso-ui'},
format='json')
response = self.client.post(url, {'username': 'dummy.mahasiswa', 'password': 'lalala', 'login-type': 'sso-ui'}, format='json')
self.assertEqual(response.status_code, status.HTTP_200_OK)
@requests_mock.Mocker()
def test_successful_supervisor_login_relogin(self, m):
m.post('https://api.cs.ui.ac.id/authentication/ldap/v2/', json={
"username": "dummy.dosen",
"nama": "Dummy Dosen",
"state": 1,
"kode_org": "01.00.12.01:dosen",
"kodeidentitas": "1234567891",
"nama_role": "dosen"
}, status_code=200)
url = '/api/login/'
response = self.client.post(url, {'username': 'dummy.dosen', 'password': 'lalala', 'login-type': 'sso-ui'}, format='json')
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
response = self.client.post(url, {'username': 'dummy.dosen', 'password': 'lalala', 'login-type': 'sso-ui'}, format='json')
self.assertEqual(response.status_code, status.HTTP_200_OK)
@requests_mock.Mocker()
def test_failed_sso_login(self, m):
m.post('https://api.cs.ui.ac.id/authentication/ldap/v2/', json={
"state": 0
}, status_code=200)
url = '/api/login/'
response = self.client.post(url, {'username': 'dummy.salah', 'password': 'lalala', 'login-type': 'sso-ui'}, format='json')
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
response = self.client.post(url, {'username': 'dummy.perusahaan.salah', 'password': 'lalala', 'login-type': 'perusahaan'}, format='json')
def test_failed_company_login(self):
url = '/api/login/'
response = self.client.post(url, {'username': 'dummy.company.failed', 'password': 'lalala', 'login-type': 'company'}, format='json')
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
def test_success_company_login(self):
new_user = User.objects.create_user('dummy.login.company', 'dummy.login.company@company.com', 'lalala123')
new_company = Company.objects.create(user=new_user, description="lalalala", verified=True, logo=None, alamat=None)
url = '/api/login/'
response = self.client.post(url, {'username': 'dummy.login.company', 'password': 'lalala123', 'login-type': 'company'}, format='json')
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
def test_bad_request(self):
url = '/api/login/'
response = self.client.post(url, {'uesrname': 'lalala'}, format='json')
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
\ No newline at end of file
from datetime import datetime
import requests_mock
from rest_framework import status
from rest_framework.test import APITestCase
from django.contrib.auth.models import User
from core.models.accounts import Company
from core.models.vacancies import Vacancy
class ApplicationTests(APITestCase):
@requests_mock.Mocker()
def test_application_list(self, m):
m.post('https://api.cs.ui.ac.id/authentication/ldap/v2/', json={
"username": "dummy.mahasiswa",
"nama": "Dummy Mahasiswa",
"state": 1,
"kode_org": "01.00.12.01:mahasiswa",
"kodeidentitas": "1234567890",
"nama_role": "mahasiswa"
}, status_code=200)
url = '/api/login/'