Skip to content

Commit

Permalink
Merge pull request #81 from ProjectMirador/config-pattern
Browse files Browse the repository at this point in the history
Adds the ability to add and update configuration/settings
  • Loading branch information
aeschylus authored Dec 12, 2018
2 parents 3348150 + 083a096 commit 20436d4
Show file tree
Hide file tree
Showing 11 changed files with 399 additions and 150 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* global miradorInstance */

describe('Config updating from instance', () => {
beforeAll(async () => {
await page.goto('http://127.0.0.1:4488/__tests__/integration/mirador/');
});
it('can modify the config via api', async () => {
await page.evaluate(() => {
const a = miradorInstance.actions.updateConfig({ foo: 'bat' });
miradorInstance.store.dispatch(a);
});
const config = await page.evaluate(() => (
miradorInstance.store.getState().config
));
await expect(config.foo).toBe('bat');
});
});
2 changes: 1 addition & 1 deletion minimal_redux_poc/__tests__/integration/mirador/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<div id="mirador"></div>
<script>document.write("<script type='text/javascript' src='../../../dist/mirador.min.js?v=" + Date.now() + "'><\/script>");</script>
<script type="text/javascript">
Mirador({
var miradorInstance = Mirador({
id: 'mirador',
plugins: ['HelloWorld']
});
Expand Down
42 changes: 42 additions & 0 deletions minimal_redux_poc/__tests__/src/reducers/config.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import reducer from '../../../src/reducers/config';
import ActionTypes from '../../../src/action-types';

describe('config reducer', () => {
describe('SET_CONFIG', () => {
it('should handle SET_CONFIG', () => {
expect(reducer({}, {
type: ActionTypes.SET_CONFIG,
config: { manifestVersion: 'v3' },
})).toEqual({
manifestVersion: 'v3',
});
});
it('does not deep merge', () => {
expect(reducer({ stuff: { foo: 'bar' } }, {
type: ActionTypes.SET_CONFIG,
config: { stuff: { foo: 'bat' } },
})).toEqual({
stuff: { foo: 'bat' },
});
});
});
describe('UPDATE_CONFIG', () => {
it('should handle UPDATE_CONFIG', () => {
expect(reducer({}, {
type: ActionTypes.UPDATE_CONFIG,
config: { manifestVersion: 'v3' },
})).toEqual({
manifestVersion: 'v3',
});
});
it('does a deep merge', () => {
expect(reducer({ stuff: { foo: 'bar' }, hello: 'world' }, {
type: ActionTypes.UPDATE_CONFIG,
config: { stuff: { foo: 'bat' } },
})).toEqual({
stuff: { foo: 'bat' },
hello: 'world',
});
});
});
});
Loading

0 comments on commit 20436d4

Please sign in to comment.