Updated tags list to display visits and short URLs when remote shlink version allows it

This commit is contained in:
Alejandro Celaya
2020-05-10 10:57:49 +02:00
parent 8741f42fe8
commit 18e026e4ca
13 changed files with 143 additions and 46 deletions

View File

@@ -6,19 +6,23 @@ import TagBullet from '../../src/tags/helpers/TagBullet';
describe('<TagCard />', () => {
let wrapper;
const tagStats = {
shortUrlsCount: 48,
visitsCount: 23257,
};
beforeEach(() => {
const TagCard = createTagCard(() => '', () => '', {});
const TagCard = createTagCard(() => '', () => '', () => '', {});
wrapper = shallow(<TagCard tag="ssr" currentServerId="1" />);
wrapper = shallow(<TagCard tag="ssr" selectedServer={{ id: 1, serverNotFound: false }} tagStats={tagStats} />);
});
afterEach(() => wrapper.unmount());
it('shows a TagBullet and a link to the list filtering by the tag', () => {
const link = wrapper.find(Link);
const links = wrapper.find(Link);
const bullet = wrapper.find(TagBullet);
expect(link.prop('to')).toEqual('/server/1/list-short-urls/1?tag=ssr');
expect(links.at(0).prop('to')).toEqual('/server/1/list-short-urls/1?tag=ssr');
expect(bullet.prop('tag')).toEqual('ssr');
});
@@ -45,4 +49,13 @@ describe('<TagCard />', () => {
done();
});
});
it('shows expected tag stats', () => {
const links = wrapper.find(Link);
expect(links.at(1).prop('to')).toEqual('/server/1/list-short-urls/1?tag=ssr');
expect(links.at(1).text()).toContain('48');
expect(links.at(2).prop('to')).toEqual('/server/1/tags/ssr/visits');
expect(links.at(2).text()).toContain('23,257');
});
});

View File

@@ -53,7 +53,7 @@ describe('<TagsList />', () => {
it('renders the proper amount of groups and cards based on the amount of tags', () => {
const amountOfTags = 10;
const amountOfGroups = 4;
const wrapper = createWrapper({ filteredTags: rangeOf(amountOfTags, (i) => `tag_${i}`) });
const wrapper = createWrapper({ filteredTags: rangeOf(amountOfTags, (i) => `tag_${i}`), stats: {} });
const cards = wrapper.find(TagCard);
const groups = wrapper.find('.col-md-6');

View File

@@ -103,7 +103,7 @@ describe('tagsListReducer', () => {
it('dispatches loaded lists when no error occurs', async () => {
const tags = [ 'foo', 'bar', 'baz' ];
listTagsMock.mockResolvedValue(tags);
listTagsMock.mockResolvedValue({ data: tags, stats: [] });
buildShlinkApiClient.mockReturnValue({ listTags: listTagsMock });
await listTags(buildShlinkApiClient, true)()(dispatch, getState);
@@ -112,7 +112,7 @@ describe('tagsListReducer', () => {
expect(getState).toHaveBeenCalledTimes(1);
expect(dispatch).toHaveBeenCalledTimes(2);
expect(dispatch).toHaveBeenNthCalledWith(1, { type: LIST_TAGS_START });
expect(dispatch).toHaveBeenNthCalledWith(2, { type: LIST_TAGS, tags });
expect(dispatch).toHaveBeenNthCalledWith(2, { type: LIST_TAGS, tags, stats: {} });
});
const assertErrorResult = async () => {

View File

@@ -141,7 +141,7 @@ describe('ShlinkApiClient', () => {
const result = await listTags();
expect(expectedTags).toEqual(result);
expect({ data: expectedTags }).toEqual(result);
expect(axiosSpy).toHaveBeenCalledWith(expect.objectContaining({ url: '/tags', method: 'GET' }));
});
});