add some tests and correct deletion path
This commit is contained in:
parent
924f05b2d2
commit
916f092406
@ -457,9 +457,11 @@ func addToVideoHandlers() {
|
|||||||
return database.ManualSuccessResponse(err)
|
return database.ManualSuccessResponse(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = os.Remove(vidpath)
|
assembledPath := database.SettingsVideoPrefix + "/" + vidpath
|
||||||
|
|
||||||
|
err = os.Remove(assembledPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("unable to delete file: %s -- %s\n", vidpath, err.Error())
|
fmt.Printf("unable to delete file: %s -- %s\n", assembledPath, err.Error())
|
||||||
return database.ManualSuccessResponse(err)
|
return database.ManualSuccessResponse(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
"build": "CI=false react-scripts build",
|
"build": "CI=false react-scripts build",
|
||||||
"test": "CI=true react-scripts test --reporters=jest-junit --verbose --silent --coverage --reporters=default",
|
"test": "CI=true react-scripts test --reporters=jest-junit --verbose --silent --coverage --reporters=default",
|
||||||
"lint": "eslint --format gitlab src/",
|
"lint": "eslint --format gitlab src/",
|
||||||
"apidoc": "apidoc -i apiGo/ -o doc/"
|
"apidoc": "apidoc --single -i apiGo/ -o doc/"
|
||||||
},
|
},
|
||||||
"jest": {
|
"jest": {
|
||||||
"collectCoverageFrom": [
|
"collectCoverageFrom": [
|
||||||
|
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 React from 'react';
|
||||||
import {Player} from './Player';
|
import {Player} from './Player';
|
||||||
import {callAPI} from '../../utils/Api';
|
import {callAPI} from '../../utils/Api';
|
||||||
|
import GlobalInfos from "../../utils/GlobalInfos";
|
||||||
|
|
||||||
describe('<Player/>', function () {
|
describe('<Player/>', function () {
|
||||||
|
|
||||||
@ -84,15 +85,34 @@ describe('<Player/>', function () {
|
|||||||
expect(wrapper.find('AddTagPopup')).toHaveLength(1);
|
expect(wrapper.find('AddTagPopup')).toHaveLength(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('test delete button', done => {
|
it('test fully delete popup rendering', function () {
|
||||||
const wrapper = instance();
|
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'})
|
callAPIMock({result: 'success'})
|
||||||
|
GlobalInfos.setFullDeleteEnabled(false);
|
||||||
|
|
||||||
// request the popup to pop
|
// request the popup to pop
|
||||||
wrapper.find('.videoactions').find('Button').at(2).simulate('click');
|
wrapper.find('.videoactions').find('Button').at(2).simulate('click');
|
||||||
@ -100,12 +120,19 @@ describe('<Player/>', function () {
|
|||||||
// click the first submit button
|
// click the first submit button
|
||||||
wrapper.find('ButtonPopup').dive().find('Button').at(0).simulate('click')
|
wrapper.find('ButtonPopup').dive().find('Button').at(0).simulate('click')
|
||||||
|
|
||||||
process.nextTick(() => {
|
// refetch is called so fetch called 3 times
|
||||||
// refetch is called so fetch called 3 times
|
expect(callAPI).toHaveBeenCalledTimes(1);
|
||||||
expect(callAPI).toHaveBeenCalledTimes(1);
|
expect(callback).toHaveBeenCalledTimes(1);
|
||||||
expect(wrapper.instance().props.history.goBack).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
|
// return to last element if successful
|
||||||
this.props.history.goBack();
|
this.props.history.goBack();
|
||||||
} else {
|
} else {
|
||||||
console.error('an error occured while liking');
|
console.error('an error occured while deleting the video: ' + JSON.stringify(result));
|
||||||
console.error(result);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user