From 3c323562276014551381e8325b449252ae4772f1 Mon Sep 17 00:00:00 2001 From: Lukas Heiligenbrunner Date: Sat, 6 Feb 2021 22:18:48 +0000 Subject: [PATCH] improve insertion of reindex messages -- prevent empty string lines and add key prop to every new line --- .../ActorOverviewPage/ActorOverviewPage.tsx | 4 +- src/pages/CategoryPage/TagView.tsx | 5 +- src/pages/Player/Player.tsx | 99 ++++++++++--------- src/pages/SettingsPage/MovieSettings.test.js | 86 +++++++++------- src/pages/SettingsPage/MovieSettings.tsx | 7 +- 5 files changed, 115 insertions(+), 86 deletions(-) diff --git a/src/pages/ActorOverviewPage/ActorOverviewPage.tsx b/src/pages/ActorOverviewPage/ActorOverviewPage.tsx index 57cdf6f..812fd9f 100644 --- a/src/pages/ActorOverviewPage/ActorOverviewPage.tsx +++ b/src/pages/ActorOverviewPage/ActorOverviewPage.tsx @@ -24,7 +24,9 @@ class ActorOverviewPage extends React.Component { actors: [], NActorPopupVisible: false }; + } + componentDidMount(): void { this.fetchAvailableActors(); } @@ -36,7 +38,7 @@ class ActorOverviewPage extends React.Component { { @@ -148,7 +131,7 @@ export class Player extends React.Component { Tags: {this.state.tags.map((m: TagType) => ( - + ))} Tag Quickadd: @@ -164,6 +147,58 @@ export class Player extends React.Component { ); } + /** + * rendering of actor tiles + */ + private assembleActorTiles(): JSX.Element { + return ( +
+ {this.state.actors ? + this.state.actors.map((actr: ActorType) => ( + + )) : <> + } +
{ + this.addActor(); + }}> +
+ +
+
Add Actor
+
+
+ ); + } + + + /** + * handle the popovers generated according to state changes + * @returns {JSX.Element} + */ + handlePopOvers(): JSX.Element { + return ( + <> + {this.state.popupvisible ? + { + this.setState({popupvisible: false}); + }} + submit={this.quickAddTag} + movie_id={this.state.movie_id}/> : + null + } + { + this.state.actorpopupvisible ? + { + this.refetchActors(); + this.setState({actorpopupvisible: false}); + }} movie_id={this.state.movie_id}/> : null + } + + ); + } + /** * quick add callback to add tag to db and change gui correctly * @param tagId id of tag to add @@ -210,32 +245,6 @@ export class Player extends React.Component { }); } - /** - * handle the popovers generated according to state changes - * @returns {JSX.Element} - */ - handlePopOvers(): JSX.Element { - return ( - <> - {this.state.popupvisible ? - { - this.setState({popupvisible: false}); - }} - submit={this.quickAddTag} - movie_id={this.state.movie_id}/> : - null - } - { - this.state.actorpopupvisible ? - { - this.refetchActors(); - this.setState({actorpopupvisible: false}); - }} movie_id={this.state.movie_id}/> : null - } - - ); - } - /** * fetch all the required infos of a video from backend */ diff --git a/src/pages/SettingsPage/MovieSettings.test.js b/src/pages/SettingsPage/MovieSettings.test.js index f7bc706..1d04434 100644 --- a/src/pages/SettingsPage/MovieSettings.test.js +++ b/src/pages/SettingsPage/MovieSettings.test.js @@ -1,6 +1,7 @@ import {shallow} from 'enzyme'; import React from 'react'; import MovieSettings from './MovieSettings'; +import {callAPI} from "../../utils/Api"; describe('', function () { it('renders without crashing ', function () { @@ -49,64 +50,79 @@ describe('', function () { }); }); - it('content available received and in state', done => { - global.fetch = global.prepareFetchApi({ + it('content available received and in state', () => { + const wrapper = shallow(); + + callAPIMock({ contentAvailable: true, message: 'firstline\nsecondline' - }); - const wrapper = shallow(); + }) + wrapper.instance().updateStatus(); - process.nextTick(() => { - expect(wrapper.state()).toMatchObject({ - text: [ - 'firstline', - 'secondline' - ] - }); - - global.fetch.mockClear(); - done(); + expect(wrapper.state()).toMatchObject({ + text: [ + 'firstline', + 'secondline' + ] }); }); - it('test reindex with no content available', done => { - global.fetch = global.prepareFetchApi({ + it('test reindex with no content available', () => { + callAPIMock({ contentAvailable: false - }); + }) global.clearInterval = jest.fn(); const wrapper = shallow(); wrapper.instance().updateStatus(); - process.nextTick(() => { - // expect the refresh interval to be cleared - expect(global.clearInterval).toBeCalledTimes(1); + // expect the refresh interval to be cleared + expect(global.clearInterval).toBeCalledTimes(1); - // expect startbtn to be reenabled - expect(wrapper.state()).toMatchObject({startbtnDisabled: false}); - - global.fetch.mockClear(); - done(); - }); + // expect startbtn to be reenabled + expect(wrapper.state()).toMatchObject({startbtnDisabled: false}); }); - it('test simulate gravity cleanup', done => { - global.fetch = global.prepareFetchApi('mmi'); + it('test simulate gravity cleanup', () => { + // global.fetch = global.prepareFetchApi('mmi'); + callAPIMock({}) const wrapper = shallow(); - wrapper.instance().setState = jest.fn(), + wrapper.instance().setState = jest.fn(); - wrapper.find('button').findWhere(e => e.text() === 'Cleanup Gravity' && e.type() === 'button').simulate('click'); + wrapper.find('button').findWhere(e => e.text() === 'Cleanup Gravity' && e.type() === 'button').simulate('click'); // initial send of reindex request to server - expect(global.fetch).toBeCalledTimes(1); + expect(callAPI).toBeCalledTimes(1); - process.nextTick(() => { - expect(wrapper.instance().setState).toBeCalledTimes(1); + expect(wrapper.instance().setState).toBeCalledTimes(1); + }); - global.fetch.mockClear(); - done(); + it('test no textDiv insertion if string is empty', function () { + const wrapper = shallow(); + + callAPIMock({ + contentAvailable: true, + message: 'test' + }) + + wrapper.instance().updateStatus(); + + expect(wrapper.state()).toMatchObject({ + text: ['test'] + }); + + // expect an untouched state if we try to add an empty string... + callAPIMock({ + contentAvailable: true, + message: '' + }) + + wrapper.instance().updateStatus(); + + expect(wrapper.state()).toMatchObject({ + text: ['test'] }); }); }); diff --git a/src/pages/SettingsPage/MovieSettings.tsx b/src/pages/SettingsPage/MovieSettings.tsx index 74ce36b..2dd5cd0 100644 --- a/src/pages/SettingsPage/MovieSettings.tsx +++ b/src/pages/SettingsPage/MovieSettings.tsx @@ -47,7 +47,7 @@ class MovieSettings extends React.Component { onClick={(): void => {this.cleanupGravity();}}>Cleanup Gravity
{this.state.text.map(m => ( -
{m}
+
{m}
))}
); @@ -85,8 +85,11 @@ class MovieSettings extends React.Component { */ updateStatus = (): void => { callAPI(APINode.Settings, {action: 'getStatusMessage'}, (result: SettingsTypes.getStatusMessageType) => { - if (result.contentAvailable === true) { + if (result.contentAvailable) { + // ignore if message is empty console.log(result); + if(result.message === '') return; + // todo 2020-07-4: scroll to bottom of div here this.setState({ // insert a string for each line