correct naming of Generalinfos and added tests

This commit is contained in:
2020-08-05 22:00:55 +02:00
parent 5970e4d19e
commit f87c02c276
10 changed files with 57 additions and 24 deletions

View File

@ -1,7 +1,7 @@
import React from "react";
import {Button, Col, Form} from "react-bootstrap";
import style from "./GeneralSettings.module.css"
import StaticInfos from "../../GlobalInfos";
import GlobalInfos from "../../GlobalInfos";
class GeneralSettings extends React.Component {
constructor(props) {
@ -38,7 +38,7 @@ class GeneralSettings extends React.Component {
}
render() {
const themeStyle = StaticInfos.getThemeStyle();
const themeStyle = GlobalInfos.getThemeStyle();
return (
<>
<div className={style.GeneralForm + ' ' + themeStyle.subtextcolor}>
@ -96,9 +96,9 @@ class GeneralSettings extends React.Component {
id="custom-switch-3"
data-testid='darktheme-switch'
label="Enable Dark-Theme"
checked={StaticInfos.isDarkTheme()}
checked={GlobalInfos.isDarkTheme()}
onChange={() => {
StaticInfos.enableDarkTheme(!StaticInfos.isDarkTheme());
GlobalInfos.enableDarkTheme(!GlobalInfos.isDarkTheme());
this.forceUpdate();
// todo initiate rerender
}}
@ -128,7 +128,7 @@ class GeneralSettings extends React.Component {
updateRequest.append('tvshowpath', this.state.tvshowpath);
updateRequest.append('mediacentername', this.state.mediacentername);
updateRequest.append("tmdbsupport", this.state.tmdbsupport);
updateRequest.append("darkmodeenabled", StaticInfos.isDarkTheme());
updateRequest.append("darkmodeenabled", GlobalInfos.isDarkTheme());
fetch('/api/Settings.php', {method: 'POST', body: updateRequest})
.then((response) => response.json()

View File

@ -1,6 +1,7 @@
import {shallow} from "enzyme";
import React from "react";
import GeneralSettings from "./GeneralSettings";
import GlobalInfos from "../../GlobalInfos";
function prepareFetchApi(response) {
const mockJsonPromise = Promise.resolve(response);
@ -25,6 +26,15 @@ describe('<GeneralSettings/>', function () {
expect(wrapper.find("[data-testid='passwordfield']")).toHaveLength(1);
});
it('test theme switchbutton', function () {
const wrapper = shallow(<GeneralSettings/>);
GlobalInfos.enableDarkTheme(false);
expect(GlobalInfos.isDarkTheme()).toBe(false);
wrapper.find("[data-testid='darktheme-switch']").simulate("change");
expect(GlobalInfos.isDarkTheme()).toBe(true);
});
it('test savesettings', done => {
const wrapper = shallow(<GeneralSettings/>);

View File

@ -2,7 +2,7 @@ import React from "react";
import MovieSettings from "./MovieSettings";
import GeneralSettings from "./GeneralSettings";
import style from "./SettingsPage.module.css"
import StaticInfos from "../../GlobalInfos";
import GlobalInfos from "../../GlobalInfos";
class SettingsPage extends React.Component {
@ -28,7 +28,7 @@ class SettingsPage extends React.Component {
}
render() {
const themestyle = StaticInfos.getThemeStyle();
const themestyle = GlobalInfos.getThemeStyle();
return (
<div>
<div className={style.SettingsSidebar + ' ' + themestyle.secbackground}>