diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-09-18 17:02:45 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-09-18 17:02:45 +0300 |
commit | 80f61b4035607d7cd87de993b8f5e996bde3481f (patch) | |
tree | 06b12f51e97d87192e3dd0e05edf55143645b894 /spec/javascripts/image_diff | |
parent | 4ab54c2233e91f60a80e5b6fa2181e6899fdcc3e (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/javascripts/image_diff')
3 files changed, 57 insertions, 56 deletions
diff --git a/spec/javascripts/image_diff/helpers/init_image_diff_spec.js b/spec/javascripts/image_diff/helpers/init_image_diff_spec.js new file mode 100644 index 00000000000..ba501d58965 --- /dev/null +++ b/spec/javascripts/image_diff/helpers/init_image_diff_spec.js @@ -0,0 +1,52 @@ +import initImageDiffHelper from '~/image_diff/helpers/init_image_diff'; +import ImageDiff from '~/image_diff/image_diff'; +import ReplacedImageDiff from '~/image_diff/replaced_image_diff'; + +describe('initImageDiff', () => { + let glCache; + let fileEl; + + beforeEach(() => { + window.gl = window.gl || (window.gl = {}); + glCache = window.gl; + fileEl = document.createElement('div'); + fileEl.innerHTML = ` + <div class="diff-file"></div> + `; + + spyOn(ReplacedImageDiff.prototype, 'init').and.callFake(() => {}); + spyOn(ImageDiff.prototype, 'init').and.callFake(() => {}); + }); + + afterEach(() => { + window.gl = glCache; + }); + + it('should initialize ImageDiff if js-single-image', () => { + const diffFileEl = fileEl.querySelector('.diff-file'); + diffFileEl.innerHTML = ` + <div class="js-single-image"> + </div> + `; + + const imageDiff = initImageDiffHelper.initImageDiff(fileEl, true, false); + + expect(ImageDiff.prototype.init).toHaveBeenCalled(); + expect(imageDiff.canCreateNote).toEqual(true); + expect(imageDiff.renderCommentBadge).toEqual(false); + }); + + it('should initialize ReplacedImageDiff if js-replaced-image', () => { + const diffFileEl = fileEl.querySelector('.diff-file'); + diffFileEl.innerHTML = ` + <div class="js-replaced-image"> + </div> + `; + + const replacedImageDiff = initImageDiffHelper.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/helpers/utils_helper_spec.js b/spec/javascripts/image_diff/helpers/utils_helper_spec.js index 6f62ee3f93b..3b6378be883 100644 --- a/spec/javascripts/image_diff/helpers/utils_helper_spec.js +++ b/spec/javascripts/image_diff/helpers/utils_helper_spec.js @@ -1,6 +1,4 @@ import * as utilsHelper from '~/image_diff/helpers/utils_helper'; -import ImageDiff from '~/image_diff/image_diff'; -import ReplacedImageDiff from '~/image_diff/replaced_image_diff'; import ImageBadge from '~/image_diff/image_badge'; import * as mockData from '../mock_data'; @@ -151,53 +149,4 @@ describe('utilsHelper', () => { }); }); }); - - describe('initImageDiff', () => { - let glCache; - let fileEl; - - beforeEach(() => { - window.gl = window.gl || (window.gl = {}); - glCache = window.gl; - fileEl = document.createElement('div'); - fileEl.innerHTML = ` - <div class="diff-file"></div> - `; - - spyOn(ReplacedImageDiff.prototype, 'init').and.callFake(() => {}); - spyOn(ImageDiff.prototype, 'init').and.callFake(() => {}); - }); - - afterEach(() => { - window.gl = glCache; - }); - - it('should initialize ImageDiff if js-single-image', () => { - const diffFileEl = fileEl.querySelector('.diff-file'); - diffFileEl.innerHTML = ` - <div class="js-single-image"> - </div> - `; - - const imageDiff = utilsHelper.initImageDiff(fileEl, true, false); - - expect(ImageDiff.prototype.init).toHaveBeenCalled(); - expect(imageDiff.canCreateNote).toEqual(true); - expect(imageDiff.renderCommentBadge).toEqual(false); - }); - - it('should initialize ReplacedImageDiff if js-replaced-image', () => { - const diffFileEl = fileEl.querySelector('.diff-file'); - diffFileEl.innerHTML = ` - <div class="js-replaced-image"> - </div> - `; - - 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/init_discussion_tab_spec.js b/spec/javascripts/image_diff/init_discussion_tab_spec.js index 7cacc45ab62..5eb87e1df25 100644 --- a/spec/javascripts/image_diff/init_discussion_tab_spec.js +++ b/spec/javascripts/image_diff/init_discussion_tab_spec.js @@ -1,5 +1,5 @@ import initDiscussionTab from '~/image_diff/init_discussion_tab'; -import imageDiffHelper from '~/image_diff/helpers/index'; +import initImageDiffHelper from '~/image_diff/helpers/init_image_diff'; describe('initDiscussionTab', () => { beforeEach(() => { @@ -12,7 +12,7 @@ describe('initDiscussionTab', () => { }); it('should pass canCreateNote as false to initImageDiff', done => { - spyOn(imageDiffHelper, 'initImageDiff').and.callFake((diffFileEl, canCreateNote) => { + spyOn(initImageDiffHelper, 'initImageDiff').and.callFake((diffFileEl, canCreateNote) => { expect(canCreateNote).toEqual(false); done(); }); @@ -21,7 +21,7 @@ describe('initDiscussionTab', () => { }); it('should pass renderCommentBadge as true to initImageDiff', done => { - spyOn(imageDiffHelper, 'initImageDiff').and.callFake( + spyOn(initImageDiffHelper, 'initImageDiff').and.callFake( (diffFileEl, canCreateNote, renderCommentBadge) => { expect(renderCommentBadge).toEqual(true); done(); @@ -32,9 +32,9 @@ describe('initDiscussionTab', () => { }); it('should call initImageDiff for each diffFileEls', () => { - spyOn(imageDiffHelper, 'initImageDiff').and.callFake(() => {}); + spyOn(initImageDiffHelper, 'initImageDiff').and.callFake(() => {}); initDiscussionTab(); - expect(imageDiffHelper.initImageDiff.calls.count()).toEqual(2); + expect(initImageDiffHelper.initImageDiff.calls.count()).toEqual(2); }); }); |