Commit ca0693df authored by Jacques Erasmus's avatar Jacques Erasmus

Merge branch 'cherry-pick-a587f9b8' into 'master'

Add "empty" scenario and refactor viewers spec

See merge request gitlab-org/gitlab!66009
parents 4b22aa90 49d27c90
...@@ -13,6 +13,7 @@ import BlobContentViewer from '~/repository/components/blob_content_viewer.vue'; ...@@ -13,6 +13,7 @@ import BlobContentViewer from '~/repository/components/blob_content_viewer.vue';
import BlobEdit from '~/repository/components/blob_edit.vue'; import BlobEdit from '~/repository/components/blob_edit.vue';
import { loadViewer, viewerProps } from '~/repository/components/blob_viewers'; import { loadViewer, viewerProps } from '~/repository/components/blob_viewers';
import DownloadViewer from '~/repository/components/blob_viewers/download_viewer.vue'; import DownloadViewer from '~/repository/components/blob_viewers/download_viewer.vue';
import EmptyViewer from '~/repository/components/blob_viewers/empty_viewer.vue';
import TextViewer from '~/repository/components/blob_viewers/text_viewer.vue'; import TextViewer from '~/repository/components/blob_viewers/text_viewer.vue';
import blobInfoQuery from '~/repository/queries/blob_info.query.graphql'; import blobInfoQuery from '~/repository/queries/blob_info.query.graphql';
...@@ -124,8 +125,6 @@ describe('Blob content viewer component', () => { ...@@ -124,8 +125,6 @@ describe('Blob content viewer component', () => {
const findBlobEdit = () => wrapper.findComponent(BlobEdit); const findBlobEdit = () => wrapper.findComponent(BlobEdit);
const findBlobContent = () => wrapper.findComponent(BlobContent); const findBlobContent = () => wrapper.findComponent(BlobContent);
const findBlobButtonGroup = () => wrapper.findComponent(BlobButtonGroup); const findBlobButtonGroup = () => wrapper.findComponent(BlobButtonGroup);
const findTextViewer = () => wrapper.findComponent(TextViewer);
const findDownloadViewer = () => wrapper.findComponent(DownloadViewer);
afterEach(() => { afterEach(() => {
wrapper.destroy(); wrapper.destroy();
...@@ -225,9 +224,9 @@ describe('Blob content viewer component', () => { ...@@ -225,9 +224,9 @@ describe('Blob content viewer component', () => {
}); });
describe('Blob viewer', () => { describe('Blob viewer', () => {
beforeEach(() => { afterEach(() => {
loadViewer.mockClear(); loadViewer.mockRestore();
viewerProps.mockClear(); viewerProps.mockRestore();
}); });
it('does not render a BlobContent component if a Blob viewer is available', () => { it('does not render a BlobContent component if a Blob viewer is available', () => {
...@@ -237,39 +236,36 @@ describe('Blob content viewer component', () => { ...@@ -237,39 +236,36 @@ describe('Blob content viewer component', () => {
expect(findBlobContent().exists()).toBe(false); expect(findBlobContent().exists()).toBe(false);
}); });
it('renders a TextViewer for text files', () => { it.each`
loadViewer.mockReturnValueOnce(TextViewer); viewer | loadViewerReturnValue | viewerPropsReturnValue
viewerProps.mockReturnValueOnce({ content: 'test', fileName: 'test.js', readOnly: true }); ${'empty'} | ${EmptyViewer} | ${{}}
${'download'} | ${DownloadViewer} | ${{ filePath: '/some/file/path', fileName: 'test.js', fileSize: 100 }}
factory({ mockData: { blobInfo: simpleMockData } }); ${'text'} | ${TextViewer} | ${{ content: 'test', fileName: 'test.js', readOnly: true }}
`(
expect(findTextViewer().exists()).toBe(true); 'renders viewer component for $viewer files',
}); async ({ viewer, loadViewerReturnValue, viewerPropsReturnValue }) => {
loadViewer.mockReturnValue(loadViewerReturnValue);
it('renders a DownloadViewer for download files', async () => { viewerProps.mockReturnValue(viewerPropsReturnValue);
loadViewer.mockReturnValue(DownloadViewer);
viewerProps.mockReturnValue({ factory({
filePath: '/some/file/path', mockData: {
fileName: 'test.js', blobInfo: {
fileSize: 100, ...simpleMockData,
}); fileType: null,
simpleViewer: {
const downloadSimpleMockData = { ...simpleMockData.simpleViewer,
...simpleMockData, fileType: viewer,
fileType: null, },
simpleViewer: { },
...simpleMockData.simpleViewer, },
fileType: 'download', });
},
};
factory({ mockData: { blobInfo: downloadSimpleMockData } });
await nextTick(); await nextTick();
expect(loadViewer).toHaveBeenCalledWith('download'); expect(loadViewer).toHaveBeenCalledWith(viewer);
expect(findDownloadViewer().exists()).toBe(true); expect(wrapper.findComponent(loadViewerReturnValue).exists()).toBe(true);
}); },
);
}); });
describe('BlobHeader action slot', () => { describe('BlobHeader action slot', () => {
......
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