fix tests and send feature support within first api call

This commit is contained in:
2021-09-03 12:09:51 +02:00
parent 543ce5b250
commit 924f05b2d2
9 changed files with 135 additions and 74 deletions

View File

@ -90,16 +90,21 @@ describe('<Player/>', function () {
wrapper.setProps({history: {goBack: jest.fn()}});
global.fetch = prepareFetchApi({result: 'success'});
// global.fetch = prepareFetchApi({result: 'success'});
callAPIMock({result: 'success'})
// request the popup to pop
wrapper.find('.videoactions').find('Button').at(2).simulate('click');
// 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(global.fetch).toHaveBeenCalledTimes(1);
expect(callAPI).toHaveBeenCalledTimes(1);
expect(wrapper.instance().props.history.goBack).toHaveBeenCalledTimes(1);
global.fetch.mockClear();
done();
});
});
@ -152,16 +157,14 @@ describe('<Player/>', function () {
it('test click of quickadd tag btn', done => {
const wrapper = generatetag();
global.fetch = prepareFetchApi({result: 'success'});
callAPIMock({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();
expect(callAPI).toHaveBeenCalledTimes(1);
done();
});
});
@ -169,7 +172,7 @@ describe('<Player/>', function () {
it('test failing quickadd', done => {
const wrapper = generatetag();
global.fetch = prepareFetchApi({result: 'nonsuccess'});
callAPIMock({result: 'nonsuccess'});
global.console.error = jest.fn();
// render tag subcomponent
@ -178,8 +181,6 @@ describe('<Player/>', function () {
process.nextTick(() => {
expect(global.console.error).toHaveBeenCalledTimes(2);
global.fetch.mockClear();
done();
});
});

View File

@ -21,7 +21,7 @@ import PlyrJS from 'plyr';
import {Button} from '../../elements/GPElements/Button';
import {VideoTypes} from '../../types/ApiTypes';
import GlobalInfos from '../../utils/GlobalInfos';
import {FullyDeletePopup} from '../../elements/Popups/FullyDeletePopup/FullyDeletePopup';
import {ButtonPopup} from '../../elements/Popups/ButtonPopup/ButtonPopup';
interface Props extends RouteComponentProps<{id: string}> {}
@ -199,23 +199,46 @@ export class Player extends React.Component<Props, mystate> {
movieId={this.state.movieId}
/>
) : null}
{this.state.deletepopupvisible ? (
<FullyDeletePopup
onDiscard={(): void => this.setState({deletepopupvisible: false})}
onSubmit={(): void => {
this.setState({deletepopupvisible: false});
this.deleteVideo(true);
}}
onDeny={(): void => {
this.setState({deletepopupvisible: false});
this.deleteVideo(false);
}}
/>
) : null}
{this.state.deletepopupvisible ? this.renderDeletePopup() : null}
</>
);
}
renderDeletePopup(): JSX.Element {
if (GlobalInfos.isVideoFulldeleteable()) {
return (
<ButtonPopup
onDeny={(): void => this.setState({deletepopupvisible: false})}
onSubmit={(): void => {
this.setState({deletepopupvisible: false});
this.deleteVideo(true);
}}
onAlternativeButton={(): void => {
this.setState({deletepopupvisible: false});
this.deleteVideo(false);
}}
DenyButtonTitle='Cancel'
SubmitButtonTitle='Fully Delete!'
Title='Fully Delete Video?'
AlternativeButtonTitle='Reference Only'
/>
);
} else {
return (
<ButtonPopup
onDeny={(): void => this.setState({deletepopupvisible: false})}
onSubmit={(): void => {
this.setState({deletepopupvisible: false});
this.deleteVideo(false);
}}
DenyButtonTitle='Cancel'
SubmitButtonTitle='Delete Video Reference!'
Title='Delete Video?'
/>
);
}
}
/**
* quick add callback to add tag to db and change gui correctly
* @param tagId id of tag to add