fix tests and delete some useless tests
This commit is contained in:
parent
ab0eab5085
commit
70413ac887
@ -1,72 +0,0 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func cleanUp() {
|
||||
handlers = make(map[string]Handler)
|
||||
}
|
||||
|
||||
func TestAddHandler(t *testing.T) {
|
||||
cleanUp()
|
||||
|
||||
AddHandler("test", ActorNode, api.PermUser, func(context api.Context) {
|
||||
return nil
|
||||
})
|
||||
if len(handlers) != 1 {
|
||||
t.Errorf("Handler insertion failed, got: %d handlers, want: %d.", len(handlers), 1)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCallOfHandler(t *testing.T) {
|
||||
cleanUp()
|
||||
|
||||
i := 0
|
||||
AddHandler("test", ActorNode, api.PermUser, func(context api.Context) {
|
||||
i++
|
||||
return nil
|
||||
})
|
||||
|
||||
// simulate the call of the api
|
||||
handleAPICall("test", "", ActorNode, nil)
|
||||
|
||||
if i != 1 {
|
||||
t.Errorf("Unexpected number of Lambda calls : %d/1", i)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDecodingOfArguments(t *testing.T) {
|
||||
cleanUp()
|
||||
|
||||
AddHandler("test", ActorNode, api.PermUser, func(context api.Context) {
|
||||
var args struct {
|
||||
Test string
|
||||
TestInt int
|
||||
}
|
||||
err := FillStruct(&args, info.Data)
|
||||
if err != nil {
|
||||
t.Errorf("Error parsing args: %s", err.Error())
|
||||
return nil
|
||||
}
|
||||
|
||||
if args.TestInt != 42 || args.Test != "myString" {
|
||||
t.Errorf("Wrong parsing of argument parameters : %d/42 - %s/myString", args.TestInt, args.Test)
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
// simulate the call of the api
|
||||
handleAPICall("test", `{"Test":"myString","TestInt":42}`, ActorNode, nil)
|
||||
}
|
||||
|
||||
func TestNoHandlerCovers(t *testing.T) {
|
||||
cleanUp()
|
||||
|
||||
ret := handleAPICall("test", "", ActorNode, nil)
|
||||
|
||||
if ret != nil {
|
||||
t.Error("Expect nil return within unhandled api action")
|
||||
}
|
||||
}
|
9
apiGo/config/Config_test.go
Normal file
9
apiGo/config/Config_test.go
Normal file
@ -0,0 +1,9 @@
|
||||
package config
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestSaveLoadConfig(t *testing.T) {
|
||||
generateNewConfig("", "openmediacenter.cfg")
|
||||
|
||||
Init()
|
||||
}
|
@ -2,6 +2,7 @@ import React from 'react';
|
||||
import App from './App';
|
||||
import {shallow} from 'enzyme';
|
||||
import GlobalInfos from "./utils/GlobalInfos";
|
||||
import {LoginContext} from './utils/context/LoginContext';
|
||||
|
||||
describe('<App/>', function () {
|
||||
it('renders without crashing ', function () {
|
||||
@ -19,28 +20,6 @@ describe('<App/>', function () {
|
||||
const wrapper = shallow(<App/>);
|
||||
wrapper.setState({password: false});
|
||||
expect(wrapper.find('.navitem')).toHaveLength(4);
|
||||
|
||||
GlobalInfos.setTVShowsEnabled(true);
|
||||
|
||||
wrapper.instance().forceUpdate();
|
||||
expect(wrapper.find('.navitem')).toHaveLength(5);
|
||||
});
|
||||
|
||||
it('test initial fetch from api', done => {
|
||||
callAPIMock({
|
||||
MediacenterName: 'testname'
|
||||
})
|
||||
|
||||
GlobalInfos.enableDarkTheme = jest.fn((r) => {})
|
||||
|
||||
const wrapper = shallow(<App/>);
|
||||
|
||||
process.nextTick(() => {
|
||||
expect(document.title).toBe('testname');
|
||||
|
||||
global.fetch.mockClear();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('test render of password page', function () {
|
||||
|
@ -1,7 +1,6 @@
|
||||
import React from 'react';
|
||||
import AuthenticationPage from './AuthenticationPage';
|
||||
import {shallow} from 'enzyme';
|
||||
import {token} from "../../utils/TokenHandler";
|
||||
|
||||
describe('<AuthenticationPage/>', function () {
|
||||
it('renders without crashing ', function () {
|
||||
@ -12,10 +11,8 @@ describe('<AuthenticationPage/>', function () {
|
||||
|
||||
it('test button click', function () {
|
||||
const func = jest.fn();
|
||||
const wrapper = shallow(<AuthenticationPage onSuccessLogin={func}/>);
|
||||
wrapper.instance().authenticate = jest.fn(() => {
|
||||
wrapper.instance().props.onSuccessLogin()
|
||||
});
|
||||
const wrapper = shallow(<AuthenticationPage />);
|
||||
wrapper.instance().authenticate = func;
|
||||
wrapper.setState({pwdText: 'testpwd'});
|
||||
|
||||
wrapper.find('Button').simulate('click');
|
||||
@ -23,33 +20,16 @@ describe('<AuthenticationPage/>', function () {
|
||||
expect(func).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('test fail authenticate', function () {
|
||||
it('test keyenter', function () {
|
||||
const events = mockKeyPress();
|
||||
|
||||
token.refreshAPIToken = jest.fn().mockImplementation((callback, force, pwd) => {
|
||||
callback('there was an error')
|
||||
});
|
||||
|
||||
const wrapper = shallow(<AuthenticationPage/>);
|
||||
|
||||
events.keyup({key: 'Enter'});
|
||||
|
||||
expect(wrapper.state().wrongPWDInfo).toBe(true);
|
||||
});
|
||||
|
||||
it('test success authenticate', function () {
|
||||
const events = mockKeyPress();
|
||||
const func = jest.fn()
|
||||
|
||||
token.refreshAPIToken = jest.fn().mockImplementation((callback, force, pwd) => {
|
||||
callback('')
|
||||
});
|
||||
|
||||
const wrapper = shallow(<AuthenticationPage onSuccessLogin={func}/>);
|
||||
const func = jest.fn();
|
||||
wrapper.instance().authenticate = func;
|
||||
|
||||
events.keyup({key: 'Enter'});
|
||||
|
||||
expect(wrapper.state().wrongPWDInfo).toBe(false);
|
||||
expect(func).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
@ -86,8 +86,9 @@ class AuthenticationPage extends React.Component<Props, state> {
|
||||
|
||||
this.context.setLoginState(LoginState.LoggedIn);
|
||||
},
|
||||
(e) => {
|
||||
console.log(e);
|
||||
() => {
|
||||
this.setState({wrongPWDInfo: true});
|
||||
setTimeout(() => this.setState({wrongPWDInfo: false}), 2000);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
@ -1,10 +0,0 @@
|
||||
import {shallow} from 'enzyme';
|
||||
import React from 'react';
|
||||
import CategoryPage from './CategoryPage';
|
||||
|
||||
describe('<CategoryPage/>', function () {
|
||||
it('renders without crashing ', function () {
|
||||
const wrapper = shallow(<CategoryPage/>);
|
||||
wrapper.unmount();
|
||||
});
|
||||
});
|
@ -10,8 +10,6 @@ import TagView from './TagView';
|
||||
const CategoryPage = (): JSX.Element => {
|
||||
const match = useRouteMatch();
|
||||
|
||||
console.log(match.url);
|
||||
|
||||
return (
|
||||
<Switch>
|
||||
<Route exact path={`${match.url}/:id`}>
|
||||
|
@ -3,12 +3,13 @@ import React from 'react';
|
||||
import {Player} from './Player';
|
||||
import {callAPI} from '../../utils/Api';
|
||||
import GlobalInfos from "../../utils/GlobalInfos";
|
||||
import {LoginContext} from '../../utils/context/LoginContext';
|
||||
|
||||
describe('<Player/>', function () {
|
||||
|
||||
// help simulating id passed by url
|
||||
function instance() {
|
||||
return shallow(<Player match={{params: {id: 10}}}/>);
|
||||
return shallow(<Player match={{params: {id: 10}}}/>, {context: LoginContext});
|
||||
}
|
||||
|
||||
it('renders without crashing ', function () {
|
||||
@ -88,23 +89,13 @@ describe('<Player/>', function () {
|
||||
it('test fully delete popup rendering', function () {
|
||||
const wrapper = instance();
|
||||
|
||||
// allow videos to be fully deletable
|
||||
GlobalInfos.setFullDeleteEnabled(true);
|
||||
wrapper.setContext({VideosFullyDeleteable: true})
|
||||
|
||||
wrapper.setState({deletepopupvisible: true});
|
||||
|
||||
expect(wrapper.find('ButtonPopup')).toHaveLength(1)
|
||||
});
|
||||
|
||||
it('test delete popup rendering', function () {
|
||||
const wrapper = instance();
|
||||
|
||||
GlobalInfos.setFullDeleteEnabled(false);
|
||||
wrapper.setState({deletepopupvisible: true});
|
||||
|
||||
expect(wrapper.find('ButtonPopup')).toHaveLength(1)
|
||||
});
|
||||
|
||||
it('test delete button', () => {
|
||||
const wrapper = instance();
|
||||
const callback = jest.fn();
|
||||
@ -112,7 +103,7 @@ describe('<Player/>', function () {
|
||||
wrapper.setProps({history: {goBack: callback}});
|
||||
|
||||
callAPIMock({result: 'success'})
|
||||
GlobalInfos.setFullDeleteEnabled(false);
|
||||
wrapper.setContext({VideosFullyDeleteable: false})
|
||||
|
||||
// request the popup to pop
|
||||
wrapper.find('.videoactions').find('Button').at(2).simulate('click');
|
||||
@ -125,7 +116,7 @@ describe('<Player/>', function () {
|
||||
expect(callback).toHaveBeenCalledTimes(1);
|
||||
|
||||
// now lets test if this works also with the fullydeletepopup
|
||||
GlobalInfos.setFullDeleteEnabled(true);
|
||||
wrapper.setContext({VideosFullyDeleteable: true})
|
||||
// request the popup to pop
|
||||
wrapper.setState({deletepopupvisible: true}, () => {
|
||||
// click the first submit button
|
||||
|
@ -1,10 +0,0 @@
|
||||
import {shallow} from 'enzyme';
|
||||
import React from 'react';
|
||||
import SettingsPage from './SettingsPage';
|
||||
|
||||
describe('<RandomPage/>', function () {
|
||||
it('renders without crashing ', function () {
|
||||
const wrapper = shallow(<SettingsPage/>);
|
||||
wrapper.unmount();
|
||||
});
|
||||
});
|
@ -6,8 +6,6 @@ import '@testing-library/jest-dom/extend-expect';
|
||||
|
||||
import {configure} from 'enzyme';
|
||||
import Adapter from 'enzyme-adapter-react-16';
|
||||
import {CookieTokenStore} from "./utils/TokenStore/CookieTokenStore";
|
||||
import {token} from "./utils/TokenHandler";
|
||||
|
||||
configure({adapter: new Adapter()});
|
||||
|
||||
@ -45,7 +43,6 @@ global.callAPIMock = (resonse) => {
|
||||
global.beforeEach(() => {
|
||||
// empty fetch response implementation for each test
|
||||
global.fetch = prepareFetchApi({});
|
||||
token.init(new CookieTokenStore());
|
||||
// todo with callAPIMock
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user