Skip to content
This repository has been archived by the owner on Apr 16, 2021. It is now read-only.

Commit

Permalink
icon can be derived from the marker type
Browse files Browse the repository at this point in the history
  • Loading branch information
Frederic Lavigne committed Sep 9, 2016
1 parent 9280c05 commit b355d5e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 14 deletions.
2 changes: 0 additions & 2 deletions src/routes/Dashboard/components/Map/Map.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,13 @@ export const Map = (props) => (
.filter(shipment => (shipment.currentLocation != null))
.map(shipment => <MapMarker
type="shipment"
icon="truck"
lat={shipment.currentLocation.latitude}
lng={shipment.currentLocation.longitude}
></MapMarker>)}
{props.retailers
// keep only shipments with a current location
.map(retailer => <MapMarker
type="retailer"
icon="circle"
lat={retailer.address.latitude}
lng={retailer.address.longitude}
></MapMarker>)}
Expand Down
22 changes: 16 additions & 6 deletions src/routes/Dashboard/components/MapMarker/MapMarker.jsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
import React from 'react';
import classes from './MapMarker.scss';

export const MapMarker = (props) => (
<div className={classes[props.type]}>
<i className={'fa fa-' + props.icon} />
export const MapMarker = (props) => {
let markerIcon;
switch (props.type) {
case 'retailer':
markerIcon = 'fa fa-circle';
break;
case 'shipment':
markerIcon = 'fa fa-truck';
break;
default:
}

return (<div className={classes[props.type]}>
{markerIcon ? <i className={markerIcon} /> : ''}
<div className={classes.mapMarkerPopup}>
{props.children}
</div>
</div>
);
</div>);
};

MapMarker.propTypes = {
type: React.PropTypes.oneOf(['distributionCenter', 'retailer', 'shipment']).isRequired,
icon: React.PropTypes.string,
children: React.PropTypes.element,
};

Expand Down
26 changes: 20 additions & 6 deletions src/routes/Dashboard/components/MapMarker/MapMarker.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,34 @@ import React from 'react';
import { shallow } from 'enzyme';
import MapMarker from './MapMarker';

const setup = () => {
const setup = (aType) => {
const spies = {
};
const props = {
type: 'retailer',
type: aType,
};
const component = shallow(<MapMarker {...props} />);

return { spies, props, component };
};

test('(Component) Has expected elements.', t => {
const { component } = setup();
test('(Component) Distribution Center has expected elements.', t => {
const { component } = setup('distributionCenter');

t.true(component.is('div'),
'is wrapped by a div.');
t.true(component.is('div'), 'is wrapped by a div.');
t.is(component.find('i.fa').length, 0, 'has no icon');
});

test('(Component) Retailer has expected elements.', t => {
const { component } = setup('retailer');

t.true(component.is('div'), 'is wrapped by a div.');
t.is(component.find('i.fa-circle').length, 1, 'has an icon');
});

test('(Component) Shipment has expected elements.', t => {
const { component } = setup('shipment');

t.true(component.is('div'), 'is wrapped by a div.');
t.is(component.find('i.fa-truck').length, 1, 'has an icon');
});

0 comments on commit b355d5e

Please sign in to comment.