From afbaf78b0d819326741a01b093bdbc4702570417 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Thu, 1 Apr 2021 15:14:27 +0000 Subject: Add latest changes from gitlab-org/gitlab@13-10-stable-ee --- spec/frontend/__helpers__/test_constants.js | 3 ++ spec/frontend/emoji/components/utils_spec.js | 56 ++++++++++++++++++++++ .../content_viewer/viewers/image_viewer_spec.js | 18 +++++-- 3 files changed, 72 insertions(+), 5 deletions(-) create mode 100644 spec/frontend/emoji/components/utils_spec.js (limited to 'spec/frontend') diff --git a/spec/frontend/__helpers__/test_constants.js b/spec/frontend/__helpers__/test_constants.js index 69b78f556aa..628b9b054d3 100644 --- a/spec/frontend/__helpers__/test_constants.js +++ b/spec/frontend/__helpers__/test_constants.js @@ -6,6 +6,8 @@ const DUMMY_IMAGE_URL = `${FIXTURES_PATH}/static/images/one_white_pixel.png`; const GREEN_BOX_IMAGE_URL = `${FIXTURES_PATH}/static/images/green_box.png`; const RED_BOX_IMAGE_URL = `${FIXTURES_PATH}/static/images/red_box.png`; +const DUMMY_IMAGE_BLOB_PATH = 'SpongeBlob.png'; + // NOTE: module.exports is needed so that this file can be used // by environment.js // @@ -16,4 +18,5 @@ module.exports = { DUMMY_IMAGE_URL, GREEN_BOX_IMAGE_URL, RED_BOX_IMAGE_URL, + DUMMY_IMAGE_BLOB_PATH, }; diff --git a/spec/frontend/emoji/components/utils_spec.js b/spec/frontend/emoji/components/utils_spec.js new file mode 100644 index 00000000000..36521eb1051 --- /dev/null +++ b/spec/frontend/emoji/components/utils_spec.js @@ -0,0 +1,56 @@ +import Cookies from 'js-cookie'; +import { getFrequentlyUsedEmojis, addToFrequentlyUsed } from '~/emoji/components/utils'; + +jest.mock('js-cookie'); + +describe('getFrequentlyUsedEmojis', () => { + it('it returns null when no saved emojis set', () => { + jest.spyOn(Cookies, 'get').mockReturnValue(null); + + expect(getFrequentlyUsedEmojis()).toBe(null); + }); + + it('it returns frequently used emojis object', () => { + jest.spyOn(Cookies, 'get').mockReturnValue('thumbsup,thumbsdown'); + + expect(getFrequentlyUsedEmojis()).toEqual({ + frequently_used: { + emojis: [['thumbsup', 'thumbsdown']], + top: 0, + height: 71, + }, + }); + }); +}); + +describe('addToFrequentlyUsed', () => { + it('sets cookie value', () => { + jest.spyOn(Cookies, 'get').mockReturnValue(null); + + addToFrequentlyUsed('thumbsup'); + + expect(Cookies.set).toHaveBeenCalledWith('frequently_used_emojis', 'thumbsup', { + expires: 365, + }); + }); + + it('sets cookie value to include previously set cookie value', () => { + jest.spyOn(Cookies, 'get').mockReturnValue('thumbsdown'); + + addToFrequentlyUsed('thumbsup'); + + expect(Cookies.set).toHaveBeenCalledWith('frequently_used_emojis', 'thumbsdown,thumbsup', { + expires: 365, + }); + }); + + it('sets cookie value with uniq values', () => { + jest.spyOn(Cookies, 'get').mockReturnValue('thumbsup'); + + addToFrequentlyUsed('thumbsup'); + + expect(Cookies.set).toHaveBeenCalledWith('frequently_used_emojis', 'thumbsup', { + expires: 365, + }); + }); +}); diff --git a/spec/frontend/vue_shared/components/content_viewer/viewers/image_viewer_spec.js b/spec/frontend/vue_shared/components/content_viewer/viewers/image_viewer_spec.js index af3b63ad7e5..974d06a6ed4 100644 --- a/spec/frontend/vue_shared/components/content_viewer/viewers/image_viewer_spec.js +++ b/spec/frontend/vue_shared/components/content_viewer/viewers/image_viewer_spec.js @@ -1,12 +1,12 @@ -import { mount } from '@vue/test-utils'; -import { GREEN_BOX_IMAGE_URL } from 'spec/test_constants'; +import { shallowMount } from '@vue/test-utils'; +import { GREEN_BOX_IMAGE_URL, DUMMY_IMAGE_BLOB_PATH } from 'spec/test_constants'; import ImageViewer from '~/vue_shared/components/content_viewer/viewers/image_viewer.vue'; describe('Image Viewer', () => { let wrapper; it('renders image preview', () => { - wrapper = mount(ImageViewer, { + wrapper = shallowMount(ImageViewer, { propsData: { path: GREEN_BOX_IMAGE_URL, fileSize: 1024 }, }); @@ -22,7 +22,7 @@ describe('Image Viewer', () => { `( 'shows file size as "$humanizedFileSize", if fileSize=$fileSize and renderInfo=$renderInfo', ({ fileSize, renderInfo, elementExists, humanizedFileSize }) => { - wrapper = mount(ImageViewer, { + wrapper = shallowMount(ImageViewer, { propsData: { path: GREEN_BOX_IMAGE_URL, fileSize, renderInfo }, }); @@ -36,11 +36,19 @@ describe('Image Viewer', () => { describe('file path', () => { it('should output a valid URL path for the image', () => { - wrapper = mount(ImageViewer, { + wrapper = shallowMount(ImageViewer, { propsData: { path: '/url/hello#1.jpg' }, }); expect(wrapper.find('img').attributes('src')).toBe('/url/hello%231.jpg'); }); + it('outputs path without transformations when outputting a Blob', () => { + const file = new File([], DUMMY_IMAGE_BLOB_PATH); + const path = window.URL.createObjectURL(file); + wrapper = shallowMount(ImageViewer, { + propsData: { path }, + }); + expect(wrapper.find('img').attributes('src')).toBe(path); + }); }); }); -- cgit v1.2.3