2020-08-30 20:45:17 +03:00
|
|
|
import { shallow, ShallowWrapper } from 'enzyme';
|
|
|
|
import { Mock } from 'ts-mockery';
|
2020-09-13 10:47:29 +03:00
|
|
|
import shortUrlsListCreator, { ShortUrlsListProps } from '../../src/short-urls/ShortUrlsList';
|
2020-08-30 20:45:17 +03:00
|
|
|
import { ShortUrl } from '../../src/short-urls/data';
|
2020-09-06 20:41:15 +03:00
|
|
|
import { MercureBoundProps } from '../../src/mercure/helpers/boundToMercureHub';
|
2020-12-07 13:17:19 +03:00
|
|
|
import { ShortUrlsList as ShortUrlsListModel } from '../../src/short-urls/reducers/shortUrlsList';
|
|
|
|
import SortingDropdown from '../../src/utils/SortingDropdown';
|
2019-09-14 19:23:26 +03:00
|
|
|
|
|
|
|
describe('<ShortUrlsList />', () => {
|
2020-08-30 20:45:17 +03:00
|
|
|
let wrapper: ShallowWrapper;
|
2020-12-07 13:17:19 +03:00
|
|
|
const ShortUrlsTable = () => null;
|
2019-09-14 19:23:26 +03:00
|
|
|
const listShortUrlsMock = jest.fn();
|
|
|
|
const resetShortUrlParamsMock = jest.fn();
|
2020-12-07 13:17:19 +03:00
|
|
|
const shortUrlsList = Mock.of<ShortUrlsListModel>({
|
|
|
|
shortUrls: {
|
|
|
|
data: [
|
|
|
|
Mock.of<ShortUrl>({
|
|
|
|
shortCode: 'testShortCode',
|
|
|
|
shortUrl: 'https://www.example.com/testShortUrl',
|
|
|
|
longUrl: 'https://www.example.com/testLongUrl',
|
|
|
|
tags: [ 'test tag' ],
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
},
|
|
|
|
});
|
2019-09-14 19:23:26 +03:00
|
|
|
|
2020-12-07 13:17:19 +03:00
|
|
|
const ShortUrlsList = shortUrlsListCreator(ShortUrlsTable);
|
2019-09-14 19:23:26 +03:00
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
wrapper = shallow(
|
|
|
|
<ShortUrlsList
|
2020-08-30 20:45:17 +03:00
|
|
|
{...Mock.all<ShortUrlsListProps>()}
|
2020-09-06 20:41:15 +03:00
|
|
|
{...Mock.of<MercureBoundProps>({ mercureInfo: { loading: true } })}
|
2019-09-14 19:23:26 +03:00
|
|
|
listShortUrls={listShortUrlsMock}
|
|
|
|
resetShortUrlParams={resetShortUrlParamsMock}
|
|
|
|
shortUrlsListParams={{
|
|
|
|
page: '1',
|
|
|
|
tags: [ 'test tag' ],
|
|
|
|
searchTerm: 'example.com',
|
|
|
|
}}
|
2020-08-30 20:45:17 +03:00
|
|
|
match={{ params: {} } as any}
|
|
|
|
location={{} as any}
|
2020-12-07 13:17:19 +03:00
|
|
|
shortUrlsList={shortUrlsList}
|
2020-08-22 09:10:31 +03:00
|
|
|
/>,
|
2020-09-06 20:41:15 +03:00
|
|
|
).dive(); // Dive is needed as this component is wrapped in a HOC
|
2019-09-14 19:23:26 +03:00
|
|
|
});
|
|
|
|
|
2020-08-30 20:45:17 +03:00
|
|
|
afterEach(jest.resetAllMocks);
|
|
|
|
afterEach(() => wrapper?.unmount());
|
2019-09-14 19:23:26 +03:00
|
|
|
|
2020-12-07 13:17:19 +03:00
|
|
|
it('wraps a ShortUrlsTable', () => {
|
|
|
|
expect(wrapper.find(ShortUrlsTable)).toHaveLength(1);
|
2019-09-14 19:23:26 +03:00
|
|
|
});
|
|
|
|
|
2020-12-07 13:17:19 +03:00
|
|
|
it('wraps a SortingDropdown', () => {
|
|
|
|
expect(wrapper.find(SortingDropdown)).toHaveLength(1);
|
2019-09-14 19:23:26 +03:00
|
|
|
});
|
|
|
|
});
|