Skip to content

Commit

Permalink
Add arrayOf proptype validation to MarkableMap
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick Maher committed Mar 21, 2017
1 parent b9c8565 commit d3b2862
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
14 changes: 12 additions & 2 deletions components/Map/MarkableMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import isEqual from 'lodash/fp/isEqual';
import uniqueId from 'lodash/fp/uniqueId';
import cx from 'classnames';

import lngLat from '../../utils/propTypeValidations/lngLat';
import minLngLatBounds from '../../utils/geoUtils/minLngLatBounds';
import mapboxgl from '../../utils/mapboxgl/mapboxgl';
import MarkerContainer from './MarkerContainer';
Expand All @@ -27,8 +28,17 @@ import css from './MarkableMap.css';

export default class MarkableMap extends Component {
static propTypes = {
// TODO: shapeOf prop type
markers: PropTypes.array,
markers: PropTypes.arrayOf(
PropTypes.shape({
id: React.PropTypes.oneOfType([
PropTypes.string,
PropTypes.number,
]).isRequired,
lngLat: lngLat.isRequired,
label: PropTypes.string.isRequired,
props: PropTypes.object,
})
),
MarkerComponent: PropTypes.func.isRequired,
autoFit: PropTypes.bool,
};
Expand Down
14 changes: 7 additions & 7 deletions components/Map/MarkableMap.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ it('it renders the active marker correctly', () => {
<MarkableMap
ref={ (c) => { component = c; } }
MarkerComponent={ SpaceMarker }
markers={ [{ id: 1, lngLat: [1, 0] }] }
markers={ [{ id: 1, lngLat: [1, 0], label: 'test' }] }
/>,
div
);
Expand All @@ -54,7 +54,7 @@ it('it autosizes the map correctly', () => {
ReactDOM.render(
<MarkableMap
MarkerComponent={ SpaceMarker }
markers={ [{ id: 1, lngLat: [1, 0] }] }
markers={ [{ id: 1, lngLat: [1, 0], label: 'test' }] }
autoFit
/>,
div
Expand All @@ -68,8 +68,8 @@ it('it autosizes the map correctly', () => {
<MarkableMap
MarkerComponent={ SpaceMarker }
markers={ [
{ id: 1, lngLat: [0, 0] },
{ id: 2, lngLat: [1, 1] },
{ id: 1, lngLat: [0, 0], label: 'test' },
{ id: 2, lngLat: [1, 1], label: 'test' },
] }
autoFit
/>,
Expand All @@ -87,8 +87,8 @@ it('it autosizes the map correctly', () => {
<MarkableMap
MarkerComponent={ SpaceMarker }
markers={ [
{ id: 1, lngLat: [0, 0] },
{ id: 2, lngLat: [1, 1] },
{ id: 1, lngLat: [0, 0], label: 'test' },
{ id: 2, lngLat: [1, 1], label: 'test' },
] }
autoFit
/>,
Expand All @@ -106,7 +106,7 @@ it('unmounts without crashing', () => {
ReactDOM.render(
<MarkableMap
MarkerComponent={ SpaceMarker }
markers={ [{ id: 1, lngLat: [1, 0] }] }
markers={ [{ id: 1, lngLat: [1, 0], label: 'test' }] }
/>,
div
);
Expand Down

0 comments on commit d3b2862

Please sign in to comment.