Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-12-20 18:07:34 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2019-12-20 18:07:34 +0300
commit8b61452138ecc511b52cd49be4ee6b8a80390c50 (patch)
tree122b817432c2a0f0e23767bd95791a89b20540c0 /spec/frontend/image_diff
parentf864f8a7aafa45b0e4c04e4312f89da4b1227c0f (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/image_diff')
-rw-r--r--spec/frontend/image_diff/helpers/init_image_diff_spec.js52
-rw-r--r--spec/frontend/image_diff/init_discussion_tab_spec.js42
2 files changed, 94 insertions, 0 deletions
diff --git a/spec/frontend/image_diff/helpers/init_image_diff_spec.js b/spec/frontend/image_diff/helpers/init_image_diff_spec.js
new file mode 100644
index 00000000000..dc872ace265
--- /dev/null
+++ b/spec/frontend/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>
+ `;
+
+ jest.spyOn(ReplacedImageDiff.prototype, 'init').mockImplementation(() => {});
+ jest.spyOn(ImageDiff.prototype, 'init').mockImplementation(() => {});
+ });
+
+ 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/frontend/image_diff/init_discussion_tab_spec.js b/spec/frontend/image_diff/init_discussion_tab_spec.js
new file mode 100644
index 00000000000..f459fdf5a08
--- /dev/null
+++ b/spec/frontend/image_diff/init_discussion_tab_spec.js
@@ -0,0 +1,42 @@
+import initDiscussionTab from '~/image_diff/init_discussion_tab';
+import initImageDiffHelper from '~/image_diff/helpers/init_image_diff';
+
+describe('initDiscussionTab', () => {
+ beforeEach(() => {
+ setFixtures(`
+ <div class="timeline-content">
+ <div class="diff-file js-image-file"></div>
+ <div class="diff-file js-image-file"></div>
+ </div>
+ `);
+ });
+
+ it('should pass canCreateNote as false to initImageDiff', done => {
+ jest
+ .spyOn(initImageDiffHelper, 'initImageDiff')
+ .mockImplementation((diffFileEl, canCreateNote) => {
+ expect(canCreateNote).toEqual(false);
+ done();
+ });
+
+ initDiscussionTab();
+ });
+
+ it('should pass renderCommentBadge as true to initImageDiff', done => {
+ jest
+ .spyOn(initImageDiffHelper, 'initImageDiff')
+ .mockImplementation((diffFileEl, canCreateNote, renderCommentBadge) => {
+ expect(renderCommentBadge).toEqual(true);
+ done();
+ });
+
+ initDiscussionTab();
+ });
+
+ it('should call initImageDiff for each diffFileEls', () => {
+ jest.spyOn(initImageDiffHelper, 'initImageDiff').mockImplementation(() => {});
+ initDiscussionTab();
+
+ expect(initImageDiffHelper.initImageDiff.mock.calls.length).toEqual(2);
+ });
+});