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>2021-04-01 18:14:27 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-04-01 18:14:27 +0300
commitafbaf78b0d819326741a01b093bdbc4702570417 (patch)
treea16a6f2a8fcc18e60f25ac72df6ab22cfe0eae79 /spec/frontend
parent38b3003b67db3f2eadfa81fd28b13d168f665766 (diff)
Add latest changes from gitlab-org/gitlab@13-10-stable-ee
Diffstat (limited to 'spec/frontend')
-rw-r--r--spec/frontend/__helpers__/test_constants.js3
-rw-r--r--spec/frontend/emoji/components/utils_spec.js56
-rw-r--r--spec/frontend/vue_shared/components/content_viewer/viewers/image_viewer_spec.js18
3 files changed, 72 insertions, 5 deletions
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);
+ });
});
});