Migrated remaining tags-related elements to TS

This commit is contained in:
Alejandro Celaya
2020-08-30 20:48:09 +02:00
parent 18883caa6d
commit f8ea1ae3d5
8 changed files with 198 additions and 225 deletions

View File

@@ -1,11 +1,14 @@
import React from 'react';
import { shallow } from 'enzyme';
import { shallow, ShallowWrapper } from 'enzyme';
import { Link } from 'react-router-dom';
import { Mock } from 'ts-mockery';
import createTagCard from '../../src/tags/TagCard';
import TagBullet from '../../src/tags/helpers/TagBullet';
import ColorGenerator from '../../src/utils/services/ColorGenerator';
import { ReachableServer } from '../../src/servers/data';
describe('<TagCard />', () => {
let wrapper;
let wrapper: ShallowWrapper;
const tagStats = {
shortUrlsCount: 48,
visitsCount: 23257,
@@ -14,9 +17,17 @@ describe('<TagCard />', () => {
const EditTagModal = jest.fn();
beforeEach(() => {
const TagCard = createTagCard(DeleteTagConfirmModal, EditTagModal, () => '', {});
const TagCard = createTagCard(DeleteTagConfirmModal, EditTagModal, () => null, Mock.all<ColorGenerator>());
wrapper = shallow(<TagCard tag="ssr" selectedServer={{ id: 1, serverNotFound: false }} tagStats={tagStats} />);
wrapper = shallow(
<TagCard
tag="ssr"
selectedServer={Mock.of<ReachableServer>({ id: '1' })}
tagStats={tagStats}
displayed={true}
toggle={() => {}}
/>,
);
});
afterEach(() => wrapper.unmount());

View File

@@ -1,30 +1,34 @@
import React from 'react';
import { shallow } from 'enzyme';
import { shallow, ShallowWrapper } from 'enzyme';
import { identity } from 'ramda';
import createTagsList from '../../src/tags/TagsList';
import { Mock } from 'ts-mockery';
import createTagsList, { TagsListProps } from '../../src/tags/TagsList';
import Message from '../../src/utils/Message';
import SearchField from '../../src/utils/SearchField';
import { rangeOf } from '../../src/utils/utils';
import { TagsList } from '../../src/tags/reducers/tagsList';
describe('<TagsList />', () => {
let wrapper;
let wrapper: ShallowWrapper;
const filterTags = jest.fn();
const TagCard = () => '';
const createWrapper = (tagsList) => {
const params = { serverId: '1' };
const TagsList = createTagsList(TagCard);
const TagCard = () => null;
const createWrapper = (tagsList: Partial<TagsList>) => {
const TagsListComp = createTagsList(TagCard);
wrapper = shallow(
<TagsList forceListTags={identity} filterTags={filterTags} match={{ params }} tagsList={tagsList} />,
<TagsListComp
{...Mock.all<TagsListProps>()}
forceListTags={identity}
filterTags={filterTags}
tagsList={Mock.of<TagsList>(tagsList)}
/>,
);
return wrapper;
};
afterEach(() => {
wrapper && wrapper.unmount();
filterTags.mockReset();
});
afterEach(() => wrapper?.unmount());
afterEach(jest.clearAllMocks);
it('shows a loading message when tags are being loaded', () => {
const wrapper = createWrapper({ loading: true });