mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2025-01-09 09:47:28 +03:00
Fixed tests
This commit is contained in:
parent
5616d045ab
commit
bec755b121
9 changed files with 36 additions and 27 deletions
|
@ -1,12 +1,15 @@
|
||||||
import { shallow } from 'enzyme';
|
import { shallow } from 'enzyme';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { NavLink } from 'react-router-dom';
|
import { NavLink } from 'react-router-dom';
|
||||||
import AsideMenu from '../../src/common/AsideMenu';
|
import asideMenuCreator from '../../src/common/AsideMenu';
|
||||||
|
|
||||||
describe('<AsideMenu />', () => {
|
describe('<AsideMenu />', () => {
|
||||||
let wrapped;
|
let wrapped;
|
||||||
|
const DeleteServerButton = () => '';
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
const AsideMenu = asideMenuCreator(DeleteServerButton);
|
||||||
|
|
||||||
wrapped = shallow(<AsideMenu selectedServer={{ id: 'abc123' }} />);
|
wrapped = shallow(<AsideMenu selectedServer={{ id: 'abc123' }} />);
|
||||||
});
|
});
|
||||||
afterEach(() => wrapped.unmount());
|
afterEach(() => wrapped.unmount());
|
||||||
|
@ -20,6 +23,6 @@ describe('<AsideMenu />', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('contains a button to delete server', () => {
|
it('contains a button to delete server', () => {
|
||||||
expect(wrapped.find('DeleteServerButton')).toHaveLength(1);
|
expect(wrapped.find(DeleteServerButton)).toHaveLength(1);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -2,11 +2,11 @@ import React from 'react';
|
||||||
import { shallow } from 'enzyme';
|
import { shallow } from 'enzyme';
|
||||||
import { identity } from 'ramda';
|
import { identity } from 'ramda';
|
||||||
import sinon from 'sinon';
|
import sinon from 'sinon';
|
||||||
import CreateServer from '../../src/servers/CreateServer';
|
import createServerConstruct from '../../src/servers/CreateServer';
|
||||||
import ImportServersBtn from '../../src/servers/helpers/ImportServersBtn';
|
|
||||||
|
|
||||||
describe('<CreateServer />', () => {
|
describe('<CreateServer />', () => {
|
||||||
let wrapper;
|
let wrapper;
|
||||||
|
const ImportServersBtn = () => '';
|
||||||
const createServerMock = sinon.fake();
|
const createServerMock = sinon.fake();
|
||||||
const historyMock = {
|
const historyMock = {
|
||||||
push: sinon.fake(),
|
push: sinon.fake(),
|
||||||
|
@ -16,6 +16,8 @@ describe('<CreateServer />', () => {
|
||||||
createServerMock.resetHistory();
|
createServerMock.resetHistory();
|
||||||
historyMock.push.resetHistory();
|
historyMock.push.resetHistory();
|
||||||
|
|
||||||
|
const CreateServer = createServerConstruct(ImportServersBtn);
|
||||||
|
|
||||||
wrapper = shallow(
|
wrapper = shallow(
|
||||||
<CreateServer createServer={createServerMock} resetSelectedServer={identity} history={historyMock} />
|
<CreateServer createServer={createServerMock} resetSelectedServer={identity} history={historyMock} />
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,12 +1,14 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { shallow } from 'enzyme';
|
import { shallow } from 'enzyme';
|
||||||
import DeleteServerButton from '../../src/servers/DeleteServerButton';
|
import deleteServerButtonConstruct from '../../src/servers/DeleteServerButton';
|
||||||
import DeleteServerModal from '../../src/servers/DeleteServerModal';
|
import DeleteServerModal from '../../src/servers/DeleteServerModal';
|
||||||
|
|
||||||
describe('<DeleteServerButton />', () => {
|
describe('<DeleteServerButton />', () => {
|
||||||
let wrapper;
|
let wrapper;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
const DeleteServerButton = deleteServerButtonConstruct(DeleteServerModal);
|
||||||
|
|
||||||
wrapper = shallow(<DeleteServerButton server={{}} className="button" />);
|
wrapper = shallow(<DeleteServerButton server={{}} className="button" />);
|
||||||
});
|
});
|
||||||
afterEach(() => wrapper.unmount());
|
afterEach(() => wrapper.unmount());
|
||||||
|
|
|
@ -2,7 +2,7 @@ import React from 'react';
|
||||||
import { shallow } from 'enzyme';
|
import { shallow } from 'enzyme';
|
||||||
import sinon from 'sinon';
|
import sinon from 'sinon';
|
||||||
import { Modal, ModalBody, ModalFooter, ModalHeader } from 'reactstrap';
|
import { Modal, ModalBody, ModalFooter, ModalHeader } from 'reactstrap';
|
||||||
import { DeleteServerModalComponent } from '../../src/servers/DeleteServerModal';
|
import DeleteServerModal from '../../src/servers/DeleteServerModal';
|
||||||
|
|
||||||
describe('<DeleteServerModal />', () => {
|
describe('<DeleteServerModal />', () => {
|
||||||
let wrapper;
|
let wrapper;
|
||||||
|
@ -17,7 +17,7 @@ describe('<DeleteServerModal />', () => {
|
||||||
historyMock.push.resetHistory();
|
historyMock.push.resetHistory();
|
||||||
|
|
||||||
wrapper = shallow(
|
wrapper = shallow(
|
||||||
<DeleteServerModalComponent
|
<DeleteServerModal
|
||||||
server={{ name: serverName }}
|
server={{ name: serverName }}
|
||||||
toggle={toggleMock}
|
toggle={toggleMock}
|
||||||
isOpen={true}
|
isOpen={true}
|
||||||
|
|
|
@ -2,10 +2,11 @@ import { identity, values } from 'ramda';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { shallow } from 'enzyme';
|
import { shallow } from 'enzyme';
|
||||||
import { DropdownItem, DropdownToggle } from 'reactstrap';
|
import { DropdownItem, DropdownToggle } from 'reactstrap';
|
||||||
import ServersDropdown from '../../src/servers/ServersDropdown';
|
import serversDropdownCreator from '../../src/servers/ServersDropdown';
|
||||||
|
|
||||||
describe('<ServersDropdown />', () => {
|
describe('<ServersDropdown />', () => {
|
||||||
let wrapped;
|
let wrapped;
|
||||||
|
let ServersDropdown;
|
||||||
const servers = {
|
const servers = {
|
||||||
'1a': { name: 'foo', id: 1 },
|
'1a': { name: 'foo', id: 1 },
|
||||||
'2b': { name: 'bar', id: 2 },
|
'2b': { name: 'bar', id: 2 },
|
||||||
|
@ -13,6 +14,7 @@ describe('<ServersDropdown />', () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
ServersDropdown = serversDropdownCreator({});
|
||||||
wrapped = shallow(<ServersDropdown servers={servers} listServers={identity} />);
|
wrapped = shallow(<ServersDropdown servers={servers} listServers={identity} />);
|
||||||
});
|
});
|
||||||
afterEach(() => wrapped.unmount());
|
afterEach(() => wrapped.unmount());
|
||||||
|
|
|
@ -2,7 +2,7 @@ import React from 'react';
|
||||||
import sinon from 'sinon';
|
import sinon from 'sinon';
|
||||||
import { shallow } from 'enzyme';
|
import { shallow } from 'enzyme';
|
||||||
import { UncontrolledTooltip } from 'reactstrap';
|
import { UncontrolledTooltip } from 'reactstrap';
|
||||||
import { ImportServersBtnComponent } from '../../../src/servers/helpers/ImportServersBtn';
|
import importServersBtnConstruct from '../../../src/servers/helpers/ImportServersBtn';
|
||||||
|
|
||||||
describe('<ImportServersBtn />', () => {
|
describe('<ImportServersBtn />', () => {
|
||||||
let wrapper;
|
let wrapper;
|
||||||
|
@ -21,13 +21,10 @@ describe('<ImportServersBtn />', () => {
|
||||||
serversImporterMock.importServersFromFile.resetHistory();
|
serversImporterMock.importServersFromFile.resetHistory();
|
||||||
fileRef.current.click.resetHistory();
|
fileRef.current.click.resetHistory();
|
||||||
|
|
||||||
|
const ImportServersBtn = importServersBtnConstruct(serversImporterMock);
|
||||||
|
|
||||||
wrapper = shallow(
|
wrapper = shallow(
|
||||||
<ImportServersBtnComponent
|
<ImportServersBtn createServers={createServersMock} fileRef={fileRef} onImport={onImportMock} />
|
||||||
createServers={createServersMock}
|
|
||||||
serversImporter={serversImporterMock}
|
|
||||||
fileRef={fileRef}
|
|
||||||
onImport={onImportMock}
|
|
||||||
/>
|
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
afterEach(() => wrapper.unmount());
|
afterEach(() => wrapper.unmount());
|
||||||
|
|
|
@ -1,13 +1,14 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { shallow } from 'enzyme';
|
import { shallow } from 'enzyme';
|
||||||
import sinon from 'sinon';
|
import sinon from 'sinon';
|
||||||
import { SearchBarComponent } from '../../src/short-urls/SearchBar';
|
import searchBarCreator from '../../src/short-urls/SearchBar';
|
||||||
import SearchField from '../../src/utils/SearchField';
|
import SearchField from '../../src/utils/SearchField';
|
||||||
import Tag from '../../src/tags/helpers/Tag';
|
|
||||||
|
|
||||||
describe('<SearchBar />', () => {
|
describe('<SearchBar />', () => {
|
||||||
let wrapper;
|
let wrapper;
|
||||||
const listShortUrlsMock = sinon.spy();
|
const listShortUrlsMock = sinon.spy();
|
||||||
|
const Tag = () => '';
|
||||||
|
const SearchBar = searchBarCreator(Tag);
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
listShortUrlsMock.resetHistory();
|
listShortUrlsMock.resetHistory();
|
||||||
|
@ -18,13 +19,13 @@ describe('<SearchBar />', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('renders a SearchField', () => {
|
it('renders a SearchField', () => {
|
||||||
wrapper = shallow(<SearchBarComponent shortUrlsListParams={{}} />);
|
wrapper = shallow(<SearchBar shortUrlsListParams={{}} />);
|
||||||
|
|
||||||
expect(wrapper.find(SearchField)).toHaveLength(1);
|
expect(wrapper.find(SearchField)).toHaveLength(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('renders no tags when the list of tags is empty', () => {
|
it('renders no tags when the list of tags is empty', () => {
|
||||||
wrapper = shallow(<SearchBarComponent shortUrlsListParams={{}} />);
|
wrapper = shallow(<SearchBar shortUrlsListParams={{}} />);
|
||||||
|
|
||||||
expect(wrapper.find(Tag)).toHaveLength(0);
|
expect(wrapper.find(Tag)).toHaveLength(0);
|
||||||
});
|
});
|
||||||
|
@ -32,13 +33,13 @@ describe('<SearchBar />', () => {
|
||||||
it('renders the proper amount of tags', () => {
|
it('renders the proper amount of tags', () => {
|
||||||
const tags = [ 'foo', 'bar', 'baz' ];
|
const tags = [ 'foo', 'bar', 'baz' ];
|
||||||
|
|
||||||
wrapper = shallow(<SearchBarComponent shortUrlsListParams={{ tags }} />);
|
wrapper = shallow(<SearchBar shortUrlsListParams={{ tags }} />);
|
||||||
|
|
||||||
expect(wrapper.find(Tag)).toHaveLength(tags.length);
|
expect(wrapper.find(Tag)).toHaveLength(tags.length);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('updates short URLs list when search field changes', () => {
|
it('updates short URLs list when search field changes', () => {
|
||||||
wrapper = shallow(<SearchBarComponent shortUrlsListParams={{}} listShortUrls={listShortUrlsMock} />);
|
wrapper = shallow(<SearchBar shortUrlsListParams={{}} listShortUrls={listShortUrlsMock} />);
|
||||||
const searchField = wrapper.find(SearchField);
|
const searchField = wrapper.find(SearchField);
|
||||||
|
|
||||||
expect(listShortUrlsMock.callCount).toEqual(0);
|
expect(listShortUrlsMock.callCount).toEqual(0);
|
||||||
|
@ -48,7 +49,7 @@ describe('<SearchBar />', () => {
|
||||||
|
|
||||||
it('updates short URLs list when a tag is removed', () => {
|
it('updates short URLs list when a tag is removed', () => {
|
||||||
wrapper = shallow(
|
wrapper = shallow(
|
||||||
<SearchBarComponent shortUrlsListParams={{ tags: [ 'foo' ] }} listShortUrls={listShortUrlsMock} />
|
<SearchBar shortUrlsListParams={{ tags: [ 'foo' ] }} listShortUrls={listShortUrlsMock} />
|
||||||
);
|
);
|
||||||
const tag = wrapper.find(Tag).first();
|
const tag = wrapper.find(Tag).first();
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { shallow } from 'enzyme';
|
import { shallow } from 'enzyme';
|
||||||
import { ShortUrlsComponent as ShortUrls } from '../../src/short-urls/ShortUrls';
|
import shortUrlsCreator from '../../src/short-urls/ShortUrls';
|
||||||
import Paginator from '../../src/short-urls/Paginator';
|
import Paginator from '../../src/short-urls/Paginator';
|
||||||
import ShortUrlsList from '../../src/short-urls/ShortUrlsList';
|
|
||||||
import SearchBar from '../../src/short-urls/SearchBar';
|
|
||||||
|
|
||||||
describe('<ShortUrlsList />', () => {
|
describe('<ShortUrls />', () => {
|
||||||
let wrapper;
|
let wrapper;
|
||||||
|
const SearchBar = () => '';
|
||||||
|
const ShortUrlsList = () => '';
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
const params = {
|
const params = {
|
||||||
|
@ -14,6 +14,8 @@ describe('<ShortUrlsList />', () => {
|
||||||
page: '1',
|
page: '1',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const ShortUrls = shortUrlsCreator(SearchBar, ShortUrlsList);
|
||||||
|
|
||||||
wrapper = shallow(<ShortUrls match={{ params }} shortUrlsList={{ data: [] }} />);
|
wrapper = shallow(<ShortUrls match={{ params }} shortUrlsList={{ data: [] }} />);
|
||||||
});
|
});
|
||||||
afterEach(() => wrapper.unmount());
|
afterEach(() => wrapper.unmount());
|
||||||
|
|
|
@ -2,7 +2,7 @@ import React from 'react';
|
||||||
import { shallow } from 'enzyme';
|
import { shallow } from 'enzyme';
|
||||||
import { identity, range } from 'ramda';
|
import { identity, range } from 'ramda';
|
||||||
import * as sinon from 'sinon';
|
import * as sinon from 'sinon';
|
||||||
import { TagsListComponent as TagsList } from '../../src/tags/TagsList';
|
import TagsList from '../../src/tags/TagsList';
|
||||||
import MuttedMessage from '../../src/utils/MuttedMessage';
|
import MuttedMessage from '../../src/utils/MuttedMessage';
|
||||||
import TagCard from '../../src/tags/TagCard';
|
import TagCard from '../../src/tags/TagCard';
|
||||||
import SearchField from '../../src/utils/SearchField';
|
import SearchField from '../../src/utils/SearchField';
|
||||||
|
|
Loading…
Reference in a new issue