mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-02-27 12:16:36 +00:00
Created page for tag visit stats
This commit is contained in:
@@ -7,7 +7,7 @@ import reducer, {
|
||||
import { SHORT_URL_TAGS_EDITED } from '../../../src/short-urls/reducers/shortUrlTags';
|
||||
import { SHORT_URL_DELETED } from '../../../src/short-urls/reducers/shortUrlDeletion';
|
||||
import { SHORT_URL_META_EDITED } from '../../../src/short-urls/reducers/shortUrlMeta';
|
||||
import { CREATE_SHORT_URL_VISIT } from '../../../src/visits/reducers/shortUrlVisits';
|
||||
import { CREATE_VISIT } from '../../../src/visits/reducers/visitCreation';
|
||||
|
||||
describe('shortUrlsListReducer', () => {
|
||||
describe('reducer', () => {
|
||||
@@ -103,7 +103,7 @@ describe('shortUrlsListReducer', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('updates visits count on CREATE_SHORT_URL_VISIT', () => {
|
||||
it('updates visits count on CREATE_VISIT', () => {
|
||||
const shortCode = 'abc123';
|
||||
const shortUrl = {
|
||||
shortCode,
|
||||
@@ -119,7 +119,7 @@ describe('shortUrlsListReducer', () => {
|
||||
},
|
||||
};
|
||||
|
||||
expect(reducer(state, { type: CREATE_SHORT_URL_VISIT, shortUrl })).toEqual({
|
||||
expect(reducer(state, { type: CREATE_VISIT, shortUrl })).toEqual({
|
||||
shortUrls: {
|
||||
data: [
|
||||
{ shortCode, domain: 'example.com', visitsCount: 5 },
|
||||
|
||||
@@ -71,6 +71,28 @@ describe('ShlinkApiClient', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('getTagVisits', () => {
|
||||
it('properly returns tag visits', async () => {
|
||||
const expectedVisits = [ 'foo', 'bar' ];
|
||||
const axiosSpy = jest.fn(createAxiosMock({
|
||||
data: {
|
||||
visits: {
|
||||
data: expectedVisits,
|
||||
},
|
||||
},
|
||||
}));
|
||||
const { getTagVisits } = new ShlinkApiClient(axiosSpy);
|
||||
|
||||
const actualVisits = await getTagVisits('foo', {});
|
||||
|
||||
expect({ data: expectedVisits }).toEqual(actualVisits);
|
||||
expect(axiosSpy).toHaveBeenCalledWith(expect.objectContaining({
|
||||
url: '/tags/foo/visits',
|
||||
method: 'GET',
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
||||
describe('getShortUrl', () => {
|
||||
it.each(shortCodesWithDomainCombinations)('properly returns short URL', async (shortCode, domain) => {
|
||||
const expectedShortUrl = { foo: 'bar' };
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
import reducer, {
|
||||
getShortUrlVisits,
|
||||
cancelGetShortUrlVisits,
|
||||
createNewVisit,
|
||||
GET_SHORT_URL_VISITS_START,
|
||||
GET_SHORT_URL_VISITS_ERROR,
|
||||
GET_SHORT_URL_VISITS,
|
||||
GET_SHORT_URL_VISITS_LARGE,
|
||||
GET_SHORT_URL_VISITS_CANCEL,
|
||||
CREATE_SHORT_URL_VISIT,
|
||||
} from '../../../src/visits/reducers/shortUrlVisits';
|
||||
import { CREATE_VISIT } from '../../../src/visits/reducers/visitCreation';
|
||||
|
||||
describe('shortUrlVisitsReducer', () => {
|
||||
describe('reducer', () => {
|
||||
@@ -54,7 +53,7 @@ describe('shortUrlVisitsReducer', () => {
|
||||
it.each([
|
||||
[{ shortCode: 'abc123' }, [{}, {}, {}]],
|
||||
[{ shortCode: 'def456' }, [{}, {}]],
|
||||
])('appends a new visit on CREATE_SHORT_URL_VISIT', (state, expectedVisits) => {
|
||||
])('appends a new visit on CREATE_VISIT', (state, expectedVisits) => {
|
||||
const shortUrl = {
|
||||
shortCode: 'abc123',
|
||||
};
|
||||
@@ -63,7 +62,7 @@ describe('shortUrlVisitsReducer', () => {
|
||||
visits: [{}, {}],
|
||||
};
|
||||
|
||||
const { visits } = reducer(prevState, { type: CREATE_SHORT_URL_VISIT, shortUrl, visit: {} });
|
||||
const { visits } = reducer(prevState, { type: CREATE_VISIT, shortUrl, visit: {} });
|
||||
|
||||
expect(visits).toEqual(expectedVisits);
|
||||
});
|
||||
@@ -138,11 +137,4 @@ describe('shortUrlVisitsReducer', () => {
|
||||
it('just returns the action with proper type', () =>
|
||||
expect(cancelGetShortUrlVisits()).toEqual({ type: GET_SHORT_URL_VISITS_CANCEL }));
|
||||
});
|
||||
|
||||
describe('createNewVisit', () => {
|
||||
it('just returns the action with proper type', () =>
|
||||
expect(createNewVisit({ shortUrl: {}, visit: {} })).toEqual(
|
||||
{ type: CREATE_SHORT_URL_VISIT, shortUrl: {}, visit: {} }
|
||||
));
|
||||
});
|
||||
});
|
||||
|
||||
10
test/visits/reducers/visitCreation.test.js
Normal file
10
test/visits/reducers/visitCreation.test.js
Normal file
@@ -0,0 +1,10 @@
|
||||
import { CREATE_VISIT, createNewVisit } from '../../../src/visits/reducers/visitCreation';
|
||||
|
||||
describe('visitCreationReducer', () => {
|
||||
describe('createNewVisit', () => {
|
||||
it('just returns the action with proper type', () =>
|
||||
expect(createNewVisit({ shortUrl: {}, visit: {} })).toEqual(
|
||||
{ type: CREATE_VISIT, shortUrl: {}, visit: {} }
|
||||
));
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user