Commit 8280c93b authored by Robert Knight's avatar Robert Knight

Rewrite and better explain config param filtering

Rewrite the config param filtering to make it more obvious what is going
on and extract a couple of helper functions to make the test more
readable.
parent 423e5ce7
...@@ -31,19 +31,19 @@ export default class Host extends Guest { ...@@ -31,19 +31,19 @@ export default class Host extends Guest {
} }
} }
// Make a copy of all config settings except `config.sidebarAppUrl`, the app base URL, // Make a copy of the config for use by the sidebar app with several
// and `config.pluginClasses` // annotator-only properties removed. nb. We don't currently strip all the
const configParam = // annotator-only properties here. That's OK because validation / filtering
'config=' + // happens in the sidebar app itself. It just results in unnecessary content
encodeURIComponent( // in the sidebar iframe's URL string.
JSON.stringify( const sidebarConfig = { ...config };
Object.assign({}, config, { ['sidebarAppUrl', 'pluginClasses'].forEach(
sidebarAppUrl: undefined, key => delete sidebarConfig[key]
pluginClasses: undefined,
})
)
); );
const configParam =
'config=' + encodeURIComponent(JSON.stringify(sidebarConfig));
const sidebarAppSrc = config.sidebarAppUrl + '#' + configParam; const sidebarAppSrc = config.sidebarAppUrl + '#' + configParam;
// Create the iframe // Create the iframe
......
...@@ -97,18 +97,23 @@ describe('Host', () => { ...@@ -97,18 +97,23 @@ describe('Host', () => {
host.publish('panelReady'); host.publish('panelReady');
}); });
function getConfigString(host) {
return host.frame[0].children[0].src;
}
function configFragment(config) {
return '#config=' + encodeURIComponent(JSON.stringify(config));
}
it('passes config to the sidebar iframe', () => { it('passes config to the sidebar iframe', () => {
const appURL = new URL( const appURL = new URL(
'/base/annotator/test/empty.html', '/base/annotator/test/empty.html',
window.location.href window.location.href
); );
const host = createHost({ annotations: '1234' }); const host = createHost({ annotations: '1234' });
const configStr = encodeURIComponent(
JSON.stringify({ annotations: '1234' })
);
assert.equal( assert.equal(
host.frame[0].children[0].src, getConfigString(host),
appURL + '#config=' + configStr appURL + configFragment({ annotations: '1234' })
); );
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment