Commit 243a067e authored by Phil Hughes's avatar Phil Hughes

Merge branch '333852-hide-incidents-edit-btn' into 'master'

Hide edit severity btn for users without permissions

See merge request gitlab-org/gitlab!66642
parents bbcf7818 bc2a3899
...@@ -23,6 +23,7 @@ export default { ...@@ -23,6 +23,7 @@ export default {
GlLink, GlLink,
SeverityToken, SeverityToken,
}, },
inject: ['canUpdate'],
props: { props: {
projectPath: { projectPath: {
type: String, type: String,
...@@ -153,6 +154,7 @@ export default { ...@@ -153,6 +154,7 @@ export default {
> >
{{ $options.i18n.SEVERITY }} {{ $options.i18n.SEVERITY }}
<gl-link <gl-link
v-if="canUpdate"
data-testid="editButton" data-testid="editButton"
href="#" href="#"
@click="toggleFormDropdown" @click="toggleFormDropdown"
......
...@@ -493,7 +493,7 @@ function mountSeverityComponent() { ...@@ -493,7 +493,7 @@ function mountSeverityComponent() {
return false; return false;
} }
const { fullPath, iid, severity } = getSidebarOptions(); const { fullPath, iid, severity, editable } = getSidebarOptions();
return new Vue({ return new Vue({
el: severityContainerEl, el: severityContainerEl,
...@@ -501,6 +501,9 @@ function mountSeverityComponent() { ...@@ -501,6 +501,9 @@ function mountSeverityComponent() {
components: { components: {
SidebarSeverity, SidebarSeverity,
}, },
provide: {
canUpdate: editable,
},
render: (createElement) => render: (createElement) =>
createElement('sidebar-severity', { createElement('sidebar-severity', {
props: { props: {
......
import { GlDropdown, GlDropdownItem, GlLoadingIcon, GlTooltip, GlSprintf } from '@gitlab/ui'; import { GlDropdown, GlDropdownItem, GlLoadingIcon, GlTooltip, GlSprintf } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils'; import { nextTick } from 'vue';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import waitForPromises from 'helpers/wait_for_promises'; import waitForPromises from 'helpers/wait_for_promises';
import createFlash from '~/flash'; import createFlash from '~/flash';
import { INCIDENT_SEVERITY, ISSUABLE_TYPES } from '~/sidebar/components/severity/constants'; import { INCIDENT_SEVERITY, ISSUABLE_TYPES } from '~/sidebar/components/severity/constants';
...@@ -15,6 +16,7 @@ describe('SidebarSeverity', () => { ...@@ -15,6 +16,7 @@ describe('SidebarSeverity', () => {
const projectPath = 'gitlab-org/gitlab-test'; const projectPath = 'gitlab-org/gitlab-test';
const iid = '1'; const iid = '1';
const severity = 'CRITICAL'; const severity = 'CRITICAL';
let canUpdate = true;
function createComponent(props = {}) { function createComponent(props = {}) {
const propsData = { const propsData = {
...@@ -25,8 +27,11 @@ describe('SidebarSeverity', () => { ...@@ -25,8 +27,11 @@ describe('SidebarSeverity', () => {
...props, ...props,
}; };
mutate = jest.fn(); mutate = jest.fn();
wrapper = shallowMount(SidebarSeverity, { wrapper = shallowMountExtended(SidebarSeverity, {
propsData, propsData,
provide: {
canUpdate,
},
mocks: { mocks: {
$apollo: { $apollo: {
mutate, mutate,
...@@ -45,24 +50,36 @@ describe('SidebarSeverity', () => { ...@@ -45,24 +50,36 @@ describe('SidebarSeverity', () => {
afterEach(() => { afterEach(() => {
if (wrapper) { if (wrapper) {
wrapper.destroy(); wrapper.destroy();
wrapper = null;
} }
}); });
const findSeverityToken = () => wrapper.findAll(SeverityToken); const findSeverityToken = () => wrapper.findAllComponents(SeverityToken);
const findEditBtn = () => wrapper.find('[data-testid="editButton"]'); const findEditBtn = () => wrapper.findByTestId('editButton');
const findDropdown = () => wrapper.find(GlDropdown); const findDropdown = () => wrapper.findComponent(GlDropdown);
const findCriticalSeverityDropdownItem = () => wrapper.find(GlDropdownItem); const findCriticalSeverityDropdownItem = () => wrapper.findComponent(GlDropdownItem);
const findLoadingIcon = () => wrapper.find(GlLoadingIcon); const findLoadingIcon = () => wrapper.findComponent(GlLoadingIcon);
const findTooltip = () => wrapper.find(GlTooltip); const findTooltip = () => wrapper.findComponent(GlTooltip);
const findCollapsedSeverity = () => wrapper.find({ ref: 'severity' }); const findCollapsedSeverity = () => wrapper.find({ ref: 'severity' });
it('renders severity widget', () => { describe('Severity widget', () => {
expect(findEditBtn().exists()).toBe(true); it('renders severity dropdown and token', () => {
expect(findSeverityToken().exists()).toBe(true); expect(findSeverityToken().exists()).toBe(true);
expect(findDropdown().exists()).toBe(true); expect(findDropdown().exists()).toBe(true);
}); });
describe('edit button', () => {
it('is rendered when `canUpdate` provided as `true`', () => {
expect(findEditBtn().exists()).toBe(true);
});
it('is NOT rendered when `canUpdate` provided as `false`', () => {
canUpdate = false;
createComponent();
expect(findEditBtn().exists()).toBe(false);
});
});
});
describe('Update severity', () => { describe('Update severity', () => {
it('calls `$apollo.mutate` with `updateIssuableSeverity`', () => { it('calls `$apollo.mutate` with `updateIssuableSeverity`', () => {
jest jest
...@@ -100,7 +117,7 @@ describe('SidebarSeverity', () => { ...@@ -100,7 +117,7 @@ describe('SidebarSeverity', () => {
); );
findCriticalSeverityDropdownItem().vm.$emit('click'); findCriticalSeverityDropdownItem().vm.$emit('click');
await wrapper.vm.$nextTick(); await nextTick();
expect(findLoadingIcon().exists()).toBe(true); expect(findLoadingIcon().exists()).toBe(true);
resolvePromise(); resolvePromise();
...@@ -128,27 +145,29 @@ describe('SidebarSeverity', () => { ...@@ -128,27 +145,29 @@ describe('SidebarSeverity', () => {
it('should expand the dropdown on collapsed icon click', async () => { it('should expand the dropdown on collapsed icon click', async () => {
wrapper.vm.isDropdownShowing = false; wrapper.vm.isDropdownShowing = false;
await wrapper.vm.$nextTick(); await nextTick();
expect(findDropdown().classes(HIDDDEN_CLASS)).toBe(true); expect(findDropdown().classes(HIDDDEN_CLASS)).toBe(true);
findCollapsedSeverity().trigger('click'); findCollapsedSeverity().trigger('click');
await wrapper.vm.$nextTick(); await nextTick();
expect(findDropdown().classes(SHOWN_CLASS)).toBe(true); expect(findDropdown().classes(SHOWN_CLASS)).toBe(true);
}); });
}); });
describe('expanded', () => { describe('expanded', () => {
it('toggles dropdown with edit button', async () => { it('toggles dropdown with edit button', async () => {
canUpdate = true;
createComponent();
wrapper.vm.isDropdownShowing = false; wrapper.vm.isDropdownShowing = false;
await wrapper.vm.$nextTick(); await nextTick();
expect(findDropdown().classes(HIDDDEN_CLASS)).toBe(true); expect(findDropdown().classes(HIDDDEN_CLASS)).toBe(true);
findEditBtn().vm.$emit('click'); findEditBtn().vm.$emit('click');
await wrapper.vm.$nextTick(); await nextTick();
expect(findDropdown().classes(SHOWN_CLASS)).toBe(true); expect(findDropdown().classes(SHOWN_CLASS)).toBe(true);
findEditBtn().vm.$emit('click'); findEditBtn().vm.$emit('click');
await wrapper.vm.$nextTick(); await nextTick();
expect(findDropdown().classes(HIDDDEN_CLASS)).toBe(true); expect(findDropdown().classes(HIDDDEN_CLASS)).toBe(true);
}); });
}); });
......
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