Files
OpenMediaCenter/src/pages/CategoryPage/CategoryPage.test.js

123 lines
3.4 KiB
JavaScript
Raw Normal View History

import {mount, shallow} from 'enzyme';
import React from 'react';
import CategoryPage from './CategoryPage';
2020-06-12 15:57:30 +00:00
describe('<CategoryPage/>', function () {
it('renders without crashing ', function () {
const wrapper = shallow(<CategoryPage/>);
wrapper.unmount();
});
it('test tag fetch call', done => {
global.fetch = global.prepareFetchApi(['first', 'second']);
2020-06-12 15:57:30 +00:00
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 errored fetch call', done => {
global.fetch = global.prepareFetchApi({});
2020-06-12 15:57:30 +00:00
let message;
global.console.log = jest.fn((m) => {
message = m;
2020-06-17 19:51:02 +02:00
});
2020-06-12 15:57:30 +00:00
shallow(<CategoryPage/>);
2020-06-12 15:57:30 +00:00
expect(global.fetch).toHaveBeenCalledTimes(1);
process.nextTick(() => {
//callback to close window should have called
expect(message).toBe('no connection to backend');
2020-06-12 15:57:30 +00:00
global.fetch.mockClear();
done();
});
});
it('test new tag popup', function () {
const wrapper = mount(<CategoryPage/>);
expect(wrapper.find('NewTagPopup')).toHaveLength(0);
2020-06-12 15:57:30 +00:00
wrapper.find('[data-testid="btnaddtag"]').simulate('click');
// newtagpopup should be showing now
expect(wrapper.find('NewTagPopup')).toHaveLength(1);
2020-06-12 15:57:30 +00:00
// click close button in modal
wrapper.find('.modal-header').find('button').simulate('click');
expect(wrapper.find('NewTagPopup')).toHaveLength(0);
2020-06-12 15:57:30 +00:00
});
it('test setpage callback', done => {
global.fetch = global.prepareFetchApi([{}, {}]);
2020-06-12 15:57:30 +00:00
const wrapper = mount(<CategoryPage/>);
wrapper.setState({
loadedtags: [
{
tag_name: 'testname',
2020-06-12 15:57:30 +00:00
tag_id: 42
}
]
});
wrapper.find('TagPreview').find('div').first().simulate('click');
2020-06-12 15:57:30 +00:00
process.nextTick(() => {
// expect callback to have loaded correct tag
expect(wrapper.state().selected).toBe('testname');
2020-06-12 15:57:30 +00:00
global.fetch.mockClear();
done();
});
});
it('test back to category view callback', function () {
const wrapper = shallow(<CategoryPage/>);
wrapper.setState({
selected: 'test'
2020-06-12 15:57:30 +00:00
});
expect(wrapper.state().selected).not.toBeNull();
wrapper.find('[data-testid="backbtn"]').simulate('click');
2020-06-12 15:57:30 +00:00
expect(wrapper.state().selected).toBeNull();
});
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 = mount(<CategoryPage category='fullhd'/>);
wrapper.instance().loadTag = func;
console.log(wrapper.debug());
expect(func).toBeCalledTimes(0);
wrapper.find('SideBar').find('Tag').forEach(e => {
e.simulate('click');
});
expect(func).toBeCalledTimes(4);
});
2020-06-12 15:57:30 +00:00
});