2020-06-12 15:57:30 +00:00
|
|
|
import React from 'react';
|
2020-10-25 18:48:23 +00:00
|
|
|
import {shallow} from 'enzyme';
|
2020-06-12 15:57:30 +00:00
|
|
|
|
2020-10-25 18:48:23 +00:00
|
|
|
import Preview, {TagPreview} from './Preview';
|
2020-06-12 15:57:30 +00:00
|
|
|
|
|
|
|
describe('<Preview/>', function () {
|
|
|
|
it('renders without crashing ', function () {
|
2021-04-20 21:17:34 +02:00
|
|
|
const wrapper = shallow(<Preview movieId={1} name='test' picLoader={callback => callback('')}/>);
|
2020-06-12 15:57:30 +00:00
|
|
|
wrapper.unmount();
|
|
|
|
});
|
|
|
|
|
2021-04-20 21:17:34 +02:00
|
|
|
it('picture rendered correctly', () => {
|
|
|
|
const func = jest.fn();
|
|
|
|
const wrapper = shallow(<Preview movieId={1} name='test' picLoader={callback => {
|
|
|
|
func();
|
|
|
|
callback('42');
|
|
|
|
}}/>);
|
2020-06-12 15:57:30 +00:00
|
|
|
|
2021-04-20 21:17:34 +02:00
|
|
|
// expect picloader tobe called once
|
|
|
|
expect(func).toHaveBeenCalledTimes(1)
|
2020-06-12 15:57:30 +00:00
|
|
|
|
2021-04-20 21:17:34 +02:00
|
|
|
// received picture should be rendered into wrapper
|
|
|
|
expect(wrapper.find('.previewimage').props().src).toBe('42');
|
|
|
|
// check if preview title renders correctly
|
|
|
|
expect(wrapper.find('.previewtitle').text()).toBe('test');
|
2020-06-12 15:57:30 +00:00
|
|
|
});
|
2020-06-18 22:08:26 +02:00
|
|
|
|
|
|
|
it('spinner loads correctly', function () {
|
2021-04-20 21:17:34 +02:00
|
|
|
// if callback is never called --> infinite spinner
|
|
|
|
const wrapper = shallow(<Preview movieId={1} name='test' picLoader={callback => {}}/>);
|
2020-06-18 22:08:26 +02:00
|
|
|
|
|
|
|
// expect load animation to be visible
|
2020-10-25 18:48:23 +00:00
|
|
|
expect(wrapper.find('.loadAnimation')).toHaveLength(1);
|
2020-06-18 22:08:26 +02:00
|
|
|
});
|
2020-06-12 15:57:30 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('<TagPreview/>', function () {
|
|
|
|
it('renders without crashing ', function () {
|
|
|
|
const wrapper = shallow(<TagPreview/>);
|
|
|
|
wrapper.unmount();
|
|
|
|
});
|
|
|
|
|
|
|
|
// check if preview title renders correctly
|
|
|
|
it('renders title', () => {
|
|
|
|
const wrapper = shallow(<TagPreview name='test'/>);
|
|
|
|
expect(wrapper.find('.tagpreviewtitle').text()).toBe('test');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|