From 916f092406009d9459ef80261bbeb9eedcadc2a5 Mon Sep 17 00:00:00 2001 From: lukas Date: Sun, 5 Sep 2021 15:01:11 +0200 Subject: [PATCH] add some tests and correct deletion path --- apiGo/api/Video.go | 6 ++- package.json | 2 +- .../Popups/ButtonPopup/ButtonPopup.test.js | 51 +++++++++++++++++++ src/pages/Player/Player.test.js | 43 +++++++++++++--- src/pages/Player/Player.tsx | 3 +- 5 files changed, 92 insertions(+), 13 deletions(-) create mode 100644 src/elements/Popups/ButtonPopup/ButtonPopup.test.js diff --git a/apiGo/api/Video.go b/apiGo/api/Video.go index b060c19..373d3a2 100644 --- a/apiGo/api/Video.go +++ b/apiGo/api/Video.go @@ -457,9 +457,11 @@ func addToVideoHandlers() { return database.ManualSuccessResponse(err) } - err = os.Remove(vidpath) + assembledPath := database.SettingsVideoPrefix + "/" + vidpath + + err = os.Remove(assembledPath) 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) } } diff --git a/package.json b/package.json index 6bc2499..1890f28 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "build": "CI=false react-scripts build", "test": "CI=true react-scripts test --reporters=jest-junit --verbose --silent --coverage --reporters=default", "lint": "eslint --format gitlab src/", - "apidoc": "apidoc -i apiGo/ -o doc/" + "apidoc": "apidoc --single -i apiGo/ -o doc/" }, "jest": { "collectCoverageFrom": [ diff --git a/src/elements/Popups/ButtonPopup/ButtonPopup.test.js b/src/elements/Popups/ButtonPopup/ButtonPopup.test.js new file mode 100644 index 0000000..9ce12ea --- /dev/null +++ b/src/elements/Popups/ButtonPopup/ButtonPopup.test.js @@ -0,0 +1,51 @@ +import {shallow} from 'enzyme'; +import React from 'react'; +import {ButtonPopup} from './ButtonPopup'; +import exp from "constants"; + +describe('', function () { + it('renders without crashing ', function () { + const wrapper = shallow(); + wrapper.unmount(); + }); + + it('renders two buttons', function () { + const wrapper = shallow(); + expect(wrapper.find('Button')).toHaveLength(2); + }); + + it('renders three buttons if alternative defined', function () { + const wrapper = shallow(); + 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(); + 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(); + wrapper.find('PopupBase').props().onHide(); + expect(ondeny).toHaveBeenCalledTimes(1); + + wrapper.find('PopupBase').props().ParentSubmit(); + expect(onsubmit).toHaveBeenCalledTimes(1); + }); +}); diff --git a/src/pages/Player/Player.test.js b/src/pages/Player/Player.test.js index 254ef73..92206a8 100644 --- a/src/pages/Player/Player.test.js +++ b/src/pages/Player/Player.test.js @@ -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('', function () { @@ -84,15 +85,34 @@ describe('', 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('', 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); }); }); diff --git a/src/pages/Player/Player.tsx b/src/pages/Player/Player.tsx index 99ae64e..d777d84 100644 --- a/src/pages/Player/Player.tsx +++ b/src/pages/Player/Player.tsx @@ -373,8 +373,7 @@ export class Player extends React.Component { // 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)); } } );