Commit 22067f14 authored by Jacques Erasmus's avatar Jacques Erasmus

Merge branch '323210-vue-blob-header-delete-button' into 'master'

Update blob header to support delete button group

See merge request gitlab-org/gitlab!64666
parents 934f044d 84ac02ef
<script> <script>
import { GlButton, GlModalDirective } from '@gitlab/ui'; import { GlButtonGroup, GlButton, GlModalDirective } from '@gitlab/ui';
import { uniqueId } from 'lodash'; import { uniqueId } from 'lodash';
import { sprintf, __ } from '~/locale'; import { sprintf, __ } from '~/locale';
import getRefMixin from '../mixins/get_ref'; import getRefMixin from '../mixins/get_ref';
...@@ -9,8 +9,10 @@ export default { ...@@ -9,8 +9,10 @@ export default {
i18n: { i18n: {
replace: __('Replace'), replace: __('Replace'),
replacePrimaryBtnText: __('Replace file'), replacePrimaryBtnText: __('Replace file'),
delete: __('Delete'),
}, },
components: { components: {
GlButtonGroup,
GlButton, GlButton,
UploadBlobModal, UploadBlobModal,
}, },
...@@ -48,7 +50,7 @@ export default { ...@@ -48,7 +50,7 @@ export default {
replaceModalId() { replaceModalId() {
return uniqueId('replace-modal'); return uniqueId('replace-modal');
}, },
title() { replaceModalTitle() {
return sprintf(__('Replace %{name}'), { name: this.name }); return sprintf(__('Replace %{name}'), { name: this.name });
}, },
}, },
...@@ -57,13 +59,16 @@ export default { ...@@ -57,13 +59,16 @@ export default {
<template> <template>
<div class="gl-mr-3"> <div class="gl-mr-3">
<gl-button v-gl-modal="replaceModalId"> <gl-button-group>
{{ $options.i18n.replace }} <gl-button v-gl-modal="replaceModalId">
</gl-button> {{ $options.i18n.replace }}
</gl-button>
<gl-button>{{ $options.i18n.delete }}</gl-button>
</gl-button-group>
<upload-blob-modal <upload-blob-modal
:modal-id="replaceModalId" :modal-id="replaceModalId"
:modal-title="title" :modal-title="replaceModalTitle"
:commit-message="title" :commit-message="replaceModalTitle"
:target-branch="targetBranch || ref" :target-branch="targetBranch || ref"
:original-branch="originalBranch || ref" :original-branch="originalBranch || ref"
:can-push-code="canPushCode" :can-push-code="canPushCode"
......
...@@ -7,14 +7,14 @@ import { SIMPLE_BLOB_VIEWER, RICH_BLOB_VIEWER } from '~/blob/components/constant ...@@ -7,14 +7,14 @@ 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 BlobButtonGroup from './blob_button_group.vue';
import BlobEdit from './blob_edit.vue'; import BlobEdit from './blob_edit.vue';
import BlobReplace from './blob_replace.vue';
export default { export default {
components: { components: {
BlobHeader, BlobHeader,
BlobEdit, BlobEdit,
BlobReplace, BlobButtonGroup,
BlobContent, BlobContent,
GlLoadingIcon, GlLoadingIcon,
}, },
...@@ -132,7 +132,7 @@ export default { ...@@ -132,7 +132,7 @@ export default {
> >
<template #actions> <template #actions>
<blob-edit :edit-path="blobInfo.editBlobPath" :web-ide-path="blobInfo.ideEditPath" /> <blob-edit :edit-path="blobInfo.editBlobPath" :web-ide-path="blobInfo.ideEditPath" />
<blob-replace <blob-button-group
v-if="isLoggedIn" v-if="isLoggedIn"
:path="path" :path="path"
:name="blobInfo.name" :name="blobInfo.name"
......
import { GlButton } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import BlobReplace from '~/repository/components/blob_replace.vue'; import { createMockDirective, getBinding } from 'helpers/vue_mock_directive';
import BlobButtonGroup from '~/repository/components/blob_button_group.vue';
import UploadBlobModal from '~/repository/components/upload_blob_modal.vue'; import UploadBlobModal from '~/repository/components/upload_blob_modal.vue';
const DEFAULT_PROPS = { const DEFAULT_PROPS = {
...@@ -14,11 +17,11 @@ const DEFAULT_INJECT = { ...@@ -14,11 +17,11 @@ const DEFAULT_INJECT = {
originalBranch: 'master', originalBranch: 'master',
}; };
describe('BlobReplace component', () => { describe('BlobButtonGroup component', () => {
let wrapper; let wrapper;
const createComponent = (props = {}) => { const createComponent = (props = {}) => {
wrapper = shallowMount(BlobReplace, { wrapper = shallowMount(BlobButtonGroup, {
propsData: { propsData: {
...DEFAULT_PROPS, ...DEFAULT_PROPS,
...props, ...props,
...@@ -26,6 +29,9 @@ describe('BlobReplace component', () => { ...@@ -26,6 +29,9 @@ describe('BlobReplace component', () => {
provide: { provide: {
...DEFAULT_INJECT, ...DEFAULT_INJECT,
}, },
directives: {
GlModal: createMockDirective(),
},
}); });
}; };
...@@ -34,6 +40,7 @@ describe('BlobReplace component', () => { ...@@ -34,6 +40,7 @@ describe('BlobReplace component', () => {
}); });
const findUploadBlobModal = () => wrapper.findComponent(UploadBlobModal); const findUploadBlobModal = () => wrapper.findComponent(UploadBlobModal);
const findReplaceButton = () => wrapper.findAll(GlButton).at(0);
it('renders component', () => { it('renders component', () => {
createComponent(); createComponent();
...@@ -46,6 +53,28 @@ describe('BlobReplace component', () => { ...@@ -46,6 +53,28 @@ describe('BlobReplace component', () => {
}); });
}); });
describe('buttons', () => {
beforeEach(() => {
createComponent();
});
it('renders both the replace and delete button', () => {
expect(wrapper.findAll(GlButton)).toHaveLength(2);
});
it('renders the buttons in the correct order', () => {
expect(wrapper.findAll(GlButton).at(0).text()).toBe('Replace');
expect(wrapper.findAll(GlButton).at(1).text()).toBe('Delete');
});
it('triggers the UploadBlobModal from the replace button', () => {
const { value } = getBinding(findReplaceButton().element, 'gl-modal');
const modalId = findUploadBlobModal().props('modalId');
expect(modalId).toEqual(value);
});
});
it('renders UploadBlobModal', () => { it('renders UploadBlobModal', () => {
createComponent(); createComponent();
......
...@@ -3,9 +3,9 @@ import { shallowMount, mount } from '@vue/test-utils'; ...@@ -3,9 +3,9 @@ import { shallowMount, mount } from '@vue/test-utils';
import { nextTick } from 'vue'; 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 BlobButtonGroup from '~/repository/components/blob_button_group.vue';
import BlobContentViewer from '~/repository/components/blob_content_viewer.vue'; 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 BlobReplace from '~/repository/components/blob_replace.vue';
let wrapper; let wrapper;
const simpleMockData = { const simpleMockData = {
...@@ -80,7 +80,7 @@ describe('Blob content viewer component', () => { ...@@ -80,7 +80,7 @@ describe('Blob content viewer component', () => {
const findBlobHeader = () => wrapper.findComponent(BlobHeader); const findBlobHeader = () => wrapper.findComponent(BlobHeader);
const findBlobEdit = () => wrapper.findComponent(BlobEdit); const findBlobEdit = () => wrapper.findComponent(BlobEdit);
const findBlobContent = () => wrapper.findComponent(BlobContent); const findBlobContent = () => wrapper.findComponent(BlobContent);
const findBlobReplace = () => wrapper.findComponent(BlobReplace); const findBlobButtonGroup = () => wrapper.findComponent(BlobButtonGroup);
afterEach(() => { afterEach(() => {
wrapper.destroy(); wrapper.destroy();
...@@ -200,7 +200,7 @@ describe('Blob content viewer component', () => { ...@@ -200,7 +200,7 @@ describe('Blob content viewer component', () => {
}); });
}); });
describe('BlobReplace', () => { describe('BlobButtonGroup', () => {
const { name, path } = simpleMockData; const { name, path } = simpleMockData;
it('renders component', async () => { it('renders component', async () => {
...@@ -210,13 +210,13 @@ describe('Blob content viewer component', () => { ...@@ -210,13 +210,13 @@ describe('Blob content viewer component', () => {
mockData: { blobInfo: simpleMockData }, mockData: { blobInfo: simpleMockData },
stubs: { stubs: {
BlobContent: true, BlobContent: true,
BlobReplace: true, BlobButtonGroup: true,
}, },
}); });
await nextTick(); await nextTick();
expect(findBlobReplace().props()).toMatchObject({ expect(findBlobButtonGroup().props()).toMatchObject({
name, name,
path, path,
}); });
...@@ -235,7 +235,7 @@ describe('Blob content viewer component', () => { ...@@ -235,7 +235,7 @@ describe('Blob content viewer component', () => {
await nextTick(); await nextTick();
expect(findBlobReplace().exists()).toBe(false); expect(findBlobButtonGroup().exists()).toBe(false);
}); });
}); });
}); });
......
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