Fakultas Ilmu Komputer UI

Commit d0c8fd06 authored by Syahrul Findi's avatar Syahrul Findi
Browse files

fix(coverage): Exclude migrations folder in the sonarQube check

parent 15d9c05f
{
"extends": "airbnb",
"extends": ["airbnb", "prettier"],
"env": {
"amd": true,
"browser": true,
......@@ -14,12 +14,12 @@
"react/no-multi-comp": [0, { "ignoreStateless": 1 }],
"import/extensions": ["off", "never"],
"import/no-unresolved": 0,
"no-underscore-dangle" : 0,
"linebreak-style" : 0,
"no-extra-bind" : 0
"no-underscore-dangle": 0,
"linebreak-style": 0,
"no-extra-bind": 0
},
"parser": "babel-eslint",
"parserOptions": {
"sourceType": "module"
}
}
\ No newline at end of file
}
import React from 'react';
import React, { useState, useEffect } from 'react';
import PropTypes from 'prop-types';
import CourseList from './components/CourseList';
import Server from './lib/Server';
export default class TranscriptPage extends React.Component {
static propTypes = {
params: PropTypes.object.isRequired,
user: PropTypes.object.isRequired,
};
const TranscriptPage = ({ user: { role }, params: { id } }) => {
const [text, setText] = useState('Mohon Tunggu...');
const [data, setData] = useState(undefined);
useEffect(() => {
const url =
role === 'student'
? `/students/${id}/transcript/`
: `/applications/${id}/transcript/`;
constructor(props) {
super(props);
/* istanbul ignore next */
this.state = { text: 'Mohon Tunggu..' };
const url = this.props.user.role === 'student'
? `/students/${this.props.params.id}/transcript/`
: `/applications/${this.props.params.id}/transcript/`;
Server.get(url).then(
(response) => this.setState({ data: response }),
() => this.setState({
text: 'Anda tidak berhak untuk melihat transkrip ini',
}),
(response) => setData(response),
() => setText('Anda tidak berhak untuk melihat transkrip ini'),
);
}
});
render() {
return this.state.data ? (
<CourseList data={this.state.data} />
) : (
<h5 style={{ textAlign: 'center' }}>
{' '}
{this.state.text}
{' '}
</h5>
);
}
}
return data ? (
<CourseList data={data} />
) : (
<h5 style={{ textAlign: 'center' }}>{text}</h5>
);
};
TranscriptPage.propTypes = {
params: PropTypes.object.isRequired,
user: PropTypes.object.isRequired,
};
export default TranscriptPage;
......@@ -9,24 +9,21 @@ import Pagination from './components/Pagination';
import Storage from './lib/Storage';
export default class VacancyPage extends React.Component {
static propTypes = {
user: PropTypes.object.isRequired,
};
static getId(user) {
const role = user.role;
const { role, data } = user;
if (role === 'student') {
return user.data.student.id;
} else if (
role === 'company' ||
(role === 'admin' && user.data.company != null)
) {
return user.data.company.id;
} else if (
return data.student.id;
}
if (role === 'company' || (role === 'admin' && data.company != null)) {
return data.company.id;
}
if (
role === 'supervisor' ||
(role === 'admin' && user.data.supervisor != null)
(role === 'admin' && data.supervisor != null)
) {
return user.data.supervisor.id;
return data.supervisor.id;
}
return 0;
......@@ -36,123 +33,82 @@ export default class VacancyPage extends React.Component {
super(props);
/* istanbul ignore next */
this.state = {
vacancies: [],
id: VacancyPage.getId(this.props.user),
id: VacancyPage.getId(props.user),
};
console.log('vacancy');
Storage.set('menu-active-state', 'Beranda');
}
generateVacancies() {
if (this.props.user.role === 'student') {
const { user } = this.props;
const { id } = this.state;
if (user.role === 'student') {
return (
<Tabs selected={0}>
<Pane label="Lowongan">
<Pagination
key={1}
url="/vacancies/"
child={
<VacancyList
user={this.props.user}
key={1}
userId={this.state.id}
/>
}
child={<VacancyList user={user} key={1} userId={id} />}
/>
</Pane>
<Pane label="Lamaran Saya">
<Pagination
key={2}
url={`/students/${this.state.id}/applied-vacancies/`}
child={
<VacancyList
user={this.props.user}
key={2}
userId={this.state.id}
/>
}
url={`/students/${id}/applied-vacancies/`}
child={<VacancyList user={user} key={2} userId={id} />}
/>
</Pane>
<Pane label="Ditandai">
<Pagination
key={3}
url={`/students/${this.state.id}/bookmarked-vacancies/`}
child={
<VacancyList
key={3}
user={this.props.user}
userId={this.state.id}
/>
}
url={`/students/${id}/bookmarked-vacancies/`}
child={<VacancyList key={3} user={user} userId={id} />}
/>
</Pane>
<Pane label="Lowongan Tersedia">
<Pagination
key={4}
url="/vacancies/opened_only=1"
child={
<VacancyList
user={this.props.user}
key={4}
userId={this.state.id}
/>
}
child={<VacancyList user={user} key={4} userId={id} />}
/>
</Pane>
</Tabs>
);
} else if (
(this.props.user.role === 'admin' &&
this.props.user.data.company != null) ||
this.props.user.role === 'company'
}
if (
(user.role === 'admin' && user.data.company != null) ||
user.role === 'company'
) {
return (
<Segment className="paginationCompany">
<Pagination
key={1}
url={`/companies/${this.state.id}/vacancies/`}
child={
<VacancyList
key={1}
user={this.props.user}
userId={this.state.id}
/>
}
url={`/companies/${id}/vacancies/`}
child={<VacancyList key={1} user={user} userId={id} />}
error="Akun anda belum terverifikasi. Harap hubungi pihak administrasi"
/>
</Segment>
);
} else if (
this.props.user.role === 'admin' ||
this.props.user.role === 'supervisor'
) {
}
if (user.role === 'admin' || user.role === 'supervisor') {
return (
<Tabs selected={0}>
<Pane label="Lowongan Belum Terverifikasi">
<Pagination
key={1}
url="/vacancies/?verified=false"
child={
<VacancyList
user={this.props.user}
key={1}
userId={this.state.id}
/>
}
child={<VacancyList user={user} key={1} userId={id} />}
/>
</Pane>
<Pane label="Lowongan Terverifikasi">
<Pagination
key={2}
url="/vacancies/?verified=true"
child={
<VacancyList
user={this.props.user}
key={2}
userId={this.state.id}
/>
}
child={<VacancyList user={user} key={2} userId={id} />}
/>
</Pane>
</Tabs>
......@@ -170,11 +126,13 @@ export default class VacancyPage extends React.Component {
}
companyHeader() {
if (
(this.props.user.role === 'admin' &&
this.props.user.data.company != null) ||
this.props.user.role === 'company'
) {
const {
user: {
role,
data: { company },
},
} = this.props;
if ((role === 'admin' && company != null) || role === 'company') {
return (
<div style={{ float: 'left' }}>
<Button
......@@ -201,18 +159,19 @@ export default class VacancyPage extends React.Component {
}
render() {
console.log(this.props.user);
const {
user: { role },
} = this.props;
return (
<div className="applicant">
<br />
{this.props.user.role === 'student' || (
{role === 'student' || (
<div
className="administrationButtons"
style={{ display: 'inline-block' }}
>
{this.companyHeader()}
{(this.props.user.role === 'admin' ||
this.props.user.role === 'supervisor') && (
{(role === 'admin' || role === 'supervisor') && (
<Button
as={Link}
to="/rekap"
......@@ -229,3 +188,5 @@ export default class VacancyPage extends React.Component {
);
}
}
VacancyPage.propTypes = { user: PropTypes.object.isRequired };
import React from 'react';
import ReactTestUtils from 'react-dom/test-utils';
import fetchMock from 'fetch-mock';
import sinon from 'sinon';
import TranscriptPage from '../TranscriptPage';
import Server from '../lib/Server';
class Wrapper extends React.Component {
render() {
return this.props.children;
}
}
describe('TranscriptPage', () => {
let stub;
const data = {
transcript: [
{ kelas: { nm_kls: 'kelas1', nm_mk_cl: { nm_mk: 'mata_kuliah' } }, nilai: 'A' },
{ kelas: { nm_kls: 'kelas2', nm_mk_cl: { nm_mk: 'mata_kuliah' } }, nilai: 'B' },
{
kelas: { nm_kls: 'kelas1', nm_mk_cl: { nm_mk: 'mata_kuliah' } },
nilai: 'A',
},
{
kelas: { nm_kls: 'kelas2', nm_mk_cl: { nm_mk: 'mata_kuliah' } },
nilai: 'B',
},
{ nilai: 'B' },
],
name: 'Badak Terbang',
......@@ -15,12 +31,28 @@ describe('TranscriptPage', () => {
fetchMock.get('*', data);
before(() => {
stub = sinon.stub(Server, 'get').resolves(data);
});
after(() => Server.get.restore());
it('renders for admin without problem', () => {
const transcriptPage1 = ReactTestUtils.renderIntoDocument(<TranscriptPage params={{ id: 1 }} user={{ role: 'student' }} />);
const transcriptPage2 = ReactTestUtils.renderIntoDocument(<TranscriptPage params={{ id: 1 }} user={{ role: 'admin' }} />);
transcriptPage1.setState({ data });
transcriptPage2.setState({ data });
expect(transcriptPage1).to.exist;
expect(transcriptPage2).to.exist;
const transcriptPage = ReactTestUtils.renderIntoDocument(
<Wrapper>
<TranscriptPage params={{ id: 1 }} user={{ role: 'admin' }} />
</Wrapper>,
);
return expect(transcriptPage).to.exist;
});
it('renders for student withour problem', () => {
const transcriptPage = ReactTestUtils.renderIntoDocument(
<Wrapper>
<TranscriptPage params={{ id: 1 }} user={{ role: 'student' }} />
</Wrapper>,
);
return expect(transcriptPage).to.exist;
});
});
This diff is collapsed.
......@@ -6,7 +6,7 @@
## Project Configuration
sonar.projectKey=id.ac.ui.cs.foss:kape
sonar.sources=core,assets/js
sonar.exclusions=.devcontainer/,.gitlab/,.config.js,.tmp/,assets/admin/**/*,assets/rest_framework/**/*,assets/rest_framework_swagger/**/*,assets/silk/**/*,kape/**/*,manage.py,core/tests/**/*,assets/js/__test__/**/*
sonar.exclusions=.devcontainer/,.gitlab/,.config.js,.tmp/,assets/admin/**/*,assets/rest_framework/**/*,assets/rest_framework_swagger/**/*,assets/silk/**/*,kape/**/*,manage.py,core/tests/**/*,assets/js/__test__/**/*,core/migrations/**/*
sonar.scm.provider=git
sonar.projectVersion=1.0.0
sonar.python.coverage.reportPaths=test/backend/coverage.xml
......
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