Skip to content

Commit

Permalink
Shared RO late load & Url Plugin double slash fix (#936)
Browse files Browse the repository at this point in the history
* shared RO updates
- reinitialize menus when receiving a new shared resize observer
- initialize when handler loads
- update tests

* urlPlugin - do not add // when updating url + unit tests
  • Loading branch information
iisa authored Feb 8, 2022
1 parent 3a79764 commit 4ca4610
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/BookNavigator/book-navigator.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export class BookNavigator extends LitElement {

if (changed.has('sharedObserver') && this.bookreader) {
this.loadSharedObserver();
this.initializeBookSubmenus();
}
}

Expand Down Expand Up @@ -461,11 +462,16 @@ export class BookNavigator extends LitElement {
this.brHeight = contentRect.height;
}

if (!startBrWidth && this.brWidth) {
// loading up, let's update side menus
this.initializeBookSubmenus();
}

const widthChange = startBrWidth !== this.brWidth;
const heightChange = startBrHeight !== this.brHeight;

if (!animating && (widthChange || heightChange)) {
this.bookreader.resize();
this.bookreader?.resize();
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/plugins/url/UrlPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export class UrlPlugin {
const concatenatedPath = urlStrPath !== '/' ? urlStrPath : '';
if (this.urlMode == 'history') {
if (window.history && window.history.replaceState) {
const newUrlPath = `${this.urlHistoryBasePath}${concatenatedPath}`;
const newUrlPath = `${this.urlHistoryBasePath}${concatenatedPath}`.trim().replace(/(\/+)/g, '/');
window.history.replaceState({}, null, newUrlPath);
}
} else {
Expand Down
15 changes: 15 additions & 0 deletions tests/jest/plugins/url/UrlPlugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,21 @@ describe('UrlPlugin tests', () => {
const locationUrl = `${window.location.pathname}${window.location.search}`;
expect(locationUrl).toEqual('/details/foo/page/12?q=hello&view=theater');
});

test('strips leading slash of incoming path name for no double slash', () => {
const urlPlugin = new UrlPlugin();
urlPlugin.urlMode = 'history';

urlPlugin.urlHistoryBasePath = '/details/SubBookTest/book1/GPORFP/';
urlPlugin.urlState = {
"mode": "1up",
};

urlPlugin.setUrlParam('sort', 'title_asc');
urlPlugin.setUrlParam('mode', 'thumb');

expect(window.location.href).toEqual('http://localhost/details/SubBookTest/book1/GPORFP/mode/thumb?sort=title_asc');
});
});

});
9 changes: 9 additions & 0 deletions tests/karma/BookNavigator/book-navigator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,10 @@ describe('<book-navigator>', () => {
const el = fixtureSync(container());
const brStub = {
resize: sinon.fake(),
options: {},
refs: {
$brContainer: document.createElement('div')
}
};
el.bookreader = brStub;
await elementUpdated(el);
Expand All @@ -349,7 +353,12 @@ describe('<book-navigator>', () => {
const brStub = {
animating: false,
resize: sinon.fake(),
options: {},
refs: {
$brContainer: document.createElement('div')
}
};

el.bookreader = brStub;
await elementUpdated(el);
expect(el.brWidth).to.equal(0);
Expand Down

0 comments on commit 4ca4610

Please sign in to comment.