2020-10-25 18:48:23 +00:00
|
|
|
import {shallow} from 'enzyme';
|
|
|
|
import React from 'react';
|
|
|
|
import Player from './Player';
|
2020-06-12 15:57:30 +00:00
|
|
|
|
|
|
|
describe('<Player/>', function () {
|
|
|
|
it('renders without crashing ', function () {
|
|
|
|
const wrapper = shallow(<Player/>);
|
|
|
|
wrapper.unmount();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('plyr insertion', function () {
|
|
|
|
const wrapper = shallow(<Player/>);
|
|
|
|
|
|
|
|
wrapper.setState({
|
|
|
|
sources: [
|
|
|
|
{
|
|
|
|
src: '/tstvid.mp4',
|
|
|
|
type: 'video/mp4',
|
2020-10-25 18:48:23 +00:00
|
|
|
size: 1080
|
2020-06-12 15:57:30 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
});
|
2020-11-27 22:43:12 +00:00
|
|
|
|
|
|
|
expect(wrapper.find('Plyr').dive().find('video')).toHaveLength(1);
|
2020-06-12 15:57:30 +00:00
|
|
|
});
|
|
|
|
|
2020-10-09 14:00:51 +00:00
|
|
|
function simulateLikeButtonClick() {
|
2020-06-12 15:57:30 +00:00
|
|
|
const wrapper = shallow(<Player/>);
|
|
|
|
|
|
|
|
// initial fetch for getting movie data
|
|
|
|
expect(global.fetch).toHaveBeenCalledTimes(1);
|
2020-10-25 18:48:23 +00:00
|
|
|
wrapper.find('.videoactions').find('button').first().simulate('click');
|
2020-06-12 15:57:30 +00:00
|
|
|
// fetch for liking
|
|
|
|
expect(global.fetch).toHaveBeenCalledTimes(2);
|
|
|
|
|
2020-09-26 18:43:30 +00:00
|
|
|
return wrapper;
|
|
|
|
}
|
|
|
|
|
|
|
|
it('likebtn click', done => {
|
|
|
|
global.fetch = global.prepareFetchApi({result: 'success'});
|
|
|
|
global.console.error = jest.fn();
|
|
|
|
|
|
|
|
simulateLikeButtonClick();
|
|
|
|
|
|
|
|
|
2020-06-12 15:57:30 +00:00
|
|
|
process.nextTick(() => {
|
2020-09-26 18:43:30 +00:00
|
|
|
expect(global.fetch).toHaveBeenCalledTimes(2);
|
|
|
|
expect(global.console.error).toHaveBeenCalledTimes(0);
|
2020-06-12 15:57:30 +00:00
|
|
|
|
|
|
|
global.fetch.mockClear();
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('errored likebtn click', done => {
|
2020-08-05 17:55:51 +00:00
|
|
|
global.fetch = global.prepareFetchApi({result: 'nosuccess'});
|
2020-09-26 18:43:30 +00:00
|
|
|
global.console.error = jest.fn();
|
2020-06-12 15:57:30 +00:00
|
|
|
|
2020-09-26 18:43:30 +00:00
|
|
|
simulateLikeButtonClick();
|
2020-06-12 15:57:30 +00:00
|
|
|
|
|
|
|
process.nextTick(() => {
|
|
|
|
// refetch is called so fetch called 3 times
|
|
|
|
expect(global.fetch).toHaveBeenCalledTimes(2);
|
2020-09-26 18:43:30 +00:00
|
|
|
expect(global.console.error).toHaveBeenCalledTimes(2);
|
2020-06-12 15:57:30 +00:00
|
|
|
|
|
|
|
global.fetch.mockClear();
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('show tag popup', function () {
|
|
|
|
const wrapper = shallow(<Player/>);
|
2020-10-25 18:48:23 +00:00
|
|
|
expect(wrapper.find('AddTagPopup')).toHaveLength(0);
|
2020-10-03 07:06:27 +00:00
|
|
|
// todo dynamic button find without index
|
2020-10-25 18:48:23 +00:00
|
|
|
wrapper.find('.videoactions').find('button').at(1).simulate('click');
|
2020-06-12 15:57:30 +00:00
|
|
|
// addtagpopup should be showing now
|
2020-10-25 18:48:23 +00:00
|
|
|
expect(wrapper.find('AddTagPopup')).toHaveLength(1);
|
2020-06-12 15:57:30 +00:00
|
|
|
});
|
|
|
|
|
2020-10-03 07:06:27 +00:00
|
|
|
it('test delete button', done => {
|
2020-12-11 18:23:13 +00:00
|
|
|
const wrapper = shallow(<Player/>);
|
|
|
|
|
|
|
|
const func = jest.fn();
|
|
|
|
prepareViewBinding(func)
|
|
|
|
|
2020-10-25 18:48:23 +00:00
|
|
|
global.fetch = prepareFetchApi({result: 'success'});
|
2020-10-03 07:06:27 +00:00
|
|
|
|
2020-10-25 18:48:23 +00:00
|
|
|
wrapper.find('.videoactions').find('button').at(2).simulate('click');
|
2020-10-03 07:06:27 +00:00
|
|
|
|
|
|
|
process.nextTick(() => {
|
|
|
|
// refetch is called so fetch called 3 times
|
|
|
|
expect(global.fetch).toHaveBeenCalledTimes(1);
|
2020-12-11 18:23:13 +00:00
|
|
|
expect(func).toHaveBeenCalledTimes(1);
|
2020-10-03 07:06:27 +00:00
|
|
|
|
|
|
|
global.fetch.mockClear();
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-06-12 15:57:30 +00:00
|
|
|
it('hide click ', function () {
|
|
|
|
const wrapper = shallow(<Player/>);
|
|
|
|
|
2020-12-11 18:23:13 +00:00
|
|
|
const func = jest.fn();
|
|
|
|
prepareViewBinding(func);
|
2020-06-12 15:57:30 +00:00
|
|
|
|
|
|
|
expect(func).toHaveBeenCalledTimes(0);
|
|
|
|
wrapper.find('.closebutton').simulate('click');
|
|
|
|
// addtagpopup should be showing now
|
|
|
|
expect(func).toHaveBeenCalledTimes(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('inserts Tags correctly', function () {
|
|
|
|
const wrapper = shallow(<Player/>);
|
|
|
|
|
2020-10-25 18:48:23 +00:00
|
|
|
expect(wrapper.find('Tag')).toHaveLength(0);
|
2020-06-12 15:57:30 +00:00
|
|
|
|
|
|
|
wrapper.setState({
|
|
|
|
tags: [
|
|
|
|
{tag_name: 'first'},
|
|
|
|
{tag_name: 'second'}
|
|
|
|
]
|
|
|
|
});
|
|
|
|
|
2020-10-25 18:48:23 +00:00
|
|
|
expect(wrapper.find('Tag')).toHaveLength(2);
|
2020-06-12 15:57:30 +00:00
|
|
|
});
|
2020-09-26 18:43:30 +00:00
|
|
|
|
|
|
|
it('inserts tag quickadd correctly', function () {
|
|
|
|
generatetag();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('test click of quickadd tag btn', done => {
|
|
|
|
const wrapper = generatetag();
|
|
|
|
|
|
|
|
global.fetch = prepareFetchApi({result: 'success'});
|
|
|
|
|
|
|
|
// render tag subcomponent
|
2020-10-25 18:48:23 +00:00
|
|
|
const tag = wrapper.find('Tag').first().dive();
|
2020-09-26 18:43:30 +00:00
|
|
|
tag.simulate('click');
|
|
|
|
|
|
|
|
process.nextTick(() => {
|
|
|
|
expect(global.fetch).toHaveBeenCalledTimes(1);
|
|
|
|
|
|
|
|
global.fetch.mockClear();
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('test failing quickadd', done => {
|
|
|
|
const wrapper = generatetag();
|
|
|
|
|
|
|
|
global.fetch = prepareFetchApi({result: 'nonsuccess'});
|
|
|
|
global.console.error = jest.fn();
|
|
|
|
|
|
|
|
// render tag subcomponent
|
2020-10-25 18:48:23 +00:00
|
|
|
const tag = wrapper.find('Tag').first().dive();
|
2020-09-26 18:43:30 +00:00
|
|
|
tag.simulate('click');
|
|
|
|
|
|
|
|
process.nextTick(() => {
|
|
|
|
expect(global.console.error).toHaveBeenCalledTimes(2);
|
|
|
|
|
|
|
|
global.fetch.mockClear();
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-10-09 14:00:51 +00:00
|
|
|
function generatetag() {
|
2020-09-26 18:43:30 +00:00
|
|
|
const wrapper = shallow(<Player/>);
|
|
|
|
|
2020-10-25 18:48:23 +00:00
|
|
|
expect(wrapper.find('Tag')).toHaveLength(0);
|
2020-09-26 18:43:30 +00:00
|
|
|
|
|
|
|
wrapper.setState({
|
|
|
|
suggesttag: [
|
2020-10-25 18:48:23 +00:00
|
|
|
{tag_name: 'first', tag_id: 1}
|
2020-09-26 18:43:30 +00:00
|
|
|
]
|
|
|
|
});
|
|
|
|
|
2020-10-25 18:48:23 +00:00
|
|
|
expect(wrapper.find('Tag')).toHaveLength(1);
|
2020-09-26 18:43:30 +00:00
|
|
|
|
|
|
|
return wrapper;
|
|
|
|
}
|
2020-06-12 15:57:30 +00:00
|
|
|
});
|