add some tests and correct deletion path
This commit is contained in:
		@@ -2,6 +2,7 @@ import {shallow} from 'enzyme';
 | 
			
		||||
import React from 'react';
 | 
			
		||||
import {Player} from './Player';
 | 
			
		||||
import {callAPI} from '../../utils/Api';
 | 
			
		||||
import GlobalInfos from "../../utils/GlobalInfos";
 | 
			
		||||
 | 
			
		||||
describe('<Player/>', function () {
 | 
			
		||||
 | 
			
		||||
@@ -84,15 +85,34 @@ describe('<Player/>', function () {
 | 
			
		||||
        expect(wrapper.find('AddTagPopup')).toHaveLength(1);
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    it('test delete button', done => {
 | 
			
		||||
    it('test fully delete popup rendering', function () {
 | 
			
		||||
        const wrapper = instance();
 | 
			
		||||
 | 
			
		||||
        // allow videos to be fully deletable
 | 
			
		||||
        GlobalInfos.setFullDeleteEnabled(true);
 | 
			
		||||
 | 
			
		||||
        wrapper.setProps({history: {goBack: jest.fn()}});
 | 
			
		||||
        wrapper.setState({deletepopupvisible: true});
 | 
			
		||||
 | 
			
		||||
        // global.fetch = prepareFetchApi({result: 'success'});
 | 
			
		||||
        expect(wrapper.find('ButtonPopup')).toHaveLength(1)
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    it('test delete popup rendering', function () {
 | 
			
		||||
        const wrapper = instance();
 | 
			
		||||
 | 
			
		||||
        GlobalInfos.setFullDeleteEnabled(false);
 | 
			
		||||
        wrapper.setState({deletepopupvisible: true});
 | 
			
		||||
 | 
			
		||||
        expect(wrapper.find('ButtonPopup')).toHaveLength(1)
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    it('test delete button', () => {
 | 
			
		||||
        const wrapper = instance();
 | 
			
		||||
        const callback = jest.fn();
 | 
			
		||||
 | 
			
		||||
        wrapper.setProps({history: {goBack: callback}});
 | 
			
		||||
 | 
			
		||||
        callAPIMock({result: 'success'})
 | 
			
		||||
        GlobalInfos.setFullDeleteEnabled(false);
 | 
			
		||||
 | 
			
		||||
        // request the popup to pop
 | 
			
		||||
        wrapper.find('.videoactions').find('Button').at(2).simulate('click');
 | 
			
		||||
@@ -100,12 +120,19 @@ describe('<Player/>', function () {
 | 
			
		||||
        // click the first submit button
 | 
			
		||||
        wrapper.find('ButtonPopup').dive().find('Button').at(0).simulate('click')
 | 
			
		||||
 | 
			
		||||
        process.nextTick(() => {
 | 
			
		||||
            // refetch is called so fetch called 3 times
 | 
			
		||||
            expect(callAPI).toHaveBeenCalledTimes(1);
 | 
			
		||||
            expect(wrapper.instance().props.history.goBack).toHaveBeenCalledTimes(1);
 | 
			
		||||
        // refetch is called so fetch called 3 times
 | 
			
		||||
        expect(callAPI).toHaveBeenCalledTimes(1);
 | 
			
		||||
        expect(callback).toHaveBeenCalledTimes(1);
 | 
			
		||||
 | 
			
		||||
            done();
 | 
			
		||||
        // now lets test if this works also with the fullydeletepopup
 | 
			
		||||
        GlobalInfos.setFullDeleteEnabled(true);
 | 
			
		||||
        // request the popup to pop
 | 
			
		||||
        wrapper.setState({deletepopupvisible: true}, () => {
 | 
			
		||||
            // click the first submit button
 | 
			
		||||
            wrapper.find('ButtonPopup').dive().find('Button').at(0).simulate('click')
 | 
			
		||||
 | 
			
		||||
            expect(callAPI).toHaveBeenCalledTimes(2);
 | 
			
		||||
            expect(callback).toHaveBeenCalledTimes(2);
 | 
			
		||||
        });
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -373,8 +373,7 @@ export class Player extends React.Component<Props, mystate> {
 | 
			
		||||
                    // return to last element if successful
 | 
			
		||||
                    this.props.history.goBack();
 | 
			
		||||
                } else {
 | 
			
		||||
                    console.error('an error occured while liking');
 | 
			
		||||
                    console.error(result);
 | 
			
		||||
                    console.error('an error occured while deleting the video: ' + JSON.stringify(result));
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        );
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user