fix some tests
fix merge issues
This commit is contained in:
6
src/pages/ActorOverviewPage/ActorOverviewPage.module.css
Normal file
6
src/pages/ActorOverviewPage/ActorOverviewPage.module.css
Normal file
@ -0,0 +1,6 @@
|
||||
.container {
|
||||
float: left;
|
||||
margin-right: 20px;
|
||||
padding-left: 20px;
|
||||
width: 70%;
|
||||
}
|
43
src/pages/ActorOverviewPage/ActorOverviewPage.test.js
Normal file
43
src/pages/ActorOverviewPage/ActorOverviewPage.test.js
Normal file
@ -0,0 +1,43 @@
|
||||
import {shallow} from 'enzyme';
|
||||
import React from 'react';
|
||||
import ActorOverviewPage from './ActorOverviewPage';
|
||||
|
||||
describe('<ActorOverviewPage/>', function () {
|
||||
it('renders without crashing ', function () {
|
||||
const wrapper = shallow(<ActorOverviewPage/>);
|
||||
wrapper.unmount();
|
||||
});
|
||||
|
||||
it('test inerstion of actor tiles', function () {
|
||||
const wrapper = shallow(<ActorOverviewPage/>);
|
||||
|
||||
wrapper.setState({
|
||||
actors: [{
|
||||
thumbnail: '',
|
||||
name: 'testname',
|
||||
actor_id: 42
|
||||
}]
|
||||
});
|
||||
|
||||
expect(wrapper.find('ActorTile')).toHaveLength(1);
|
||||
});
|
||||
|
||||
it('test newtagpopup visibility', function () {
|
||||
const wrapper = shallow(<ActorOverviewPage/>);
|
||||
|
||||
expect(wrapper.find('NewActorPopup')).toHaveLength(0);
|
||||
|
||||
wrapper.find('SideBar').find('Button').simulate('click');
|
||||
|
||||
expect(wrapper.find('NewActorPopup')).toHaveLength(1);
|
||||
});
|
||||
|
||||
it('test popup hiding', function () {
|
||||
const wrapper = shallow(<ActorOverviewPage/>);
|
||||
wrapper.setState({NActorPopupVisible: true});
|
||||
|
||||
wrapper.find('NewActorPopup').props().onHide();
|
||||
|
||||
expect(wrapper.find('NewActorPopup')).toHaveLength(0);
|
||||
});
|
||||
});
|
57
src/pages/ActorOverviewPage/ActorOverviewPage.tsx
Normal file
57
src/pages/ActorOverviewPage/ActorOverviewPage.tsx
Normal file
@ -0,0 +1,57 @@
|
||||
import React from 'react';
|
||||
import {callAPI} from '../../utils/Api';
|
||||
import {ActorType} from '../../api/VideoTypes';
|
||||
import ActorTile from '../../elements/ActorTile/ActorTile';
|
||||
import PageTitle from '../../elements/PageTitle/PageTitle';
|
||||
import SideBar from '../../elements/SideBar/SideBar';
|
||||
import style from './ActorOverviewPage.module.css';
|
||||
import {Button} from '../../elements/GPElements/Button';
|
||||
import NewActorPopup from '../../elements/Popups/NewActorPopup/NewActorPopup';
|
||||
|
||||
interface props {
|
||||
}
|
||||
|
||||
interface state {
|
||||
actors: ActorType[];
|
||||
NActorPopupVisible: boolean
|
||||
}
|
||||
|
||||
class ActorOverviewPage extends React.Component<props, state> {
|
||||
constructor(props: props) {
|
||||
super(props);
|
||||
|
||||
this.state = {
|
||||
actors: [],
|
||||
NActorPopupVisible: false
|
||||
};
|
||||
|
||||
this.fetchAvailableActors();
|
||||
}
|
||||
|
||||
render(): JSX.Element {
|
||||
return (
|
||||
<>
|
||||
<PageTitle title='Actors' subtitle={this.state.actors.length + ' Actors'}/>
|
||||
<SideBar>
|
||||
<Button title='Add Actor' onClick={(): void => this.setState({NActorPopupVisible: true})}/>
|
||||
</SideBar>
|
||||
<div className={style.container}>
|
||||
{this.state.actors.map((el) => (<ActorTile actor={el}/>))}
|
||||
</div>
|
||||
{this.state.NActorPopupVisible ?
|
||||
<NewActorPopup onHide={(): void => {
|
||||
this.setState({NActorPopupVisible: false});
|
||||
this.fetchAvailableActors(); // refetch actors
|
||||
}}/> : null}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
fetchAvailableActors(): void {
|
||||
callAPI<ActorType[]>('actor.php', {action: 'getAllActors'}, result => {
|
||||
this.setState({actors: result});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export default ActorOverviewPage;
|
@ -1,51 +0,0 @@
|
||||
import React from 'react';
|
||||
import PageTitle from '../../elements/PageTitle/PageTitle';
|
||||
import SideBar, {SideBarTitle} from '../../elements/SideBar/SideBar';
|
||||
import {FontAwesomeIcon} from '@fortawesome/react-fontawesome';
|
||||
import {faUser} from '@fortawesome/free-solid-svg-icons';
|
||||
import style from './ActorPage.module.css';
|
||||
import VideoContainer from '../../elements/VideoContainer/VideoContainer';
|
||||
import {callAPI} from '../../utils/Api';
|
||||
|
||||
class ActorPage extends React.Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
|
||||
this.state = {data: undefined};
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<>
|
||||
<PageTitle title={this.props.actor.name} subtitle={this.state.data ? this.state.data.length + ' videos' : null}/>
|
||||
<SideBar>
|
||||
<div className={style.pic}>
|
||||
<FontAwesomeIcon style={{color: 'white'}} icon={faUser} size='10x'/>
|
||||
</div>
|
||||
<SideBarTitle>Attention: This is an early preview!</SideBarTitle>
|
||||
</SideBar>
|
||||
{this.state.data ?
|
||||
<VideoContainer
|
||||
data={this.state.data}/> :
|
||||
<div>No Data found!</div>}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
this.getActorInfo();
|
||||
}
|
||||
|
||||
/**
|
||||
* request more actor info from backend
|
||||
*/
|
||||
getActorInfo() {
|
||||
// todo 2020-12-4: fetch to db
|
||||
callAPI('actor.php', {action: 'getActorInfo', actorid: this.props.actor.actor_id}, result => {
|
||||
console.log(result);
|
||||
this.setState({data: result.videos ? result.videos : []});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export default ActorPage;
|
@ -1,4 +1,9 @@
|
||||
.pic {
|
||||
text-align: center;
|
||||
margin-bottom: 25px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.overviewbutton {
|
||||
float: right;
|
||||
margin-top: 25px;
|
||||
}
|
||||
|
@ -1,12 +1,27 @@
|
||||
import {shallow} from 'enzyme';
|
||||
import React from 'react';
|
||||
import ActorPage from './ActorPage';
|
||||
import {ActorPage} from './ActorPage';
|
||||
|
||||
describe('<ActorPage/>', function () {
|
||||
it('renders without crashing ', function () {
|
||||
const wrapper = shallow(<ActorPage actor={{id: 5, name: 'usr1'}}/>);
|
||||
const wrapper = shallow(<ActorPage match={{params: {id: 10}}}/>);
|
||||
wrapper.unmount();
|
||||
});
|
||||
|
||||
it('fetch infos', function () {
|
||||
callAPIMock({
|
||||
videos: [{
|
||||
movie_id: 0,
|
||||
movie_name: 'test'
|
||||
}], info: {
|
||||
thumbnail: '',
|
||||
name: '',
|
||||
actor_id: 0
|
||||
}
|
||||
});
|
||||
|
||||
const wrapper = shallow(<ActorPage match={{params: {id: 10}}}/>);
|
||||
|
||||
expect(wrapper.find('VideoContainer')).toHaveLength(1);
|
||||
});
|
||||
});
|
||||
|
87
src/pages/ActorPage/ActorPage.tsx
Normal file
87
src/pages/ActorPage/ActorPage.tsx
Normal file
@ -0,0 +1,87 @@
|
||||
import React from 'react';
|
||||
import PageTitle from '../../elements/PageTitle/PageTitle';
|
||||
import SideBar, {SideBarTitle} from '../../elements/SideBar/SideBar';
|
||||
import {FontAwesomeIcon} from '@fortawesome/react-fontawesome';
|
||||
import {faUser} from '@fortawesome/free-solid-svg-icons';
|
||||
import style from './ActorPage.module.css';
|
||||
import VideoContainer from '../../elements/VideoContainer/VideoContainer';
|
||||
import {callAPI} from '../../utils/Api';
|
||||
import {ActorType, VideoUnloadedType} from '../../api/VideoTypes';
|
||||
import {Link, withRouter} from 'react-router-dom';
|
||||
import {RouteComponentProps} from 'react-router';
|
||||
import {Button} from '../../elements/GPElements/Button';
|
||||
|
||||
interface state {
|
||||
data: VideoUnloadedType[],
|
||||
actor: ActorType
|
||||
}
|
||||
|
||||
/**
|
||||
* empty default props with id in url
|
||||
*/
|
||||
interface props extends RouteComponentProps<{ id: string }> {
|
||||
}
|
||||
|
||||
/**
|
||||
* result of actor fetch
|
||||
*/
|
||||
interface videofetchresult {
|
||||
videos: VideoUnloadedType[];
|
||||
info: ActorType;
|
||||
}
|
||||
|
||||
/**
|
||||
* info page about a specific actor and a list of all its videos
|
||||
*/
|
||||
export class ActorPage extends React.Component<props, state> {
|
||||
constructor(props: props) {
|
||||
super(props);
|
||||
|
||||
this.state = {data: [], actor: {actor_id: 0, name: '', thumbnail: ''}};
|
||||
}
|
||||
|
||||
render(): JSX.Element {
|
||||
return (
|
||||
<>
|
||||
<PageTitle title={this.state.actor.name} subtitle={this.state.data ? this.state.data.length + ' videos' : null}>
|
||||
<span className={style.overviewbutton}>
|
||||
<Link to='/actors'>
|
||||
<Button onClick={(): void => {}} title='Go to Actor overview'/>
|
||||
</Link>
|
||||
</span>
|
||||
</PageTitle>
|
||||
<SideBar>
|
||||
<div className={style.pic}>
|
||||
<FontAwesomeIcon style={{color: 'white'}} icon={faUser} size='10x'/>
|
||||
</div>
|
||||
<SideBarTitle>Attention: This is an early preview!</SideBarTitle>
|
||||
</SideBar>
|
||||
{this.state.data.length !== 0 ?
|
||||
<VideoContainer
|
||||
data={this.state.data}/> :
|
||||
<div>No Data found!</div>}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
componentDidMount(): void {
|
||||
this.getActorInfo();
|
||||
}
|
||||
|
||||
/**
|
||||
* request more actor info from backend
|
||||
*/
|
||||
getActorInfo(): void {
|
||||
callAPI('actor.php', {
|
||||
action: 'getActorInfo',
|
||||
actorid: this.props.match.params.id
|
||||
}, (result: videofetchresult) => {
|
||||
this.setState({
|
||||
data: result.videos ? result.videos : [],
|
||||
actor: result.info
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export default withRouter(ActorPage);
|
@ -1,140 +0,0 @@
|
||||
import React from 'react';
|
||||
import SideBar, {SideBarTitle} from '../../elements/SideBar/SideBar';
|
||||
import Tag from '../../elements/Tag/Tag';
|
||||
import videocontainerstyle from '../../elements/VideoContainer/VideoContainer.module.css';
|
||||
|
||||
import {TagPreview} from '../../elements/Preview/Preview';
|
||||
import NewTagPopup from '../../elements/Popups/NewTagPopup/NewTagPopup';
|
||||
import PageTitle, {Line} from '../../elements/PageTitle/PageTitle';
|
||||
import VideoContainer from '../../elements/VideoContainer/VideoContainer';
|
||||
import {callAPI} from '../../utils/Api';
|
||||
|
||||
/**
|
||||
* Component for Category Page
|
||||
* Contains a Tag Overview and loads specific Tag videos in VideoContainer
|
||||
*/
|
||||
class CategoryPage extends React.Component {
|
||||
constructor(props, context) {
|
||||
super(props, context);
|
||||
|
||||
this.state = {
|
||||
loadedtags: [],
|
||||
selected: null
|
||||
};
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
// check if predefined category is set
|
||||
if (this.props.category) {
|
||||
this.fetchVideoData(this.props.category);
|
||||
} else {
|
||||
this.loadTags();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* render the Title and SideBar component for the Category page
|
||||
* @returns {JSX.Element} corresponding jsx element for Title and Sidebar
|
||||
*/
|
||||
renderSideBarATitle() {
|
||||
return (
|
||||
<>
|
||||
<PageTitle
|
||||
title='Categories'
|
||||
subtitle={!this.state.selected ? this.state.loadedtags.length + ' different Tags' : this.state.selected}/>
|
||||
|
||||
<SideBar>
|
||||
<SideBarTitle>Default Tags:</SideBarTitle>
|
||||
<Tag onclick={(tag) => {this.loadTag(tag);}}>All</Tag>
|
||||
<Tag onclick={(tag) => {this.loadTag(tag);}}>FullHd</Tag>
|
||||
<Tag onclick={(tag) => {this.loadTag(tag);}}>LowQuality</Tag>
|
||||
<Tag onclick={(tag) => {this.loadTag(tag);}}>HD</Tag>
|
||||
<Line/>
|
||||
<button data-testid='btnaddtag' className='btn btn-success' onClick={() => {
|
||||
this.setState({popupvisible: true});
|
||||
}}>Add a new Tag!
|
||||
</button>
|
||||
</SideBar></>
|
||||
);
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<>
|
||||
{this.renderSideBarATitle()}
|
||||
|
||||
{this.state.selected ?
|
||||
<>
|
||||
{this.videodata ?
|
||||
<VideoContainer
|
||||
data={this.videodata}/> : null}
|
||||
<button data-testid='backbtn' className='btn btn-success'
|
||||
onClick={this.loadCategoryPageDefault}>Back
|
||||
</button>
|
||||
</> :
|
||||
<div className={videocontainerstyle.maincontent}>
|
||||
{this.state.loadedtags ?
|
||||
this.state.loadedtags.map((m) => (
|
||||
<TagPreview
|
||||
key={m.tag_name}
|
||||
name={m.tag_name}
|
||||
tag_id={m.tag_id}
|
||||
categorybinding={this.loadTag}/>
|
||||
)) :
|
||||
'loading'}
|
||||
</div>
|
||||
}
|
||||
|
||||
{this.state.popupvisible ?
|
||||
<NewTagPopup show={this.state.popupvisible}
|
||||
onHide={() => {
|
||||
console.error("setstatecalled!");
|
||||
this.setState({popupvisible: false});
|
||||
this.loadTags();
|
||||
}}/> :
|
||||
null
|
||||
}
|
||||
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* load a specific tag into a new previewcontainer
|
||||
* @param tagname
|
||||
*/
|
||||
loadTag = (tagname) => {
|
||||
this.fetchVideoData(tagname);
|
||||
};
|
||||
|
||||
/**
|
||||
* fetch data for a specific tag from backend
|
||||
* @param tag tagname
|
||||
*/
|
||||
fetchVideoData(tag) {
|
||||
callAPI('video.php', {action: 'getMovies', tag: tag}, result => {
|
||||
this.videodata = result;
|
||||
this.setState({selected: null}); // needed to trigger the state reload correctly
|
||||
this.setState({selected: tag});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* go back to the default category overview
|
||||
*/
|
||||
loadCategoryPageDefault = () => {
|
||||
this.setState({selected: null});
|
||||
this.loadTags();
|
||||
};
|
||||
|
||||
/**
|
||||
* load all available tags from db.
|
||||
*/
|
||||
loadTags() {
|
||||
callAPI('tags.php', {action: 'getAllTags'}, result => {
|
||||
this.setState({loadedtags: result});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export default CategoryPage;
|
@ -1,4 +1,4 @@
|
||||
import {mount, shallow} from 'enzyme';
|
||||
import {shallow} from 'enzyme';
|
||||
import React from 'react';
|
||||
import CategoryPage from './CategoryPage';
|
||||
|
||||
@ -8,22 +8,6 @@ describe('<CategoryPage/>', function () {
|
||||
wrapper.unmount();
|
||||
});
|
||||
|
||||
it('test tag fetch call', done => {
|
||||
global.fetch = global.prepareFetchApi(['first', 'second']);
|
||||
|
||||
const wrapper = shallow(<CategoryPage/>);
|
||||
|
||||
expect(global.fetch).toHaveBeenCalledTimes(1);
|
||||
|
||||
process.nextTick(() => {
|
||||
//callback to close window should have called
|
||||
expect(wrapper.state().loadedtags.length).toBe(2);
|
||||
|
||||
global.fetch.mockClear();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('test new tag popup', function () {
|
||||
const wrapper = shallow(<CategoryPage/>);
|
||||
|
||||
@ -33,63 +17,31 @@ describe('<CategoryPage/>', function () {
|
||||
expect(wrapper.find('NewTagPopup')).toHaveLength(1);
|
||||
});
|
||||
|
||||
it('test setpage callback', done => {
|
||||
global.fetch = global.prepareFetchApi([{}, {}]);
|
||||
|
||||
it('test add popup', function () {
|
||||
const wrapper = shallow(<CategoryPage/>);
|
||||
|
||||
wrapper.setState({
|
||||
loadedtags: [
|
||||
{
|
||||
tag_name: 'testname',
|
||||
tag_id: 42
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
wrapper.find('TagPreview').dive().find('div').first().simulate('click');
|
||||
|
||||
process.nextTick(() => {
|
||||
// expect callback to have loaded correct tag
|
||||
expect(wrapper.state().selected).toBe('testname');
|
||||
|
||||
global.fetch.mockClear();
|
||||
done();
|
||||
});
|
||||
expect(wrapper.find('NewTagPopup')).toHaveLength(0);
|
||||
wrapper.setState({popupvisible: true});
|
||||
expect(wrapper.find('NewTagPopup')).toHaveLength(1);
|
||||
});
|
||||
|
||||
it('test back to category view callback', function () {
|
||||
it('test hiding of popup', function () {
|
||||
const wrapper = shallow(<CategoryPage/>);
|
||||
wrapper.setState({popupvisible: true});
|
||||
|
||||
wrapper.find('NewTagPopup').props().onHide();
|
||||
|
||||
expect(wrapper.find('NewTagPopup')).toHaveLength(0);
|
||||
});
|
||||
|
||||
it('test setting of subtitle', function () {
|
||||
const wrapper = shallow(<CategoryPage/>);
|
||||
|
||||
wrapper.setState({
|
||||
selected: 'test'
|
||||
});
|
||||
expect(wrapper.state().selected).not.toBeNull();
|
||||
wrapper.find('[data-testid="backbtn"]').simulate('click');
|
||||
expect(wrapper.state().selected).toBeNull();
|
||||
});
|
||||
expect(wrapper.find('PageTitle').props().subtitle).not.toBe('testtitle');
|
||||
|
||||
it('load categorypage with predefined tag', function () {
|
||||
const func = jest.fn();
|
||||
CategoryPage.prototype.fetchVideoData = func;
|
||||
|
||||
shallow(<CategoryPage category='fullhd'/>);
|
||||
|
||||
expect(func).toBeCalledTimes(1);
|
||||
});
|
||||
|
||||
it('test sidebar tag clicks', function () {
|
||||
const func = jest.fn();
|
||||
|
||||
const wrapper = shallow(<CategoryPage category='fullhd'/>);
|
||||
wrapper.instance().loadTag = func;
|
||||
|
||||
expect(func).toBeCalledTimes(0);
|
||||
wrapper.find('SideBar').find('Tag').forEach(e => {
|
||||
e.dive().simulate('click');
|
||||
});
|
||||
|
||||
expect(func).toBeCalledTimes(4);
|
||||
wrapper.instance().setSubTitle('testtitle');
|
||||
|
||||
// test if prop of title is set correctly
|
||||
expect(wrapper.find('PageTitle').props().subtitle).toBe('testtitle');
|
||||
});
|
||||
});
|
||||
|
83
src/pages/CategoryPage/CategoryPage.tsx
Normal file
83
src/pages/CategoryPage/CategoryPage.tsx
Normal file
@ -0,0 +1,83 @@
|
||||
import React from 'react';
|
||||
import SideBar, {SideBarTitle} from '../../elements/SideBar/SideBar';
|
||||
import Tag from '../../elements/Tag/Tag';
|
||||
import NewTagPopup from '../../elements/Popups/NewTagPopup/NewTagPopup';
|
||||
import PageTitle, {Line} from '../../elements/PageTitle/PageTitle';
|
||||
import {Route, Switch} from 'react-router-dom';
|
||||
import {DefaultTags} from '../../api/GeneralTypes';
|
||||
import {CategoryViewWR} from './CategoryView';
|
||||
import TagView from './TagView';
|
||||
|
||||
|
||||
interface CategoryPageState {
|
||||
popupvisible: boolean;
|
||||
subtitle: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Component for Category Page
|
||||
* Contains a Tag Overview and loads specific Tag videos in VideoContainer
|
||||
*/
|
||||
class CategoryPage extends React.Component<{}, CategoryPageState> {
|
||||
constructor(props: {}) {
|
||||
super(props);
|
||||
|
||||
this.state = {
|
||||
popupvisible: false,
|
||||
subtitle: ''
|
||||
};
|
||||
|
||||
this.setSubTitle = this.setSubTitle.bind(this);
|
||||
}
|
||||
|
||||
render(): JSX.Element {
|
||||
return (
|
||||
<>
|
||||
<PageTitle
|
||||
title='Categories'
|
||||
subtitle={this.state.subtitle}/>
|
||||
|
||||
<SideBar>
|
||||
<SideBarTitle>Default Tags:</SideBarTitle>
|
||||
<Tag tagInfo={DefaultTags.all}/>
|
||||
<Tag tagInfo={DefaultTags.fullhd}/>
|
||||
<Tag tagInfo={DefaultTags.hd}/>
|
||||
<Tag tagInfo={DefaultTags.lowq}/>
|
||||
|
||||
<Line/>
|
||||
<button data-testid='btnaddtag' className='btn btn-success' onClick={(): void => {
|
||||
this.setState({popupvisible: true});
|
||||
}}>Add a new Tag!
|
||||
</button>
|
||||
</SideBar>
|
||||
<Switch>
|
||||
<Route path='/categories/:id'>
|
||||
<CategoryViewWR setSubTitle={this.setSubTitle}/>
|
||||
</Route>
|
||||
<Route path='/categories'>
|
||||
<TagView setSubTitle={this.setSubTitle}/>
|
||||
</Route>
|
||||
</Switch>
|
||||
|
||||
{this.state.popupvisible ?
|
||||
<NewTagPopup show={this.state.popupvisible}
|
||||
onHide={(): void => {
|
||||
this.setState({popupvisible: false});
|
||||
// this.loadTags();
|
||||
}}/> :
|
||||
null
|
||||
}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* set the subtitle of this page
|
||||
* @param subtitle string as subtitle
|
||||
*/
|
||||
setSubTitle(subtitle: string): void {
|
||||
this.setState({subtitle: subtitle});
|
||||
}
|
||||
}
|
||||
|
||||
export default CategoryPage;
|
24
src/pages/CategoryPage/CategoryView.test.js
Normal file
24
src/pages/CategoryPage/CategoryView.test.js
Normal file
@ -0,0 +1,24 @@
|
||||
import {shallow} from 'enzyme';
|
||||
import React from 'react';
|
||||
import {CategoryView} from './CategoryView';
|
||||
|
||||
describe('<CategoryView/>', function () {
|
||||
function instance() {
|
||||
return shallow(<CategoryView match={{params: {id: 10}}}/>);
|
||||
}
|
||||
|
||||
it('renders without crashing ', function () {
|
||||
const wrapper = instance();
|
||||
wrapper.unmount();
|
||||
});
|
||||
|
||||
it('test backbutton', function () {
|
||||
const wrapper = instance();
|
||||
const func = jest.fn();
|
||||
wrapper.setProps({history: {push: func}});
|
||||
|
||||
expect(func).toHaveBeenCalledTimes(0);
|
||||
wrapper.find('button').simulate('click');
|
||||
expect(func).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
75
src/pages/CategoryPage/CategoryView.tsx
Normal file
75
src/pages/CategoryPage/CategoryView.tsx
Normal file
@ -0,0 +1,75 @@
|
||||
import {RouteComponentProps} from 'react-router';
|
||||
import React from 'react';
|
||||
import {VideoUnloadedType} from '../../api/VideoTypes';
|
||||
import VideoContainer from '../../elements/VideoContainer/VideoContainer';
|
||||
import {callAPI} from '../../utils/Api';
|
||||
import {withRouter} from 'react-router-dom';
|
||||
|
||||
interface CategoryViewProps extends RouteComponentProps<{ id: string }> {
|
||||
setSubTitle: (title: string) => void
|
||||
}
|
||||
|
||||
interface CategoryViewState {
|
||||
loaded: boolean
|
||||
}
|
||||
|
||||
/**
|
||||
* plain class (for unit testing only)
|
||||
*/
|
||||
export class CategoryView extends React.Component<CategoryViewProps, CategoryViewState> {
|
||||
private videodata: VideoUnloadedType[] = [];
|
||||
|
||||
constructor(props: CategoryViewProps) {
|
||||
super(props);
|
||||
|
||||
this.state = {
|
||||
loaded: false
|
||||
};
|
||||
}
|
||||
|
||||
componentDidMount(): void {
|
||||
this.fetchVideoData(parseInt(this.props.match.params.id));
|
||||
}
|
||||
|
||||
componentDidUpdate(prevProps: Readonly<CategoryViewProps>, prevState: Readonly<CategoryViewState>): void {
|
||||
// trigger video refresh if id changed
|
||||
if (prevProps.match.params.id !== this.props.match.params.id) {
|
||||
this.setState({loaded: false});
|
||||
this.fetchVideoData(parseInt(this.props.match.params.id));
|
||||
}
|
||||
}
|
||||
|
||||
render(): JSX.Element {
|
||||
return (
|
||||
<>
|
||||
{this.state.loaded ?
|
||||
<VideoContainer
|
||||
data={this.videodata}/> : null}
|
||||
|
||||
<button data-testid='backbtn' className='btn btn-success'
|
||||
onClick={(): void => {
|
||||
this.props.history.push('/categories');
|
||||
}}>Back to Categories
|
||||
</button>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* fetch data for a specific tag from backend
|
||||
* @param id tagid
|
||||
*/
|
||||
fetchVideoData(id: number): void {
|
||||
callAPI<VideoUnloadedType[]>('video.php', {action: 'getMovies', tag: id}, result => {
|
||||
this.videodata = result;
|
||||
this.setState({loaded: true});
|
||||
this.props.setSubTitle(this.videodata.length + ' Videos');
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* export with react Router wrapped (default use)
|
||||
*/
|
||||
export const CategoryViewWR = withRouter(CategoryView);
|
17
src/pages/CategoryPage/TagView.test.js
Normal file
17
src/pages/CategoryPage/TagView.test.js
Normal file
@ -0,0 +1,17 @@
|
||||
import {shallow} from 'enzyme';
|
||||
import React from 'react';
|
||||
import TagView from './TagView';
|
||||
|
||||
describe('<TagView/>', function () {
|
||||
it('renders without crashing ', function () {
|
||||
const wrapper = shallow(<TagView/>);
|
||||
wrapper.unmount();
|
||||
});
|
||||
|
||||
it('test Tag insertion', function () {
|
||||
const wrapper = shallow(<TagView/>);
|
||||
wrapper.setState({loadedtags: [{tag_name: 'test', tag_id: 42}]});
|
||||
|
||||
expect(wrapper.find('TagPreview')).toHaveLength(1);
|
||||
});
|
||||
});
|
55
src/pages/CategoryPage/TagView.tsx
Normal file
55
src/pages/CategoryPage/TagView.tsx
Normal file
@ -0,0 +1,55 @@
|
||||
import {TagType} from '../../api/VideoTypes';
|
||||
import React from 'react';
|
||||
import videocontainerstyle from '../../elements/VideoContainer/VideoContainer.module.css';
|
||||
import {Link} from 'react-router-dom';
|
||||
import {TagPreview} from '../../elements/Preview/Preview';
|
||||
import {callAPI} from '../../utils/Api';
|
||||
|
||||
interface TagViewState {
|
||||
loadedtags: TagType[];
|
||||
}
|
||||
|
||||
interface props {
|
||||
setSubTitle: (title: string) => void
|
||||
}
|
||||
|
||||
class TagView extends React.Component<props, TagViewState> {
|
||||
constructor(props: props) {
|
||||
super(props);
|
||||
|
||||
this.state = {loadedtags: []};
|
||||
}
|
||||
|
||||
componentDidMount(): void {
|
||||
this.loadTags();
|
||||
}
|
||||
|
||||
render(): JSX.Element {
|
||||
return (
|
||||
<>
|
||||
<div className={videocontainerstyle.maincontent}>
|
||||
{this.state.loadedtags ?
|
||||
this.state.loadedtags.map((m) => (
|
||||
<Link to={'/categories/' + m.tag_id}><TagPreview
|
||||
key={m.tag_id}
|
||||
name={m.tag_name}
|
||||
tag_id={m.tag_id}/></Link>
|
||||
)) :
|
||||
'loading'}
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* load all available tags from db.
|
||||
*/
|
||||
loadTags(): void {
|
||||
callAPI<TagType[]>('tags.php', {action: 'getAllTags'}, result => {
|
||||
this.setState({loadedtags: result});
|
||||
this.props.setSubTitle(result.length + ' different Tags');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export default TagView;
|
@ -1,142 +0,0 @@
|
||||
import React from 'react';
|
||||
import SideBar, {SideBarItem, SideBarTitle} from '../../elements/SideBar/SideBar';
|
||||
import Tag from '../../elements/Tag/Tag';
|
||||
import VideoContainer from '../../elements/VideoContainer/VideoContainer';
|
||||
|
||||
import style from './HomePage.module.css';
|
||||
import PageTitle, {Line} from '../../elements/PageTitle/PageTitle';
|
||||
import {callAPI} from '../../utils/Api';
|
||||
|
||||
/**
|
||||
* The home page component showing on the initial pageload
|
||||
*/
|
||||
class HomePage extends React.Component {
|
||||
/** keyword variable needed temporary store search keyword */
|
||||
keyword = '';
|
||||
|
||||
constructor(props, context) {
|
||||
super(props, context);
|
||||
|
||||
this.state = {
|
||||
sideinfo: {
|
||||
videonr: null,
|
||||
fullhdvideonr: null,
|
||||
hdvideonr: null,
|
||||
sdvideonr: null,
|
||||
tagnr: null
|
||||
},
|
||||
subtitle: 'All Videos',
|
||||
data: [],
|
||||
selectionnr: 0
|
||||
};
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
// initial get of all videos
|
||||
this.fetchVideoData('All');
|
||||
this.fetchStartData();
|
||||
}
|
||||
|
||||
/**
|
||||
* fetch available videos for specified tag
|
||||
* this function clears all preview elements an reloads gravity with tag
|
||||
*
|
||||
* @param tag tag to fetch videos
|
||||
*/
|
||||
fetchVideoData(tag) {
|
||||
callAPI('video.php', {action: 'getMovies', tag: tag}, (result) => {
|
||||
this.setState({
|
||||
data: []
|
||||
});
|
||||
this.setState({
|
||||
data: result,
|
||||
selectionnr: result.length,
|
||||
tag: tag + ' Videos'
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* fetch the necessary data for left info box
|
||||
*/
|
||||
fetchStartData() {
|
||||
callAPI('video.php', {action: 'getStartData'}, (result) => {
|
||||
this.setState({
|
||||
sideinfo: {
|
||||
videonr: result['total'],
|
||||
fullhdvideonr: result['fullhd'],
|
||||
hdvideonr: result['hd'],
|
||||
sdvideonr: result['sd'],
|
||||
tagnr: result['tags']
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* search for a keyword in db and update previews
|
||||
*
|
||||
* @param keyword The keyword to search for
|
||||
*/
|
||||
searchVideos(keyword) {
|
||||
console.log('search called');
|
||||
|
||||
callAPI('video.php', {action: 'getSearchKeyWord', keyword: keyword}, (result) => {
|
||||
this.setState({
|
||||
data: []
|
||||
});
|
||||
this.setState({
|
||||
data: result,
|
||||
selectionnr: result.length,
|
||||
tag: 'Search result: ' + keyword
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<>
|
||||
<PageTitle
|
||||
title='Home Page'
|
||||
subtitle={this.state.subtitle + ' - ' + this.state.selectionnr}>
|
||||
<form className={'form-inline ' + style.searchform} onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
this.searchVideos(this.keyword);
|
||||
}}>
|
||||
<input data-testid='searchtextfield' className='form-control mr-sm-2'
|
||||
type='text' placeholder='Search'
|
||||
onChange={(e) => {
|
||||
this.keyword = e.target.value;
|
||||
}}/>
|
||||
<button data-testid='searchbtnsubmit' className='btn btn-success' type='submit'>Search</button>
|
||||
</form>
|
||||
</PageTitle>
|
||||
<SideBar>
|
||||
<SideBarTitle>Infos:</SideBarTitle>
|
||||
<Line/>
|
||||
<SideBarItem><b>{this.state.sideinfo.videonr}</b> Videos Total!</SideBarItem>
|
||||
<SideBarItem><b>{this.state.sideinfo.fullhdvideonr}</b> FULL-HD Videos!</SideBarItem>
|
||||
<SideBarItem><b>{this.state.sideinfo.hdvideonr}</b> HD Videos!</SideBarItem>
|
||||
<SideBarItem><b>{this.state.sideinfo.sdvideonr}</b> SD Videos!</SideBarItem>
|
||||
<SideBarItem><b>{this.state.sideinfo.tagnr}</b> different Tags!</SideBarItem>
|
||||
<Line/>
|
||||
<SideBarTitle>Default Tags:</SideBarTitle>
|
||||
<Tag onclick={() => this.fetchVideoData('All')}>All</Tag>
|
||||
<Tag onclick={() => this.fetchVideoData('FullHd')}>FullHd</Tag>
|
||||
<Tag onclick={() => this.fetchVideoData('LowQuality')}>LowQuality</Tag>
|
||||
<Tag onclick={() => this.fetchVideoData('HD')}>HD</Tag>
|
||||
</SideBar>
|
||||
{this.state.data.length !== 0 ?
|
||||
<VideoContainer
|
||||
data={this.state.data}/> :
|
||||
<div>No Data found!</div>}
|
||||
<div className={style.rightinfo}>
|
||||
|
||||
</div>
|
||||
|
||||
</>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default HomePage;
|
@ -1,7 +1,8 @@
|
||||
import {shallow} from 'enzyme';
|
||||
import React from 'react';
|
||||
import HomePage from './HomePage';
|
||||
import {HomePage} from './HomePage';
|
||||
import VideoContainer from '../../elements/VideoContainer/VideoContainer';
|
||||
import {SearchHandling} from './SearchHandling';
|
||||
|
||||
describe('<HomePage/>', function () {
|
||||
it('renders without crashing ', function () {
|
||||
@ -54,23 +55,15 @@ describe('<HomePage/>', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('test form submit', done => {
|
||||
global.fetch = global.prepareFetchApi([{}, {}]);
|
||||
|
||||
it('test form submit', () => {
|
||||
const func = jest.fn();
|
||||
const wrapper = shallow(<HomePage/>);
|
||||
wrapper.setProps({history: {push: () => func()}});
|
||||
|
||||
const fakeEvent = {preventDefault: () => console.log('preventDefault')};
|
||||
wrapper.find('.searchform').simulate('submit', fakeEvent);
|
||||
|
||||
expect(wrapper.state().selectionnr).toBe(0);
|
||||
|
||||
process.nextTick(() => {
|
||||
// state to be set correctly with response
|
||||
expect(wrapper.state().selectionnr).toBe(2);
|
||||
|
||||
global.fetch.mockClear();
|
||||
done();
|
||||
});
|
||||
expect(func).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('test no backend connection behaviour', done => {
|
||||
@ -123,3 +116,24 @@ describe('<HomePage/>', function () {
|
||||
testBtn(tags.first());
|
||||
});
|
||||
});
|
||||
|
||||
describe('<SearchHandling/>', () => {
|
||||
it('renders without crashing', function () {
|
||||
const wrapper = shallow(<SearchHandling match={{params: {name: 'testname'}}}/>);
|
||||
wrapper.unmount();
|
||||
});
|
||||
|
||||
it('renders videos correctly into container', function () {
|
||||
const wrapper = shallow(<SearchHandling match={{params: {name: 'testname'}}}/>);
|
||||
|
||||
wrapper.setState({
|
||||
data: [{
|
||||
movie_id: 42,
|
||||
movie_name: 'testname'
|
||||
}]
|
||||
});
|
||||
|
||||
// expect video container to be visible
|
||||
expect(wrapper.find('VideoContainer')).toHaveLength(1);
|
||||
});
|
||||
});
|
||||
|
156
src/pages/HomePage/HomePage.tsx
Normal file
156
src/pages/HomePage/HomePage.tsx
Normal file
@ -0,0 +1,156 @@
|
||||
import React from 'react';
|
||||
import SideBar, {SideBarItem, SideBarTitle} from '../../elements/SideBar/SideBar';
|
||||
import Tag from '../../elements/Tag/Tag';
|
||||
import VideoContainer from '../../elements/VideoContainer/VideoContainer';
|
||||
|
||||
import style from './HomePage.module.css';
|
||||
import PageTitle, {Line} from '../../elements/PageTitle/PageTitle';
|
||||
import {callAPI} from '../../utils/Api';
|
||||
import {Route, Switch, withRouter} from 'react-router-dom';
|
||||
import {VideoUnloadedType} from '../../api/VideoTypes';
|
||||
import {RouteComponentProps} from 'react-router';
|
||||
import SearchHandling from './SearchHandling';
|
||||
|
||||
interface props extends RouteComponentProps {}
|
||||
|
||||
interface state {
|
||||
sideinfo: {
|
||||
videonr: number,
|
||||
fullhdvideonr: number,
|
||||
hdvideonr: number,
|
||||
sdvideonr: number,
|
||||
tagnr: number
|
||||
},
|
||||
subtitle: string,
|
||||
data: VideoUnloadedType[],
|
||||
selectionnr: number
|
||||
}
|
||||
|
||||
interface startDataData {
|
||||
total: number;
|
||||
fullhd: number;
|
||||
hd: number;
|
||||
sd: number;
|
||||
tags: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* The home page component showing on the initial pageload
|
||||
*/
|
||||
export class HomePage extends React.Component<props, state> {
|
||||
/** keyword variable needed temporary store search keyword */
|
||||
keyword = '';
|
||||
|
||||
constructor(props: props) {
|
||||
super(props);
|
||||
|
||||
this.state = {
|
||||
sideinfo: {
|
||||
videonr: 0,
|
||||
fullhdvideonr: 0,
|
||||
hdvideonr: 0,
|
||||
sdvideonr: 0,
|
||||
tagnr: 0
|
||||
},
|
||||
subtitle: 'All Videos',
|
||||
data: [],
|
||||
selectionnr: 0
|
||||
};
|
||||
}
|
||||
|
||||
componentDidMount(): void {
|
||||
// initial get of all videos
|
||||
this.fetchVideoData('All');
|
||||
this.fetchStartData();
|
||||
}
|
||||
|
||||
/**
|
||||
* fetch available videos for specified tag
|
||||
* this function clears all preview elements an reloads gravity with tag
|
||||
*
|
||||
* @param tag tag to fetch videos
|
||||
*/
|
||||
fetchVideoData(tag: string): void {
|
||||
callAPI('video.php', {action: 'getMovies', tag: tag}, (result: VideoUnloadedType[]) => {
|
||||
this.setState({
|
||||
data: []
|
||||
});
|
||||
this.setState({
|
||||
data: result,
|
||||
selectionnr: result.length,
|
||||
subtitle: `${tag} Videos`
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* fetch the necessary data for left info box
|
||||
*/
|
||||
fetchStartData(): void {
|
||||
callAPI('video.php', {action: 'getStartData'}, (result: startDataData) => {
|
||||
this.setState({
|
||||
sideinfo: {
|
||||
videonr: result['total'],
|
||||
fullhdvideonr: result['fullhd'],
|
||||
hdvideonr: result['hd'],
|
||||
sdvideonr: result['sd'],
|
||||
tagnr: result['tags']
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
render(): JSX.Element {
|
||||
return (
|
||||
<>
|
||||
<Switch>
|
||||
<Route path='/search/:name'>
|
||||
<SearchHandling/>
|
||||
</Route>
|
||||
<Route path='/'>
|
||||
<PageTitle
|
||||
title='Home Page'
|
||||
subtitle={this.state.subtitle + ' - ' + this.state.selectionnr}>
|
||||
<form className={'form-inline ' + style.searchform} onSubmit={(e): void => {
|
||||
e.preventDefault();
|
||||
this.props.history.push('/search/' + this.keyword);
|
||||
}}>
|
||||
<input data-testid='searchtextfield' className='form-control mr-sm-2'
|
||||
type='text' placeholder='Search'
|
||||
onChange={(e): void => {
|
||||
this.keyword = e.target.value;
|
||||
}}/>
|
||||
<button data-testid='searchbtnsubmit' className='btn btn-success' type='submit'>Search</button>
|
||||
</form>
|
||||
</PageTitle>
|
||||
<SideBar>
|
||||
<SideBarTitle>Infos:</SideBarTitle>
|
||||
<Line/>
|
||||
<SideBarItem><b>{this.state.sideinfo.videonr}</b> Videos Total!</SideBarItem>
|
||||
<SideBarItem><b>{this.state.sideinfo.fullhdvideonr}</b> FULL-HD Videos!</SideBarItem>
|
||||
<SideBarItem><b>{this.state.sideinfo.hdvideonr}</b> HD Videos!</SideBarItem>
|
||||
<SideBarItem><b>{this.state.sideinfo.sdvideonr}</b> SD Videos!</SideBarItem>
|
||||
<SideBarItem><b>{this.state.sideinfo.tagnr}</b> different Tags!</SideBarItem>
|
||||
<Line/>
|
||||
<SideBarTitle>Default Tags:</SideBarTitle>
|
||||
<Tag tagInfo={{tag_name: 'All', tag_id: -1}} onclick={(): void => this.fetchVideoData('All')}/>
|
||||
<Tag tagInfo={{tag_name: 'FullHd', tag_id: -1}} onclick={(): void => this.fetchVideoData('FullHd')}/>
|
||||
<Tag tagInfo={{tag_name: 'LowQuality', tag_id: -1}} onclick={(): void => this.fetchVideoData('LowQuality')}/>
|
||||
<Tag tagInfo={{tag_name: 'HD', tag_id: -1}} onclick={(): void => this.fetchVideoData('HD')}/>
|
||||
</SideBar>
|
||||
{this.state.data.length !== 0 ?
|
||||
<VideoContainer
|
||||
data={this.state.data}/> :
|
||||
<div>No Data found!</div>}
|
||||
<div className={style.rightinfo}>
|
||||
|
||||
</div>
|
||||
</Route>
|
||||
</Switch>
|
||||
</>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default withRouter(HomePage);
|
70
src/pages/HomePage/SearchHandling.tsx
Normal file
70
src/pages/HomePage/SearchHandling.tsx
Normal file
@ -0,0 +1,70 @@
|
||||
import {RouteComponentProps} from 'react-router';
|
||||
import React from 'react';
|
||||
import {withRouter} from 'react-router-dom';
|
||||
import {callAPI} from '../../utils/Api';
|
||||
import {VideoUnloadedType} from '../../api/VideoTypes';
|
||||
import VideoContainer from '../../elements/VideoContainer/VideoContainer';
|
||||
import PageTitle from '../../elements/PageTitle/PageTitle';
|
||||
import SideBar from '../../elements/SideBar/SideBar';
|
||||
|
||||
interface params {
|
||||
name: string;
|
||||
}
|
||||
|
||||
interface props extends RouteComponentProps<params> {}
|
||||
|
||||
interface state {
|
||||
data: VideoUnloadedType[];
|
||||
}
|
||||
|
||||
export class SearchHandling extends React.Component<props, state> {
|
||||
constructor(props: props) {
|
||||
super(props);
|
||||
|
||||
this.state = {
|
||||
data: []
|
||||
};
|
||||
}
|
||||
|
||||
componentDidMount(): void {
|
||||
this.searchVideos(this.props.match.params.name);
|
||||
}
|
||||
|
||||
render(): JSX.Element {
|
||||
return (
|
||||
<>
|
||||
<PageTitle title='Search' subtitle={this.props.match.params.name + ': ' + this.state.data.length}/>
|
||||
<SideBar hiddenFrame/>
|
||||
{this.getVideoData()}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* get videocontainer if data loaded
|
||||
*/
|
||||
getVideoData(): JSX.Element {
|
||||
if (this.state.data.length !== 0) {
|
||||
return (
|
||||
<VideoContainer data={this.state.data}/>
|
||||
);
|
||||
} else {
|
||||
return (<div>No Data found!</div>);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* search for a keyword in db and update previews
|
||||
*
|
||||
* @param keyword The keyword to search for
|
||||
*/
|
||||
searchVideos(keyword: string): void {
|
||||
callAPI('video.php', {action: 'getSearchKeyWord', keyword: keyword}, (result: VideoUnloadedType[]) => {
|
||||
this.setState({
|
||||
data: result
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export default withRouter(SearchHandling);
|
@ -24,24 +24,16 @@
|
||||
margin-top: 13px;
|
||||
}
|
||||
|
||||
.button {
|
||||
border-radius: 5px;
|
||||
border-width: 0;
|
||||
color: white;
|
||||
margin-right: 15px;
|
||||
padding: 6px;
|
||||
}
|
||||
|
||||
.actorAddTile {
|
||||
color: white;
|
||||
cursor: pointer;
|
||||
float: left;
|
||||
padding-left: 25px;
|
||||
padding-top: 50px;
|
||||
cursor: pointer;
|
||||
color: white;
|
||||
transition: opacity ease 0.5s;
|
||||
}
|
||||
|
||||
.actorAddTile:hover{
|
||||
.actorAddTile:hover {
|
||||
opacity: 0.7;
|
||||
transition: opacity ease 0.5s;
|
||||
}
|
||||
|
@ -1,16 +1,22 @@
|
||||
import {shallow} from 'enzyme';
|
||||
import React from 'react';
|
||||
import Player from './Player';
|
||||
import {Player} from './Player';
|
||||
import {callAPI} from '../../utils/Api';
|
||||
|
||||
describe('<Player/>', function () {
|
||||
|
||||
// help simulating id passed by url
|
||||
function instance() {
|
||||
return shallow(<Player match={{params: {id: 10}}}/>);
|
||||
}
|
||||
|
||||
it('renders without crashing ', function () {
|
||||
const wrapper = shallow(<Player/>);
|
||||
const wrapper = instance();
|
||||
wrapper.unmount();
|
||||
});
|
||||
|
||||
it('plyr insertion', function () {
|
||||
const wrapper = shallow(<Player/>);
|
||||
const wrapper = instance();
|
||||
|
||||
wrapper.setState({
|
||||
sources: [
|
||||
@ -26,11 +32,11 @@ describe('<Player/>', function () {
|
||||
});
|
||||
|
||||
function simulateLikeButtonClick() {
|
||||
const wrapper = shallow(<Player/>);
|
||||
const wrapper = instance();
|
||||
|
||||
// initial fetch for getting movie data
|
||||
expect(global.fetch).toHaveBeenCalledTimes(1);
|
||||
wrapper.find('.videoactions').find('button').first().simulate('click');
|
||||
wrapper.find('.videoactions').find('Button').first().simulate('click');
|
||||
// fetch for liking
|
||||
expect(global.fetch).toHaveBeenCalledTimes(2);
|
||||
|
||||
@ -70,28 +76,28 @@ describe('<Player/>', function () {
|
||||
});
|
||||
|
||||
it('show tag popup', function () {
|
||||
const wrapper = shallow(<Player/>);
|
||||
const wrapper = instance();
|
||||
expect(wrapper.find('AddTagPopup')).toHaveLength(0);
|
||||
// todo dynamic button find without index
|
||||
wrapper.find('.videoactions').find('button').at(1).simulate('click');
|
||||
wrapper.find('.videoactions').find('Button').at(1).simulate('click');
|
||||
// addtagpopup should be showing now
|
||||
expect(wrapper.find('AddTagPopup')).toHaveLength(1);
|
||||
});
|
||||
|
||||
it('test delete button', done => {
|
||||
const wrapper = shallow(<Player/>);
|
||||
const wrapper = instance();
|
||||
|
||||
const func = jest.fn();
|
||||
prepareViewBinding(func);
|
||||
|
||||
wrapper.setProps({history: {goBack: jest.fn()}});
|
||||
|
||||
global.fetch = prepareFetchApi({result: 'success'});
|
||||
|
||||
wrapper.find('.videoactions').find('button').at(2).simulate('click');
|
||||
wrapper.find('.videoactions').find('Button').at(2).simulate('click');
|
||||
|
||||
process.nextTick(() => {
|
||||
// refetch is called so fetch called 3 times
|
||||
expect(global.fetch).toHaveBeenCalledTimes(1);
|
||||
expect(func).toHaveBeenCalledTimes(1);
|
||||
expect(wrapper.instance().props.history.goBack).toHaveBeenCalledTimes(1);
|
||||
|
||||
global.fetch.mockClear();
|
||||
done();
|
||||
@ -99,19 +105,20 @@ describe('<Player/>', function () {
|
||||
});
|
||||
|
||||
it('hide click ', function () {
|
||||
const wrapper = shallow(<Player/>);
|
||||
const wrapper = instance();
|
||||
|
||||
const func = jest.fn();
|
||||
prepareViewBinding(func);
|
||||
|
||||
wrapper.setProps({history: {goBack: func}});
|
||||
|
||||
expect(func).toHaveBeenCalledTimes(0);
|
||||
wrapper.find('.closebutton').simulate('click');
|
||||
// addtagpopup should be showing now
|
||||
// backstack should be popped once
|
||||
expect(func).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('inserts Tags correctly', function () {
|
||||
const wrapper = shallow(<Player/>);
|
||||
const wrapper = instance();
|
||||
|
||||
expect(wrapper.find('Tag')).toHaveLength(0);
|
||||
|
||||
@ -165,7 +172,7 @@ describe('<Player/>', function () {
|
||||
});
|
||||
|
||||
it('showspopups correctly', function () {
|
||||
const wrapper = shallow(<Player/>);
|
||||
const wrapper = instance();
|
||||
|
||||
wrapper.setState({popupvisible: true}, () => {
|
||||
// is the AddTagpopu rendered?
|
||||
@ -180,13 +187,13 @@ describe('<Player/>', function () {
|
||||
|
||||
|
||||
it('quickadd tag correctly', function () {
|
||||
const wrapper = shallow(<Player/>);
|
||||
const wrapper = instance();
|
||||
global.callAPIMock({result: 'success'});
|
||||
|
||||
wrapper.setState({suggesttag: [{tag_name: 'test', tag_id: 1}]}, () => {
|
||||
// mock funtion should have not been called
|
||||
expect(callAPI).toBeCalledTimes(0);
|
||||
wrapper.find('Tag').findWhere(p => p.text() === 'test').parent().dive().simulate('click');
|
||||
wrapper.find('Tag').findWhere(p => p.props().tagInfo.tag_name === 'test').dive().simulate('click');
|
||||
// mock function should have been called once
|
||||
expect(callAPI).toBeCalledTimes(1);
|
||||
|
||||
@ -198,13 +205,13 @@ describe('<Player/>', function () {
|
||||
});
|
||||
|
||||
it('test adding of already existing tag', function () {
|
||||
const wrapper = shallow(<Player/>);
|
||||
const wrapper = instance();
|
||||
global.callAPIMock({result: 'success'});
|
||||
|
||||
wrapper.setState({suggesttag: [{tag_name: 'test', tag_id: 1}], tags: [{tag_name: 'test', tag_id: 1}]}, () => {
|
||||
// mock funtion should have not been called
|
||||
expect(callAPI).toBeCalledTimes(0);
|
||||
wrapper.find('Tag').findWhere(p => p.text() === 'test').last().parent().dive().simulate('click');
|
||||
wrapper.find('Tag').findWhere(p => p.props().tagInfo.tag_name === 'test').last().dive().simulate('click');
|
||||
// mock function should have been called once
|
||||
expect(callAPI).toBeCalledTimes(1);
|
||||
|
||||
@ -217,7 +224,7 @@ describe('<Player/>', function () {
|
||||
});
|
||||
|
||||
function generatetag() {
|
||||
const wrapper = shallow(<Player/>);
|
||||
const wrapper = instance();
|
||||
|
||||
expect(wrapper.find('Tag')).toHaveLength(0);
|
||||
|
||||
@ -233,7 +240,7 @@ describe('<Player/>', function () {
|
||||
}
|
||||
|
||||
it('test addactor popup showing', function () {
|
||||
const wrapper = shallow(<Player/>);
|
||||
const wrapper = instance();
|
||||
|
||||
expect(wrapper.find('AddActorPopup')).toHaveLength(0);
|
||||
|
||||
@ -244,7 +251,7 @@ describe('<Player/>', function () {
|
||||
});
|
||||
|
||||
it('test hiding of addactor popup', function () {
|
||||
const wrapper = shallow(<Player/>);
|
||||
const wrapper = instance();
|
||||
wrapper.instance().addActor();
|
||||
|
||||
expect(wrapper.find('AddActorPopup')).toHaveLength(1);
|
||||
@ -253,4 +260,36 @@ describe('<Player/>', function () {
|
||||
|
||||
expect(wrapper.find('AddActorPopup')).toHaveLength(0);
|
||||
});
|
||||
|
||||
it('test addtagpopup hiding', function () {
|
||||
const wrapper = instance();
|
||||
|
||||
wrapper.setState({popupvisible: true});
|
||||
expect(wrapper.find('AddTagPopup')).toHaveLength(1);
|
||||
|
||||
wrapper.find('AddTagPopup').props().onHide();
|
||||
|
||||
expect(wrapper.find('AddTagPopup')).toHaveLength(0);
|
||||
});
|
||||
|
||||
it('test insertion of actor tiles', function () {
|
||||
const wrapper = instance();
|
||||
wrapper.setState({
|
||||
actors: [{
|
||||
thumbnail: '',
|
||||
name: 'testname',
|
||||
actor_id: 42
|
||||
}]
|
||||
});
|
||||
|
||||
expect(wrapper.find('ActorTile')).toHaveLength(1);
|
||||
});
|
||||
|
||||
it('test Addactor button', function () {
|
||||
const wrapper = instance();
|
||||
expect(wrapper.state().actorpopupvisible).toBe(false);
|
||||
wrapper.find('.actorAddTile').simulate('click');
|
||||
|
||||
expect(wrapper.state().actorpopupvisible).toBe(true);
|
||||
});
|
||||
});
|
||||
|
@ -12,16 +12,36 @@ import {FontAwesomeIcon} from '@fortawesome/react-fontawesome';
|
||||
import {faPlusCircle} from '@fortawesome/free-solid-svg-icons';
|
||||
import AddActorPopup from '../../elements/Popups/AddActorPopup/AddActorPopup';
|
||||
import ActorTile from '../../elements/ActorTile/ActorTile';
|
||||
import GlobalInfos from '../../utils/GlobalInfos';
|
||||
import {withRouter} from 'react-router-dom';
|
||||
import {callAPI, getBackendDomain} from '../../utils/Api';
|
||||
import {RouteComponentProps} from 'react-router';
|
||||
import {GeneralSuccess} from '../../api/GeneralTypes';
|
||||
import {ActorType, loadVideoType, TagType} from '../../api/VideoTypes';
|
||||
import PlyrJS from 'plyr';
|
||||
import {Button} from '../../elements/GPElements/Button';
|
||||
|
||||
interface myprops extends RouteComponentProps<{ id: string }> {}
|
||||
|
||||
interface mystate {
|
||||
sources?: PlyrJS.SourceInfo,
|
||||
movie_id: number,
|
||||
movie_name: string,
|
||||
likes: number,
|
||||
quality: number,
|
||||
length: number,
|
||||
tags: TagType[],
|
||||
suggesttag: TagType[],
|
||||
popupvisible: boolean,
|
||||
actorpopupvisible: boolean,
|
||||
actors: ActorType[]
|
||||
}
|
||||
|
||||
/**
|
||||
* Player page loads when a video is selected to play and handles the video view
|
||||
* and actions such as tag adding and liking
|
||||
*/
|
||||
class Player extends React.Component {
|
||||
options = {
|
||||
export class Player extends React.Component<myprops, mystate> {
|
||||
options: PlyrJS.Options = {
|
||||
controls: [
|
||||
'play-large', // The large play button in the center
|
||||
'play', // Play/pause playback
|
||||
@ -38,130 +58,31 @@ class Player extends React.Component {
|
||||
]
|
||||
};
|
||||
|
||||
constructor(props, context) {
|
||||
super(props, context);
|
||||
constructor(props: myprops) {
|
||||
super(props);
|
||||
|
||||
this.state = {
|
||||
sources: null,
|
||||
movie_id: null,
|
||||
movie_name: null,
|
||||
likes: null,
|
||||
quality: null,
|
||||
length: null,
|
||||
movie_id: -1,
|
||||
movie_name: '',
|
||||
likes: 0,
|
||||
quality: 0,
|
||||
length: 0,
|
||||
tags: [],
|
||||
suggesttag: [],
|
||||
popupvisible: false,
|
||||
actorpopupvisible: false
|
||||
actorpopupvisible: false,
|
||||
actors: []
|
||||
};
|
||||
|
||||
this.quickAddTag = this.quickAddTag.bind(this);
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
componentDidMount(): void {
|
||||
// initial fetch of current movie data
|
||||
this.fetchMovieData();
|
||||
}
|
||||
|
||||
/**
|
||||
* quick add callback to add tag to db and change gui correctly
|
||||
* @param tagId id of tag to add
|
||||
* @param tagName name of tag to add
|
||||
*/
|
||||
quickAddTag(tagId, tagName) {
|
||||
callAPI('tags.php', {action: 'addTag', id: tagId, movieid: this.props.movie_id}, (result) => {
|
||||
if (result.result !== 'success') {
|
||||
console.error('error occured while writing to db -- todo error handling');
|
||||
console.error(result.result);
|
||||
} else {
|
||||
// check if tag has already been added
|
||||
const tagIndex = this.state.tags.map(function (e) {
|
||||
return e.tag_name;
|
||||
}).indexOf(tagName);
|
||||
|
||||
// only add tag if it isn't already there
|
||||
if (tagIndex === -1) {
|
||||
// update tags if successful
|
||||
let array = [...this.state.suggesttag]; // make a separate copy of the array (because of setState)
|
||||
const quickaddindex = this.state.suggesttag.map(function (e) {
|
||||
return e.tag_id;
|
||||
}).indexOf(tagId);
|
||||
|
||||
// check if tag is available in quickadds
|
||||
if (quickaddindex !== -1) {
|
||||
array.splice(quickaddindex, 1);
|
||||
|
||||
this.setState({
|
||||
tags: [...this.state.tags, {tag_name: tagName}],
|
||||
suggesttag: array
|
||||
});
|
||||
} else {
|
||||
this.setState({
|
||||
tags: [...this.state.tags, {tag_name: tagName}]
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* handle the popovers generated according to state changes
|
||||
* @returns {JSX.Element}
|
||||
*/
|
||||
handlePopOvers() {
|
||||
return (
|
||||
<>
|
||||
{this.state.popupvisible ?
|
||||
<AddTagPopup onHide={() => {this.setState({popupvisible: false});}}
|
||||
submit={this.quickAddTag}
|
||||
movie_id={this.state.movie_id}/> :
|
||||
null
|
||||
}
|
||||
{
|
||||
this.state.actorpopupvisible ?
|
||||
<AddActorPopup onHide={() => {
|
||||
this.refetchActors();
|
||||
this.setState({actorpopupvisible: false});
|
||||
}} movie_id={this.state.movie_id}/> : null
|
||||
}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* generate sidebar with all items
|
||||
*/
|
||||
assembleSideBar() {
|
||||
return (
|
||||
<SideBar>
|
||||
<SideBarTitle>Infos:</SideBarTitle>
|
||||
<Line/>
|
||||
<SideBarItem><b>{this.state.likes}</b> Likes!</SideBarItem>
|
||||
{this.state.quality !== 0 ?
|
||||
<SideBarItem><b>{this.state.quality}p</b> Quality!</SideBarItem> : null}
|
||||
{this.state.length !== 0 ?
|
||||
<SideBarItem><b>{Math.round(this.state.length / 60)}</b> Minutes of length!</SideBarItem> : null}
|
||||
<Line/>
|
||||
<SideBarTitle>Tags:</SideBarTitle>
|
||||
{this.state.tags.map((m) => (
|
||||
<Tag key={m.tag_name}>{m.tag_name}</Tag>
|
||||
))}
|
||||
<Line/>
|
||||
<SideBarTitle>Tag Quickadd:</SideBarTitle>
|
||||
{this.state.suggesttag.map((m) => (
|
||||
<Tag
|
||||
key={m.tag_name}
|
||||
onclick={() => {
|
||||
this.quickAddTag(m.tag_id, m.tag_name);
|
||||
}}>
|
||||
{m.tag_name}
|
||||
</Tag>
|
||||
))}
|
||||
</SideBar>
|
||||
);
|
||||
}
|
||||
|
||||
render() {
|
||||
render(): JSX.Element {
|
||||
return (
|
||||
<div id='videocontainer'>
|
||||
<PageTitle
|
||||
@ -178,25 +99,18 @@ class Player extends React.Component {
|
||||
options={this.options}/> :
|
||||
<div>not loaded yet</div>}
|
||||
<div className={style.videoactions}>
|
||||
<button className={style.button} style={{backgroundColor: 'green'}} onClick={() => this.likebtn()}>
|
||||
Like this Video!
|
||||
</button>
|
||||
<button className={style.button} style={{backgroundColor: '#3574fe'}} onClick={() => this.setState({popupvisible: true})}>
|
||||
Give this Video a Tag
|
||||
</button>
|
||||
<button className={style.button} style={{backgroundColor: 'red'}} onClick={() => {
|
||||
this.deleteVideo();
|
||||
}}>Delete Video
|
||||
</button>
|
||||
<Button onClick={(): void => this.likebtn()} title='Like this Video!' color={{backgroundColor: 'green'}}/>
|
||||
<Button onClick={(): void => this.setState({popupvisible: true})} title='Give this Video a Tag' color={{backgroundColor: '#3574fe'}}/>
|
||||
<Button title='Delete Video' onClick={(): void => {this.deleteVideo();}} color={{backgroundColor: 'red'}}/>
|
||||
</div>
|
||||
{/* rendering of actor tiles */}
|
||||
<div className={style.actorcontainer}>
|
||||
{this.state.actors ?
|
||||
this.state.actors.map((actr) => (
|
||||
this.state.actors.map((actr: ActorType) => (
|
||||
<ActorTile actor={actr}/>
|
||||
)) : <></>
|
||||
}
|
||||
<div className={style.actorAddTile} onClick={() => {
|
||||
<div className={style.actorAddTile} onClick={(): void => {
|
||||
this.addActor();
|
||||
}}>
|
||||
<div className={style.actorAddTile_thumbnail}>
|
||||
@ -208,7 +122,7 @@ class Player extends React.Component {
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<button className={style.closebutton} onClick={() => this.closebtn()}>Close</button>
|
||||
<button className={style.closebutton} onClick={(): void => this.closebtn()}>Close</button>
|
||||
{
|
||||
// handle the popovers switched on and off according to state changes
|
||||
this.handlePopOvers()
|
||||
@ -217,11 +131,115 @@ class Player extends React.Component {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* generate sidebar with all items
|
||||
*/
|
||||
assembleSideBar(): JSX.Element {
|
||||
return (
|
||||
<SideBar>
|
||||
<SideBarTitle>Infos:</SideBarTitle>
|
||||
<Line/>
|
||||
<SideBarItem><b>{this.state.likes}</b> Likes!</SideBarItem>
|
||||
{this.state.quality !== 0 ?
|
||||
<SideBarItem><b>{this.state.quality}p</b> Quality!</SideBarItem> : null}
|
||||
{this.state.length !== 0 ?
|
||||
<SideBarItem><b>{Math.round(this.state.length / 60)}</b> Minutes of length!</SideBarItem> : null}
|
||||
<Line/>
|
||||
<SideBarTitle>Tags:</SideBarTitle>
|
||||
{this.state.tags.map((m: TagType) => (
|
||||
<Tag tagInfo={m}/>
|
||||
))}
|
||||
<Line/>
|
||||
<SideBarTitle>Tag Quickadd:</SideBarTitle>
|
||||
{this.state.suggesttag.map((m: TagType) => (
|
||||
<Tag
|
||||
tagInfo={m}
|
||||
key={m.tag_name}
|
||||
onclick={(): void => {
|
||||
this.quickAddTag(m.tag_id, m.tag_name);
|
||||
}}/>
|
||||
))}
|
||||
</SideBar>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* quick add callback to add tag to db and change gui correctly
|
||||
* @param tagId id of tag to add
|
||||
* @param tagName name of tag to add
|
||||
*/
|
||||
quickAddTag(tagId: number, tagName: string): void {
|
||||
callAPI('tags.php', {
|
||||
action: 'addTag',
|
||||
id: tagId,
|
||||
movieid: this.props.match.params.id
|
||||
}, (result: GeneralSuccess) => {
|
||||
if (result.result !== 'success') {
|
||||
console.error('error occured while writing to db -- todo error handling');
|
||||
console.error(result.result);
|
||||
} else {
|
||||
// check if tag has already been added
|
||||
const tagIndex = this.state.tags.map(function (e: TagType) {
|
||||
return e.tag_name;
|
||||
}).indexOf(tagName);
|
||||
|
||||
// only add tag if it isn't already there
|
||||
if (tagIndex === -1) {
|
||||
// update tags if successful
|
||||
let array = [...this.state.suggesttag]; // make a separate copy of the array (because of setState)
|
||||
const quickaddindex = this.state.suggesttag.map(function (e: TagType) {
|
||||
return e.tag_id;
|
||||
}).indexOf(tagId);
|
||||
|
||||
// check if tag is available in quickadds
|
||||
if (quickaddindex !== -1) {
|
||||
array.splice(quickaddindex, 1);
|
||||
|
||||
this.setState({
|
||||
tags: [...this.state.tags, {tag_name: tagName, tag_id: tagId}],
|
||||
suggesttag: array
|
||||
});
|
||||
} else {
|
||||
this.setState({
|
||||
tags: [...this.state.tags, {tag_name: tagName, tag_id: tagId}]
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* handle the popovers generated according to state changes
|
||||
* @returns {JSX.Element}
|
||||
*/
|
||||
handlePopOvers(): JSX.Element {
|
||||
return (
|
||||
<>
|
||||
{this.state.popupvisible ?
|
||||
<AddTagPopup onHide={(): void => {
|
||||
this.setState({popupvisible: false});
|
||||
}}
|
||||
submit={this.quickAddTag}
|
||||
movie_id={this.state.movie_id}/> :
|
||||
null
|
||||
}
|
||||
{
|
||||
this.state.actorpopupvisible ?
|
||||
<AddActorPopup onHide={(): void => {
|
||||
this.refetchActors();
|
||||
this.setState({actorpopupvisible: false});
|
||||
}} movie_id={this.state.movie_id}/> : null
|
||||
}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* fetch all the required infos of a video from backend
|
||||
*/
|
||||
fetchMovieData() {
|
||||
callAPI('video.php', {action: 'loadVideo', movieid: this.props.movie_id}, result => {
|
||||
fetchMovieData(): void {
|
||||
callAPI('video.php', {action: 'loadVideo', movieid: this.props.match.params.id}, (result: loadVideoType) => {
|
||||
this.setState({
|
||||
sources: {
|
||||
type: 'video',
|
||||
@ -243,7 +261,6 @@ class Player extends React.Component {
|
||||
suggesttag: result.suggesttag,
|
||||
actors: result.actors
|
||||
});
|
||||
console.log(this.state);
|
||||
});
|
||||
}
|
||||
|
||||
@ -251,8 +268,8 @@ class Player extends React.Component {
|
||||
/**
|
||||
* click handler for the like btn
|
||||
*/
|
||||
likebtn() {
|
||||
callAPI('video.php', {action: 'addLike', movieid: this.props.movie_id}, result => {
|
||||
likebtn(): void {
|
||||
callAPI('video.php', {action: 'addLike', movieid: this.props.match.params.id}, (result: GeneralSuccess) => {
|
||||
if (result.result === 'success') {
|
||||
// likes +1 --> avoid reload of all data
|
||||
this.setState({likes: this.state.likes + 1});
|
||||
@ -267,18 +284,18 @@ class Player extends React.Component {
|
||||
* closebtn click handler
|
||||
* calls callback to viewbinding to show previous page agains
|
||||
*/
|
||||
closebtn() {
|
||||
GlobalInfos.getViewBinding().returnToLastElement();
|
||||
closebtn(): void {
|
||||
this.props.history.goBack();
|
||||
}
|
||||
|
||||
/**
|
||||
* delete the current video and return to last page
|
||||
*/
|
||||
deleteVideo() {
|
||||
callAPI('video.php', {action: 'deleteVideo', movieid: this.props.movie_id}, result => {
|
||||
deleteVideo(): void {
|
||||
callAPI('video.php', {action: 'deleteVideo', movieid: this.props.match.params.id}, (result: GeneralSuccess) => {
|
||||
if (result.result === 'success') {
|
||||
// return to last element if successful
|
||||
GlobalInfos.getViewBinding().returnToLastElement();
|
||||
this.props.history.goBack();
|
||||
} else {
|
||||
console.error('an error occured while liking');
|
||||
console.error(result);
|
||||
@ -289,15 +306,19 @@ class Player extends React.Component {
|
||||
/**
|
||||
* show the actor add popup
|
||||
*/
|
||||
addActor() {
|
||||
addActor(): void {
|
||||
this.setState({actorpopupvisible: true});
|
||||
}
|
||||
|
||||
refetchActors() {
|
||||
callAPI('actor.php', {action: 'getActorsOfVideo', videoid: this.props.movie_id}, result => {
|
||||
/**
|
||||
* fetch the available video actors again
|
||||
*/
|
||||
refetchActors(): void {
|
||||
callAPI<ActorType[]>('actor.php', {action: 'getActorsOfVideo', videoid: this.props.match.params.id}, result => {
|
||||
this.setState({actors: result});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export default Player;
|
||||
export default withRouter(Player);
|
||||
|
@ -5,13 +5,24 @@ import Tag from '../../elements/Tag/Tag';
|
||||
import PageTitle from '../../elements/PageTitle/PageTitle';
|
||||
import VideoContainer from '../../elements/VideoContainer/VideoContainer';
|
||||
import {callAPI} from '../../utils/Api';
|
||||
import {TagType, VideoUnloadedType} from '../../api/VideoTypes';
|
||||
|
||||
interface state {
|
||||
videos: VideoUnloadedType[];
|
||||
tags: TagType[];
|
||||
}
|
||||
|
||||
interface GetRandomMoviesType {
|
||||
rows: VideoUnloadedType[];
|
||||
tags: TagType[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Randompage shuffles random viedeopreviews and provides a shuffle btn
|
||||
*/
|
||||
class RandomPage extends React.Component {
|
||||
constructor(props, context) {
|
||||
super(props, context);
|
||||
class RandomPage extends React.Component<{}, state> {
|
||||
constructor(props: {}) {
|
||||
super(props);
|
||||
|
||||
this.state = {
|
||||
videos: [],
|
||||
@ -19,11 +30,11 @@ class RandomPage extends React.Component {
|
||||
};
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
componentDidMount(): void {
|
||||
this.loadShuffledvideos(4);
|
||||
}
|
||||
|
||||
render() {
|
||||
render(): JSX.Element {
|
||||
return (
|
||||
<div>
|
||||
<PageTitle title='Random Videos'
|
||||
@ -32,7 +43,7 @@ class RandomPage extends React.Component {
|
||||
<SideBar>
|
||||
<SideBarTitle>Visible Tags:</SideBarTitle>
|
||||
{this.state.tags.map((m) => (
|
||||
<Tag key={m.tag_name}>{m.tag_name}</Tag>
|
||||
<Tag key={m.tag_id} tagInfo={m}/>
|
||||
))}
|
||||
</SideBar>
|
||||
|
||||
@ -40,7 +51,7 @@ class RandomPage extends React.Component {
|
||||
<VideoContainer
|
||||
data={this.state.videos}>
|
||||
<div className={style.Shufflebutton}>
|
||||
<button onClick={() => this.shuffleclick()} className={style.btnshuffle}>Shuffle</button>
|
||||
<button onClick={(): void => this.shuffleclick()} className={style.btnshuffle}>Shuffle</button>
|
||||
</div>
|
||||
</VideoContainer>
|
||||
:
|
||||
@ -53,7 +64,7 @@ class RandomPage extends React.Component {
|
||||
/**
|
||||
* click handler for shuffle btn
|
||||
*/
|
||||
shuffleclick() {
|
||||
shuffleclick(): void {
|
||||
this.loadShuffledvideos(4);
|
||||
}
|
||||
|
||||
@ -61,8 +72,8 @@ class RandomPage extends React.Component {
|
||||
* load random videos from backend
|
||||
* @param nr number of videos to load
|
||||
*/
|
||||
loadShuffledvideos(nr) {
|
||||
callAPI('video.php', {action: 'getRandomMovies', number: nr}, result => {
|
||||
loadShuffledvideos(nr: number): void {
|
||||
callAPI<GetRandomMoviesType>('video.php', {action: 'getRandomMovies', number: nr}, result => {
|
||||
console.log(result);
|
||||
|
||||
this.setState({videos: []}); // needed to trigger rerender of main videoview
|
@ -8,7 +8,7 @@
|
||||
width: 40%;
|
||||
}
|
||||
|
||||
.customapiform{
|
||||
.customapiform {
|
||||
margin-top: 15px;
|
||||
width: 40%;
|
||||
}
|
||||
|
@ -29,6 +29,13 @@ describe('<GeneralSettings/>', function () {
|
||||
|
||||
it('test savesettings', done => {
|
||||
const wrapper = shallow(<GeneralSettings/>);
|
||||
wrapper.setState({
|
||||
passwordsupport: true,
|
||||
videopath: '',
|
||||
tvshowpath: '',
|
||||
mediacentername: '',
|
||||
tmdbsupport: true
|
||||
});
|
||||
|
||||
global.fetch = global.prepareFetchApi({success: true});
|
||||
|
||||
@ -47,6 +54,13 @@ describe('<GeneralSettings/>', function () {
|
||||
|
||||
it('test failing savesettings', done => {
|
||||
const wrapper = shallow(<GeneralSettings/>);
|
||||
wrapper.setState({
|
||||
passwordsupport: true,
|
||||
videopath: '',
|
||||
tvshowpath: '',
|
||||
mediacentername: '',
|
||||
tmdbsupport: true
|
||||
});
|
||||
|
||||
global.fetch = global.prepareFetchApi({success: false});
|
||||
|
||||
|
@ -26,6 +26,7 @@
|
||||
.SettingSidebarElement {
|
||||
background-color: #919fd9;
|
||||
border-radius: 7px;
|
||||
color: black;
|
||||
font-weight: bold;
|
||||
margin: 10px 5px 5px;
|
||||
padding: 5px;
|
||||
|
@ -7,34 +7,4 @@ describe('<RandomPage/>', function () {
|
||||
const wrapper = shallow(<SettingsPage/>);
|
||||
wrapper.unmount();
|
||||
});
|
||||
|
||||
it('simulate topic clicka', function () {
|
||||
const wrapper = shallow(<SettingsPage/>);
|
||||
|
||||
simulateSideBarClick('General', wrapper);
|
||||
expect(wrapper.state().currentpage).toBe('general');
|
||||
expect(wrapper.find('.SettingsContent').find('GeneralSettings')).toHaveLength(1);
|
||||
|
||||
simulateSideBarClick('Movies', wrapper);
|
||||
expect(wrapper.state().currentpage).toBe('movies');
|
||||
expect(wrapper.find('.SettingsContent').find('MovieSettings')).toHaveLength(1);
|
||||
|
||||
simulateSideBarClick('TV Shows', wrapper);
|
||||
expect(wrapper.state().currentpage).toBe('tv');
|
||||
expect(wrapper.find('.SettingsContent').find('span')).toHaveLength(1);
|
||||
});
|
||||
|
||||
function simulateSideBarClick(name, wrapper) {
|
||||
wrapper.find('.SettingSidebarElement').findWhere(it =>
|
||||
it.text() === name &&
|
||||
it.type() === 'div').simulate('click');
|
||||
}
|
||||
|
||||
it('simulate unknown topic', function () {
|
||||
const wrapper = shallow(<SettingsPage/>);
|
||||
wrapper.setState({currentpage: 'unknown'});
|
||||
|
||||
expect(wrapper.find('.SettingsContent').text()).toBe('unknown button clicked');
|
||||
|
||||
});
|
||||
});
|
||||
|
@ -3,59 +3,44 @@ import MovieSettings from './MovieSettings';
|
||||
import GeneralSettings from './GeneralSettings';
|
||||
import style from './SettingsPage.module.css';
|
||||
import GlobalInfos from '../../utils/GlobalInfos';
|
||||
|
||||
type SettingsPageState = {
|
||||
currentpage: string
|
||||
}
|
||||
import {NavLink, Redirect, Route, Switch} from 'react-router-dom';
|
||||
|
||||
/**
|
||||
* The Settingspage handles all kinds of settings for the mediacenter
|
||||
* and is basically a wrapper for child-tabs
|
||||
*/
|
||||
class SettingsPage extends React.Component<{}, SettingsPageState> {
|
||||
constructor(props: Readonly<{}> | {}, context?: any) {
|
||||
super(props, context);
|
||||
|
||||
this.state = {
|
||||
currentpage: 'general'
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* load the selected tab
|
||||
* @returns {JSX.Element|string} the jsx element of the selected tab
|
||||
*/
|
||||
getContent(): JSX.Element | string {
|
||||
switch (this.state.currentpage) {
|
||||
case 'general':
|
||||
return <GeneralSettings/>;
|
||||
case 'movies':
|
||||
return <MovieSettings/>;
|
||||
case 'tv':
|
||||
return <span/>; // todo this page
|
||||
default:
|
||||
return 'unknown button clicked';
|
||||
}
|
||||
}
|
||||
|
||||
render() : JSX.Element {
|
||||
class SettingsPage extends React.Component {
|
||||
render(): JSX.Element {
|
||||
const themestyle = GlobalInfos.getThemeStyle();
|
||||
return (
|
||||
<div>
|
||||
<div className={style.SettingsSidebar + ' ' + themestyle.secbackground}>
|
||||
<div className={style.SettingsSidebarTitle + ' ' + themestyle.lighttextcolor}>Settings</div>
|
||||
<div onClick={() => this.setState({currentpage: 'general'})}
|
||||
className={style.SettingSidebarElement}>General
|
||||
</div>
|
||||
<div onClick={() => this.setState({currentpage: 'movies'})}
|
||||
className={style.SettingSidebarElement}>Movies
|
||||
</div>
|
||||
<div onClick={() => this.setState({currentpage: 'tv'})}
|
||||
className={style.SettingSidebarElement}>TV Shows
|
||||
</div>
|
||||
<NavLink to='/settings/general'>
|
||||
<div className={style.SettingSidebarElement}>General</div>
|
||||
</NavLink>
|
||||
<NavLink to='/settings/movies'>
|
||||
<div className={style.SettingSidebarElement}>Movies</div>
|
||||
</NavLink>
|
||||
<NavLink to='/settings/tv'>
|
||||
<div className={style.SettingSidebarElement}>TV Shows</div>
|
||||
</NavLink>
|
||||
</div>
|
||||
<div className={style.SettingsContent}>
|
||||
{this.getContent()}
|
||||
<Switch>
|
||||
<Route path="/settings/general">
|
||||
<GeneralSettings/>
|
||||
</Route>
|
||||
<Route path="/settings/movies">
|
||||
<MovieSettings/>
|
||||
</Route>
|
||||
<Route path="/settings/tv">
|
||||
<span/>
|
||||
</Route>
|
||||
<Route path="/settings">
|
||||
<Redirect to='/settings/general'/>
|
||||
</Route>
|
||||
</Switch>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
Reference in New Issue
Block a user