diff options
Diffstat (limited to 'spec/frontend/image_diff')
-rw-r--r-- | spec/frontend/image_diff/init_discussion_tab_spec.js | 6 | ||||
-rw-r--r-- | spec/frontend/image_diff/replaced_image_diff_spec.js | 64 |
2 files changed, 36 insertions, 34 deletions
diff --git a/spec/frontend/image_diff/init_discussion_tab_spec.js b/spec/frontend/image_diff/init_discussion_tab_spec.js index 5bc0c738944..f6f05037c95 100644 --- a/spec/frontend/image_diff/init_discussion_tab_spec.js +++ b/spec/frontend/image_diff/init_discussion_tab_spec.js @@ -11,23 +11,21 @@ describe('initDiscussionTab', () => { `); }); - it('should pass canCreateNote as false to initImageDiff', (done) => { + it('should pass canCreateNote as false to initImageDiff', () => { jest .spyOn(initImageDiffHelper, 'initImageDiff') .mockImplementation((diffFileEl, canCreateNote) => { expect(canCreateNote).toEqual(false); - done(); }); initDiscussionTab(); }); - it('should pass renderCommentBadge as true to initImageDiff', (done) => { + it('should pass renderCommentBadge as true to initImageDiff', () => { jest .spyOn(initImageDiffHelper, 'initImageDiff') .mockImplementation((diffFileEl, canCreateNote, renderCommentBadge) => { expect(renderCommentBadge).toEqual(true); - done(); }); initDiscussionTab(); diff --git a/spec/frontend/image_diff/replaced_image_diff_spec.js b/spec/frontend/image_diff/replaced_image_diff_spec.js index cc4a2530fc4..2b401fc46bf 100644 --- a/spec/frontend/image_diff/replaced_image_diff_spec.js +++ b/spec/frontend/image_diff/replaced_image_diff_spec.js @@ -176,34 +176,36 @@ describe('ReplacedImageDiff', () => { expect(ImageDiff.prototype.bindEvents).toHaveBeenCalled(); }); - it('should register click eventlistener to 2-up view mode', (done) => { - jest.spyOn(ReplacedImageDiff.prototype, 'changeView').mockImplementation((viewMode) => { - expect(viewMode).toEqual(viewTypes.TWO_UP); - done(); - }); + it('should register click eventlistener to 2-up view mode', () => { + const changeViewSpy = jest + .spyOn(ReplacedImageDiff.prototype, 'changeView') + .mockImplementation(() => {}); replacedImageDiff.bindEvents(); replacedImageDiff.viewModesEls[viewTypes.TWO_UP].click(); + + expect(changeViewSpy).toHaveBeenCalledWith(viewTypes.TWO_UP, expect.any(Object)); }); - it('should register click eventlistener to swipe view mode', (done) => { - jest.spyOn(ReplacedImageDiff.prototype, 'changeView').mockImplementation((viewMode) => { - expect(viewMode).toEqual(viewTypes.SWIPE); - done(); - }); + it('should register click eventlistener to swipe view mode', () => { + const changeViewSpy = jest + .spyOn(ReplacedImageDiff.prototype, 'changeView') + .mockImplementation(() => {}); replacedImageDiff.bindEvents(); replacedImageDiff.viewModesEls[viewTypes.SWIPE].click(); + + expect(changeViewSpy).toHaveBeenCalledWith(viewTypes.SWIPE, expect.any(Object)); }); - it('should register click eventlistener to onion skin view mode', (done) => { - jest.spyOn(ReplacedImageDiff.prototype, 'changeView').mockImplementation((viewMode) => { - expect(viewMode).toEqual(viewTypes.SWIPE); - done(); - }); + it('should register click eventlistener to onion skin view mode', () => { + const changeViewSpy = jest + .spyOn(ReplacedImageDiff.prototype, 'changeView') + .mockImplementation(() => {}); replacedImageDiff.bindEvents(); replacedImageDiff.viewModesEls[viewTypes.SWIPE].click(); + expect(changeViewSpy).toHaveBeenCalledWith(viewTypes.SWIPE, expect.any(Object)); }); }); @@ -325,32 +327,34 @@ describe('ReplacedImageDiff', () => { setupImageFrameEls(); }); - it('should pass showCommentIndicator normalized indicator values', (done) => { + it('should pass showCommentIndicator normalized indicator values', () => { jest.spyOn(imageDiffHelper, 'showCommentIndicator').mockImplementation(() => {}); - jest + const resizeCoordinatesToImageElementSpy = jest .spyOn(imageDiffHelper, 'resizeCoordinatesToImageElement') - .mockImplementation((imageEl, meta) => { - expect(meta.x).toEqual(indicator.x); - expect(meta.y).toEqual(indicator.y); - expect(meta.width).toEqual(indicator.image.width); - expect(meta.height).toEqual(indicator.image.height); - done(); - }); + .mockImplementation(() => {}); + replacedImageDiff.renderNewView(indicator); + + expect(resizeCoordinatesToImageElementSpy).toHaveBeenCalledWith(undefined, { + x: indicator.x, + y: indicator.y, + width: indicator.image.width, + height: indicator.image.height, + }); }); - it('should call showCommentIndicator', (done) => { + it('should call showCommentIndicator', () => { const normalized = { normalized: true, }; jest.spyOn(imageDiffHelper, 'resizeCoordinatesToImageElement').mockReturnValue(normalized); - jest + const showCommentIndicatorSpy = jest .spyOn(imageDiffHelper, 'showCommentIndicator') - .mockImplementation((imageFrameEl, normalizedIndicator) => { - expect(normalizedIndicator).toEqual(normalized); - done(); - }); + .mockImplementation(() => {}); + replacedImageDiff.renderNewView(indicator); + + expect(showCommentIndicatorSpy).toHaveBeenCalledWith(undefined, normalized); }); }); }); |