Commit 74da7a21 authored by Nicolò Maria Mezzopera's avatar Nicolò Maria Mezzopera

Merge branch '323210-vue-blob-header-edit' into 'master'

Convert BlobHeader to Vue: Add Edit button

See merge request gitlab-org/gitlab!60986
parents ec7b1214 d3605803
...@@ -7,10 +7,12 @@ import { SIMPLE_BLOB_VIEWER, RICH_BLOB_VIEWER } from '~/blob/components/constant ...@@ -7,10 +7,12 @@ import { SIMPLE_BLOB_VIEWER, RICH_BLOB_VIEWER } from '~/blob/components/constant
import createFlash from '~/flash'; import createFlash from '~/flash';
import { __ } from '~/locale'; import { __ } from '~/locale';
import blobInfoQuery from '../queries/blob_info.query.graphql'; import blobInfoQuery from '../queries/blob_info.query.graphql';
import BlobHeaderEdit from './blob_header_edit.vue';
export default { export default {
components: { components: {
BlobHeader, BlobHeader,
BlobHeaderEdit,
BlobContent, BlobContent,
GlLoadingIcon, GlLoadingIcon,
}, },
...@@ -122,7 +124,11 @@ export default { ...@@ -122,7 +124,11 @@ export default {
:active-viewer-type="viewer.type" :active-viewer-type="viewer.type"
:has-render-error="hasRenderError" :has-render-error="hasRenderError"
@viewer-changed="switchViewer" @viewer-changed="switchViewer"
/> >
<template #actions>
<blob-header-edit :edit-path="blobInfo.editBlobPath" />
</template>
</blob-header>
<blob-content <blob-content
:blob="blobInfo" :blob="blobInfo"
:content="blobInfo.rawTextBlob" :content="blobInfo.rawTextBlob"
......
<script>
import { GlButton } from '@gitlab/ui';
import { __ } from '~/locale';
export default {
i18n: {
edit: __('Edit'),
},
components: {
GlButton,
},
props: {
editPath: {
type: String,
required: true,
},
},
};
</script>
<template>
<gl-button category="primary" variant="confirm" class="gl-mr-3" :href="editPath">
{{ $options.i18n.edit }}
</gl-button>
</template>
import { GlLoadingIcon } from '@gitlab/ui'; import { GlLoadingIcon } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils'; import { shallowMount, mount } from '@vue/test-utils';
import { nextTick } from 'vue';
import BlobContent from '~/blob/components/blob_content.vue'; import BlobContent from '~/blob/components/blob_content.vue';
import BlobHeader from '~/blob/components/blob_header.vue'; import BlobHeader from '~/blob/components/blob_header.vue';
import BlobContentViewer from '~/repository/components/blob_content_viewer.vue'; import BlobContentViewer from '~/repository/components/blob_content_viewer.vue';
import BlobHeaderEdit from '~/repository/components/blob_header_edit.vue';
let wrapper; let wrapper;
const simpleMockData = { const simpleMockData = {
...@@ -44,8 +46,11 @@ const richMockData = { ...@@ -44,8 +46,11 @@ const richMockData = {
}, },
}; };
function factory({ props = {}, mockData = {} } = {}, loading = false) { const createFactory = (mountFn) => (
wrapper = shallowMount(BlobContentViewer, { { props = {}, mockData = {}, stubs = {} } = {},
loading = false,
) => {
wrapper = mountFn(BlobContentViewer, {
propsData: { propsData: {
path: 'some_file.js', path: 'some_file.js',
projectPath: 'some/path', projectPath: 'some/path',
...@@ -60,20 +65,21 @@ function factory({ props = {}, mockData = {} } = {}, loading = false) { ...@@ -60,20 +65,21 @@ function factory({ props = {}, mockData = {} } = {}, loading = false) {
}, },
}, },
}, },
stubs,
}); });
wrapper.setData(mockData); wrapper.setData(mockData);
} };
const factory = createFactory(shallowMount);
const fullFactory = createFactory(mount);
describe('Blob content viewer component', () => { describe('Blob content viewer component', () => {
const findLoadingIcon = () => wrapper.find(GlLoadingIcon); const findLoadingIcon = () => wrapper.find(GlLoadingIcon);
const findBlobHeader = () => wrapper.find(BlobHeader); const findBlobHeader = () => wrapper.find(BlobHeader);
const findBlobHeaderEdit = () => wrapper.find(BlobHeaderEdit);
const findBlobContent = () => wrapper.find(BlobContent); const findBlobContent = () => wrapper.find(BlobContent);
beforeEach(() => {
factory({ mockData: { blobInfo: simpleMockData } });
});
afterEach(() => { afterEach(() => {
wrapper.destroy(); wrapper.destroy();
}); });
...@@ -85,6 +91,10 @@ describe('Blob content viewer component', () => { ...@@ -85,6 +91,10 @@ describe('Blob content viewer component', () => {
}); });
describe('simple viewer', () => { describe('simple viewer', () => {
beforeEach(() => {
factory({ mockData: { blobInfo: simpleMockData } });
});
it('renders a BlobHeader component', () => { it('renders a BlobHeader component', () => {
expect(findBlobHeader().props('activeViewerType')).toEqual('simple'); expect(findBlobHeader().props('activeViewerType')).toEqual('simple');
expect(findBlobHeader().props('hasRenderError')).toEqual(false); expect(findBlobHeader().props('hasRenderError')).toEqual(false);
...@@ -140,7 +150,7 @@ describe('Blob content viewer component', () => { ...@@ -140,7 +150,7 @@ describe('Blob content viewer component', () => {
expect(findBlobHeader().props('activeViewerType')).toEqual('rich'); expect(findBlobHeader().props('activeViewerType')).toEqual('rich');
findBlobHeader().vm.$emit('viewer-changed', 'simple'); findBlobHeader().vm.$emit('viewer-changed', 'simple');
await wrapper.vm.$nextTick(); await nextTick();
expect(findBlobHeader().props('activeViewerType')).toEqual('simple'); expect(findBlobHeader().props('activeViewerType')).toEqual('simple');
expect(findBlobContent().props('activeViewer')).toEqual( expect(findBlobContent().props('activeViewer')).toEqual(
...@@ -150,4 +160,28 @@ describe('Blob content viewer component', () => { ...@@ -150,4 +160,28 @@ describe('Blob content viewer component', () => {
); );
}); });
}); });
describe('BlobHeader action slot', () => {
it('renders BlobHeaderEdit button in simple viewer', async () => {
fullFactory({
mockData: { blobInfo: simpleMockData },
stubs: {
BlobContent: true,
},
});
await nextTick();
expect(findBlobHeaderEdit().props('editPath')).toEqual('some_file.js/edit');
});
it('renders BlobHeaderEdit button in rich viewer', async () => {
fullFactory({
mockData: { blobInfo: richMockData },
stubs: {
BlobContent: true,
},
});
await nextTick();
expect(findBlobHeaderEdit().props('editPath')).toEqual('some_file.js/edit');
});
});
}); });
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