mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2024-12-23 17:40:23 +03:00
Improved VisitsParser test
This commit is contained in:
parent
bb6fb6b9ea
commit
c599d2837b
3 changed files with 33 additions and 4 deletions
|
@ -106,7 +106,7 @@ const ShortUrlVisits = ({
|
||||||
extraHeaderContent={[
|
extraHeaderContent={[
|
||||||
() => (
|
() => (
|
||||||
<OpenMapModalBtn
|
<OpenMapModalBtn
|
||||||
title="Cities"
|
modalTitle="Cities"
|
||||||
locations={values(processCitiesStatsForMap(visits))}
|
locations={values(processCitiesStatsForMap(visits))}
|
||||||
/>
|
/>
|
||||||
),
|
),
|
||||||
|
|
|
@ -8,14 +8,14 @@ import './OpenMapModalBtn.scss';
|
||||||
|
|
||||||
export default class OpenMapModalBtn extends React.Component {
|
export default class OpenMapModalBtn extends React.Component {
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
title: PropTypes.string.isRequired,
|
modalTitle: PropTypes.string.isRequired,
|
||||||
locations: PropTypes.arrayOf(PropTypes.object),
|
locations: PropTypes.arrayOf(PropTypes.object),
|
||||||
};
|
};
|
||||||
|
|
||||||
state = { mapIsOpened: false };
|
state = { mapIsOpened: false };
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { title, locations = [] } = this.props;
|
const { modalTitle, locations = [] } = this.props;
|
||||||
const toggleMap = () => this.setState(({ mapIsOpened }) => ({ mapIsOpened: !mapIsOpened }));
|
const toggleMap = () => this.setState(({ mapIsOpened }) => ({ mapIsOpened: !mapIsOpened }));
|
||||||
const buttonRef = React.createRef();
|
const buttonRef = React.createRef();
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ export default class OpenMapModalBtn extends React.Component {
|
||||||
<FontAwesomeIcon icon={mapIcon} />
|
<FontAwesomeIcon icon={mapIcon} />
|
||||||
</button>
|
</button>
|
||||||
<UncontrolledTooltip placement="bottom" target={() => buttonRef.current}>Show in map</UncontrolledTooltip>
|
<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>
|
</React.Fragment>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import {
|
||||||
processReferrersStats,
|
processReferrersStats,
|
||||||
processCountriesStats,
|
processCountriesStats,
|
||||||
processCitiesStats,
|
processCitiesStats,
|
||||||
|
processCitiesStatsForMap,
|
||||||
} from '../../../src/visits/services/VisitsParser';
|
} from '../../../src/visits/services/VisitsParser';
|
||||||
|
|
||||||
describe('VisitsParser', () => {
|
describe('VisitsParser', () => {
|
||||||
|
@ -14,6 +15,8 @@ describe('VisitsParser', () => {
|
||||||
visitLocation: {
|
visitLocation: {
|
||||||
countryName: 'Spain',
|
countryName: 'Spain',
|
||||||
cityName: 'Zaragoza',
|
cityName: 'Zaragoza',
|
||||||
|
latitude: '123.45',
|
||||||
|
longitude: '-543.21',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -22,6 +25,8 @@ describe('VisitsParser', () => {
|
||||||
visitLocation: {
|
visitLocation: {
|
||||||
countryName: 'United States',
|
countryName: 'United States',
|
||||||
cityName: 'New York',
|
cityName: 'New York',
|
||||||
|
latitude: '1029',
|
||||||
|
longitude: '6758',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -36,6 +41,8 @@ describe('VisitsParser', () => {
|
||||||
visitLocation: {
|
visitLocation: {
|
||||||
countryName: 'Spain',
|
countryName: 'Spain',
|
||||||
cityName: 'Zaragoza',
|
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 ],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue