Skip to content

Commit

Permalink
Fix: Flaky ImageViewer test (#811)
Browse files Browse the repository at this point in the history
Stub out actually opening content inside an iframe
  • Loading branch information
tonyjin authored Jun 21, 2018
1 parent d292f36 commit 7ac4797
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/lib/viewers/image/ImageViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Browser from '../../Browser';
import ImageBaseViewer from './ImageBaseViewer';
import { ICON_FULLSCREEN_IN, ICON_FULLSCREEN_OUT, ICON_ROTATE_LEFT } from '../../icons/icons';
import { CLASS_INVISIBLE } from '../../constants';
import { openContentInsideIframe } from '../../util';
import * as util from '../../util';
import './Image.scss';

const CSS_CLASS_IMAGE = 'bp-image';
Expand Down Expand Up @@ -277,7 +277,7 @@ class ImageViewer extends ImageBaseViewer {
* @return {void}
*/
print() {
this.printframe = openContentInsideIframe(this.imageEl.outerHTML);
this.printframe = util.openContentInsideIframe(this.imageEl.outerHTML);
this.printframe.contentWindow.focus();

this.printImage = this.printframe.contentDocument.querySelector('img');
Expand Down
19 changes: 15 additions & 4 deletions src/lib/viewers/image/__tests__/ImageViewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,10 +348,21 @@ describe('lib/viewers/image/ImageViewer', () => {

describe('print()', () => {
beforeEach(() => {
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.execCommand = sandbox.stub();
stubs.focus = sandbox.stub();
stubs.print = sandbox.stub();
stubs.mockIframe = {
contentWindow: {
document: {
execCommand: stubs.execCommand
},
focus: stubs.focus,
print: stubs.print
},
contentDocument: {
querySelector: sandbox.stub().returns(containerEl.querySelector('img'))
}
};

stubs.openContentInsideIframe = sandbox.stub(util, 'openContentInsideIframe').returns(stubs.mockIframe);
stubs.getName = sandbox.stub(Browser, 'getName');
Expand Down

0 comments on commit 7ac4797

Please sign in to comment.