Improved VisitsParser test

This commit is contained in:
Alejandro Celaya 2019-01-09 07:59:56 +01:00
parent bb6fb6b9ea
commit c599d2837b
3 changed files with 33 additions and 4 deletions

View file

@ -106,7 +106,7 @@ const ShortUrlVisits = ({
extraHeaderContent={[
() => (
<OpenMapModalBtn
title="Cities"
modalTitle="Cities"
locations={values(processCitiesStatsForMap(visits))}
/>
),

View file

@ -8,14 +8,14 @@ import './OpenMapModalBtn.scss';
export default class OpenMapModalBtn extends React.Component {
static propTypes = {
title: PropTypes.string.isRequired,
modalTitle: PropTypes.string.isRequired,
locations: PropTypes.arrayOf(PropTypes.object),
};
state = { mapIsOpened: false };
render() {
const { title, locations = [] } = this.props;
const { modalTitle, locations = [] } = this.props;
const toggleMap = () => this.setState(({ mapIsOpened }) => ({ mapIsOpened: !mapIsOpened }));
const buttonRef = React.createRef();
@ -25,7 +25,7 @@ export default class OpenMapModalBtn extends React.Component {
<FontAwesomeIcon icon={mapIcon} />
</button>
<UncontrolledTooltip placement="bottom" target={() => buttonRef.current}>Show in map</UncontrolledTooltip>
<MapModal toggle={toggleMap} isOpen={this.state.mapIsOpened} title={title} locations={locations} />
<MapModal toggle={toggleMap} isOpen={this.state.mapIsOpened} title={modalTitle} locations={locations} />
</React.Fragment>
);
}

View file

@ -4,6 +4,7 @@ import {
processReferrersStats,
processCountriesStats,
processCitiesStats,
processCitiesStatsForMap,
} from '../../../src/visits/services/VisitsParser';
describe('VisitsParser', () => {
@ -14,6 +15,8 @@ describe('VisitsParser', () => {
visitLocation: {
countryName: 'Spain',
cityName: 'Zaragoza',
latitude: '123.45',
longitude: '-543.21',
},
},
{
@ -22,6 +25,8 @@ describe('VisitsParser', () => {
visitLocation: {
countryName: 'United States',
cityName: 'New York',
latitude: '1029',
longitude: '6758',
},
},
{
@ -36,6 +41,8 @@ describe('VisitsParser', () => {
visitLocation: {
countryName: 'Spain',
cityName: 'Zaragoza',
latitude: '123.45',
longitude: '-543.21',
},
},
{
@ -92,4 +99,26 @@ describe('VisitsParser', () => {
});
});
});
describe('processCitiesStatsForMap', () => {
it('properly parses cities stats with lat and long', () => {
const zaragozaLat = 123.45;
const zaragozaLong = -543.21;
const newYorkLat = 1029;
const newYorkLong = 6758;
expect(processCitiesStatsForMap(visits)).toEqual({
'Zaragoza': {
cityName: 'Zaragoza',
count: 2,
latLong: [ zaragozaLat, zaragozaLong ],
},
'New York': {
cityName: 'New York',
count: 1,
latLong: [ newYorkLat, newYorkLong ],
},
});
});
});
});