Fixed tests

This commit is contained in:
Alejandro Celaya
2018-12-17 22:32:51 +01:00
parent 5616d045ab
commit bec755b121
9 changed files with 36 additions and 27 deletions

View File

@@ -1,13 +1,14 @@
import React from 'react';
import { shallow } from 'enzyme';
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 Tag from '../../src/tags/helpers/Tag';
describe('<SearchBar />', () => {
let wrapper;
const listShortUrlsMock = sinon.spy();
const Tag = () => '';
const SearchBar = searchBarCreator(Tag);
afterEach(() => {
listShortUrlsMock.resetHistory();
@@ -18,13 +19,13 @@ describe('<SearchBar />', () => {
});
it('renders a SearchField', () => {
wrapper = shallow(<SearchBarComponent shortUrlsListParams={{}} />);
wrapper = shallow(<SearchBar shortUrlsListParams={{}} />);
expect(wrapper.find(SearchField)).toHaveLength(1);
});
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);
});
@@ -32,13 +33,13 @@ describe('<SearchBar />', () => {
it('renders the proper amount of tags', () => {
const tags = [ 'foo', 'bar', 'baz' ];
wrapper = shallow(<SearchBarComponent shortUrlsListParams={{ tags }} />);
wrapper = shallow(<SearchBar shortUrlsListParams={{ tags }} />);
expect(wrapper.find(Tag)).toHaveLength(tags.length);
});
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);
expect(listShortUrlsMock.callCount).toEqual(0);
@@ -48,7 +49,7 @@ describe('<SearchBar />', () => {
it('updates short URLs list when a tag is removed', () => {
wrapper = shallow(
<SearchBarComponent shortUrlsListParams={{ tags: [ 'foo' ] }} listShortUrls={listShortUrlsMock} />
<SearchBar shortUrlsListParams={{ tags: [ 'foo' ] }} listShortUrls={listShortUrlsMock} />
);
const tag = wrapper.find(Tag).first();