Commit 768e759c authored by Kev's avatar Kev Committed by Kushal Pandya

Hide "Health status" edit button when the user has no permission'

parent e6ebfd93
...@@ -36,7 +36,8 @@ export default { ...@@ -36,7 +36,8 @@ export default {
<template> <template>
<status <status
:is-editable="mediator.store.editable && isOpen" :is-open="isOpen"
:is-editable="mediator.store.editable"
:is-fetching="mediator.store.isFetching.status" :is-fetching="mediator.store.isFetching.status"
:status="mediator.store.status" :status="mediator.store.status"
@onDropdownClick="handleDropdownClick" @onDropdownClick="handleDropdownClick"
......
...@@ -26,6 +26,11 @@ export default { ...@@ -26,6 +26,11 @@ export default {
}, },
mixins: [Tracking.mixin()], mixins: [Tracking.mixin()],
props: { props: {
isOpen: {
type: Boolean,
required: false,
default: false,
},
isEditable: { isEditable: {
type: Boolean, type: Boolean,
required: false, required: false,
...@@ -74,7 +79,7 @@ export default { ...@@ -74,7 +79,7 @@ export default {
}; };
}, },
editTooltip() { editTooltip() {
const tooltipText = !this.isEditable const tooltipText = !this.isOpen
? s__('Health status cannot be edited because this issue is closed') ? s__('Health status cannot be edited because this issue is closed')
: ''; : '';
...@@ -147,12 +152,17 @@ export default { ...@@ -147,12 +152,17 @@ export default {
<div class="hide-collapsed"> <div class="hide-collapsed">
<p class="title gl-display-flex justify-content-between"> <p class="title gl-display-flex justify-content-between">
<span data-testid="statusTitle">{{ s__('Sidebar|Health status') }}</span> <span data-testid="statusTitle">{{ s__('Sidebar|Health status') }}</span>
<span v-gl-tooltip.topleft="editTooltip" data-testid="editButtonTooltip" tabindex="0"> <span
v-if="isEditable"
v-gl-tooltip.topleft="editTooltip"
data-testid="editButtonTooltip"
tabindex="0"
>
<gl-button <gl-button
ref="editButton" ref="editButton"
variant="link" variant="link"
class="edit-link btn-link-hover gl-text-black-normal!" class="edit-link btn-link-hover gl-text-black-normal!"
:disabled="!isEditable" :disabled="!isOpen"
@click.stop="toggleFormDropdown" @click.stop="toggleFormDropdown"
@keydown.esc="hideDropdown" @keydown.esc="hideDropdown"
> >
......
---
title: Hide "Health status" edit button when the user has no permission
merge_request: 49535
author: Kev @KevSlashNull
type: fixed
...@@ -39,7 +39,11 @@ describe('SidebarStatus', () => { ...@@ -39,7 +39,11 @@ describe('SidebarStatus', () => {
beforeEach(() => { beforeEach(() => {
createMediator(); createMediator();
createWrapper(); createWrapper({
getters: {
getNoteableData: {},
},
});
}); });
afterEach(() => { afterEach(() => {
......
...@@ -76,32 +76,65 @@ describe('Status', () => { ...@@ -76,32 +76,65 @@ describe('Status', () => {
}); });
describe('edit button', () => { describe('edit button', () => {
it('is displayed when user can edit', () => { it('is displayed when user can edit and the issue is open', () => {
const props = { const props = {
isEditable: true, isEditable: true,
isOpen: true,
}; };
shallowMountStatus(props); shallowMountStatus(props);
expect(getEditButton(wrapper).exists()).toBe(true); expect(getEditButton(wrapper).exists()).toBe(true);
expect(getEditButton(wrapper).props().disabled).toBe(false);
}); });
describe('when disabled', () => { describe('when closed and user does not have permission', () => {
beforeEach(() => { beforeEach(() => {
const props = { const props = {
isEditable: false, isEditable: false,
isOpen: false,
}; };
shallowMountStatus(props); shallowMountStatus(props);
}); });
it('is disabled when user cannot edit', () => {
expect(getEditButton(wrapper).attributes().disabled).toBe('true'); it('does not render the edit button', () => {
expect(getEditButton(wrapper).exists()).toBe(false);
});
});
describe('when closed and user has permission', () => {
beforeEach(() => {
const props = {
isEditable: true,
isOpen: false,
};
shallowMountStatus(props);
}); });
it('will render a tooltip with an informative message', () => { it('will render a tooltip with an informative message', () => {
const tooltipTitle = 'Health status cannot be edited because this issue is closed'; const tooltipTitle = 'Health status cannot be edited because this issue is closed';
expect(getEditButtonTooltipValue(wrapper).title).toBe(tooltipTitle); expect(getEditButtonTooltipValue(wrapper).title).toBe(tooltipTitle);
}); });
it('is disabled', () => {
expect(getEditButton(wrapper).props().disabled).toBe(true);
});
});
describe('when the user does not have permission', () => {
beforeEach(() => {
const props = {
isEditable: false,
};
shallowMountStatus(props);
});
it('does not render the edit button', () => {
expect(getEditButton(wrapper).exists()).toBe(false);
});
}); });
}); });
...@@ -198,6 +231,7 @@ describe('Status', () => { ...@@ -198,6 +231,7 @@ describe('Status', () => {
beforeEach(() => { beforeEach(() => {
const props = { const props = {
isEditable: true, isEditable: true,
isOpen: true,
}; };
mountStatus(props); mountStatus(props);
...@@ -215,6 +249,7 @@ describe('Status', () => { ...@@ -215,6 +249,7 @@ describe('Status', () => {
beforeEach(() => { beforeEach(() => {
const props = { const props = {
isEditable: true, isEditable: true,
isOpen: true,
}; };
mountStatus(props); mountStatus(props);
......
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