diff --git a/src/lib/Preview.js b/src/lib/Preview.js index 94ea81e4e..76f5b1b2e 100644 --- a/src/lib/Preview.js +++ b/src/lib/Preview.js @@ -1175,10 +1175,6 @@ class Preview extends EventEmitter { this.ui.showLoadingDownloadButton(this.download); } - // Update the loading indicators - this.ui.hideCrawler(); - this.ui.setLoadingIcon(this.file.extension); - // Determine the asset loader to use const loader = this.getLoader(this.file); diff --git a/src/lib/__tests__/Preview-test.js b/src/lib/__tests__/Preview-test.js index 6064ebd39..7aa89a313 100644 --- a/src/lib/__tests__/Preview-test.js +++ b/src/lib/__tests__/Preview-test.js @@ -1666,8 +1666,6 @@ describe('lib/Preview', () => { stubs.destroy = jest.spyOn(preview, 'destroy'); stubs.checkPermission = jest.spyOn(file, 'checkPermission').mockReturnValue(true); stubs.canDownload = jest.spyOn(file, 'canDownload').mockReturnValue(false); - stubs.hideCrawler = jest.spyOn(preview.ui, 'hideCrawler').mockImplementation(); - stubs.setLoadingIcon = jest.spyOn(preview.ui, 'setLoadingIcon').mockImplementation(); stubs.showLoadingDownloadButton = jest.spyOn(preview.ui, 'showLoadingDownloadButton').mockImplementation(); stubs.loadPromiseResolve = Promise.resolve(); stubs.determineRepresentationStatusPromise = Promise.resolve(); @@ -1715,27 +1713,16 @@ describe('lib/Preview', () => { test('should show the loading download button if file can be downloaded', () => { stubs.canDownload.mockReturnValue(true); - preview.loadViewer(); + preview.loadViewer({}); expect(stubs.showLoadingDownloadButton).toBeCalled(); }); test("should not show the loading download button if file can't be downloaded", () => { stubs.canDownload.mockReturnValue(false); - preview.loadViewer(); + preview.loadViewer({}); expect(stubs.showLoadingDownloadButton).not.toBeCalled(); }); - test('should show the file-specific loading icon', () => { - preview.file.extension = 'pdf'; - preview.loadViewer(); - expect(stubs.setLoadingIcon).toBeCalledWith('pdf'); - }); - - test('should hide the loading crawler', () => { - preview.loadViewer(); - expect(stubs.hideCrawler).toBeCalled(); - }); - test('should throw an unsupported error if there is no loader for general file types', () => { stubs.getLoader.mockReturnValue(undefined); diff --git a/src/lib/viewers/BaseViewer.js b/src/lib/viewers/BaseViewer.js index d2fa219aa..fbfda6cde 100644 --- a/src/lib/viewers/BaseViewer.js +++ b/src/lib/viewers/BaseViewer.js @@ -194,6 +194,9 @@ class BaseViewer extends EventEmitter { // From the perspective of viewers bp-content holds everything this.containerEl = container.querySelector(SELECTOR_BOX_PREVIEW_CONTENT); + // Update the loading indicators + this.setupLoading(); + // Attach event listeners this.addCommonListeners(); @@ -220,6 +223,20 @@ class BaseViewer extends EventEmitter { this.isSetup = true; } + /** + * Removes the crawler and sets the file type specific loading icon + * + * @return {void} + */ + setupLoading() { + const { file = {} } = this.options; + + if (this.previewUI) { + this.previewUI.hideCrawler(); + this.previewUI.setLoadingIcon(file.extension); + } + } + /** * Destroys the viewer * diff --git a/src/lib/viewers/__tests__/BaseViewer-test.js b/src/lib/viewers/__tests__/BaseViewer-test.js index 8a15b5643..27b289ac3 100644 --- a/src/lib/viewers/__tests__/BaseViewer-test.js +++ b/src/lib/viewers/__tests__/BaseViewer-test.js @@ -37,11 +37,13 @@ describe('lib/viewers/BaseViewer', () => { }, }); base.previewUI = { - replaceHeader: jest.fn(), + hideCrawler: jest.fn(), notification: { show: jest.fn(), hide: jest.fn(), }, + replaceHeader: jest.fn(), + setLoadingIcon: jest.fn(), }; }); @@ -116,6 +118,17 @@ describe('lib/viewers/BaseViewer', () => { }); }); + describe('setupLoading()', () => { + test('should hide the crawler and set the file-specific loading icon', () => { + base.options.file = { extension: 'pdf' }; + + base.setupLoading(); + + expect(base.previewUI.hideCrawler).toBeCalled(); + expect(base.previewUI.setLoadingIcon).toBeCalledWith('pdf'); + }); + }); + describe('getResizeHandler()', () => { test('should return a resize handler', () => { expect(typeof base.getResizeHandler()).toBe('function'); diff --git a/src/lib/viewers/error/PreviewErrorViewer.js b/src/lib/viewers/error/PreviewErrorViewer.js index 371f4b20b..06f64385d 100644 --- a/src/lib/viewers/error/PreviewErrorViewer.js +++ b/src/lib/viewers/error/PreviewErrorViewer.js @@ -44,7 +44,7 @@ class PreviewErrorViewer extends BaseViewer { * @override * @return {void} */ - finishLoadingSetup() { + setupLoading() { /* no op, custom loading logic for errors */ }