Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions __mocks__/FileForm.test.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import React from "react";
import Enzyme, {shallow} from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
import checkPropTypes from 'check-prop-types';
import FileForm from '../src/components/file/FileForm';

Enzyme.configure({
adapter: new Adapter(),
});

const setupWrapper = () => shallow(<FileForm
submitText="submitText"
onSubmit={() => { }}
branch="branch"
/>)

const findByAttribute = (wrapper, attribute) => wrapper.find(`[data-test='${attribute}']`)

// render tests
test('render fileForm', () => {
const wrapper = setupWrapper();
const fileForm = findByAttribute(wrapper, 'component-fileForm');
Expand Down Expand Up @@ -43,4 +43,17 @@ test('render submit-button', () => {
const wrapper = setupWrapper();
const submit = findByAttribute(wrapper, 'submit-button');
expect(submit.length).toBe(1);
});

// PropTypes tests
test('PropTypes', () => {
const expectedProps = {
submitText: "text",
onSubmit: () => {},
branch: 'branch',
filepath: 'filepath',
defaultContent: 'defaultContent',
}
let propError = checkPropTypes(FileForm.propTypes, expectedProps, 'prop', FileForm.name);
expect(propError).toBeUndefined();
});
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"babel-jest": "24.9.0",
"babel-loader": "^8.0.6",
"babel-plugin-istanbul": "6.0.0",
"check-prop-types": "^1.1.2",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: discuss with the team:
Seems like a helpful idea to verify prop-types on PUBLIC libraries.

"coveralls": "3.0.7",
"cypress": "^6.8.0",
"enzyme": "^3.11.0",
Expand Down
3 changes: 3 additions & 0 deletions src/components/file/FileForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ FileForm.propTypes = {
submitText: PropTypes.string,
/** Function run when submit button is clicked */
onSubmit: PropTypes.func.isRequired,
branch: PropTypes.string,
filepath: PropTypes.string,
defaultContent: PropTypes.string,
Copy link
Contributor

@ancientTexts-net ancientTexts-net Sep 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NOTE: there were a few missing proptypes 👍

};

FileForm.defaultProps = { submitText: 'Submit' };
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4549,6 +4549,11 @@ check-more-types@2.24.0, check-more-types@^2.24.0:
resolved "https://registry.yarnpkg.com/check-more-types/-/check-more-types-2.24.0.tgz#1420ffb10fd444dcfc79b43891bbfffd32a84600"
integrity sha1-FCD/sQ/URNz8ebQ4kbv//TKoRgA=

check-prop-types@^1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/check-prop-types/-/check-prop-types-1.1.2.tgz#c42df4fbdb509fbd4d8a102d113bb0ca01c21e67"
integrity sha512-hGDrZ1yhRgKuP1yzZ5sUX/PPmlKBLOF1GyF0Z008Sienko3BFZmlCXnmq+npRTIL/WlFCUzThyd+F5PQnnT1ug==

cheerio-select@^1.5.0:
version "1.5.0"
resolved "https://registry.yarnpkg.com/cheerio-select/-/cheerio-select-1.5.0.tgz#faf3daeb31b17c5e1a9dabcee288aaf8aafa5823"
Expand Down