Commit f69f3803 authored by Robert Knight's avatar Robert Knight

Fix clicking on PDF closing sidebar when side-by-side is active

Fix a regression introduced in b52f00e0 where clicking in a PDF
when side-by-side is active would cause the sidebar to close instead of
remaining open. That PR made `PdfSidebar` no longer inherit (indirectly)
from Guest but did not update the references to the `closeSidebarOnDocumentClick`
property of the Guest.
parent 3771ff0e
......@@ -51,7 +51,7 @@ export default class PdfSidebar extends Sidebar {
*/
activateSideBySide(width) {
this.sideBySideActive = true;
this.closeSidebarOnDocumentClick = false;
this.guest.closeSidebarOnDocumentClick = false;
this.pdfContainer.style.width = width + 'px';
this.pdfContainer.classList.add('hypothesis-side-by-side');
}
......@@ -62,7 +62,7 @@ export default class PdfSidebar extends Sidebar {
*/
deactivateSideBySide() {
this.sideBySideActive = false;
this.closeSidebarOnDocumentClick = true;
this.guest.closeSidebarOnDocumentClick = true;
this.pdfContainer.style.width = 'auto';
this.pdfContainer.classList.remove('hypothesis-side-by-side');
}
......
......@@ -4,7 +4,7 @@ import Delegator from '../delegator';
import { mockBaseClass } from '../../test-util/mock-base';
class FakeSidebar extends Delegator {
constructor(element, config, guest) {
constructor(element, guest, config) {
super(element, config);
this.guest = guest;
}
......@@ -17,12 +17,12 @@ class FakeSidebar extends Delegator {
describe('PdfSidebar', () => {
const sandbox = sinon.createSandbox();
let fakeGuest;
let fakePDFViewerApplication;
let fakePDFContainer;
let fakePDFViewerUpdate;
const createPdfSidebar = config => {
const fakeGuest = {};
const element = document.createElement('div');
return new PdfSidebar(element, fakeGuest, config);
};
......@@ -46,6 +46,10 @@ describe('PdfSidebar', () => {
// Can't stub an undefined property in a sandbox
window.PDFViewerApplication = fakePDFViewerApplication;
fakeGuest = {
closeSidebarOnDocumentClick: true,
};
unmockSidebar = mockBaseClass(PdfSidebar, FakeSidebar);
});
......@@ -90,6 +94,18 @@ describe('PdfSidebar', () => {
assert.equal(fakePDFContainer.style.width, 1300 - 428 + 'px');
});
it('disables closing sidebar on document click when side-by-side is active', () => {
const sidebar = createPdfSidebar();
sidebar.activateSideBySide();
assert.isFalse(fakeGuest.closeSidebarOnDocumentClick);
});
it('enables closing sidebar on document click when side-by-side is inactive', () => {
const sidebar = createPdfSidebar();
sidebar.deactivateSideBySide();
assert.isTrue(fakeGuest.closeSidebarOnDocumentClick);
});
it('does not activate side-by-side mode if there is not enough room', () => {
sandbox.stub(window, 'innerWidth').value(800);
const sidebar = createPdfSidebar();
......
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