mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-03-13 02:53:47 +00:00
Created ShortUrlsRow test
This commit is contained in:
108
test/short-urls/helpers/ShortUrlsRow.test.js
Normal file
108
test/short-urls/helpers/ShortUrlsRow.test.js
Normal file
@@ -0,0 +1,108 @@
|
||||
import React from 'react';
|
||||
import { shallow } from 'enzyme';
|
||||
import moment from 'moment';
|
||||
import Moment from 'react-moment';
|
||||
import { assoc, toString } from 'ramda';
|
||||
import * as sinon from 'sinon';
|
||||
import createShortUrlsRow from '../../../src/short-urls/helpers/ShortUrlsRow';
|
||||
import ExternalLink from '../../../src/utils/ExternalLink';
|
||||
import Tag from '../../../src/tags/helpers/Tag';
|
||||
|
||||
describe('<ShortUrlsRow />', () => {
|
||||
let wrapper;
|
||||
const mockFunction = () => '';
|
||||
const ShortUrlsRowMenu = mockFunction;
|
||||
const stateFlagTimeout = sinon.spy();
|
||||
const colorGenerator = {
|
||||
getColorForKey: mockFunction,
|
||||
setColorForKey: mockFunction,
|
||||
};
|
||||
const server = {
|
||||
url: 'https://doma.in',
|
||||
};
|
||||
const shortUrl = {
|
||||
shortCode: 'abc123',
|
||||
shortUrl: 'http://doma.in/abc123',
|
||||
longUrl: 'http://foo.com/bar',
|
||||
dateCreated: moment('2018-05-23 18:30:41').format(),
|
||||
tags: [ 'nodejs', 'reactjs' ],
|
||||
visitsCount: 45,
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
const ShortUrlsRow = createShortUrlsRow(ShortUrlsRowMenu, colorGenerator, stateFlagTimeout);
|
||||
|
||||
wrapper = shallow(
|
||||
<ShortUrlsRow shortUrlsListParams={{}} refreshList={mockFunction} selecrtedServer={server} shortUrl={shortUrl} />
|
||||
);
|
||||
});
|
||||
afterEach(() => wrapper.unmount());
|
||||
|
||||
it('renders date in first column', () => {
|
||||
const col = wrapper.find('td').first();
|
||||
const moment = col.find(Moment);
|
||||
|
||||
expect(moment.html()).toContain('>2018-05-23 18:30</time>');
|
||||
});
|
||||
|
||||
it('renders short URL in second row', () => {
|
||||
const col = wrapper.find('td').at(1);
|
||||
const link = col.find(ExternalLink);
|
||||
|
||||
expect(link.prop('href')).toEqual(shortUrl.shortUrl);
|
||||
});
|
||||
|
||||
it('renders long URL in third row', () => {
|
||||
const col = wrapper.find('td').at(2); // eslint-disable-line no-magic-numbers
|
||||
const link = col.find(ExternalLink);
|
||||
|
||||
expect(link.prop('href')).toEqual(shortUrl.longUrl);
|
||||
});
|
||||
|
||||
describe('renders list of tags in fourth row', () => {
|
||||
it('with tags', () => {
|
||||
const col = wrapper.find('td').at(3); // eslint-disable-line no-magic-numbers
|
||||
const tags = col.find(Tag);
|
||||
|
||||
expect(tags).toHaveLength(shortUrl.tags.length);
|
||||
shortUrl.tags.forEach((tagValue, index) => {
|
||||
const tag = tags.at(index);
|
||||
|
||||
expect(tag.prop('text')).toEqual(tagValue);
|
||||
});
|
||||
});
|
||||
|
||||
it('without tags', () => {
|
||||
wrapper.setProps({ shortUrl: assoc('tags', [], shortUrl) });
|
||||
|
||||
const col = wrapper.find('td').at(3); // eslint-disable-line no-magic-numbers
|
||||
|
||||
expect(col.text()).toContain('No tags');
|
||||
});
|
||||
});
|
||||
|
||||
it('renders visits count in fifth row', () => {
|
||||
const col = wrapper.find('td').at(4); // eslint-disable-line no-magic-numbers
|
||||
|
||||
expect(col.text()).toEqual(toString(shortUrl.visitsCount));
|
||||
});
|
||||
|
||||
it('updates state when copied to clipboard', () => {
|
||||
const col = wrapper.find('td').at(5); // eslint-disable-line no-magic-numbers
|
||||
const menu = col.find(ShortUrlsRowMenu);
|
||||
|
||||
expect(menu).toHaveLength(1);
|
||||
expect(stateFlagTimeout.called).toEqual(false);
|
||||
menu.simulate('copyToClipboard');
|
||||
expect(stateFlagTimeout.calledOnce).toEqual(true);
|
||||
});
|
||||
|
||||
it('shows copy hint when state prop is true', () => {
|
||||
// eslint-disable-next-line no-magic-numbers
|
||||
const isHidden = () => wrapper.find('td').at(5).find('.short-urls-row__copy-hint').prop('hidden');
|
||||
|
||||
expect(isHidden()).toEqual(true);
|
||||
wrapper.setState({ copiedToClipboard: true });
|
||||
expect(isHidden()).toEqual(false);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user