Commit 0ee0a889 authored by Andrew Fontaine's avatar Andrew Fontaine

Merge branch 'external-download-link' into 'master'

Ensure the correct download link is used for static objects

See merge request gitlab-org/gitlab!82580
parents 4e041c9b 2bd7376f
...@@ -17,7 +17,7 @@ export default { ...@@ -17,7 +17,7 @@ export default {
data() { data() {
return { return {
fileName: this.blob.name, fileName: this.blob.name,
filePath: this.blob.rawPath, filePath: this.blob.externalStorageUrl || this.blob.rawPath,
fileSize: this.blob.rawSize || 0, fileSize: this.blob.rawSize || 0,
}; };
}, },
......
...@@ -21,7 +21,7 @@ export default { ...@@ -21,7 +21,7 @@ export default {
data() { data() {
return { return {
fileName: this.blob.name, fileName: this.blob.name,
filePath: this.blob.rawPath, filePath: this.blob.externalStorageUrl || this.blob.rawPath,
}; };
}, },
}; };
......
...@@ -18,7 +18,7 @@ export default { ...@@ -18,7 +18,7 @@ export default {
}, },
data() { data() {
return { return {
url: this.blob.rawPath, url: this.blob.externalStorageUrl || this.blob.rawPath,
fileSize: this.blob.rawSize, fileSize: this.blob.rawSize,
totalPages: 0, totalPages: 0,
}; };
......
...@@ -23,6 +23,8 @@ describe('Text Viewer', () => { ...@@ -23,6 +23,8 @@ describe('Text Viewer', () => {
}); });
}; };
const findLink = () => wrapper.findComponent(GlLink);
it('renders download human readable file size text', () => { it('renders download human readable file size text', () => {
createComponent(); createComponent();
...@@ -42,7 +44,7 @@ describe('Text Viewer', () => { ...@@ -42,7 +44,7 @@ describe('Text Viewer', () => {
createComponent(); createComponent();
const { rawPath, name } = DEFAULT_BLOB_DATA; const { rawPath, name } = DEFAULT_BLOB_DATA;
expect(wrapper.findComponent(GlLink).attributes()).toMatchObject({ expect(findLink().attributes()).toMatchObject({
rel: 'nofollow', rel: 'nofollow',
target: '_blank', target: '_blank',
href: rawPath, href: rawPath,
...@@ -50,6 +52,13 @@ describe('Text Viewer', () => { ...@@ -50,6 +52,13 @@ describe('Text Viewer', () => {
}); });
}); });
it('renders the correct link href when stored externally', () => {
const externalStorageUrl = 'https://cdn.test.com/project/some/file.js?token=1234';
createComponent({ externalStorageUrl });
expect(findLink().attributes('href')).toBe(externalStorageUrl);
});
it('renders download icon', () => { it('renders download icon', () => {
createComponent(); createComponent();
......
...@@ -10,9 +10,9 @@ describe('LFS Viewer', () => { ...@@ -10,9 +10,9 @@ describe('LFS Viewer', () => {
rawPath: '/some/file/path', rawPath: '/some/file/path',
}; };
const createComponent = () => { const createComponent = (blobData = {}) => {
wrapper = shallowMount(LfsViewer, { wrapper = shallowMount(LfsViewer, {
propsData: { blob: { ...DEFAULT_BLOB_DATA } }, propsData: { blob: { ...DEFAULT_BLOB_DATA, ...blobData } },
stubs: { GlSprintf }, stubs: { GlSprintf },
}); });
}; };
...@@ -38,4 +38,11 @@ describe('LFS Viewer', () => { ...@@ -38,4 +38,11 @@ describe('LFS Viewer', () => {
download: name, download: name,
}); });
}); });
it('renders the correct link href when stored externally', () => {
const externalStorageUrl = 'https://cdn.test.com/project/some/file.js?token=1234';
createComponent({ externalStorageUrl });
expect(findLink().attributes('href')).toBe(externalStorageUrl);
});
}); });
import { GlButton } from '@gitlab/ui'; import { GlButton } from '@gitlab/ui';
import { nextTick } from 'vue';
import Component from '~/repository/components/blob_viewers/pdf_viewer.vue'; import Component from '~/repository/components/blob_viewers/pdf_viewer.vue';
import PdfViewer from '~/blob/pdf/pdf_viewer.vue'; import PdfViewer from '~/blob/pdf/pdf_viewer.vue';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper'; import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
...@@ -8,9 +9,9 @@ describe('PDF Viewer', () => { ...@@ -8,9 +9,9 @@ describe('PDF Viewer', () => {
const DEFAULT_BLOB_DATA = { rawPath: 'some/pdf_blob.pdf' }; const DEFAULT_BLOB_DATA = { rawPath: 'some/pdf_blob.pdf' };
const createComponent = (rawSize = 999) => { const createComponent = (rawSize = 999, externalStorageUrl) => {
wrapper = shallowMountExtended(Component, { wrapper = shallowMountExtended(Component, {
propsData: { blob: { ...DEFAULT_BLOB_DATA, rawSize } }, propsData: { blob: { ...DEFAULT_BLOB_DATA, rawSize, externalStorageUrl } },
}); });
}; };
...@@ -45,10 +46,14 @@ describe('PDF Viewer', () => { ...@@ -45,10 +46,14 @@ describe('PDF Viewer', () => {
}); });
describe('Too many pages', () => { describe('Too many pages', () => {
beforeEach(() => { const loadComponent = (externalStorageUrl) => {
createComponent(); const rawSize = 999;
findPDFViewer().vm.$emit('pdflabload', 100); const totalPages = 100;
}); createComponent(rawSize, externalStorageUrl);
findPDFViewer().vm.$emit('pdflabload', totalPages);
};
beforeEach(() => loadComponent());
it('does not a PDF Viewer component', () => { it('does not a PDF Viewer component', () => {
expect(findPDFViewer().exists()).toBe(false); expect(findPDFViewer().exists()).toBe(false);
...@@ -56,6 +61,15 @@ describe('PDF Viewer', () => { ...@@ -56,6 +61,15 @@ describe('PDF Viewer', () => {
it('renders a download button', () => { it('renders a download button', () => {
expect(findDownLoadButton().exists()).toBe(true); expect(findDownLoadButton().exists()).toBe(true);
expect(findDownLoadButton().attributes('href')).toBe(DEFAULT_BLOB_DATA.rawPath);
});
it('renders the correct href when stored externally', async () => {
const externalStorageUrl = 'https://cdn.test.com/project/some/file.js?token=1234';
loadComponent(externalStorageUrl);
await nextTick();
expect(findDownLoadButton().attributes('href')).toBe(externalStorageUrl);
}); });
}); });
}); });
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment