Commit 2a586727 authored by Tom Quirk's avatar Tom Quirk

Address reviewer feedback

Add more coverage for issue_field.
parent e093779a
...@@ -13,8 +13,18 @@ export default { ...@@ -13,8 +13,18 @@ export default {
IssueFieldDropdown, IssueFieldDropdown,
SidebarEditableItem, SidebarEditableItem,
}, },
inject: {
// In this context, `canUpdate` means: "can a user update any part of the sidebar?"
// `canUpdate` is also injected into `sidebar-editable-item`. Here, it's used, in
// conjunction with with its `canEdit` prop, to conditionally display the
// "edit" button.
canUpdate: {
default: false,
},
},
props: { props: {
canEdit: { // 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,
...@@ -99,7 +109,7 @@ export default { ...@@ -99,7 +109,7 @@ export default {
ref="editableItem" ref="editableItem"
:loading="updating" :loading="updating"
:title="title" :title="title"
:can-edit="canEdit" :can-edit="canEditField"
@open="showDropdown" @open="showDropdown"
> >
<template #collapsed> <template #collapsed>
...@@ -121,7 +131,7 @@ export default { ...@@ -121,7 +131,7 @@ export default {
<template #default> <template #default>
<issue-field-dropdown <issue-field-dropdown
v-if="canEdit" 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-edit="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"
......
...@@ -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(),
...@@ -26,6 +26,7 @@ describe('IssueField', () => { ...@@ -26,6 +26,7 @@ describe('IssueField', () => {
}, },
provide: { provide: {
canUpdate: true, canUpdate: true,
...provide,
}, },
}); });
}; };
...@@ -40,6 +41,7 @@ describe('IssueField', () => { ...@@ -40,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(() => {
...@@ -97,24 +99,45 @@ describe('IssueField', () => { ...@@ -97,24 +99,45 @@ describe('IssueField', () => {
}); });
}); });
describe('with canEdit = true', () => { describe.each`
beforeEach(() => { canUpdate | canEditField | expectEditButton
createComponent({ ${false} | ${false} | ${false}
props: { canEdit: true }, ${false} | ${true} | ${false}
${true} | ${false} | ${false}
${true} | ${true} | ${true}
`(
'when `canUpdate` is `$canUpdate` and `canEditField` is `$canEditField`',
({ canUpdate, canEditField, expectEditButton }) => {
beforeEach(() => {
createComponent({
props: { canEditField },
provide: {
canUpdate,
},
});
}); });
});
it('renders "Edit" button', () => {
expect(findEditButton().text()).toBe('Edit');
});
it('emits "issue-field-fetch" when dropdown is opened', () => { it('renders "Edit" button correctly', () => {
wrapper.vm.$refs.dropdown.showDropdown = jest.fn(); expect(findEditButton().exists()).toBe(expectEditButton);
});
findEditableItem().vm.$emit('open'); it('renders dropdown in sidebar-editable-item', () => {
expect(findEditableItemDropdown().exists()).toBe(expectEditButton);
});
expect(wrapper.vm.$refs.dropdown.showDropdown).toHaveBeenCalled(); if (expectEditButton) {
expect(wrapper.emitted('issue-field-fetch')).toHaveLength(1); 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');
expect(dropdown.vm.showDropdown).toHaveBeenCalled();
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