Tests are borked; they need refactoring to react-testing-library

This commit is contained in:
James Barnsley
2021-03-14 19:49:23 +13:00
parent 6204819d57
commit 8e1055ce3e
10 changed files with 19568 additions and 159 deletions

View File

@ -1,15 +1,32 @@
import React from 'react';
import { shallow } from 'enzyme';
import { render } from 'enzyme';
import { GridItem } from '../../src/js/components/GridItem';
jest.mock('react-redux', () => ({
useSelector: jest.fn(),
useDispatch: () => jest.fn(),
}));
jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
useHistory: () => ({
location: {
pathname: 'iris.local:6680/iris/artist/123:abc',
},
}),
useLocation: () => ({
pathname: 'iris.local:6680/iris/artist/123:abc',
}),
}));
describe('<GridItem />', () => {
it('should handle album', () => {
const item = {
uri: 'spotify:album:alpha',
type: 'album',
name: 'One',
};
const dom = shallow(<GridItem item={item} />);
const dom = render(<GridItem item={item} />);
expect(dom.find('.grid__item__name').text()).toEqual('One');
expect(dom.find('.grid__item__secondary__content').length).toBe(1);
});
@ -17,11 +34,13 @@ describe('<GridItem />', () => {
it('should handle artist', () => {
const item = {
uri: 'spotify:artist:alpha',
type: 'artist',
name: 'Alpha',
followers: 123,
albums_uris: ['spotify:album:beta'],
};
const dom = shallow(<GridItem item={item} />);
const dom = render(<GridItem item={item} />);
console.debug( dom.find('.grid__item__secondary__content') );
expect(dom.find('.grid__item__name').text()).toEqual('Alpha');
expect(dom.find('.grid__item__secondary__content').childAt(0).render().text()).toEqual('123 followers');
expect(dom.find('.grid__item__secondary__content').childAt(1).render().text()).toEqual('1 albums');
@ -30,13 +49,14 @@ describe('<GridItem />', () => {
it('should handle playlist', () => {
const item = {
uri: 'spotify:playlist:alpha',
type: 'playlist',
name: 'One',
tracks: [
{ uri: 'spotify:track:123' },
{ uri: 'spotify:track:456' },
],
};
const dom = shallow(<GridItem item={item} />);
const dom = render(<GridItem item={item} />);
expect(dom.find('.grid__item__name').text()).toEqual('One');
expect(dom.find('.grid__item__secondary__content').render().text()).toEqual('2 tracks');
});