2020-10-25 18:48:23 +00:00
|
|
|
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 => {
|
2020-10-25 18:48:23 +00:00
|
|
|
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 => {
|
2020-08-05 17:55:51 +00:00
|
|
|
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
|
|
|
|
2020-08-05 17:55:51 +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
|
2020-10-25 18:48:23 +00:00
|
|
|
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/>);
|
|
|
|
|
2020-10-25 18:48:23 +00:00
|
|
|
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
|
2020-10-25 18:48:23 +00:00
|
|
|
expect(wrapper.find('NewTagPopup')).toHaveLength(1);
|
2020-06-12 15:57:30 +00:00
|
|
|
|
|
|
|
// click close button in modal
|
2020-10-25 18:48:23 +00:00
|
|
|
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 => {
|
2020-08-05 17:55:51 +00:00
|
|
|
global.fetch = global.prepareFetchApi([{}, {}]);
|
2020-06-12 15:57:30 +00:00
|
|
|
|
|
|
|
const wrapper = mount(<CategoryPage/>);
|
|
|
|
|
|
|
|
wrapper.setState({
|
|
|
|
loadedtags: [
|
|
|
|
{
|
2020-10-25 18:48:23 +00:00
|
|
|
tag_name: 'testname',
|
2020-06-12 15:57:30 +00:00
|
|
|
tag_id: 42
|
|
|
|
}
|
|
|
|
]
|
|
|
|
});
|
|
|
|
|
2020-10-25 18:48:23 +00:00
|
|
|
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
|
2020-10-25 18:48:23 +00:00
|
|
|
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({
|
2020-10-25 18:48:23 +00:00
|
|
|
selected: 'test'
|
2020-06-12 15:57:30 +00:00
|
|
|
});
|
|
|
|
expect(wrapper.state().selected).not.toBeNull();
|
2020-10-25 18:48:23 +00:00
|
|
|
wrapper.find('[data-testid="backbtn"]').simulate('click');
|
2020-06-12 15:57:30 +00:00
|
|
|
expect(wrapper.state().selected).toBeNull();
|
|
|
|
});
|
2020-06-24 22:47:46 +02:00
|
|
|
|
|
|
|
it('load categorypage with predefined tag', function () {
|
|
|
|
const func = jest.fn();
|
|
|
|
CategoryPage.prototype.fetchVideoData = func;
|
|
|
|
|
2020-10-19 21:12:07 +00:00
|
|
|
shallow(<CategoryPage category='fullhd'/>);
|
2020-06-24 22:47:46 +02:00
|
|
|
|
|
|
|
expect(func).toBeCalledTimes(1);
|
|
|
|
});
|
2020-07-18 01:10:04 +02:00
|
|
|
|
|
|
|
it('test sidebar tag clicks', function () {
|
|
|
|
const func = jest.fn();
|
|
|
|
|
2020-10-19 21:12:07 +00:00
|
|
|
const wrapper = mount(<CategoryPage category='fullhd'/>);
|
2020-07-18 01:10:04 +02:00
|
|
|
wrapper.instance().loadTag = func;
|
|
|
|
|
|
|
|
console.log(wrapper.debug());
|
|
|
|
|
|
|
|
expect(func).toBeCalledTimes(0);
|
2020-10-25 18:48:23 +00:00
|
|
|
wrapper.find('SideBar').find('Tag').forEach(e => {
|
|
|
|
e.simulate('click');
|
|
|
|
});
|
2020-07-18 01:10:04 +02:00
|
|
|
|
|
|
|
expect(func).toBeCalledTimes(4);
|
|
|
|
|
|
|
|
});
|
2020-06-12 15:57:30 +00:00
|
|
|
});
|