add some tests and correct deletion path
This commit is contained in:
		
							
								
								
									
										51
									
								
								src/elements/Popups/ButtonPopup/ButtonPopup.test.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										51
									
								
								src/elements/Popups/ButtonPopup/ButtonPopup.test.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,51 @@
 | 
			
		||||
import {shallow} from 'enzyme';
 | 
			
		||||
import React from 'react';
 | 
			
		||||
import {ButtonPopup} from './ButtonPopup';
 | 
			
		||||
import exp from "constants";
 | 
			
		||||
 | 
			
		||||
describe('<ButtonPopup/>', function () {
 | 
			
		||||
    it('renders without crashing ', function () {
 | 
			
		||||
        const wrapper = shallow(<ButtonPopup/>);
 | 
			
		||||
        wrapper.unmount();
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    it('renders two buttons', function () {
 | 
			
		||||
        const wrapper = shallow(<ButtonPopup/>);
 | 
			
		||||
        expect(wrapper.find('Button')).toHaveLength(2);
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    it('renders three buttons if alternative defined', function () {
 | 
			
		||||
        const wrapper = shallow(<ButtonPopup AlternativeButtonTitle='alt'/>);
 | 
			
		||||
        expect(wrapper.find('Button')).toHaveLength(3);
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    it('test click handlings', function () {
 | 
			
		||||
        const althandler = jest.fn();
 | 
			
		||||
        const denyhandler = jest.fn();
 | 
			
		||||
        const submithandler = jest.fn();
 | 
			
		||||
 | 
			
		||||
        const wrapper = shallow(<ButtonPopup DenyButtonTitle='deny' onDeny={denyhandler} SubmitButtonTitle='submit'
 | 
			
		||||
                                             onSubmit={submithandler} AlternativeButtonTitle='alt'
 | 
			
		||||
                                             onAlternativeButton={althandler}/>);
 | 
			
		||||
        wrapper.find('Button').findWhere(e => e.props().title === "deny").simulate('click');
 | 
			
		||||
        expect(denyhandler).toHaveBeenCalledTimes(1);
 | 
			
		||||
 | 
			
		||||
        wrapper.find('Button').findWhere(e => e.props().title === "alt").simulate('click');
 | 
			
		||||
        expect(althandler).toHaveBeenCalledTimes(1);
 | 
			
		||||
 | 
			
		||||
        wrapper.find('Button').findWhere(e => e.props().title === "submit").simulate('click');
 | 
			
		||||
        expect(submithandler).toHaveBeenCalledTimes(1);
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    it('test Parentsubmit and parenthide callbacks', function () {
 | 
			
		||||
        const ondeny = jest.fn();
 | 
			
		||||
        const onsubmit = jest.fn();
 | 
			
		||||
 | 
			
		||||
        const wrapper = shallow(<ButtonPopup DenyButtonTitle='deny' SubmitButtonTitle='submit' onDeny={ondeny} onSubmit={onsubmit} AlternativeButtonTitle='alt'/>);
 | 
			
		||||
        wrapper.find('PopupBase').props().onHide();
 | 
			
		||||
        expect(ondeny).toHaveBeenCalledTimes(1);
 | 
			
		||||
 | 
			
		||||
        wrapper.find('PopupBase').props().ParentSubmit();
 | 
			
		||||
        expect(onsubmit).toHaveBeenCalledTimes(1);
 | 
			
		||||
    });
 | 
			
		||||
});
 | 
			
		||||
@@ -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