diff --git a/src/App.js b/src/App.js index 65e6daa2f..f1a7090ee 100644 --- a/src/App.js +++ b/src/App.js @@ -1,6 +1,7 @@ import React, { Component } from 'react'; import PropTypes from 'prop-types'; import { okapi as okapiConfig, config } from 'stripes-config'; +import merge from 'lodash/merge'; import connectErrorEpic from './connectErrorEpic'; import configureEpics from './configureEpics'; @@ -13,7 +14,8 @@ import Root from './components/Root'; export default class StripesCore extends Component { static propTypes = { - history: PropTypes.object + history: PropTypes.object, + initialState: PropTypes.object }; constructor(props) { @@ -22,17 +24,23 @@ export default class StripesCore extends Component { const okapi = (typeof okapiConfig === 'object' && Object.keys(okapiConfig).length > 0) ? okapiConfig : { withoutOkapi: true }; + const initialState = merge({}, { okapi }, props.initialState); + this.logger = configureLogger(config); this.logger.log('core', 'Starting Stripes ...'); this.epics = configureEpics(connectErrorEpic); - this.store = configureStore({ okapi }, this.logger, this.epics); + this.store = configureStore(initialState, this.logger, this.epics); if (!okapi.withoutOkapi) discoverServices(this.store); this.actionNames = gatherActions(); } render() { + // no need to pass along `initialState` + // eslint-disable-next-line no-unused-vars + const { initialState, ...props } = this.props; + return ( ); } diff --git a/test/bigtest/helpers/setup-application.js b/test/bigtest/helpers/setup-application.js index acc40549a..ad81367bf 100644 --- a/test/bigtest/helpers/setup-application.js +++ b/test/bigtest/helpers/setup-application.js @@ -23,16 +23,37 @@ export default function setupApplication({ disableAuth = true, modules = [], translations = {}, + permissions = {}, stripesConfig, mirageOptions, scenarios } = {}) { beforeEach(async function () { + const initialState = {}; + + // when auth is disabled, add a fake user to the store + if (disableAuth) { + initialState.okapi = { + token: 'test', + currentUser: { + id: 'test', + username: 'testuser', + firstName: 'Test', + lastName: 'User', + email: 'user@folio.org', + addresses: [], + servicePoints: [] + }, + currentPerms: permissions + }; + } + + // mount the app this.app = await setupAppForTesting(App, { mountId: 'testing-root', props: { - disableAuth + initialState }, setup: () => {