mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2025-01-07 16:57:27 +03:00
Created VisitsParser test
This commit is contained in:
parent
a83be0b45c
commit
26a3fdfd3d
4 changed files with 88 additions and 9 deletions
src
test
|
@ -7,11 +7,15 @@ import Moment from 'react-moment'
|
|||
import { connect } from 'react-redux'
|
||||
import { Card, CardBody, CardHeader, UncontrolledTooltip } from 'reactstrap'
|
||||
import DateInput from '../common/DateInput'
|
||||
import VisitsParser from '../visits/services/VisitsParser'
|
||||
import visitsParser from '../visits/services/VisitsParser'
|
||||
import { getShortUrlVisits } from './reducers/shortUrlVisits'
|
||||
import './ShortUrlVisits.scss'
|
||||
import MutedMessage from '../utils/MuttedMessage';
|
||||
|
||||
const defaultProps = {
|
||||
visitsParser,
|
||||
};
|
||||
|
||||
export class ShortUrlsVisits extends React.Component {
|
||||
state = { startDate: undefined, endDate: undefined };
|
||||
loadVisits = () => {
|
||||
|
@ -167,8 +171,6 @@ export class ShortUrlsVisits extends React.Component {
|
|||
}
|
||||
}
|
||||
|
||||
ShortUrlsVisits.defaultProps = {
|
||||
visitsParser: VisitsParser
|
||||
};
|
||||
ShortUrlsVisits.defaultProps = defaultProps;
|
||||
|
||||
export default connect(pick(['selectedServer', 'shortUrlVisits']), { getShortUrlVisits })(ShortUrlsVisits);
|
||||
|
|
|
@ -21,14 +21,14 @@ const browserFromUserAgent = userAgent => {
|
|||
const lowerUserAgent = userAgent.toLowerCase();
|
||||
|
||||
switch (true) {
|
||||
case (lowerUserAgent.indexOf('opera') >= 0 || lowerUserAgent.indexOf('opr') >= 0):
|
||||
return 'Opera';
|
||||
case (lowerUserAgent.indexOf('firefox') >= 0):
|
||||
return 'Firefox';
|
||||
case (lowerUserAgent.indexOf('chrome') >= 0):
|
||||
return 'Chrome';
|
||||
case (lowerUserAgent.indexOf('safari') >= 0):
|
||||
return 'Safari';
|
||||
case (lowerUserAgent.indexOf('opera') >= 0):
|
||||
return 'Opera';
|
||||
case (lowerUserAgent.indexOf('msie') >= 0):
|
||||
return 'Internet Explorer';
|
||||
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';
|
||||
|
||||
describe('shortUrlsListParamsReducer', () => {
|
||||
describe('reduce', () => {
|
||||
describe('reducer', () => {
|
||||
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)
|
||||
);
|
||||
|
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