2020-06-09 18:10:26 +00:00
|
|
|
import React from 'react';
|
|
|
|
import App from './App';
|
2020-06-10 13:41:41 +00:00
|
|
|
import {shallow} from 'enzyme'
|
2020-06-09 18:10:26 +00:00
|
|
|
|
|
|
|
describe('<App/>', function () {
|
2020-06-12 15:57:30 +00:00
|
|
|
it('renders without crashing ', function () {
|
|
|
|
const wrapper = shallow(<App/>);
|
|
|
|
wrapper.unmount();
|
|
|
|
});
|
2020-06-09 18:10:26 +00:00
|
|
|
|
2020-06-12 15:57:30 +00:00
|
|
|
it('renders title', () => {
|
|
|
|
const wrapper = shallow(<App/>);
|
2020-08-02 17:55:06 +00:00
|
|
|
expect(wrapper.find('.navbrand').text()).toBe('OpenMediaCenter');
|
2020-06-12 15:57:30 +00:00
|
|
|
});
|
2020-06-09 18:10:26 +00:00
|
|
|
|
2020-06-12 15:57:30 +00:00
|
|
|
it('are navlinks correct', function () {
|
|
|
|
const wrapper = shallow(<App/>);
|
2020-08-02 17:55:06 +00:00
|
|
|
expect(wrapper.find('.navitem')).toHaveLength(4);
|
2020-06-12 15:57:30 +00:00
|
|
|
});
|
2020-06-18 17:42:42 +00:00
|
|
|
|
|
|
|
it('simulate video view change ', function () {
|
|
|
|
const wrapper = shallow(<App/>);
|
2020-07-13 20:56:43 +00:00
|
|
|
wrapper.setState({generalSettingsLoaded: true}); // simulate fetch to have already finisheed
|
2020-06-18 17:42:42 +00:00
|
|
|
|
2020-08-02 17:55:06 +00:00
|
|
|
wrapper.instance().changeRootElement(<div id='testit'/>);
|
2020-06-18 17:42:42 +00:00
|
|
|
|
|
|
|
expect(wrapper.find("#testit")).toHaveLength(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('test hide video again', function () {
|
|
|
|
const wrapper = shallow(<App/>);
|
2020-07-13 20:56:43 +00:00
|
|
|
wrapper.setState({generalSettingsLoaded: true}); // simulate fetch to have already finisheed
|
2020-06-18 17:42:42 +00:00
|
|
|
|
2020-08-02 17:55:06 +00:00
|
|
|
wrapper.instance().changeRootElement(<div id='testit'/>);
|
2020-06-18 17:42:42 +00:00
|
|
|
|
|
|
|
expect(wrapper.find("#testit")).toHaveLength(1);
|
|
|
|
|
2020-06-21 21:08:46 +00:00
|
|
|
wrapper.instance().returnToLastElement();
|
2020-06-18 17:42:42 +00:00
|
|
|
|
|
|
|
expect(wrapper.find("HomePage")).toHaveLength(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('test fallback to last loaded page', function () {
|
|
|
|
const wrapper = shallow(<App/>);
|
2020-07-13 20:56:43 +00:00
|
|
|
wrapper.setState({generalSettingsLoaded: true}); // simulate fetch to have already finisheed
|
2020-06-18 17:42:42 +00:00
|
|
|
|
2020-08-02 17:55:06 +00:00
|
|
|
wrapper.find(".navitem").findWhere(t => t.text() === "Random Video" && t.type() === "div").simulate("click");
|
2020-06-18 17:42:42 +00:00
|
|
|
|
2020-08-02 17:55:06 +00:00
|
|
|
wrapper.instance().changeRootElement(<div id='testit'/>);
|
2020-06-18 17:42:42 +00:00
|
|
|
|
|
|
|
expect(wrapper.find("#testit")).toHaveLength(1);
|
|
|
|
|
2020-06-21 21:08:46 +00:00
|
|
|
wrapper.instance().returnToLastElement();
|
2020-06-18 17:42:42 +00:00
|
|
|
|
|
|
|
expect(wrapper.find("RandomPage")).toHaveLength(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('test home click', function () {
|
|
|
|
const wrapper = shallow(<App/>);
|
2020-07-13 20:56:43 +00:00
|
|
|
wrapper.setState({generalSettingsLoaded: true}); // simulate fetch to have already finisheed
|
|
|
|
|
2020-06-18 17:42:42 +00:00
|
|
|
wrapper.setState({page: "wrongvalue"});
|
|
|
|
expect(wrapper.find("HomePage")).toHaveLength(0);
|
2020-08-02 17:55:06 +00:00
|
|
|
wrapper.find(".navitem").findWhere(t => t.text() === "Home" && t.type() === "div").simulate("click");
|
2020-06-18 17:42:42 +00:00
|
|
|
expect(wrapper.find("HomePage")).toHaveLength(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('test category click', function () {
|
|
|
|
const wrapper = shallow(<App/>);
|
2020-07-13 20:56:43 +00:00
|
|
|
wrapper.setState({generalSettingsLoaded: true}); // simulate fetch to have already finisheed
|
2020-06-18 17:42:42 +00:00
|
|
|
|
|
|
|
expect(wrapper.find("CategoryPage")).toHaveLength(0);
|
2020-08-02 17:55:06 +00:00
|
|
|
wrapper.find(".navitem").findWhere(t => t.text() === "Categories" && t.type() === "div").simulate("click");
|
2020-06-18 17:42:42 +00:00
|
|
|
expect(wrapper.find("CategoryPage")).toHaveLength(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('test settings click', function () {
|
|
|
|
const wrapper = shallow(<App/>);
|
2020-07-13 20:56:43 +00:00
|
|
|
wrapper.setState({generalSettingsLoaded: true}); // simulate fetch to have already finisheed
|
2020-06-18 17:42:42 +00:00
|
|
|
|
|
|
|
expect(wrapper.find("SettingsPage")).toHaveLength(0);
|
2020-08-02 17:55:06 +00:00
|
|
|
wrapper.find(".navitem").findWhere(t => t.text() === "Settings" && t.type() === "div").simulate("click");
|
2020-06-18 17:42:42 +00:00
|
|
|
expect(wrapper.find("SettingsPage")).toHaveLength(1);
|
|
|
|
});
|
2020-07-15 18:08:22 +00:00
|
|
|
|
|
|
|
it('test initial fetch from api', done => {
|
2020-08-05 17:55:51 +00:00
|
|
|
global.fetch = global.prepareFetchApi({
|
2020-07-15 18:08:22 +00:00
|
|
|
generalSettingsLoaded: true,
|
|
|
|
passwordsupport: true,
|
|
|
|
mediacentername: "testname"
|
|
|
|
});
|
|
|
|
|
|
|
|
const wrapper = shallow(<App/>);
|
|
|
|
|
2020-07-16 17:13:54 +00:00
|
|
|
|
|
|
|
const func = jest.fn();
|
|
|
|
wrapper.instance().setState = func;
|
|
|
|
|
2020-07-15 18:08:22 +00:00
|
|
|
expect(global.fetch).toBeCalledTimes(1);
|
|
|
|
|
|
|
|
process.nextTick(() => {
|
2020-07-16 17:13:54 +00:00
|
|
|
expect(func).toBeCalledTimes(1);
|
2020-07-15 18:08:22 +00:00
|
|
|
|
|
|
|
global.fetch.mockClear();
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2020-06-09 18:10:26 +00:00
|
|
|
});
|