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,18 +31,18 @@ export default class Host extends Guest {
}
}
// Make a copy of all config settings except `config.sidebarAppUrl`, the app base URL,
// and `config.pluginClasses`
// Make a copy of the config for use by the sidebar app with several
// annotator-only properties removed. nb. We don't currently strip all the
// annotator-only properties here. That's OK because validation / filtering
// happens in the sidebar app itself. It just results in unnecessary content
// in the sidebar iframe's URL string.
const sidebarConfig = { ...config };
['sidebarAppUrl', 'pluginClasses'].forEach(
key => delete sidebarConfig[key]
);
const configParam =
'config=' +
encodeURIComponent(
JSON.stringify(
Object.assign({}, config, {
sidebarAppUrl: undefined,
pluginClasses: undefined,
})
)
);
'config=' + encodeURIComponent(JSON.stringify(sidebarConfig));
const sidebarAppSrc = config.sidebarAppUrl + '#' + configParam;
......
......@@ -97,18 +97,23 @@ describe('Host', () => {
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', () => {
const appURL = new URL(
'/base/annotator/test/empty.html',
window.location.href
);
const host = createHost({ annotations: '1234' });
const configStr = encodeURIComponent(
JSON.stringify({ annotations: '1234' })
);
assert.equal(
host.frame[0].children[0].src,
appURL + '#config=' + configStr
getConfigString(host),
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