Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rithm add prop types #16

Merged
merged 11 commits into from
Jun 27, 2019
138 changes: 90 additions & 48 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@
"husky": "^1.3.1",
"jest-dom": "^3.0.0",
"prettier": "1.15.3",
"pretty-quick": "^1.11.1",
"pretty-quick": "^1.8.0",
"prop-types": "^15.7.2",
"react-testing-library": "^5.4.2",

Choose a reason for hiding this comment

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

Remove

Copy link
Author

Choose a reason for hiding this comment

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

Removed

"redux-mock-store": "^1.5.3"
}
}
9 changes: 9 additions & 0 deletions src/components/App.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import Header from '../components/Header';
import SidebarContainer from '../containers/SidebarContainer';
import PreviewContainer from '../containers/PreviewContainer';
Expand Down Expand Up @@ -48,4 +49,12 @@ class App extends Component {
}
}

App.defaultProps = {
onEscape: () => {}
};

App.propTypes = {
onEscape: PropTypes.func.isRequired
};

export default App;
17 changes: 17 additions & 0 deletions src/components/Burst.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { getCalcState, setCalcState } from '../lib/calc-helpers';
import { getBurstErrors } from '../lib/input-helpers';
Expand Down Expand Up @@ -160,4 +161,20 @@ class Burst extends Component {
}
}

Burst.defaultProps = {
expanded: false,
width: 300,
height: 300,
oversample: false,
requestBurst: () => {}
};

Burst.propTypes = {
expanded: PropTypes.bool.isRequired,
width: PropTypes.number.isRequired,
height: PropTypes.number.isRequired,
oversample: PropTypes.bool.isRequired,
requestBurst: PropTypes.func.isRequired
};

export default Burst;
5 changes: 5 additions & 0 deletions src/components/ErrorToast.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import PropTypes from 'prop-types';
import './ErrorToast.css';

const ErrorToast = ({ message }) => {
Expand All @@ -10,6 +11,10 @@ const ErrorToast = ({ message }) => {
);
};

ErrorToast.propTypes = {

Choose a reason for hiding this comment

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

Be consistent -- propTypes before defaultProps or vice versa, not one or the other.

Copy link
Author

Choose a reason for hiding this comment

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

Fixed

message: PropTypes.string.isRequired
};

ErrorToast.defaultProps = {
message: ''
};
Expand Down
13 changes: 13 additions & 0 deletions src/components/Frame.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import './Frame.css';

Expand All @@ -24,4 +25,16 @@ const Frame = ({ imageSrc, playing, togglePlaying }) => (
</div>
);

Frame.defaultProps = {
imageSrc: '',
playing: false,
togglePlaying: () => {}
};

Frame.propTypes = {
imageSrc: PropTypes.string.isRequired,
playing: PropTypes.bool.isRequired,
togglePlaying: PropTypes.func.isRequired
};

export default Frame;
30 changes: 29 additions & 1 deletion src/components/Preview.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import Frame from './Frame';
import GenerateGifFormContainer from '../containers/GenerateGifFormContainer';
Expand Down Expand Up @@ -147,10 +148,37 @@ class Preview extends Component {
}

Preview.defaultProps = {
expanded: false,
previewIdx: 0,
playing: false,
frames: {},
frameIDs: [],
gifData: ''
gifProgress: 0,
width: 300,
height: 300,
oversample: false,
interval: 100,
updatePreviewIdx: () => {},
generateGIF: () => {},
startAnimation: () => {},
stopAnimation: () => {}
};

Preview.propTypes = {
expanded: PropTypes.bool.isRequired,
previewIdx: PropTypes.number.isRequired,
playing: PropTypes.bool.isRequired,
frames: PropTypes.object.isRequired,
frameIDs: PropTypes.array.isRequired,
gifProgress: PropTypes.number.isRequired,
width: PropTypes.number.isRequired,
height: PropTypes.number.isRequired,
oversample: PropTypes.bool.isRequired,
interval: PropTypes.number.isRequired,
updatePreviewIdx: PropTypes.func.isRequired,
generateGIF: PropTypes.func.isRequired,
startAnimation: PropTypes.func.isRequired,
stopAnimation: PropTypes.func.isRequired
};

export default Preview;
8 changes: 7 additions & 1 deletion src/components/Preview.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ describe('<Preview/>', () => {

it('renders appropriate content', () => {
const { getByTestId } = global.renderWithRedux(
<Preview expanded previewIdx={0} frames={{ 1: 'test' }} frameIDs={[1]} />
<Preview
expanded
previewIdx={0}
frames={{ 1: 'test' }}
frameIDs={[1]}
gifData={[]}
/>
);
expect(getByTestId('Preview-scrubber').firstChild.type).toBe('range');
expect(getByTestId('Preview-scrubber-counter').textContent).toBe('1 / 1');
Expand Down
19 changes: 19 additions & 0 deletions src/components/Settings.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { isPositiveInteger, isProperBound } from '../lib/input-helpers';
import './Settings.css';
Expand Down Expand Up @@ -161,4 +162,22 @@ class Settings extends Component {
}
}

Settings.defaultProps = {
expanded: false,
width: 300,
height: 300,
oversample: false,
interval: 100,
updateSetting: () => {}
};

Settings.propTypes = {
expanded: PropTypes.bool.isRequired,
width: PropTypes.number.isRequired,
height: PropTypes.number.isRequired,
oversample: PropTypes.bool.isRequired,
interval: PropTypes.number.isRequired,
updateSetting: PropTypes.func.isRequired
};

export default Settings;
23 changes: 22 additions & 1 deletion src/components/Sidebar.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import SidebarButton from './SidebarButton';
import SidebarButtonWithBadge from './SidebarButtonWithBadge';
import panes from '../constants/pane-types';
Expand Down Expand Up @@ -113,8 +114,28 @@ class Sidebar extends Component {
}
}

Sidebar.propTypes = {
numFrames: PropTypes.number.isRequired,
expandedPane: PropTypes.string.isRequired,
gifData: PropTypes.string.isRequired,
width: PropTypes.number.isRequired,
height: PropTypes.number.isRequired,
oversample: PropTypes.bool.isRequired,
requestFrame: PropTypes.func.isRequired,
togglePane: PropTypes.func.isRequired,
reset: PropTypes.func.isRequired
};

Sidebar.defaultProps = {
gifData: ''
numFrames: 0,
expandedPane: 'NONE',
gifData: '',
width: 100,
height: 100,
oversample: false,
requestFrame: () => {},
togglePane: () => {},
reset: () => {}
};

export default Sidebar;
10 changes: 10 additions & 0 deletions src/components/SidebarButton.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import camera from './icons/camera.svg';
import preview from './icons/preview.svg';
Expand Down Expand Up @@ -47,6 +48,15 @@ const SidebarButton = ({ children, icon, onClick, expanded }) => (
);

SidebarButton.defaultProps = {
icon: '',
onClick: () => {},
expanded: false
};

SidebarButton.propTypes = {
icon: PropTypes.string.isRequired,
onClick: PropTypes.func.isRequired,
expanded: PropTypes.bool,
icon: 'icon'
};

Expand Down
2 changes: 1 addition & 1 deletion src/components/SidebarButton.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ afterEach(cleanup);

describe('<SidebarButton/>', () => {
it('renders without crashing', () => {
global.renderWithRedux(<SidebarButton />);
global.renderWithRedux(<SidebarButton icon="icon" />);

Choose a reason for hiding this comment

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

What does this addition do?

Copy link
Author

Choose a reason for hiding this comment

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

removed, no longer needed with default props added

});

it('renders appropriate content', () => {
Expand Down
19 changes: 19 additions & 0 deletions src/components/SidebarButtonWithBadge.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import SidebarButton from './SidebarButton';

Expand All @@ -18,4 +19,22 @@ const SidebarButtonWithBadge = ({ showBadge, value, color, ...props }) => (
</SidebarButton>
);

SidebarButtonWithBadge.defaultProps = {
icon: '',
onClick: () => {},
expanded: false,
color: '',
showBadge: false,
value: 0
};

SidebarButtonWithBadge.propTypes = {
icon: PropTypes.string.isRequired,
onClick: PropTypes.func.isRequired,
expanded: PropTypes.bool,
color: PropTypes.string.isRequired,
showBadge: PropTypes.bool.isRequired,
value: PropTypes.number.isRequired
};

export default SidebarButtonWithBadge;
4 changes: 2 additions & 2 deletions src/components/SidebarButtonWithBadge.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ afterEach(cleanup);

describe('<SidebarButtonWithBadge/>', () => {
it('renders without crashing', () => {
global.renderWithRedux(<SidebarButtonWithBadge />);
global.renderWithRedux(<SidebarButtonWithBadge icon="icon" />);
});

it('renders appropriate content', () => {
const { getByTestId } = global.renderWithRedux(
<SidebarButtonWithBadge showBadge={true} color="color" />
<SidebarButtonWithBadge showBadge={true} color="color" icon="icon" />
);
// check that badge is present
expect(getByTestId('SidebarButton-icon-button').lastChild).toBeTruthy();
Expand Down
3 changes: 2 additions & 1 deletion src/setupTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import { render } from '@testing-library/react';
import rootReducer from './reducers';

global.console = {
log: jest.fn()
log: jest.fn(),
error: jest.fn()
};

global.Desmos = {
Expand Down