diff --git a/src/lib/viewers/image/Image.js b/src/lib/viewers/image/Image.js index d78405d55..b0e4fe1f3 100644 --- a/src/lib/viewers/image/Image.js +++ b/src/lib/viewers/image/Image.js @@ -286,6 +286,10 @@ class Image extends Base { this.printframe = openContentInsideIframe(this.imageEl.outerHTML); this.printframe.contentWindow.focus(); + this.printImage = this.printframe.contentDocument.querySelector('img'); + this.printImage.style.display = 'block'; + this.printImage.style.margin = '0 auto'; + if (Browser.getName() === 'Explorer' || Browser.getName() === 'Edge') { this.printframe.contentWindow.document.execCommand('print', false, null); } else { diff --git a/src/lib/viewers/image/__tests__/Image-test.js b/src/lib/viewers/image/__tests__/Image-test.js index 7b03d5eee..c93e07ca5 100644 --- a/src/lib/viewers/image/__tests__/Image-test.js +++ b/src/lib/viewers/image/__tests__/Image-test.js @@ -416,45 +416,42 @@ describe('lib/viewers/image/Image', () => { describe('print()', () => { beforeEach(() => { - stubs.iframe = { - contentWindow: { - focus: sandbox.stub(), - print: sandbox.stub(), - document: { - execCommand: sandbox.stub() - } - } - }; + stubs.mockIframe = util.openContentInsideIframe(image.imageEl.outerHTML); + stubs.focus = sandbox.stub(stubs.mockIframe.contentWindow, 'focus'); + stubs.execCommand = sandbox.stub(stubs.mockIframe.contentWindow.document, 'execCommand'); + stubs.print = sandbox.stub(stubs.mockIframe.contentWindow, 'print'); - stubs.openContentInsideIframe = sandbox.stub(util, 'openContentInsideIframe').returns(stubs.iframe); + stubs.openContentInsideIframe = sandbox.stub(util, 'openContentInsideIframe').returns(stubs.mockIframe); stubs.getName = sandbox.stub(Browser, 'getName'); }); - it('should open the content inside an iframe, and focus', () => { + it('should open the content inside an iframe, center, and focus', () => { image.print(); expect(stubs.openContentInsideIframe).to.be.called; - expect(stubs.iframe.contentWindow.focus).to.be.called; + expect(image.printImage.style.display).to.equal('block'); + expect(image.printImage.style.margin).to.equal('0px auto'); + expect(stubs.focus).to.be.called; }); it('should execute the print command if the browser is Explorer', () => { stubs.getName.returns('Explorer'); image.print(); - expect(stubs.iframe.contentWindow.document.execCommand).to.be.calledWith('print', false, null); + expect(stubs.execCommand).to.be.calledWith('print', false, null); }); it('should execute the print command if the browser is Edge', () => { stubs.getName.returns('Edge'); image.print(); - expect(stubs.iframe.contentWindow.document.execCommand).to.be.calledWith('print', false, null); + expect(stubs.execCommand).to.be.calledWith('print', false, null); }); it('should call the contentWindow print for other browsers', () => { stubs.getName.returns('Chrome'); image.print(); - expect(stubs.iframe.contentWindow.print).to.be.called; + expect(stubs.print).to.be.called; }); });