From 6168721025dd8e98caeb2bf6844273e6690eaf69 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Fri, 7 Feb 2020 00:09:12 +0000 Subject: Add latest changes from gitlab-org/gitlab@master --- .../blob_header_filepath_spec.js.snap | 35 +++++++++ .../blob/components/blob_header_filepath_spec.js | 90 ++++++++++++++++++++++ spec/frontend/blob/components/mock_data.js | 29 +++++++ 3 files changed, 154 insertions(+) create mode 100644 spec/frontend/blob/components/__snapshots__/blob_header_filepath_spec.js.snap create mode 100644 spec/frontend/blob/components/blob_header_filepath_spec.js create mode 100644 spec/frontend/blob/components/mock_data.js (limited to 'spec/frontend/blob') diff --git a/spec/frontend/blob/components/__snapshots__/blob_header_filepath_spec.js.snap b/spec/frontend/blob/components/__snapshots__/blob_header_filepath_spec.js.snap new file mode 100644 index 00000000000..7382a3a4cf7 --- /dev/null +++ b/spec/frontend/blob/components/__snapshots__/blob_header_filepath_spec.js.snap @@ -0,0 +1,35 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Blob Header Filepath rendering matches the snapshot 1`] = ` +
+ +
+`; diff --git a/spec/frontend/blob/components/blob_header_filepath_spec.js b/spec/frontend/blob/components/blob_header_filepath_spec.js new file mode 100644 index 00000000000..d029ba2a7a4 --- /dev/null +++ b/spec/frontend/blob/components/blob_header_filepath_spec.js @@ -0,0 +1,90 @@ +import { shallowMount } from '@vue/test-utils'; +import BlobHeaderFilepath from '~/blob/components/blob_header_filepath.vue'; +import ClipboardButton from '~/vue_shared/components/clipboard_button.vue'; +import { Blob as MockBlob } from './mock_data'; +import { numberToHumanSize } from '~/lib/utils/number_utils'; + +const mockHumanReadableSize = 'a lot'; +jest.mock('~/lib/utils/number_utils', () => ({ + numberToHumanSize: jest.fn(() => mockHumanReadableSize), +})); + +describe('Blob Header Filepath', () => { + let wrapper; + + function createComponent(blobProps = {}, options = {}) { + wrapper = shallowMount(BlobHeaderFilepath, { + propsData: { + blob: Object.assign({}, MockBlob, blobProps), + }, + ...options, + }); + } + + afterEach(() => { + wrapper.destroy(); + }); + + describe('rendering', () => { + it('matches the snapshot', () => { + createComponent(); + expect(wrapper.element).toMatchSnapshot(); + }); + + it('renders regular name', () => { + createComponent(); + expect( + wrapper + .find('.js-blob-header-filepath') + .text() + .trim(), + ).toBe(MockBlob.name); + }); + + it('does not fail if the name is empty', () => { + const emptyName = ''; + createComponent({ name: emptyName }); + expect(wrapper.find('.js-blob-header-filepath').exists()).toBe(false); + }); + + it('renders copy-to-clipboard icon that copies path of the Blob', () => { + createComponent(); + const btn = wrapper.find(ClipboardButton); + expect(btn.exists()).toBe(true); + expect(btn.vm.text).toBe(MockBlob.path); + }); + + it('renders filesize in a human-friendly format', () => { + createComponent(); + expect(numberToHumanSize).toHaveBeenCalled(); + expect(wrapper.vm.blobSize).toBe(mockHumanReadableSize); + }); + + it('renders a slot and prepends its contents to the existing one', () => { + const slotContent = 'Foo Bar'; + createComponent( + {}, + { + scopedSlots: { + filepathPrepend: `${slotContent}`, + }, + }, + ); + + expect(wrapper.text()).toContain(slotContent); + expect( + wrapper + .text() + .trim() + .substring(0, slotContent.length), + ).toBe(slotContent); + }); + }); + + describe('functionality', () => { + it('sets gfm value correctly on the clipboard-button', () => { + createComponent(); + expect(wrapper.vm.gfmCopyText).toBe('`dummy.md`'); + }); + }); +}); diff --git a/spec/frontend/blob/components/mock_data.js b/spec/frontend/blob/components/mock_data.js new file mode 100644 index 00000000000..4f7b297aba0 --- /dev/null +++ b/spec/frontend/blob/components/mock_data.js @@ -0,0 +1,29 @@ +export const Blob = { + binary: false, + highlightedData: + '

\nThis one is dummy

\n

\nAnd has sub-header

\n

Even some stupid text here

', + name: 'dummy.md', + path: 'dummy.md', + rawPath: '/flightjs/flight/snippets/51/raw', + size: 75, + simpleViewer: { + collapsed: false, + fileType: 'text', + loadAsync: true, + loadingPartialName: 'loading', + renderError: null, + tooLarge: false, + type: 'simple', + }, + richViewer: { + collapsed: false, + fileType: 'markup', + loadAsync: true, + loadingPartialName: 'loading', + renderError: null, + tooLarge: false, + type: 'rich', + }, +}; + +export default {}; -- cgit v1.2.3