correct behaviour on category page on tag click
This commit is contained in:
parent
753ea99693
commit
a6f6b2d96f
@ -35,10 +35,26 @@ class CategoryPage extends React.Component {
|
|||||||
|
|
||||||
<SideBar>
|
<SideBar>
|
||||||
<div className='sidebartitle'>Default Tags:</div>
|
<div className='sidebartitle'>Default Tags:</div>
|
||||||
<Tag viewbinding={this.props.viewbinding} contentbinding={this.loadTag}>All</Tag>
|
<Tag viewbinding={{
|
||||||
<Tag viewbinding={this.props.viewbinding} contentbinding={this.loadTag}>FullHd</Tag>
|
changeRootElement: (e) => {
|
||||||
<Tag viewbinding={this.props.viewbinding} contentbinding={this.loadTag}>LowQuality</Tag>
|
this.loadTag(e.props.category)
|
||||||
<Tag viewbinding={this.props.viewbinding} contentbinding={this.loadTag}>HD</Tag>
|
}
|
||||||
|
}}>All</Tag>
|
||||||
|
<Tag viewbinding={{
|
||||||
|
changeRootElement: (e) => {
|
||||||
|
this.loadTag(e.props.category)
|
||||||
|
}
|
||||||
|
}}>FullHd</Tag>
|
||||||
|
<Tag viewbinding={{
|
||||||
|
changeRootElement: (e) => {
|
||||||
|
this.loadTag(e.props.category)
|
||||||
|
}
|
||||||
|
}}>LowQuality</Tag>
|
||||||
|
<Tag viewbinding={{
|
||||||
|
changeRootElement: (e) => {
|
||||||
|
this.loadTag(e.props.category)
|
||||||
|
}
|
||||||
|
}}>HD</Tag>
|
||||||
<hr/>
|
<hr/>
|
||||||
<button data-testid='btnaddtag' className='btn btn-success' onClick={() => {
|
<button data-testid='btnaddtag' className='btn btn-success' onClick={() => {
|
||||||
this.setState({popupvisible: true})
|
this.setState({popupvisible: true})
|
||||||
@ -46,8 +62,17 @@ class CategoryPage extends React.Component {
|
|||||||
</button>
|
</button>
|
||||||
</SideBar>
|
</SideBar>
|
||||||
|
|
||||||
{!this.state.selected ?
|
{this.state.selected ?
|
||||||
(<div className='maincontent'>
|
<>
|
||||||
|
{this.videodata ?
|
||||||
|
<VideoContainer
|
||||||
|
data={this.videodata}
|
||||||
|
viewbinding={this.props.viewbinding}/> : null}
|
||||||
|
<button data-testid='backbtn' className="btn btn-success"
|
||||||
|
onClick={this.loadCategoryPageDefault}>Back
|
||||||
|
</button>
|
||||||
|
</> :
|
||||||
|
<div className='maincontent'>
|
||||||
{this.state.loadedtags ?
|
{this.state.loadedtags ?
|
||||||
this.state.loadedtags.map((m) => (
|
this.state.loadedtags.map((m) => (
|
||||||
<TagPreview
|
<TagPreview
|
||||||
@ -58,13 +83,7 @@ class CategoryPage extends React.Component {
|
|||||||
categorybinding={this.loadTag}/>
|
categorybinding={this.loadTag}/>
|
||||||
)) :
|
)) :
|
||||||
"loading"}
|
"loading"}
|
||||||
</div>) :
|
</div>
|
||||||
<>
|
|
||||||
{this.selectionelements ? this.selectionelements : null}
|
|
||||||
<button data-testid='backbtn' className="btn btn-success"
|
|
||||||
onClick={this.loadCategoryPageDefault}>Back
|
|
||||||
</button>
|
|
||||||
</>
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{this.state.popupvisible ?
|
{this.state.popupvisible ?
|
||||||
@ -81,8 +100,6 @@ class CategoryPage extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
loadTag = (tagname) => {
|
loadTag = (tagname) => {
|
||||||
// this.selectionelements = element;
|
|
||||||
// this.setState({selected: null}); // todo save this change trigger better
|
|
||||||
this.fetchVideoData(tagname);
|
this.fetchVideoData(tagname);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -98,10 +115,8 @@ class CategoryPage extends React.Component {
|
|||||||
fetch('/api/videoload.php', {method: 'POST', body: updateRequest})
|
fetch('/api/videoload.php', {method: 'POST', body: updateRequest})
|
||||||
.then((response) => response.json()
|
.then((response) => response.json()
|
||||||
.then((result) => {
|
.then((result) => {
|
||||||
this.selectionelements =
|
this.videodata = result;
|
||||||
<VideoContainer
|
this.setState({selected: null}); // needed to trigger the state reload correctly
|
||||||
data={result}
|
|
||||||
viewbinding={this.props.viewbinding}/>;
|
|
||||||
this.setState({selected: tag});
|
this.setState({selected: tag});
|
||||||
}))
|
}))
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
@ -111,6 +126,7 @@ class CategoryPage extends React.Component {
|
|||||||
|
|
||||||
loadCategoryPageDefault = () => {
|
loadCategoryPageDefault = () => {
|
||||||
this.setState({selected: null});
|
this.setState({selected: null});
|
||||||
|
this.loadTags();
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -86,8 +86,6 @@ describe('<CategoryPage/>', function () {
|
|||||||
process.nextTick(() => {
|
process.nextTick(() => {
|
||||||
// expect callback to have loaded correct tag
|
// expect callback to have loaded correct tag
|
||||||
expect(wrapper.state().selected).toBe("testname");
|
expect(wrapper.state().selected).toBe("testname");
|
||||||
// expect to receive a videocontainer with simulated data
|
|
||||||
expect(wrapper.instance().selectionelements).toMatchObject(<VideoContainer data={[{}, {}]}/>);
|
|
||||||
|
|
||||||
global.fetch.mockClear();
|
global.fetch.mockClear();
|
||||||
done();
|
done();
|
||||||
@ -104,4 +102,13 @@ describe('<CategoryPage/>', function () {
|
|||||||
wrapper.find('[data-testid="backbtn"]').simulate("click");
|
wrapper.find('[data-testid="backbtn"]').simulate("click");
|
||||||
expect(wrapper.state().selected).toBeNull();
|
expect(wrapper.state().selected).toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('load categorypage with predefined tag', function () {
|
||||||
|
const func = jest.fn();
|
||||||
|
CategoryPage.prototype.fetchVideoData = func;
|
||||||
|
|
||||||
|
const wrapper = shallow(<CategoryPage category="fullhd"/>);
|
||||||
|
|
||||||
|
expect(func).toBeCalledTimes(1);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -118,12 +118,6 @@ class HomePage extends React.Component {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
setPage = (element, tagname) => {
|
|
||||||
this.setState({tag: tagname});
|
|
||||||
// todo warning double data download here!
|
|
||||||
this.fetchVideoData(tagname);
|
|
||||||
};
|
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
@ -152,18 +146,10 @@ class HomePage extends React.Component {
|
|||||||
<div className='sidebarinfo'><b>{this.state.sideinfo.tagnr}</b> different Tags!</div>
|
<div className='sidebarinfo'><b>{this.state.sideinfo.tagnr}</b> different Tags!</div>
|
||||||
<hr/>
|
<hr/>
|
||||||
<div className='sidebartitle'>Default Tags:</div>
|
<div className='sidebartitle'>Default Tags:</div>
|
||||||
<Tag
|
<Tag viewbinding={this.props.viewbinding}>All</Tag>
|
||||||
viewbinding={this.props.viewbinding}
|
<Tag viewbinding={this.props.viewbinding}>FullHd</Tag>
|
||||||
contentbinding={this.setPage}>All</Tag>
|
<Tag viewbinding={this.props.viewbinding}>LowQuality</Tag>
|
||||||
<Tag
|
<Tag viewbinding={this.props.viewbinding}>HD</Tag>
|
||||||
viewbinding={this.props.viewbinding}
|
|
||||||
contentbinding={this.setPage}>FullHd</Tag>
|
|
||||||
<Tag
|
|
||||||
viewbinding={this.props.viewbinding}
|
|
||||||
contentbinding={this.setPage}>LowQuality</Tag>
|
|
||||||
<Tag
|
|
||||||
viewbinding={this.props.viewbinding}
|
|
||||||
contentbinding={this.setPage}>HD</Tag>
|
|
||||||
</SideBar>
|
</SideBar>
|
||||||
{this.state.data.length !== 0 ?
|
{this.state.data.length !== 0 ?
|
||||||
<VideoContainer
|
<VideoContainer
|
||||||
|
@ -105,11 +105,4 @@ describe('<HomePage/>', function () {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it.skip('test setcontent of homepage', function () {
|
|
||||||
const wrapper = shallow(<HomePage/>);
|
|
||||||
|
|
||||||
wrapper.instance().setPage();
|
|
||||||
// todo finish test
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user