Fakultas Ilmu Komputer UI

Commit 530f3cff authored by Zamil Majdy's avatar Zamil Majdy
Browse files

[#140655219] Refactor ModalAlert

parent b3f14087
import React from 'react';
import ReactTestUtils from 'react-addons-test-utils';
import ModalAlert from '../../components/ModalAlert';
import ApplyConfirmationModal from '../../components/ApplyConfirmationModal';
describe('ModalAlert', () => {
describe('ApplyConfirmationModal', () => {
it('renders without problem', () => {
const modalAlert = ReactTestUtils.renderIntoDocument(
<ModalAlert id={4} coverLetter="letter" onChangeValue={() => {}}/>);
<ApplyConfirmationModal id={4} coverLetter="letter" onChangeValue={() => {}}/>);
expect(modalAlert).to.exist;
});
});
\ No newline at end of file
......@@ -96,7 +96,7 @@ describe('Server get test', () => {
it('Check submit method', () => {
fetchMock.get('*', {hue : "hue", hui : "hui"});
Server.submit('/test', {}, 'GET', true).then((data) => { expect(data).to.exist; });
Server.submit('/test', {hue : "hue", hui : "hui"}, 'GET', true).then((data) => { expect(data).to.exist; });
});
it('Check isloggedin method', () => {
......
......@@ -3,7 +3,7 @@ import { Modal, Button, Icon } from 'semantic-ui-react';
import Server from '../lib/Server';
import Storage from '../lib/Storage';
export default class ModalAlert extends React.Component {
export default class ApplyConfirmationModal extends React.Component {
static propTypes = {
id: React.PropTypes.number.isRequired,
onChangeValue: React.PropTypes.func.isRequired,
......@@ -34,24 +34,19 @@ export default class ModalAlert extends React.Component {
const daftarSuccess = 'Pendaftaran anda berhasil direkam. Harap menunggu kabar selanjutnya dari pihak yang terkait\n';
const daftarFailed = 'Maaf pendaftaran yang anda lakukan gagal. Harap ulangi pendaftaran atau hubungi administrator\n';
const requestData = { vacancy_id: this.props.id, cover_letter: this.props.coverLetter };
if (this.props.status == 'Daftar') {
const requestData = { vacancy_id: this.props.id, cover_letter: this.props.coverLetter };
Server.post(`/students/${studentId}/applied-vacancies/`, requestData).then(() => {
this.setState({
header: 'Pendaftaran Berhasil',
content: this.daftarSuccess,
});
}, () => {
this.setState({
header: 'Pendaftaran Gagal',
content: this.daftarFailed,
});
Server.post(`/students/${studentId}/applied-vacancies/`, requestData).then(() => {
this.setState({
header: 'Pendaftaran Berhasil',
content: daftarSuccess,
});
} else {
}
}, () => {
this.setState({
header: 'Pendaftaran Gagal',
content: daftarFailed,
});
});
}
render() {
......
import React from 'react';
import { Modal, Button, Icon, TextArea, Form } from 'semantic-ui-react';
import ModalAlert from './ModalAlert';
import { Modal, Button, TextArea, Form } from 'semantic-ui-react';
import ApplyConfirmationModal from './ApplyConfirmationModal';
export default class ApplyModal extends React.Component {
static propTypes = {
......@@ -66,7 +66,7 @@ export default class ApplyModal extends React.Component {
</Modal.Content>
<Modal.Actions>
<ModalAlert
<ApplyConfirmationModal
id={this.props.id}
onChangeValue={this.handleClose}
coverLetter={this.state.coverLetter}
......
......@@ -34,7 +34,6 @@ export default class RegisterModal extends React.Component {
e.preventDefault();
Server.submit('/register/', this.state).then((response) => {
alert('Akun berhasil dibuat :)');
Storage.set('user-data', response);
browserHistory.push('/home');
}, error => error.then(r => alert(JSON.stringify(r))));
......
......@@ -24,9 +24,10 @@ export default class App extends React.Component {
this.handleHome = this.handleHome.bind(this);
}
handleAuth = (nextState, replace) => (
Server.isLoggedIn() || replace({ pathname: '/login' })
);
handleAuth = (nextState, replace) => {
if (!Server.isLoggedIn()) replace({ pathname: '/login' });
Storage.getUserData();
};
handleHome= (nextState, replace, cb) => {
if (Server.isLoggedIn()) {
......
......@@ -19,8 +19,7 @@ export default class Server {
static submit(path, data, method = 'POST', useCache = false) {
const form = new FormData();
/* istanbul ignore next */
Object.keys(data).map(k => form.append(k, this.state[k]));
Object.keys(data).map(k => form.append(k, data[k]));
const requestData = {
'X-CSRFToken': Server.getCookie('csrftoken'),
......
......@@ -35,7 +35,6 @@ 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