diff options
author | Johann Hubert Sonntagbauer <johann.sonntagbauer@gmail.com> | 2018-10-09 21:03:09 +0300 |
---|---|---|
committer | Johann Hubert Sonntagbauer <johann.sonntagbauer@gmail.com> | 2018-10-17 07:57:29 +0300 |
commit | 6f5723a169b5d400c136dbd844fc54c68e5f8563 (patch) | |
tree | e7bad2648366ed5943293655a0abe23367e869a6 /spec/javascripts/image_diff | |
parent | 28d412e5b2b8499fba22e8fabb1d44f44449228e (diff) |
enable jasmine/new-line-before-expect
Diffstat (limited to 'spec/javascripts/image_diff')
8 files changed, 44 insertions, 0 deletions
diff --git a/spec/javascripts/image_diff/helpers/badge_helper_spec.js b/spec/javascripts/image_diff/helpers/badge_helper_spec.js index ce3add1fd90..8ea05203d00 100644 --- a/spec/javascripts/image_diff/helpers/badge_helper_spec.js +++ b/spec/javascripts/image_diff/helpers/badge_helper_spec.js @@ -90,6 +90,7 @@ describe('badge helper', () => { it('should create icon comment button', () => { const iconEl = buttonEl.querySelector('svg'); + expect(iconEl).toBeDefined(); }); }); diff --git a/spec/javascripts/image_diff/helpers/comment_indicator_helper_spec.js b/spec/javascripts/image_diff/helpers/comment_indicator_helper_spec.js index 9d05c6859df..8e3e7f1222e 100644 --- a/spec/javascripts/image_diff/helpers/comment_indicator_helper_spec.js +++ b/spec/javascripts/image_diff/helpers/comment_indicator_helper_spec.js @@ -29,9 +29,11 @@ describe('commentIndicatorHelper', () => { it('should contain image-comment-dark svg', () => { const svgEl = buttonEl.querySelector('svg'); + expect(svgEl).toBeDefined(); const svgLink = svgEl.querySelector('use').getAttribute('xlink:href'); + expect(svgLink.indexOf('image-comment-dark')).not.toBe(-1); }); }); @@ -40,6 +42,7 @@ describe('commentIndicatorHelper', () => { describe('removeCommentIndicator', () => { it('should return removed false if there is no comment-indicator', () => { const result = commentIndicatorHelper.removeCommentIndicator(containerEl); + expect(result.removed).toEqual(false); }); @@ -84,6 +87,7 @@ describe('commentIndicatorHelper', () => { it('should set commentIndicator coordinates', () => { const commentIndicatorEl = containerEl.querySelector('.comment-indicator'); + expect(commentIndicatorEl.style.left).toEqual(`${coordinate.x}px`); expect(commentIndicatorEl.style.top).toEqual(`${coordinate.y}px`); }); @@ -96,6 +100,7 @@ describe('commentIndicatorHelper', () => { it('should addCommentIndicator', () => { const buttonEl = containerEl.querySelector('.comment-indicator'); + expect(buttonEl).toBeDefined(); expect(buttonEl.style.left).toEqual(`${coordinate.x}px`); expect(buttonEl.style.top).toEqual(`${coordinate.y}px`); diff --git a/spec/javascripts/image_diff/helpers/dom_helper_spec.js b/spec/javascripts/image_diff/helpers/dom_helper_spec.js index 8dde924e8ae..ffe712af2dd 100644 --- a/spec/javascripts/image_diff/helpers/dom_helper_spec.js +++ b/spec/javascripts/image_diff/helpers/dom_helper_spec.js @@ -92,6 +92,7 @@ describe('domHelper', () => { it('should force formEl to display none', () => { const formEl = element.querySelector('.discussion-form'); + expect(formEl.style.display).toEqual('none'); }); }); @@ -111,6 +112,7 @@ describe('domHelper', () => { it('should force formEl to display block', () => { const formEl = element.querySelector('.discussion-form'); + expect(formEl.style.display).toEqual('block'); }); }); diff --git a/spec/javascripts/image_diff/helpers/utils_helper_spec.js b/spec/javascripts/image_diff/helpers/utils_helper_spec.js index 31949c39d9c..70bdf0d3609 100644 --- a/spec/javascripts/image_diff/helpers/utils_helper_spec.js +++ b/spec/javascripts/image_diff/helpers/utils_helper_spec.js @@ -57,6 +57,7 @@ describe('utilsHelper', () => { it('should return actual image properties', () => { const { actual } = result; + expect(actual.x).toEqual(imageMeta.x); expect(actual.y).toEqual(imageMeta.y); expect(actual.width).toEqual(imageMeta.width); @@ -65,6 +66,7 @@ describe('utilsHelper', () => { it('should return browser image properties', () => { const { browser } = result; + expect(browser.x).toBeDefined(); expect(browser.y).toBeDefined(); expect(browser.width).toBeDefined(); @@ -106,6 +108,7 @@ describe('utilsHelper', () => { const result = utilsHelper.getTargetSelection(event); const { browser } = result; + expect(browser.x).toEqual(event.offsetX); expect(browser.y).toEqual(event.offsetY); expect(browser.width).toEqual(imageProperties.width); @@ -117,6 +120,7 @@ describe('utilsHelper', () => { const result = utilsHelper.getTargetSelection(event); const { actual } = result; + expect(actual.x).toEqual(100); expect(actual.y).toEqual(100); expect(actual.width).toEqual(imageProperties.naturalWidth); @@ -127,24 +131,28 @@ describe('utilsHelper', () => { it('should return x = 0 if x < 0', () => { const event = generateEvent(-5, 50); const result = utilsHelper.getTargetSelection(event); + expect(result.browser.x).toEqual(0); }); it('should return x = width if x > width', () => { const event = generateEvent(1000, 50); const result = utilsHelper.getTargetSelection(event); + expect(result.browser.x).toEqual(imageProperties.width); }); it('should return y = 0 if y < 0', () => { const event = generateEvent(50, -10); const result = utilsHelper.getTargetSelection(event); + expect(result.browser.y).toEqual(0); }); it('should return y = height if y > height', () => { const event = generateEvent(50, 1000); const result = utilsHelper.getTargetSelection(event); + expect(result.browser.y).toEqual(imageProperties.height); }); }); @@ -178,6 +186,7 @@ describe('utilsHelper', () => { `; const imageDiff = utilsHelper.initImageDiff(fileEl, true, false); + expect(ImageDiff.prototype.init).toHaveBeenCalled(); expect(imageDiff.canCreateNote).toEqual(true); expect(imageDiff.renderCommentBadge).toEqual(false); @@ -191,6 +200,7 @@ describe('utilsHelper', () => { `; const replacedImageDiff = utilsHelper.initImageDiff(fileEl, false, true); + expect(ReplacedImageDiff.prototype.init).toHaveBeenCalled(); expect(replacedImageDiff.canCreateNote).toEqual(false); expect(replacedImageDiff.renderCommentBadge).toEqual(true); diff --git a/spec/javascripts/image_diff/image_badge_spec.js b/spec/javascripts/image_diff/image_badge_spec.js index 87f98fc0926..ce723e5d23c 100644 --- a/spec/javascripts/image_diff/image_badge_spec.js +++ b/spec/javascripts/image_diff/image_badge_spec.js @@ -15,6 +15,7 @@ describe('ImageBadge', () => { })); const { actual } = imageBadge; + expect(actual.x).toEqual(imageMeta.x); expect(actual.y).toEqual(imageMeta.y); expect(actual.width).toEqual(imageMeta.width); @@ -27,6 +28,7 @@ describe('ImageBadge', () => { })); const { browser } = imageBadge; + expect(browser.x).toEqual(imageMeta.x); expect(browser.y).toEqual(imageMeta.y); expect(browser.width).toEqual(imageMeta.width); @@ -35,11 +37,13 @@ describe('ImageBadge', () => { it('should save noteId', () => { const imageBadge = new ImageBadge(options); + expect(imageBadge.noteId).toEqual(noteId); }); it('should save discussionId', () => { const imageBadge = new ImageBadge(options); + expect(imageBadge.discussionId).toEqual(discussionId); }); @@ -52,6 +56,7 @@ describe('ImageBadge', () => { it('should return defaultimageMeta if actual property is not provided', () => { const { actual } = imageBadge; + expect(actual.x).toEqual(0); expect(actual.y).toEqual(0); expect(actual.width).toEqual(0); @@ -60,6 +65,7 @@ describe('ImageBadge', () => { it('should return defaultimageMeta if browser property is not provided', () => { const { browser } = imageBadge; + expect(browser.x).toEqual(0); expect(browser.y).toEqual(0); expect(browser.width).toEqual(0); diff --git a/spec/javascripts/image_diff/image_diff_spec.js b/spec/javascripts/image_diff/image_diff_spec.js index 346282328c7..9a7f288cd6b 100644 --- a/spec/javascripts/image_diff/image_diff_spec.js +++ b/spec/javascripts/image_diff/image_diff_spec.js @@ -117,11 +117,13 @@ describe('ImageDiff', () => { it('should register click event delegation to js-diff-notes-toggle', () => { element.querySelector('.js-diff-notes-toggle').click(); + expect(imageDiffHelper.toggleCollapsed).toHaveBeenCalled(); }); it('should register click event delegation to comment-indicator', () => { element.querySelector('.comment-indicator').click(); + expect(imageDiffHelper.commentIndicatorOnClick).toHaveBeenCalled(); }); }); @@ -147,6 +149,7 @@ describe('ImageDiff', () => { it('should registers load eventListener', () => { const loadEvent = new Event('load'); imageEl.dispatchEvent(loadEvent); + expect(imageDiff.renderBadges).toHaveBeenCalled(); }); }); @@ -164,24 +167,28 @@ describe('ImageDiff', () => { it('should register click.imageDiff event', () => { const event = new CustomEvent('click.imageDiff'); element.dispatchEvent(event); + expect(imageDiff.imageClicked).toHaveBeenCalled(); }); it('should register blur.imageDiff event', () => { const event = new CustomEvent('blur.imageDiff'); element.dispatchEvent(event); + expect(imageDiffHelper.removeCommentIndicator).toHaveBeenCalled(); }); it('should register addBadge.imageDiff event', () => { const event = new CustomEvent('addBadge.imageDiff'); element.dispatchEvent(event); + expect(imageDiff.addBadge).toHaveBeenCalled(); }); it('should register removeBadge.imageDiff event', () => { const event = new CustomEvent('removeBadge.imageDiff'); element.dispatchEvent(event); + expect(imageDiff.removeBadge).toHaveBeenCalled(); }); }); @@ -197,6 +204,7 @@ describe('ImageDiff', () => { it('should not register click.imageDiff event', () => { const event = new CustomEvent('click.imageDiff'); element.dispatchEvent(event); + expect(imageDiff.imageClicked).not.toHaveBeenCalled(); }); }); @@ -240,6 +248,7 @@ describe('ImageDiff', () => { it('should call renderBadge for each discussionEl', () => { const discussionEls = element.querySelectorAll('.note-container .discussion-notes .notes'); + expect(imageDiff.renderBadge.calls.count()).toEqual(discussionEls.length); }); }); @@ -336,6 +345,7 @@ describe('ImageDiff', () => { describe('cascade badge count', () => { it('should update next imageBadgeEl value', () => { const imageBadgeEls = imageDiff.imageFrameEl.querySelectorAll('.badge'); + expect(imageBadgeEls[0].innerText).toEqual('1'); expect(imageBadgeEls[1].innerText).toEqual('2'); expect(imageBadgeEls.length).toEqual(2); diff --git a/spec/javascripts/image_diff/init_discussion_tab_spec.js b/spec/javascripts/image_diff/init_discussion_tab_spec.js index 7c447d6f70d..fbc68679c41 100644 --- a/spec/javascripts/image_diff/init_discussion_tab_spec.js +++ b/spec/javascripts/image_diff/init_discussion_tab_spec.js @@ -32,6 +32,7 @@ describe('initDiscussionTab', () => { it('should call initImageDiff for each diffFileEls', () => { spyOn(imageDiffHelper, 'initImageDiff').and.callFake(() => {}); initDiscussionTab(); + expect(imageDiffHelper.initImageDiff.calls.count()).toEqual(2); }); }); diff --git a/spec/javascripts/image_diff/replaced_image_diff_spec.js b/spec/javascripts/image_diff/replaced_image_diff_spec.js index 5f8cd7c531a..49fed323871 100644 --- a/spec/javascripts/image_diff/replaced_image_diff_spec.js +++ b/spec/javascripts/image_diff/replaced_image_diff_spec.js @@ -58,6 +58,7 @@ describe('ReplacedImageDiff', () => { it('should extend ImageDiff', () => { replacedImageDiff = new ReplacedImageDiff(element); + expect(replacedImageDiff instanceof ImageDiff).toEqual(true); }); @@ -72,6 +73,7 @@ describe('ReplacedImageDiff', () => { it('should set imageFrameEls', () => { const { imageFrameEls } = replacedImageDiff; + expect(imageFrameEls).toBeDefined(); expect(imageFrameEls[viewTypes.TWO_UP]).toEqual(element.querySelector('.two-up .js-image-frame')); expect(imageFrameEls[viewTypes.SWIPE]).toEqual(element.querySelector('.swipe .js-image-frame')); @@ -80,6 +82,7 @@ describe('ReplacedImageDiff', () => { it('should set viewModesEls', () => { const { viewModesEls } = replacedImageDiff; + expect(viewModesEls).toBeDefined(); expect(viewModesEls[viewTypes.TWO_UP]).toEqual(element.querySelector('.view-modes-menu .two-up')); expect(viewModesEls[viewTypes.SWIPE]).toEqual(element.querySelector('.view-modes-menu .swipe')); @@ -97,6 +100,7 @@ describe('ReplacedImageDiff', () => { describe('currentView', () => { it('should set currentView', () => { replacedImageDiff.init(viewTypes.ONION_SKIN); + expect(replacedImageDiff.currentView).toEqual(viewTypes.ONION_SKIN); }); @@ -121,6 +125,7 @@ describe('ReplacedImageDiff', () => { it('should set imageEls', () => { replacedImageDiff.generateImageEls(); const { imageEls } = replacedImageDiff; + expect(imageEls).toBeDefined(); expect(imageEls[viewTypes.TWO_UP]).toEqual(element.querySelector('.two-up img')); expect(imageEls[viewTypes.SWIPE]).toEqual(element.querySelector('.swipe img')); @@ -138,6 +143,7 @@ describe('ReplacedImageDiff', () => { it('should call super.bindEvents', () => { replacedImageDiff.bindEvents(); + expect(ImageDiff.prototype.bindEvents).toHaveBeenCalled(); }); @@ -184,6 +190,7 @@ describe('ReplacedImageDiff', () => { expect(replacedImageDiff.imageEl).toEqual(element.querySelector('.two-up img')); replacedImageDiff.currentView = viewTypes.SWIPE; + expect(replacedImageDiff.imageEl).toEqual(element.querySelector('.swipe img')); }); }); @@ -199,6 +206,7 @@ describe('ReplacedImageDiff', () => { expect(replacedImageDiff.imageFrameEl).toEqual(element.querySelector('.two-up .js-image-frame')); replacedImageDiff.currentView = viewTypes.ONION_SKIN; + expect(replacedImageDiff.imageFrameEl).toEqual(element.querySelector('.onion-skin .js-image-frame')); }); }); @@ -248,6 +256,7 @@ describe('ReplacedImageDiff', () => { it('should call renderNewView', () => { jasmine.clock().tick(251); + expect(replacedImageDiff.renderNewView).toHaveBeenCalled(); }); }); |