2020-10-25 18:48:23 +00:00
|
|
|
import {shallow} from 'enzyme';
|
|
|
|
import React from 'react';
|
|
|
|
import GeneralSettings from './GeneralSettings';
|
2020-12-17 20:53:22 +00:00
|
|
|
import GlobalInfos from '../../utils/GlobalInfos';
|
2020-06-25 20:43:26 +00:00
|
|
|
|
|
|
|
describe('<GeneralSettings/>', function () {
|
|
|
|
it('renders without crashing ', function () {
|
|
|
|
const wrapper = shallow(<GeneralSettings/>);
|
|
|
|
wrapper.unmount();
|
|
|
|
});
|
|
|
|
|
2020-07-02 22:20:11 +00:00
|
|
|
it('test password hide/show switchbutton', function () {
|
|
|
|
const wrapper = shallow(<GeneralSettings/>);
|
|
|
|
|
2020-10-25 18:48:23 +00:00
|
|
|
expect(wrapper.find('[data-testid=\'passwordfield\']')).toHaveLength(0);
|
|
|
|
wrapper.find('FormCheck').findWhere(it => it.props().label === 'Enable Password support').simulate('change');
|
2020-07-02 22:20:11 +00:00
|
|
|
|
2020-10-25 18:48:23 +00:00
|
|
|
expect(wrapper.find('[data-testid=\'passwordfield\']')).toHaveLength(1);
|
2020-07-02 22:20:11 +00:00
|
|
|
});
|
2020-07-12 11:12:13 +00:00
|
|
|
|
2020-08-05 20:00:55 +00:00
|
|
|
it('test theme switchbutton', function () {
|
|
|
|
const wrapper = shallow(<GeneralSettings/>);
|
|
|
|
|
|
|
|
GlobalInfos.enableDarkTheme(false);
|
|
|
|
expect(GlobalInfos.isDarkTheme()).toBe(false);
|
2020-10-25 18:48:23 +00:00
|
|
|
wrapper.find('[data-testid=\'darktheme-switch\']').simulate('change');
|
2020-08-05 20:00:55 +00:00
|
|
|
expect(GlobalInfos.isDarkTheme()).toBe(true);
|
|
|
|
});
|
|
|
|
|
2020-07-12 11:12:13 +00:00
|
|
|
it('test savesettings', done => {
|
|
|
|
const wrapper = shallow(<GeneralSettings/>);
|
2020-12-29 19:39:30 +00:00
|
|
|
wrapper.setState({
|
|
|
|
passwordsupport: true,
|
|
|
|
videopath: '',
|
|
|
|
tvshowpath: '',
|
|
|
|
mediacentername: '',
|
|
|
|
tmdbsupport: true
|
|
|
|
});
|
2020-07-12 11:12:13 +00:00
|
|
|
|
2020-08-05 17:55:51 +00:00
|
|
|
global.fetch = global.prepareFetchApi({success: true});
|
2020-07-12 11:12:13 +00:00
|
|
|
|
|
|
|
expect(global.fetch).toBeCalledTimes(0);
|
2020-07-12 22:44:16 +00:00
|
|
|
const fakeEvent = {preventDefault: () => console.log('preventDefault')};
|
2020-10-25 18:48:23 +00:00
|
|
|
wrapper.find('[data-testid=\'mainformsettings\']').simulate('submit', fakeEvent);
|
2020-07-12 11:12:13 +00:00
|
|
|
expect(global.fetch).toBeCalledTimes(1);
|
|
|
|
|
|
|
|
process.nextTick(() => {
|
2020-07-12 22:44:16 +00:00
|
|
|
// todo 2020-07-13: test popup of error success here
|
2020-07-12 11:12:13 +00:00
|
|
|
|
|
|
|
global.fetch.mockClear();
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2020-07-12 22:44:16 +00:00
|
|
|
|
|
|
|
it('test failing savesettings', done => {
|
|
|
|
const wrapper = shallow(<GeneralSettings/>);
|
2020-12-29 19:39:30 +00:00
|
|
|
wrapper.setState({
|
|
|
|
passwordsupport: true,
|
|
|
|
videopath: '',
|
|
|
|
tvshowpath: '',
|
|
|
|
mediacentername: '',
|
|
|
|
tmdbsupport: true
|
|
|
|
});
|
2020-07-12 22:44:16 +00:00
|
|
|
|
2020-08-05 17:55:51 +00:00
|
|
|
global.fetch = global.prepareFetchApi({success: false});
|
2020-07-12 22:44:16 +00:00
|
|
|
|
|
|
|
expect(global.fetch).toBeCalledTimes(0);
|
|
|
|
const fakeEvent = {preventDefault: () => console.log('preventDefault')};
|
2020-10-25 18:48:23 +00:00
|
|
|
wrapper.find('[data-testid=\'mainformsettings\']').simulate('submit', fakeEvent);
|
2020-07-12 22:44:16 +00:00
|
|
|
expect(global.fetch).toBeCalledTimes(1);
|
|
|
|
|
|
|
|
process.nextTick(() => {
|
|
|
|
// todo 2020-07-13: test error popup here!
|
|
|
|
|
|
|
|
global.fetch.mockClear();
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('test videopath change event', function () {
|
|
|
|
const wrapper = shallow(<GeneralSettings/>);
|
|
|
|
|
2021-02-23 16:01:29 +00:00
|
|
|
expect(wrapper.state().generalSettings.VideoPath).not.toBe('test');
|
2020-07-12 22:44:16 +00:00
|
|
|
|
2020-10-25 18:48:23 +00:00
|
|
|
const event = {target: {name: 'pollName', value: 'test'}};
|
|
|
|
wrapper.find('[data-testid=\'videpathform\']').find('FormControl').simulate('change', event);
|
2021-02-23 16:01:29 +00:00
|
|
|
expect(wrapper.state().generalSettings.VideoPath).toBe('test');
|
2020-07-12 22:44:16 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('test tvshowpath change event', function () {
|
|
|
|
const wrapper = shallow(<GeneralSettings/>);
|
|
|
|
|
2020-10-25 18:48:23 +00:00
|
|
|
const event = {target: {name: 'pollName', value: 'test'}};
|
2021-02-23 16:01:29 +00:00
|
|
|
expect(wrapper.state().generalSettings.EpisodePath).not.toBe('test');
|
2020-10-25 18:48:23 +00:00
|
|
|
wrapper.find('[data-testid=\'tvshowpath\']').find('FormControl').simulate('change', event);
|
2021-02-23 16:01:29 +00:00
|
|
|
expect(wrapper.state().generalSettings.EpisodePath).toBe('test');
|
2020-07-12 22:44:16 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('test mediacentername-form change event', function () {
|
|
|
|
const wrapper = shallow(<GeneralSettings/>);
|
|
|
|
|
2020-10-25 18:48:23 +00:00
|
|
|
const event = {target: {name: 'pollName', value: 'test'}};
|
2021-02-23 16:01:29 +00:00
|
|
|
expect(wrapper.state().generalSettings.MediacenterName).not.toBe('test');
|
2020-10-25 18:48:23 +00:00
|
|
|
wrapper.find('[data-testid=\'nameform\']').find('FormControl').simulate('change', event);
|
2021-02-23 16:01:29 +00:00
|
|
|
expect(wrapper.state().generalSettings.MediacenterName).toBe('test');
|
2020-07-12 22:44:16 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('test password-form change event', function () {
|
|
|
|
const wrapper = shallow(<GeneralSettings/>);
|
2021-02-23 16:01:29 +00:00
|
|
|
wrapper.setState({generalSettings : {PasswordEnabled: true}});
|
2020-07-12 22:44:16 +00:00
|
|
|
|
2020-10-25 18:48:23 +00:00
|
|
|
const event = {target: {name: 'pollName', value: 'test'}};
|
2021-02-23 16:01:29 +00:00
|
|
|
expect(wrapper.state().generalSettings.Password).not.toBe('test');
|
2020-10-25 18:48:23 +00:00
|
|
|
wrapper.find('[data-testid=\'passwordfield\']').find('FormControl').simulate('change', event);
|
2021-02-23 16:01:29 +00:00
|
|
|
expect(wrapper.state().generalSettings.Password).toBe('test');
|
2020-07-12 22:44:16 +00:00
|
|
|
});
|
2020-07-17 23:10:04 +00:00
|
|
|
|
|
|
|
it('test tmdbsupport change event', function () {
|
|
|
|
const wrapper = shallow(<GeneralSettings/>);
|
2021-02-23 16:01:29 +00:00
|
|
|
wrapper.setState({generalSettings : {TMDBGrabbing: true}});
|
2020-07-17 23:10:04 +00:00
|
|
|
|
2021-02-23 16:01:29 +00:00
|
|
|
expect(wrapper.state().generalSettings.TMDBGrabbing).toBe(true);
|
2020-10-25 18:48:23 +00:00
|
|
|
wrapper.find('[data-testid=\'tmdb-switch\']').simulate('change');
|
2021-02-23 16:01:29 +00:00
|
|
|
expect(wrapper.state().generalSettings.TMDBGrabbing).toBe(false);
|
2020-07-17 23:10:04 +00:00
|
|
|
});
|
2020-10-19 21:12:07 +00:00
|
|
|
|
|
|
|
it('test insertion of 4 infoheaderitems', function () {
|
|
|
|
const wrapper = shallow(<GeneralSettings/>);
|
2020-10-25 18:48:23 +00:00
|
|
|
expect(wrapper.find('InfoHeaderItem').length).toBe(4);
|
2020-10-19 21:12:07 +00:00
|
|
|
});
|
2020-06-25 20:43:26 +00:00
|
|
|
});
|