From 3f13310a78e1ec4dc05c231f19c074e482440668 Mon Sep 17 00:00:00 2001 From: Ahmad Abdolsaheb Date: Wed, 3 Apr 2019 14:01:44 +0300 Subject: [PATCH] fix: add unit tests for legacy cert in settings --- .../src/components/settings/Certification.js | 5 +- .../components/settings/Certification.test.js | 151 ++++++++++++++++++ 2 files changed, 154 insertions(+), 2 deletions(-) create mode 100644 client/src/components/settings/Certification.test.js diff --git a/client/src/components/settings/Certification.js b/client/src/components/settings/Certification.js index d7f007bfe6..402ae0b2ca 100644 --- a/client/src/components/settings/Certification.js +++ b/client/src/components/settings/Certification.js @@ -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' diff --git a/client/src/components/settings/Certification.test.js b/client/src/components/settings/Certification.test.js new file mode 100644 index 0000000000..3d92157e91 --- /dev/null +++ b/client/src/components/settings/Certification.test.js @@ -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('', () => { + // 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( + + ); + + 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( + + ); + + 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( + + ); + 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( + + ); + 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: () => {} +};