2020-06-12 15:57:30 +00:00
|
|
|
import {shallow} from "enzyme";
|
|
|
|
import React from "react";
|
|
|
|
import Player from "./Player";
|
|
|
|
|
|
|
|
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',
|
|
|
|
size: 1080,
|
|
|
|
}
|
|
|
|
]
|
|
|
|
});
|
|
|
|
expect(wrapper.find("r")).toHaveLength(1);
|
|
|
|
});
|
|
|
|
|
2020-09-26 18:43:30 +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);
|
|
|
|
wrapper.find('.videoactions').find("button").first().simulate('click');
|
|
|
|
// 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/>);
|
|
|
|
expect(wrapper.find("AddTagPopup")).toHaveLength(0);
|
2020-10-03 07:06:27 +00:00
|
|
|
// todo dynamic button find without index
|
|
|
|
wrapper.find('.videoactions').find("button").at(1).simulate('click');
|
2020-06-12 15:57:30 +00:00
|
|
|
// addtagpopup should be showing now
|
|
|
|
expect(wrapper.find("AddTagPopup")).toHaveLength(1);
|
|
|
|
});
|
|
|
|
|
2020-10-03 07:06:27 +00:00
|
|
|
it('test delete button', done => {
|
|
|
|
const wrapper = shallow(<Player viewbinding={{
|
|
|
|
returnToLastElement: jest.fn()
|
|
|
|
}}/>);
|
|
|
|
global.fetch = prepareFetchApi({result: "success"});
|
|
|
|
|
|
|
|
wrapper.find('.videoactions').find("button").at(2).simulate('click');
|
|
|
|
|
|
|
|
process.nextTick(() => {
|
|
|
|
// refetch is called so fetch called 3 times
|
|
|
|
expect(global.fetch).toHaveBeenCalledTimes(1);
|
|
|
|
expect(wrapper.instance().props.viewbinding.returnToLastElement).toHaveBeenCalledTimes(1);
|
|
|
|
|
|
|
|
global.fetch.mockClear();
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-06-12 15:57:30 +00:00
|
|
|
it('hide click ', function () {
|
|
|
|
const wrapper = shallow(<Player/>);
|
|
|
|
const func = jest.fn();
|
|
|
|
|
|
|
|
wrapper.setProps({
|
|
|
|
viewbinding: {
|
2020-06-23 23:13:14 +02:00
|
|
|
returnToLastElement: () => {
|
2020-06-12 15:57:30 +00:00
|
|
|
func()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
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/>);
|
|
|
|
|
|
|
|
expect(wrapper.find("Tag")).toHaveLength(0);
|
|
|
|
|
|
|
|
wrapper.setState({
|
|
|
|
tags: [
|
|
|
|
{tag_name: 'first'},
|
|
|
|
{tag_name: 'second'}
|
|
|
|
]
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper.find("Tag")).toHaveLength(2);
|
|
|
|
});
|
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
|
|
|
|
const tag = wrapper.find("Tag").first().dive();
|
|
|
|
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
|
|
|
|
const tag = wrapper.find("Tag").first().dive();
|
|
|
|
tag.simulate('click');
|
|
|
|
|
|
|
|
process.nextTick(() => {
|
|
|
|
expect(global.console.error).toHaveBeenCalledTimes(2);
|
|
|
|
|
|
|
|
global.fetch.mockClear();
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
function generatetag(){
|
|
|
|
const wrapper = shallow(<Player/>);
|
|
|
|
|
|
|
|
expect(wrapper.find("Tag")).toHaveLength(0);
|
|
|
|
|
|
|
|
wrapper.setState({
|
|
|
|
suggesttag: [
|
|
|
|
{tag_name: 'first', tag_id: 1},
|
|
|
|
]
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper.find("Tag")).toHaveLength(1);
|
|
|
|
|
|
|
|
return wrapper;
|
|
|
|
}
|
2020-06-12 15:57:30 +00:00
|
|
|
});
|