Commit fcd31f67 authored by Jose Ivan Vargas's avatar Jose Ivan Vargas

Merge branch 'tomquirk/343620-make-jira-issues-unediablte' into 'master'

Fix `canUpdate` console error on external issues

See merge request gitlab-org/gitlab!72950
parents ae348f6e 2a586727
...@@ -13,14 +13,18 @@ export default { ...@@ -13,14 +13,18 @@ export default {
IssueFieldDropdown, IssueFieldDropdown,
SidebarEditableItem, SidebarEditableItem,
}, },
provide() { inject: {
return { // In this context, `canUpdate` means: "can a user update any part of the sidebar?"
isClassicSidebar: true, // `canUpdate` is also injected into `sidebar-editable-item`. Here, it's used, in
canUpdate: this.canUpdate, // conjunction with with its `canEdit` prop, to conditionally display the
}; // "edit" button.
canUpdate: {
default: false,
},
}, },
props: { props: {
canUpdate: { // In this context, `canEditField` means: "can a user edit this specific field?"
canEditField: {
type: Boolean, type: Boolean,
required: false, required: false,
default: false, default: false,
...@@ -105,6 +109,7 @@ export default { ...@@ -105,6 +109,7 @@ export default {
ref="editableItem" ref="editableItem"
:loading="updating" :loading="updating"
:title="title" :title="title"
:can-edit="canEditField"
@open="showDropdown" @open="showDropdown"
> >
<template #collapsed> <template #collapsed>
...@@ -126,7 +131,7 @@ export default { ...@@ -126,7 +131,7 @@ export default {
<template #default> <template #default>
<issue-field-dropdown <issue-field-dropdown
v-if="canUpdate" v-if="canEditField && canUpdate"
ref="dropdown" ref="dropdown"
:empty-text="dropdownEmpty" :empty-text="dropdownEmpty"
:items="items" :items="items"
......
...@@ -136,7 +136,7 @@ export default { ...@@ -136,7 +136,7 @@ export default {
<issue-due-date :due-date="issue.dueDate" /> <issue-due-date :due-date="issue.dueDate" />
<issue-field <issue-field
icon="progress" icon="progress"
:can-update="canUpdateStatus" :can-edit-field="canUpdateStatus"
:dropdown-title="$options.i18n.statusDropdownTitle" :dropdown-title="$options.i18n.statusDropdownTitle"
:dropdown-empty="$options.i18n.statusDropdownEmpty" :dropdown-empty="$options.i18n.statusDropdownEmpty"
:items="statuses" :items="statuses"
......
...@@ -17,6 +17,8 @@ export default function initJiraIssueShow({ mountPointSelector }) { ...@@ -17,6 +17,8 @@ export default function initJiraIssueShow({ mountPointSelector }) {
issueLabelsPath, issueLabelsPath,
issuesShowPath, issuesShowPath,
issuesListPath, issuesListPath,
isClassicSidebar: true,
canUpdate: false,
}, },
render: (createElement) => createElement(JiraIssuesShowApp), render: (createElement) => createElement(JiraIssuesShowApp),
}); });
......
...@@ -16,6 +16,8 @@ export default function initZentaoIssueShow({ mountPointSelector }) { ...@@ -16,6 +16,8 @@ export default function initZentaoIssueShow({ mountPointSelector }) {
provide: { provide: {
issuesShowPath, issuesShowPath,
issuesListPath, issuesListPath,
isClassicSidebar: true,
canUpdate: false,
}, },
render: (createElement) => createElement(ZentaoIssuesShowApp), render: (createElement) => createElement(ZentaoIssuesShowApp),
}); });
......
...@@ -15,7 +15,7 @@ describe('IssueField', () => { ...@@ -15,7 +15,7 @@ describe('IssueField', () => {
title: 'Field Title', title: 'Field Title',
}; };
const createComponent = ({ props = {} } = {}) => { const createComponent = ({ props = {}, provide = {} } = {}) => {
wrapper = shallowMountExtended(IssueField, { wrapper = shallowMountExtended(IssueField, {
directives: { directives: {
GlTooltip: createMockDirective(), GlTooltip: createMockDirective(),
...@@ -24,6 +24,10 @@ describe('IssueField', () => { ...@@ -24,6 +24,10 @@ describe('IssueField', () => {
stubs: { stubs: {
SidebarEditableItem, SidebarEditableItem,
}, },
provide: {
canUpdate: true,
...provide,
},
}); });
}; };
...@@ -37,6 +41,7 @@ describe('IssueField', () => { ...@@ -37,6 +41,7 @@ describe('IssueField', () => {
const findFieldCollapsedTooltip = () => getBinding(findFieldCollapsed().element, 'gl-tooltip'); const findFieldCollapsedTooltip = () => getBinding(findFieldCollapsed().element, 'gl-tooltip');
const findFieldValue = () => wrapper.findByTestId('field-value'); const findFieldValue = () => wrapper.findByTestId('field-value');
const findGlIcon = () => wrapper.findComponent(GlIcon); const findGlIcon = () => wrapper.findComponent(GlIcon);
const findEditableItemDropdown = () => wrapper.findComponent({ ref: 'dropdown' });
describe('template', () => { describe('template', () => {
beforeEach(() => { beforeEach(() => {
...@@ -94,24 +99,45 @@ describe('IssueField', () => { ...@@ -94,24 +99,45 @@ describe('IssueField', () => {
}); });
}); });
describe('with canUpdate = true', () => { describe.each`
canUpdate | canEditField | expectEditButton
${false} | ${false} | ${false}
${false} | ${true} | ${false}
${true} | ${false} | ${false}
${true} | ${true} | ${true}
`(
'when `canUpdate` is `$canUpdate` and `canEditField` is `$canEditField`',
({ canUpdate, canEditField, expectEditButton }) => {
beforeEach(() => { beforeEach(() => {
createComponent({ createComponent({
props: { canUpdate: true }, props: { canEditField },
provide: {
canUpdate,
},
}); });
}); });
it('renders "Edit" button', () => { it('renders "Edit" button correctly', () => {
expect(findEditButton().text()).toBe('Edit'); expect(findEditButton().exists()).toBe(expectEditButton);
}); });
it('emits "issue-field-fetch" when dropdown is opened', () => { it('renders dropdown in sidebar-editable-item', () => {
wrapper.vm.$refs.dropdown.showDropdown = jest.fn(); expect(findEditableItemDropdown().exists()).toBe(expectEditButton);
});
if (expectEditButton) {
describe('when sidebar-editable-item emits "open" event', () => {
it('emits "issue-field-fetch" event', () => {
const dropdown = findEditableItemDropdown();
dropdown.vm.showDropdown = jest.fn();
findEditableItem().vm.$emit('open'); findEditableItem().vm.$emit('open');
expect(wrapper.vm.$refs.dropdown.showDropdown).toHaveBeenCalled(); expect(dropdown.vm.showDropdown).toHaveBeenCalled();
expect(wrapper.emitted('issue-field-fetch')).toHaveLength(1); expect(wrapper.emitted('issue-field-fetch')).toHaveLength(1);
}); });
}); });
}
},
);
}); });
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