Skip to content

Commit

Permalink
Fix: Set up notification in Preview.finishLoading() (#579)
Browse files Browse the repository at this point in the history
- Fixes #563
  • Loading branch information
pramodsum authored Jan 11, 2018
1 parent fbeb578 commit efd0621
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
5 changes: 4 additions & 1 deletion src/lib/Preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -1064,14 +1064,17 @@ class Preview extends EventEmitter {
this.ui.finishProgressBar();
}

// Programmtically focus on the viewer after it loads
// Programmatically focus on the viewer after it loads
if (this.viewer && this.viewer.containerEl) {
this.viewer.containerEl.focus();
}

// Hide the loading indicator
this.ui.hideLoadingIndicator();

// Set up the notification
this.ui.setupNotification();

// Prefetch next few files
this.prefetchNextFiles();
}
Expand Down
13 changes: 10 additions & 3 deletions src/lib/PreviewUI.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,6 @@ class PreviewUI {
// Setup progress bar
this.progressBar = new ProgressBar(this.container);

// Setup notification
this.notification = new Notification(this.contentContainer);

// Setup loading indicator
this.setupLoading();

Expand Down Expand Up @@ -292,6 +289,16 @@ class PreviewUI {
this.progressBar.finish();
}

/**
* Setup notification
*
* @public
* @return {void}
*/
setupNotification() {
this.notification = new Notification(this.contentContainer);
}

/**
* Shows a notification message.
*
Expand Down
6 changes: 6 additions & 0 deletions src/lib/__tests__/Preview-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1514,6 +1514,7 @@ describe('lib/Preview', () => {
stubs.logPreviewEvent = sandbox.stub(preview, 'logPreviewEvent');
stubs.prefetchNextFiles = sandbox.stub(preview, 'prefetchNextFiles');
stubs.finishProgressBar = sandbox.stub(preview.ui, 'finishProgressBar');
stubs.setupNotification = sandbox.stub(preview.ui, 'setupNotification');

stubs.logger = {
done: sandbox.stub()
Expand Down Expand Up @@ -1649,6 +1650,11 @@ describe('lib/Preview', () => {
expect(stubs.hideLoadingIndicator).to.be.called;
});

it('should set up the notification', () => {
preview.finishLoading();
expect(stubs.setupNotification).to.be.called;
});

it('should prefetch next files', () => {
preview.finishLoading();
expect(stubs.prefetchNextFiles).to.be.called;
Expand Down
10 changes: 7 additions & 3 deletions src/lib/__tests__/PreviewUI-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ describe('lib/PreviewUI', () => {
// Check progress bar
expect(resultEl).to.contain(constants.SELECTOR_BOX_PREVIEW_PROGRESS_BAR);

// Check notification
expect(resultEl).to.contain(constants.SELECTOR_BOX_PREVIEW_NOTIFICATION);

// Check loading state
const loadingWrapperEl = resultEl.querySelector(constants.SELECTOR_BOX_PREVIEW_LOADING_WRAPPER);
expect(loadingWrapperEl).to.contain(constants.SELECTOR_BOX_PREVIEW_ICON);
Expand Down Expand Up @@ -202,6 +199,13 @@ describe('lib/PreviewUI', () => {
expect(crawlerEl).to.not.have.class(constants.CLASS_HIDDEN);
});
});

describe('setupNotification()', () => {
it('should set up the notification', () => {
ui.setupNotification();
expect(containerEl).to.contain(constants.SELECTOR_BOX_PREVIEW_NOTIFICATION);
})
});
});

describe('startProgressBar()', () => {
Expand Down

0 comments on commit efd0621

Please sign in to comment.