Skip to content

Commit

Permalink
Add stripes translations mocking ability to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Wil Wilsman committed Sep 19, 2018
1 parent b3404f7 commit c555329
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
4 changes: 4 additions & 0 deletions test/bigtest/helpers/setup-application.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ import {
withConfig,
clearConfig
} from './stripes-config';
import withTranslations from './translations';

export default function setupApplication({
disableAuth = true,
modules = [],
translations = {},
stripesConfig,
scenarios
} = {}) {
Expand All @@ -33,6 +35,8 @@ export default function setupApplication({
setup: () => {
this.server = startMirage(scenarios);
this.server.logging = false;

withTranslations(this.server, translations);
withModules(modules);
withConfig({
logCategories: '',
Expand Down
29 changes: 29 additions & 0 deletions test/bigtest/helpers/translations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import componentTranslations from '@folio/stripes-components/translations/stripes-components/en';
import coreTranslations from '../../../translations/stripes-core/en';

const { keys, assign } = Object;

function prefixKeys(pre, obj) {
return keys(obj).reduce((memo, key) => {
return assign(memo, { [`${pre}.${key}`]: obj[key] });
}, {});
}

const defaultTranslations = {
en: {
...prefixKeys('stripes-core', coreTranslations),
...prefixKeys('stripes-components', componentTranslations)
}
};

export default function withTranslations(server, translations = {}) {
// eslint-disable-next-line
server.pretender.get(`${__webpack_public_path__}translations/:file`, req => {
const [lang] = req.params.file.split('-');

return [200, {}, JSON.stringify({
...defaultTranslations[lang] || {},
...translations[lang] || {}
})];
});
}
9 changes: 7 additions & 2 deletions test/bigtest/tests/nav-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,16 @@ describe('Nav', () => {
modules: [{
type: 'app',
name: '@folio/ui-dummy',
displayName: 'Dummy',
displayName: 'dummy.title',
route: '/dummy',
hasSettings: true,
module: DummyApp
}]
}],
translations: {
en: {
'dummy.title': 'Dummy'
}
}
});

it('shows a settings button', () => {
Expand Down

0 comments on commit c555329

Please sign in to comment.