fix: add unit tests for legacy cert in settings

This commit is contained in:
Ahmad Abdolsaheb
2019-04-03 14:01:44 +03:00
committed by Mrugesh Mohapatra
parent c359662f85
commit 3f13310a78
2 changed files with 154 additions and 2 deletions

View File

@ -13,7 +13,6 @@ import {
import { Link, navigate } from 'gatsby';
import { createSelector } from 'reselect';
import { updateLegacyCert } from '../../redux/settings';
import { projectMap, legacyProjectMap } from '../../resources/certProjectMap';
import SectionHeader from './SectionHeader';
@ -25,6 +24,7 @@ import { maybeUrlRE } from '../../utils';
import reallyWeirdErrorMessage from '../../utils/reallyWeirdErrorMessage';
import './certification.css';
import { updateLegacyCert } from '../../redux/settings';
const mapDispatchToProps = dispatch =>
bindActionCreators({ updateLegacyCert }, dispatch);
@ -124,7 +124,7 @@ const initialState = {
}
};
class CertificationSettings extends Component {
export class CertificationSettings extends Component {
constructor(props) {
super(props);
@ -424,6 +424,7 @@ class CertificationSettings extends Component {
bsStyle='primary'
className={'col-xs-12'}
href={certLocation}
id={'button-' + superBlock}
onClick={createClickHandler(certLocation)}
style={buttonStyle}
target='_blank'

View File

@ -0,0 +1,151 @@
/* global expect */
import React from 'react';
import Enzyme from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
import { CertificationSettings } from './Certification';
Enzyme.configure({ adapter: new Adapter() });
describe('<certification />', () => {
// shallow rendering does not render children component
// form buttons are not included in shallow render
it('Should render show cert button for calimed legacy cert', () => {
const wrapper = Enzyme.shallow(
<CertificationSettings {...defaultTestProps} />
);
expect(
wrapper.find('#button-legacy-data-visualization').props().children
).toEqual('Show Certification');
});
it('Should link show cert button to the calimed legacy cert', () => {
const wrapper = Enzyme.shallow(
<CertificationSettings {...defaultTestProps} />
);
expect(
wrapper.find('#button-legacy-data-visualization').props().href
).toEqual('/certification/developementuser/legacy-data-visualization');
});
// full forms with unclaimed certs should should not shallow render button
it('Should not render show cert button for unclaimed full form', () => {
const wrapper = Enzyme.shallow(
<CertificationSettings {...defaultTestProps} />
);
expect(wrapper.exists('#button-legacy-back-end')).toEqual(false);
});
// empty forms with unclaimed certs should should not shallow render button
it('Should not render show cert button for empty form', () => {
const wrapper = Enzyme.shallow(
<CertificationSettings {...defaultTestProps} />
);
expect(wrapper.exists('#button-legacy-front-end')).toEqual(false);
});
});
const defaultTestProps = {
completedChallenges: [
{
id: 'bd7156d8c242eddfaeb5bd13',
solution: 'https://github.com/freeCodeCamp/freeCodeCamp'
},
{
id: 'bd7155d8c242eddfaeb5bd13',
solution: 'https://github.com/freeCodeCamp/freeCodeCamp'
},
{
id: 'bd7154d8c242eddfaeb5bd13',
solution: 'https://github.com/freeCodeCamp/freeCodeCamp'
},
{
id: 'bd7153d8c242eddfaeb5bd13',
solution: 'https://github.com/freeCodeCamp/freeCodeCamp'
},
{
id: 'bd7168d8c242eddfaeb5bd13',
solution: 'https://github.com/freeCodeCamp/freeCodeCamp'
},
{
id: 'bd7178d8c242eddfaeb5bd13',
solution: 'https://github.com/freeCodeCamp/freeCodeCamp'
},
{
id: 'bd7188d8c242eddfaeb5bd13',
solution: 'https://github.com/freeCodeCamp/freeCodeCamp'
},
{
id: 'bd7198d8c242eddfaeb5bd13',
solution: 'https://github.com/freeCodeCamp/freeCodeCamp'
},
{
id: 'bd7108d8c242eddfaeb5bd13',
solution: 'https://github.com/freeCodeCamp/freeCodeCamp'
},
{
id: 'bd7158d8c443edefaeb5bdef',
solution: 'https://github.com/freeCodeCamp/freeCodeCamp'
},
{
id: 'bd7158d8c443edefaeb5bdff',
solution: 'https://github.com/freeCodeCamp/freeCodeCamp'
},
{
id: 'bd7158d8c443edefaeb5bd0e',
solution: 'https://github.com/freeCodeCamp/freeCodeCamp'
},
{
id: 'bd7158d8c443edefaeb5bdee',
solution: 'https://github.com/freeCodeCamp/freeCodeCamp'
},
{
id: 'bd7158d8c443edefaeb5bd0f',
solution: 'https://github.com/freeCodeCamp/freeCodeCamp'
},
{
id: 'bd7158d8c443eddfaeb5bdef',
solution: 'https://github.com/freeCodeCamp/freeCodeCamp'
},
{
id: 'bd7158d8c443eddfaeb5bdff',
solution: 'https://github.com/freeCodeCamp/freeCodeCamp'
},
{
id: 'bd7158d8c443eddfaeb5bd0e',
solution: 'https://github.com/freeCodeCamp/freeCodeCamp'
},
{
id: 'bd7158d8c443eddfaeb5bd0f',
solution: 'https://github.com/freeCodeCamp/freeCodeCamp'
},
{
id: 'bd7158d8c443eddfaeb5bdee',
solution: 'https://github.com/freeCodeCamp/freeCodeCamp'
},
{
id: 'bd7157d8c242eddfaeb5bd13',
completedDate: 1554272923799,
solution: 'https://github.com/freeCodeCamp/freeCodeCamp'
}
],
createFlashMessage: () => {},
is2018DataVisCert: false,
isApisMicroservicesCert: false,
isBackEndCert: false,
isDataVisCert: true,
isFrontEndCert: false,
isFrontEndLibsCert: false,
isFullStackCert: false,
isHonest: false,
isInfosecQaCert: false,
isJsAlgoDataStructCert: false,
isRespWebDesignCert: false,
updateLegacyCert: () => {},
username: 'developementuser',
verifyCert: () => {},
errors: {},
submit: () => {}
};