Commit 4b36eaf9 authored by Robert Knight's avatar Robert Knight

Add client version and host URL to config passed to sidebar app

 - Add the client version to the config so that we can rule out problems
   in the sidebar app because caused by a mismatch between the version
   of the client used in the annotator and the version used in the
   sidebar app.

 - Add the host URL to the config so that we can tell in Sentry reports
   which page embedded the client. Sentry reports currently have
   `document_url` metadata that is set using `document.referrer` in the
   sidebar app, but this gets truncated to the origin in some browsers.
parent 8e47fb13
......@@ -3,7 +3,7 @@ import { mount } from 'enzyme';
import { addConfigFragment } from '../../../shared/config-fragment';
import { EventBus } from '../../util/emitter';
import NotebookModal from '../NotebookModal';
import NotebookModal, { $imports } from '../NotebookModal';
describe('NotebookModal', () => {
const notebookURL = 'https://test.hypothes.is/notebook';
......@@ -27,10 +27,21 @@ describe('NotebookModal', () => {
components = [];
eventBus = new EventBus();
emitter = eventBus.createEmitter();
const fakeCreateAppConfig = sinon.spy(config => {
const appConfig = { ...config };
delete appConfig.notebookAppUrl;
return appConfig;
});
$imports.$mock({
'../config/app': { createAppConfig: fakeCreateAppConfig },
});
});
afterEach(() => {
components.forEach(component => component.unmount());
$imports.$restore();
});
it('hides modal on first render', () => {
......
......@@ -29,6 +29,15 @@ export function createAppConfig(config) {
appConfig[key] = value;
}
// Pass the version of the client, so we can check if it is the same as the
// one used in the sidebar/notebook.
appConfig.version = '__VERSION__';
// Pass the URL of the page that embedded the client.
const hostURL = new URL(window.location.href);
hostURL.hash = '';
appConfig.hostURL = hostURL.toString();
// Some config settings are not JSON-stringifiable (e.g. JavaScript
// functions) and will be omitted when the config is JSON-stringified.
// Add a JSON-stringifiable option for each of these so that the sidebar can
......
import { createAppConfig } from '../app';
describe('createAppConfig', () => {
/**
* Filter configuration generated by `createAppConfig` to remove properties
* which are always added regardless of the input.
*/
function filterConfig(config) {
return Object.fromEntries(
Object.entries(config).filter(
([key]) => key !== 'hostURL' && key !== 'version'
)
);
}
it('copies config values', () => {
const config = {
showHighlights: true,
appType: 'via',
};
const sidebarConfig = createAppConfig(config);
const sidebarConfig = filterConfig(createAppConfig(config));
assert.deepEqual(sidebarConfig, {
showHighlights: true,
......@@ -21,7 +33,7 @@ describe('createAppConfig', () => {
notebookAppUrl: 'https://hypothes.is/notebook.html',
sidebarAppUrl: 'https://hypothes.is/app.html',
};
const sidebarConfig = createAppConfig(config);
const sidebarConfig = filterConfig(createAppConfig(config));
assert.deepEqual(sidebarConfig, {
showHighlights: true,
});
......@@ -34,11 +46,21 @@ describe('createAppConfig', () => {
notNullValue: 'test',
};
const appConfig = createAppConfig(config);
const appConfig = filterConfig(createAppConfig(config));
assert.deepEqual(appConfig, { notNullValue: 'test' });
});
it('adds client version to configuration', () => {
const config = createAppConfig({});
assert.equal(config.version, '1.0.0-dummy-version');
});
it('adds host URL to configuration', () => {
const config = createAppConfig({});
assert.equal(config.hostURL, window.location.href);
});
it('sets boolean properties to indicate presence of callbacks', () => {
const callbacks = [
'onLoginRequest',
......
......@@ -110,9 +110,16 @@ describe('Sidebar', () => {
};
FakeToolbarController = sinon.stub().returns(fakeToolbar);
const fakeCreateAppConfig = sinon.spy(config => {
const appConfig = { ...config };
delete appConfig.sidebarAppUrl;
return appConfig;
});
$imports.$mock({
'../shared/bridge': { Bridge: sinon.stub().returns(fakeBridge) },
'./bucket-bar': { default: FakeBucketBar },
'./config/app': { createAppConfig: fakeCreateAppConfig },
'./toolbar': {
ToolbarController: FakeToolbarController,
},
......
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