diff options
Diffstat (limited to 'spec/frontend/repository/components/blob_viewers')
5 files changed, 70 insertions, 36 deletions
diff --git a/spec/frontend/repository/components/blob_viewers/download_viewer_spec.js b/spec/frontend/repository/components/blob_viewers/download_viewer_spec.js index c71b2b3c55c..5fe25ced302 100644 --- a/spec/frontend/repository/components/blob_viewers/download_viewer_spec.js +++ b/spec/frontend/repository/components/blob_viewers/download_viewer_spec.js @@ -6,42 +6,33 @@ import DownloadViewer from '~/repository/components/blob_viewers/download_viewer describe('Text Viewer', () => { let wrapper; - const DEFAULT_PROPS = { - fileName: 'file_name.js', - filePath: '/some/file/path', - fileSize: 2269674, + const DEFAULT_BLOB_DATA = { + name: 'file_name.js', + rawPath: '/some/file/path', + rawSize: 2269674, }; - const createComponent = (props = {}) => { + const createComponent = (blobData = {}) => { wrapper = shallowMount(DownloadViewer, { propsData: { - ...DEFAULT_PROPS, - ...props, + blob: { + ...DEFAULT_BLOB_DATA, + ...blobData, + }, }, }); }; - it('renders component', () => { - createComponent(); - - const { fileName, filePath, fileSize } = DEFAULT_PROPS; - expect(wrapper.props()).toMatchObject({ - fileName, - filePath, - fileSize, - }); - }); - it('renders download human readable file size text', () => { createComponent(); - const downloadText = `Download (${numberToHumanSize(DEFAULT_PROPS.fileSize)})`; + const downloadText = `Download (${numberToHumanSize(DEFAULT_BLOB_DATA.rawSize)})`; expect(wrapper.text()).toBe(downloadText); }); it('renders download text', () => { createComponent({ - fileSize: 0, + rawSize: 0, }); expect(wrapper.text()).toBe('Download'); @@ -49,13 +40,13 @@ describe('Text Viewer', () => { it('renders download link', () => { createComponent(); - const { filePath, fileName } = DEFAULT_PROPS; + const { rawPath, name } = DEFAULT_BLOB_DATA; expect(wrapper.findComponent(GlLink).attributes()).toMatchObject({ rel: 'nofollow', target: '_blank', - href: filePath, - download: fileName, + href: rawPath, + download: name, }); }); 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 6735dddf51e..c23de0efdfd 100644 --- a/spec/frontend/repository/components/blob_viewers/image_viewer_spec.js +++ b/spec/frontend/repository/components/blob_viewers/image_viewer_spec.js @@ -4,13 +4,13 @@ import ImageViewer from '~/repository/components/blob_viewers/image_viewer.vue'; describe('Image Viewer', () => { let wrapper; - const propsData = { - url: 'some/image.png', - alt: 'image.png', + const DEFAULT_BLOB_DATA = { + rawPath: 'some/image.png', + name: 'image.png', }; const createComponent = () => { - wrapper = shallowMount(ImageViewer, { propsData }); + wrapper = shallowMount(ImageViewer, { propsData: { blob: DEFAULT_BLOB_DATA } }); }; const findImage = () => wrapper.find('[data-testid="image"]'); @@ -19,7 +19,7 @@ describe('Image Viewer', () => { createComponent(); expect(findImage().exists()).toBe(true); - expect(findImage().attributes('src')).toBe(propsData.url); - expect(findImage().attributes('alt')).toBe(propsData.alt); + expect(findImage().attributes('src')).toBe(DEFAULT_BLOB_DATA.rawPath); + expect(findImage().attributes('alt')).toBe(DEFAULT_BLOB_DATA.name); }); }); diff --git a/spec/frontend/repository/components/blob_viewers/lfs_viewer_spec.js b/spec/frontend/repository/components/blob_viewers/lfs_viewer_spec.js new file mode 100644 index 00000000000..5caeb85834d --- /dev/null +++ b/spec/frontend/repository/components/blob_viewers/lfs_viewer_spec.js @@ -0,0 +1,41 @@ +import { GlLink, GlSprintf } from '@gitlab/ui'; +import { shallowMount } from '@vue/test-utils'; +import LfsViewer from '~/repository/components/blob_viewers/lfs_viewer.vue'; + +describe('LFS Viewer', () => { + let wrapper; + + const DEFAULT_BLOB_DATA = { + name: 'file_name.js', + rawPath: '/some/file/path', + }; + + const createComponent = () => { + wrapper = shallowMount(LfsViewer, { + propsData: { blob: { ...DEFAULT_BLOB_DATA } }, + stubs: { GlSprintf }, + }); + }; + + const findLink = () => wrapper.findComponent(GlLink); + + beforeEach(() => createComponent()); + + afterEach(() => wrapper.destroy()); + + it('renders the correct text', () => { + expect(wrapper.text()).toBe( + 'This content could not be displayed because it is stored in LFS. You can download it instead.', + ); + }); + + it('renders download link', () => { + const { rawPath, name } = DEFAULT_BLOB_DATA; + + expect(findLink().attributes()).toMatchObject({ + target: '_blank', + href: rawPath, + download: name, + }); + }); +}); diff --git a/spec/frontend/repository/components/blob_viewers/pdf_viewer_spec.js b/spec/frontend/repository/components/blob_viewers/pdf_viewer_spec.js index fd910002529..10eea691335 100644 --- a/spec/frontend/repository/components/blob_viewers/pdf_viewer_spec.js +++ b/spec/frontend/repository/components/blob_viewers/pdf_viewer_spec.js @@ -6,10 +6,12 @@ import { shallowMountExtended } from 'helpers/vue_test_utils_helper'; describe('PDF Viewer', () => { let wrapper; - const defaultPropsData = { url: 'some/pdf_blob.pdf' }; + const DEFAULT_BLOB_DATA = { rawPath: 'some/pdf_blob.pdf' }; - const createComponent = (fileSize = 999) => { - wrapper = shallowMountExtended(Component, { propsData: { ...defaultPropsData, fileSize } }); + const createComponent = (rawSize = 999) => { + wrapper = shallowMountExtended(Component, { + propsData: { blob: { ...DEFAULT_BLOB_DATA, rawSize } }, + }); }; const findPDFViewer = () => wrapper.findComponent(PdfViewer); @@ -20,7 +22,7 @@ describe('PDF Viewer', () => { createComponent(); expect(findPDFViewer().exists()).toBe(true); - expect(findPDFViewer().props('pdf')).toBe(defaultPropsData.url); + expect(findPDFViewer().props('pdf')).toBe(DEFAULT_BLOB_DATA.rawPath); }); describe('Too large', () => { diff --git a/spec/frontend/repository/components/blob_viewers/video_viewer_spec.js b/spec/frontend/repository/components/blob_viewers/video_viewer_spec.js index 34448c03b31..2e79a1496ce 100644 --- a/spec/frontend/repository/components/blob_viewers/video_viewer_spec.js +++ b/spec/frontend/repository/components/blob_viewers/video_viewer_spec.js @@ -4,10 +4,10 @@ import VideoViewer from '~/repository/components/blob_viewers/video_viewer.vue'; describe('Video Viewer', () => { let wrapper; - const propsData = { url: 'some/video.mp4' }; + const DEFAULT_BLOB_DATA = { rawPath: 'some/video.mp4' }; const createComponent = () => { - wrapper = shallowMountExtended(VideoViewer, { propsData }); + wrapper = shallowMountExtended(VideoViewer, { propsData: { blob: { ...DEFAULT_BLOB_DATA } } }); }; const findVideo = () => wrapper.findByTestId('video'); @@ -16,7 +16,7 @@ describe('Video Viewer', () => { createComponent(); expect(findVideo().exists()).toBe(true); - expect(findVideo().attributes('src')).toBe(propsData.url); + expect(findVideo().attributes('src')).toBe(DEFAULT_BLOB_DATA.rawPath); expect(findVideo().attributes('controls')).not.toBeUndefined(); }); }); |