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-03-14 14:51:53 +00:00
|
|
|
const wrapper = shallow(<Preview movieId={1}/>);
|
2020-06-12 15:57:30 +00:00
|
|
|
wrapper.unmount();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('picture rendered correctly', done => {
|
|
|
|
const mockSuccessResponse = 'testsrc';
|
|
|
|
const mockJsonPromise = Promise.resolve(mockSuccessResponse);
|
|
|
|
const mockFetchPromise = Promise.resolve({
|
2020-10-25 18:48:23 +00:00
|
|
|
text: () => mockJsonPromise
|
2020-06-12 15:57:30 +00:00
|
|
|
});
|
|
|
|
global.fetch = jest.fn().mockImplementation(() => mockFetchPromise);
|
|
|
|
|
2021-03-14 14:51:53 +00:00
|
|
|
const wrapper = shallow(<Preview name='test' movieId={1}/>);
|
2020-06-12 15:57:30 +00:00
|
|
|
|
|
|
|
// now called 1 times
|
|
|
|
expect(global.fetch).toHaveBeenCalledTimes(1);
|
|
|
|
|
|
|
|
process.nextTick(() => {
|
|
|
|
// received picture should be rendered into wrapper
|
2020-10-25 18:48:23 +00:00
|
|
|
expect(wrapper.find('.previewimage').props().src).not.toBeNull();
|
2020-12-17 20:53:22 +00:00
|
|
|
// check if preview title renders correctly
|
|
|
|
expect(wrapper.find('.previewtitle').text()).toBe('test');
|
2020-06-12 15:57:30 +00:00
|
|
|
|
|
|
|
global.fetch.mockClear();
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
2020-06-18 22:08:26 +02:00
|
|
|
|
|
|
|
it('spinner loads correctly', function () {
|
2021-03-14 14:51:53 +00:00
|
|
|
const wrapper = shallow(<Preview movieId={1}/>);
|
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');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|