diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-07-27 15:10:33 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-07-27 15:10:33 +0300 |
commit | fdf32113c3924f7faec91101282fc28ec42fc869 (patch) | |
tree | 388fdb9982d5ae80c8bc9b9bdcc0dde98cd6ead9 /spec/frontend | |
parent | 5add82515889cf332b65bbf59394079222dc66b3 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend')
6 files changed, 38 insertions, 18 deletions
diff --git a/spec/frontend/__helpers__/shared_test_setup.js b/spec/frontend/__helpers__/shared_test_setup.js index 0217835b2a3..53a43626691 100644 --- a/spec/frontend/__helpers__/shared_test_setup.js +++ b/spec/frontend/__helpers__/shared_test_setup.js @@ -35,7 +35,7 @@ Vue.config.productionTip = false; Vue.use(Translate); -const JQUERY_MATCHERS_TO_EXCLUDE = ['toHaveLength', 'toExist']; +const JQUERY_MATCHERS_TO_EXCLUDE = ['toBeEmpty', 'toHaveLength', 'toExist']; // custom-jquery-matchers was written for an old Jest version, we need to make it compatible Object.entries(jqueryMatchers).forEach(([matcherName, matcherFactory]) => { diff --git a/spec/frontend/repository/components/blob_viewers/image_viewer_spec.js b/spec/frontend/repository/components/blob_viewers/image_viewer_spec.js index c23de0efdfd..4455851529d 100644 --- a/spec/frontend/repository/components/blob_viewers/image_viewer_spec.js +++ b/spec/frontend/repository/components/blob_viewers/image_viewer_spec.js @@ -7,19 +7,35 @@ describe('Image Viewer', () => { const DEFAULT_BLOB_DATA = { rawPath: 'some/image.png', name: 'image.png', + externalStorageUrl: '', }; - const createComponent = () => { - wrapper = shallowMount(ImageViewer, { propsData: { blob: DEFAULT_BLOB_DATA } }); + const createComponent = (blobData = DEFAULT_BLOB_DATA) => { + wrapper = shallowMount(ImageViewer, { propsData: { blob: blobData } }); }; const findImage = () => wrapper.find('[data-testid="image"]'); - it('renders a Source Editor component', () => { - createComponent(); + describe('When blob has externalStorageUrl', () => { + const externalStorageUrl = 'http://img.server.com/lfs-object/21/45/foo_bar'; - expect(findImage().exists()).toBe(true); - expect(findImage().attributes('src')).toBe(DEFAULT_BLOB_DATA.rawPath); - expect(findImage().attributes('alt')).toBe(DEFAULT_BLOB_DATA.name); + it('renders a Source Editor component with externalStorageUrl', () => { + const blobData = { ...DEFAULT_BLOB_DATA, externalStorageUrl }; + createComponent(blobData); + + expect(findImage().exists()).toBe(true); + expect(findImage().attributes('src')).toBe(externalStorageUrl); + expect(findImage().attributes('alt')).toBe(DEFAULT_BLOB_DATA.name); + }); + }); + + describe('When blob does not have an externalStorageUrl', () => { + it('renders a Source Editor component with rawPath', () => { + createComponent(DEFAULT_BLOB_DATA); + + expect(findImage().exists()).toBe(true); + expect(findImage().attributes('src')).toBe(DEFAULT_BLOB_DATA.rawPath); + expect(findImage().attributes('alt')).toBe(DEFAULT_BLOB_DATA.name); + }); }); }); diff --git a/spec/frontend/search/sidebar/components/confidentiality_filter_spec.js b/spec/frontend/search/sidebar/components/confidentiality_filter_spec.js index ef7f3359bad..68054a341a2 100644 --- a/spec/frontend/search/sidebar/components/confidentiality_filter_spec.js +++ b/spec/frontend/search/sidebar/components/confidentiality_filter_spec.js @@ -23,7 +23,7 @@ describe('ConfidentialityFilter', () => { describe('old sidebar', () => { beforeEach(() => { - createComponent({ useNewNavigation: false }); + createComponent({ useSidebarNavigation: false }); }); it('renders the component', () => { @@ -33,7 +33,7 @@ describe('ConfidentialityFilter', () => { describe('new sidebar', () => { beforeEach(() => { - createComponent({ useNewNavigation: true }); + createComponent({ useSidebarNavigation: true }); }); it('renders the component', () => { diff --git a/spec/frontend/search/sidebar/components/status_filter_spec.js b/spec/frontend/search/sidebar/components/status_filter_spec.js index 2cf5ae2a70a..fd705d5976b 100644 --- a/spec/frontend/search/sidebar/components/status_filter_spec.js +++ b/spec/frontend/search/sidebar/components/status_filter_spec.js @@ -23,7 +23,7 @@ describe('StatusFilter', () => { describe('old sidebar', () => { beforeEach(() => { - createComponent({ useNewNavigation: false }); + createComponent({ useSidebarNavigation: false }); }); it('renders the component', () => { @@ -33,7 +33,7 @@ describe('StatusFilter', () => { describe('new sidebar', () => { beforeEach(() => { - createComponent({ useNewNavigation: true }); + createComponent({ useSidebarNavigation: true }); }); it('renders the component', () => { diff --git a/spec/frontend/vue_shared/components/clipboard_button_spec.js b/spec/frontend/vue_shared/components/clipboard_button_spec.js index 08a9c2a42d8..271c99be57a 100644 --- a/spec/frontend/vue_shared/components/clipboard_button_spec.js +++ b/spec/frontend/vue_shared/components/clipboard_button_spec.js @@ -1,7 +1,8 @@ import { GlButton } from '@gitlab/ui'; -import { mount } from '@vue/test-utils'; +import { mount, createWrapper as makeWrapper } from '@vue/test-utils'; import { nextTick } from 'vue'; +import { BV_HIDE_TOOLTIP, BV_SHOW_TOOLTIP } from '~/lib/utils/constants'; import initCopyToClipboard, { CLIPBOARD_SUCCESS_EVENT, CLIPBOARD_ERROR_EVENT, @@ -31,7 +32,7 @@ describe('clipboard button', () => { title, }); - wrapper.vm.$root.$emit = jest.fn(); + const rootWrapper = makeWrapper(wrapper.vm.$root); const button = findButton(); @@ -42,7 +43,7 @@ describe('clipboard button', () => { await button.trigger(event); - expect(wrapper.vm.$root.$emit).toHaveBeenCalledWith('bv::show::tooltip', 'clipboard-button-1'); + expect(rootWrapper.emitted(BV_SHOW_TOOLTIP)[0]).toContain('clipboard-button-1'); expect(button.attributes()).toMatchObject({ title: message, @@ -56,7 +57,7 @@ describe('clipboard button', () => { title, 'aria-label': title, }); - expect(wrapper.vm.$root.$emit).toHaveBeenCalledWith('bv::hide::tooltip', 'clipboard-button-1'); + expect(rootWrapper.emitted(BV_HIDE_TOOLTIP)[0]).toContain('clipboard-button-1'); }; describe('without gfm', () => { diff --git a/spec/frontend/vue_shared/components/modal_copy_button_spec.js b/spec/frontend/vue_shared/components/modal_copy_button_spec.js index 2f8f97c5b95..7f3cf9820db 100644 --- a/spec/frontend/vue_shared/components/modal_copy_button_spec.js +++ b/spec/frontend/vue_shared/components/modal_copy_button_spec.js @@ -27,16 +27,19 @@ describe('modal copy button', () => { wrapper.trigger('click'); await nextTick(); - expect(wrapper.emitted().success).not.toBeEmpty(); + expect(wrapper.emitted('error')).toBeUndefined(); + expect(wrapper.emitted('success')).toHaveLength(1); expect(document.execCommand).toHaveBeenCalledWith('copy'); expect(root.emitted(BV_HIDE_TOOLTIP)).toEqual([['test-id']]); }); + it("should propagate the clipboard error event if execCommand doesn't work", async () => { document.execCommand = jest.fn(() => false); wrapper.trigger('click'); await nextTick(); - expect(wrapper.emitted().error).not.toBeEmpty(); + expect(wrapper.emitted('success')).toBeUndefined(); + expect(wrapper.emitted('error')).toHaveLength(1); expect(document.execCommand).toHaveBeenCalledWith('copy'); }); }); |