2019-09-14 19:23:26 +03:00
|
|
|
import React from 'react';
|
|
|
|
import { shallow } from 'enzyme';
|
|
|
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
|
|
|
import { faCaretDown as caretDownIcon, faCaretUp as caretUpIcon } from '@fortawesome/free-solid-svg-icons';
|
|
|
|
import shortUrlsListCreator, { SORTABLE_FIELDS } from '../../src/short-urls/ShortUrlsList';
|
|
|
|
|
|
|
|
describe('<ShortUrlsList />', () => {
|
|
|
|
let wrapper;
|
|
|
|
const ShortUrlsRow = () => '';
|
|
|
|
const listShortUrlsMock = jest.fn();
|
|
|
|
const resetShortUrlParamsMock = jest.fn();
|
|
|
|
|
|
|
|
const ShortUrlsList = shortUrlsListCreator(ShortUrlsRow);
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
wrapper = shallow(
|
|
|
|
<ShortUrlsList
|
|
|
|
listShortUrls={listShortUrlsMock}
|
|
|
|
resetShortUrlParams={resetShortUrlParamsMock}
|
|
|
|
shortUrlsListParams={{
|
|
|
|
page: '1',
|
|
|
|
tags: [ 'test tag' ],
|
|
|
|
searchTerm: 'example.com',
|
|
|
|
}}
|
|
|
|
match={{ params: {} }}
|
|
|
|
location={{}}
|
|
|
|
loading={false}
|
|
|
|
error={false}
|
|
|
|
shortUrlsList={
|
|
|
|
[
|
|
|
|
{
|
|
|
|
shortCode: 'testShortCode',
|
|
|
|
shortUrl: 'https://www.example.com/testShortUrl',
|
|
|
|
longUrl: 'https://www.example.com/testLongUrl',
|
|
|
|
tags: [ 'test tag' ],
|
|
|
|
},
|
|
|
|
]
|
|
|
|
}
|
2020-04-17 18:11:52 +03:00
|
|
|
mercureInfo={{ loading: true }}
|
2019-09-14 19:23:26 +03:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
2020-04-17 18:11:52 +03:00
|
|
|
jest.resetAllMocks();
|
2019-09-14 19:23:26 +03:00
|
|
|
wrapper && wrapper.unmount();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('wraps a ShortUrlsList with 1 ShortUrlsRow', () => {
|
|
|
|
expect(wrapper.find(ShortUrlsRow)).toHaveLength(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render inner table by default', () => {
|
|
|
|
expect(wrapper.find('table')).toHaveLength(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render table header by default', () => {
|
2020-04-17 18:11:52 +03:00
|
|
|
expect(wrapper.find('table').find('thead')).toHaveLength(1);
|
2019-09-14 19:23:26 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should render 6 table header cells by default', () => {
|
2020-04-17 18:11:52 +03:00
|
|
|
expect(wrapper.find('table').find('thead').find('tr').find('th')).toHaveLength(6);
|
2019-09-14 19:23:26 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should render 6 table header cells without order by icon by default', () => {
|
2020-04-17 18:11:52 +03:00
|
|
|
const thElements = wrapper.find('table').find('thead').find('tr').find('th');
|
2019-09-14 19:23:26 +03:00
|
|
|
|
2020-04-17 18:11:52 +03:00
|
|
|
thElements.forEach((thElement) => {
|
2019-09-14 19:23:26 +03:00
|
|
|
expect(thElement.find(FontAwesomeIcon)).toHaveLength(0);
|
2020-04-17 18:11:52 +03:00
|
|
|
});
|
2019-09-14 19:23:26 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should render 6 table header cells with conditional order by icon', () => {
|
2020-04-17 18:11:52 +03:00
|
|
|
const getThElementForSortableField = (sortableField) => wrapper.find('table')
|
|
|
|
.find('thead')
|
|
|
|
.find('tr')
|
|
|
|
.find('th')
|
|
|
|
.filterWhere((e) => e.text().includes(SORTABLE_FIELDS[sortableField]));
|
2019-09-14 19:23:26 +03:00
|
|
|
|
2020-04-17 18:11:52 +03:00
|
|
|
Object.keys(SORTABLE_FIELDS).forEach((sortableField) => {
|
2020-04-17 18:39:30 +03:00
|
|
|
expect(getThElementForSortableField(sortableField).find(FontAwesomeIcon)).toHaveLength(0);
|
2019-09-14 19:23:26 +03:00
|
|
|
|
2020-04-17 18:39:30 +03:00
|
|
|
getThElementForSortableField(sortableField).simulate('click');
|
2020-04-17 18:11:52 +03:00
|
|
|
expect(getThElementForSortableField(sortableField).find(FontAwesomeIcon)).toHaveLength(1);
|
2020-04-17 18:39:30 +03:00
|
|
|
expect(getThElementForSortableField(sortableField).find(FontAwesomeIcon).prop('icon')).toEqual(caretUpIcon);
|
2020-04-17 18:11:52 +03:00
|
|
|
|
2020-04-17 18:39:30 +03:00
|
|
|
getThElementForSortableField(sortableField).simulate('click');
|
2020-04-17 18:11:52 +03:00
|
|
|
expect(getThElementForSortableField(sortableField).find(FontAwesomeIcon)).toHaveLength(1);
|
2020-04-17 18:39:30 +03:00
|
|
|
expect(getThElementForSortableField(sortableField).find(FontAwesomeIcon).prop('icon')).toEqual(caretDownIcon);
|
2020-04-17 18:11:52 +03:00
|
|
|
|
2020-04-17 18:39:30 +03:00
|
|
|
getThElementForSortableField(sortableField).simulate('click');
|
|
|
|
expect(getThElementForSortableField(sortableField).find(FontAwesomeIcon)).toHaveLength(0);
|
2020-04-17 18:11:52 +03:00
|
|
|
});
|
2019-09-14 19:23:26 +03:00
|
|
|
});
|
|
|
|
});
|