diff --git a/src/pages/CategoryPage/CategoryPage.js b/src/pages/CategoryPage/CategoryPage.js index d6568d1..59d37f8 100644 --- a/src/pages/CategoryPage/CategoryPage.js +++ b/src/pages/CategoryPage/CategoryPage.js @@ -35,10 +35,26 @@ class CategoryPage extends React.Component {
Default Tags:
- All - FullHd - LowQuality - HD + { + this.loadTag(e.props.category) + } + }}>All + { + this.loadTag(e.props.category) + } + }}>FullHd + { + this.loadTag(e.props.category) + } + }}>LowQuality + { + this.loadTag(e.props.category) + } + }}>HD
- {!this.state.selected ? - (
+ {this.state.selected ? + <> + {this.videodata ? + : null} + + : +
{this.state.loadedtags ? this.state.loadedtags.map((m) => ( )) : "loading"} -
) : - <> - {this.selectionelements ? this.selectionelements : null} - - +
} {this.state.popupvisible ? @@ -81,8 +100,6 @@ class CategoryPage extends React.Component { } loadTag = (tagname) => { - // this.selectionelements = element; - // this.setState({selected: null}); // todo save this change trigger better this.fetchVideoData(tagname); }; @@ -98,10 +115,8 @@ class CategoryPage extends React.Component { fetch('/api/videoload.php', {method: 'POST', body: updateRequest}) .then((response) => response.json() .then((result) => { - this.selectionelements = - ; + this.videodata = result; + this.setState({selected: null}); // needed to trigger the state reload correctly this.setState({selected: tag}); })) .catch(() => { @@ -111,6 +126,7 @@ class CategoryPage extends React.Component { loadCategoryPageDefault = () => { this.setState({selected: null}); + this.loadTags(); }; /** diff --git a/src/pages/CategoryPage/CategoryPage.test.js b/src/pages/CategoryPage/CategoryPage.test.js index 9a50b09..1821c1e 100644 --- a/src/pages/CategoryPage/CategoryPage.test.js +++ b/src/pages/CategoryPage/CategoryPage.test.js @@ -86,8 +86,6 @@ describe('', function () { process.nextTick(() => { // expect callback to have loaded correct tag expect(wrapper.state().selected).toBe("testname"); - // expect to receive a videocontainer with simulated data - expect(wrapper.instance().selectionelements).toMatchObject(); global.fetch.mockClear(); done(); @@ -104,4 +102,13 @@ describe('', function () { wrapper.find('[data-testid="backbtn"]').simulate("click"); expect(wrapper.state().selected).toBeNull(); }); + + it('load categorypage with predefined tag', function () { + const func = jest.fn(); + CategoryPage.prototype.fetchVideoData = func; + + const wrapper = shallow(); + + expect(func).toBeCalledTimes(1); + }); }); diff --git a/src/pages/HomePage/HomePage.js b/src/pages/HomePage/HomePage.js index 727ca81..d95a511 100644 --- a/src/pages/HomePage/HomePage.js +++ b/src/pages/HomePage/HomePage.js @@ -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() { return (
@@ -152,18 +146,10 @@ class HomePage extends React.Component {
{this.state.sideinfo.tagnr} different Tags!

Default Tags:
- All - FullHd - LowQuality - HD + All + FullHd + LowQuality + HD {this.state.data.length !== 0 ? ', function () { done(); }); }); - - it.skip('test setcontent of homepage', function () { - const wrapper = shallow(); - - wrapper.instance().setPage(); - // todo finish test - }); });