From b3404f7c5b76cb3f5df3f59a899469a07ccde780 Mon Sep 17 00:00:00 2001 From: Wil Wilsman Date: Tue, 18 Sep 2018 17:38:22 -0500 Subject: [PATCH] Add stripes config mocking ability to tests --- test/bigtest/helpers/setup-application.js | 17 ++++++++++++++--- test/bigtest/helpers/stripes-config.js | 14 +++++++++++++- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/test/bigtest/helpers/setup-application.js b/test/bigtest/helpers/setup-application.js index 398b50759..38094358e 100644 --- a/test/bigtest/helpers/setup-application.js +++ b/test/bigtest/helpers/setup-application.js @@ -9,11 +9,17 @@ import App from '../../../src/App'; import 'typeface-source-sans-pro'; import '@folio/stripes-components/lib/global.css'; -import { withModules, clearModules } from './stripes-config'; +import { + withModules, + clearModules, + withConfig, + clearConfig +} from './stripes-config'; export default function setupApplication({ disableAuth = true, modules = [], + stripesConfig, scenarios } = {}) { beforeEach(async function () { @@ -28,12 +34,17 @@ export default function setupApplication({ this.server = startMirage(scenarios); this.server.logging = false; withModules(modules); + withConfig({ + logCategories: '', + ...stripesConfig + }); }, teardown: () => { - this.server.shutdown(); - localforage.clear(); + clearConfig(); clearModules(); + localforage.clear(); + this.server.shutdown(); } }); diff --git a/test/bigtest/helpers/stripes-config.js b/test/bigtest/helpers/stripes-config.js index 774b6530a..15646e531 100644 --- a/test/bigtest/helpers/stripes-config.js +++ b/test/bigtest/helpers/stripes-config.js @@ -1,5 +1,7 @@ import * as stripes from 'stripes-config'; +const { assign, keys } = Object; + export function withModule({ name, module, @@ -40,7 +42,7 @@ export function withModules(modules) { export function clearModules() { // delete existing modules and metadata - Object.keys(stripes.modules).forEach(type => { + keys(stripes.modules).forEach(type => { stripes.modules[type].forEach(module => { delete stripes.metadata[module.name]; }); @@ -51,3 +53,13 @@ export function clearModules() { // app is required stripes.modules.app = []; } + +const originalConfig = assign({}, stripes.config); + +export function withConfig(config) { + assign(stripes.config, config); +} + +export function clearConfig() { + assign(stripes.config, originalConfig); +}