Skip to content

Commit

Permalink
Tests for app reducers
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-tavares committed Jan 3, 2020
1 parent 3c639b2 commit 37147e1
Showing 1 changed file with 58 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { coreMock } from '../../../../../../../../src/core/public/mocks';
import { createStore, Store } from 'redux';
import { endpointAppReducers, GlobalState } from './index';
import { AppDispatch } from '../actions/app';

describe('app Reducers', () => {
const objectThatLooksLikeAppState = expect.objectContaining({
appBasePath: expect.stringMatching('/some/path'),
coreStartServices: expect.objectContaining({
application: expect.anything(),
chrome: expect.anything(),
docLinks: expect.anything(),
http: expect.anything(),
i18n: expect.anything(),
notifications: expect.anything(),
overlays: expect.anything(),
uiSettings: expect.anything(),
savedObjects: expect.anything(),
injectedMetadata: expect.anything(),
}),
});

let store: Store<GlobalState>;
let dispatch: AppDispatch;

beforeEach(() => {
store = createStore(endpointAppReducers);
dispatch = store.dispatch;
dispatch({
type: 'appWillMount',
payload: {
appBasePath: '/some/path',
coreStartServices: coreMock.createStart({ basePath: '/some/path' }),
},
});
});

test('it stores kibana start/mount data on `appWillMount`', () => {
expect(store.getState().app).toEqual(objectThatLooksLikeAppState);
});

test('it resets the store on `appDidUnmount`', () => {
dispatch({
type: 'appDidUnmount',
});

expect(store.getState().app).toEqual({
appBasePath: '',
coreStartServices: null,
});
});
});

0 comments on commit 37147e1

Please sign in to comment.