Commit a623fee0 authored by Lyza Danger Gardner's avatar Lyza Danger Gardner

Add `isSidebar` utility

The client application has several existing tests to see if the app is
“in sidebar mode” currently. This utility is a first step to harmonizing
this and making things consistent.
parent 5baf03dd
'use strict';
/**
* Is the instance of the application in the current `window_` within a
* sidebar (vs. single-annotation or stream view)?
*/
const isSidebar = (window_ = window) => {
return !(
window_.location.pathname.startsWith('/stream') ||
window_.location.pathname.startsWith('/a/')
);
};
module.exports = isSidebar;
'use strict';
const isSidebar = require('../is-sidebar');
describe('sidebar.utils.is-sidebar', () => {
[
'/a/random-annotation-id',
'/stream/',
'/stream',
'/a/',
'/a/foo.html',
].forEach(fakePath => {
it(`returns false if window.location is in stream or single-annotation view (${fakePath})`, () => {
const window_ = {};
window_.location = new URL(`http://www.example.com${fakePath}`);
assert.isFalse(isSidebar(window_));
});
});
['/whatever', '/anything-else', '/a', '/apples/', '/app.html'].forEach(
fakePath => {
it(`returns true if window.location is not in stream or single-annotation view (${fakePath})`, () => {
const window_ = {};
window_.location = new URL(`http://www.example.com${fakePath}`);
assert.isTrue(isSidebar(window_));
});
}
);
});
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