mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2025-01-09 09:47:28 +03:00
Created VisitsParser test
This commit is contained in:
parent
a83be0b45c
commit
26a3fdfd3d
4 changed files with 88 additions and 9 deletions
|
@ -7,11 +7,15 @@ import Moment from 'react-moment'
|
||||||
import { connect } from 'react-redux'
|
import { connect } from 'react-redux'
|
||||||
import { Card, CardBody, CardHeader, UncontrolledTooltip } from 'reactstrap'
|
import { Card, CardBody, CardHeader, UncontrolledTooltip } from 'reactstrap'
|
||||||
import DateInput from '../common/DateInput'
|
import DateInput from '../common/DateInput'
|
||||||
import VisitsParser from '../visits/services/VisitsParser'
|
import visitsParser from '../visits/services/VisitsParser'
|
||||||
import { getShortUrlVisits } from './reducers/shortUrlVisits'
|
import { getShortUrlVisits } from './reducers/shortUrlVisits'
|
||||||
import './ShortUrlVisits.scss'
|
import './ShortUrlVisits.scss'
|
||||||
import MutedMessage from '../utils/MuttedMessage';
|
import MutedMessage from '../utils/MuttedMessage';
|
||||||
|
|
||||||
|
const defaultProps = {
|
||||||
|
visitsParser,
|
||||||
|
};
|
||||||
|
|
||||||
export class ShortUrlsVisits extends React.Component {
|
export class ShortUrlsVisits extends React.Component {
|
||||||
state = { startDate: undefined, endDate: undefined };
|
state = { startDate: undefined, endDate: undefined };
|
||||||
loadVisits = () => {
|
loadVisits = () => {
|
||||||
|
@ -167,8 +171,6 @@ export class ShortUrlsVisits extends React.Component {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ShortUrlsVisits.defaultProps = {
|
ShortUrlsVisits.defaultProps = defaultProps;
|
||||||
visitsParser: VisitsParser
|
|
||||||
};
|
|
||||||
|
|
||||||
export default connect(pick(['selectedServer', 'shortUrlVisits']), { getShortUrlVisits })(ShortUrlsVisits);
|
export default connect(pick(['selectedServer', 'shortUrlVisits']), { getShortUrlVisits })(ShortUrlsVisits);
|
||||||
|
|
|
@ -21,14 +21,14 @@ const browserFromUserAgent = userAgent => {
|
||||||
const lowerUserAgent = userAgent.toLowerCase();
|
const lowerUserAgent = userAgent.toLowerCase();
|
||||||
|
|
||||||
switch (true) {
|
switch (true) {
|
||||||
|
case (lowerUserAgent.indexOf('opera') >= 0 || lowerUserAgent.indexOf('opr') >= 0):
|
||||||
|
return 'Opera';
|
||||||
case (lowerUserAgent.indexOf('firefox') >= 0):
|
case (lowerUserAgent.indexOf('firefox') >= 0):
|
||||||
return 'Firefox';
|
return 'Firefox';
|
||||||
case (lowerUserAgent.indexOf('chrome') >= 0):
|
case (lowerUserAgent.indexOf('chrome') >= 0):
|
||||||
return 'Chrome';
|
return 'Chrome';
|
||||||
case (lowerUserAgent.indexOf('safari') >= 0):
|
case (lowerUserAgent.indexOf('safari') >= 0):
|
||||||
return 'Safari';
|
return 'Safari';
|
||||||
case (lowerUserAgent.indexOf('opera') >= 0):
|
|
||||||
return 'Opera';
|
|
||||||
case (lowerUserAgent.indexOf('msie') >= 0):
|
case (lowerUserAgent.indexOf('msie') >= 0):
|
||||||
return 'Internet Explorer';
|
return 'Internet Explorer';
|
||||||
default:
|
default:
|
||||||
|
@ -98,4 +98,5 @@ export class VisitsParser {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export default new VisitsParser();
|
const visitsParser = new VisitsParser();
|
||||||
|
export default visitsParser;
|
||||||
|
|
|
@ -5,10 +5,10 @@ import reduce, {
|
||||||
import { LIST_SHORT_URLS } from '../../../src/short-urls/reducers/shortUrlsList';
|
import { LIST_SHORT_URLS } from '../../../src/short-urls/reducers/shortUrlsList';
|
||||||
|
|
||||||
describe('shortUrlsListParamsReducer', () => {
|
describe('shortUrlsListParamsReducer', () => {
|
||||||
describe('reduce', () => {
|
describe('reducer', () => {
|
||||||
const defaultState = { page: '1' };
|
const defaultState = { page: '1' };
|
||||||
|
|
||||||
it('returns default value when action is anknown', () =>
|
it('returns default value when action is unknown', () =>
|
||||||
expect(reduce(defaultState, { type: 'unknown' })).toEqual(defaultState)
|
expect(reduce(defaultState, { type: 'unknown' })).toEqual(defaultState)
|
||||||
);
|
);
|
||||||
|
|
76
test/visits/services/VisitsParser.test.js
Normal file
76
test/visits/services/VisitsParser.test.js
Normal file
|
@ -0,0 +1,76 @@
|
||||||
|
import visitsParser from '../../../src/visits/services/VisitsParser';
|
||||||
|
|
||||||
|
describe('VisitsParser', () => {
|
||||||
|
const visits = [
|
||||||
|
{
|
||||||
|
userAgent: 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0',
|
||||||
|
referer: 'https://google.com',
|
||||||
|
visitLocation: {
|
||||||
|
countryName: 'Spain',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X x.y; rv:42.0) Gecko/20100101 Firefox/42.0',
|
||||||
|
referer: 'https://google.com',
|
||||||
|
visitLocation: {
|
||||||
|
countryName: 'United States',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
userAgent: 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36',
|
||||||
|
visitLocation: {
|
||||||
|
countryName: 'Spain',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
userAgent: 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36',
|
||||||
|
referer: 'https://m.facebook.com',
|
||||||
|
visitLocation: {
|
||||||
|
countryName: 'Spain',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
userAgent: 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.106 Safari/537.36 OPR/38.0.2220.41',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
describe('processOsStats', () => {
|
||||||
|
it('properly parses OS stats', () => {
|
||||||
|
expect(visitsParser.processOsStats(visits)).toEqual({
|
||||||
|
'Linux': 3,
|
||||||
|
'Windows': 1,
|
||||||
|
'MacOS': 1,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('processBrowserStats', () => {
|
||||||
|
it('properly parses browser stats', () => {
|
||||||
|
expect(visitsParser.processBrowserStats(visits)).toEqual({
|
||||||
|
'Firefox': 2,
|
||||||
|
'Chrome': 2,
|
||||||
|
'Opera': 1,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('processReferrersStats', () => {
|
||||||
|
it('properly parses referrer stats', () => {
|
||||||
|
expect(visitsParser.processReferrersStats(visits)).toEqual({
|
||||||
|
'Unknown': 2,
|
||||||
|
'google.com': 2,
|
||||||
|
'm.facebook.com': 1,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('processCountriesStats', () => {
|
||||||
|
it('properly parses countries stats', () => {
|
||||||
|
expect(visitsParser.processCountriesStats(visits)).toEqual({
|
||||||
|
'Spain': 3,
|
||||||
|
'United States': 1,
|
||||||
|
'Unknown': 1,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in a new issue