Skip to content
Snippets Groups Projects
Verified Commit c6d9f787 authored by Natalia Tepluhina's avatar Natalia Tepluhina Committed by GitLab
Browse files

Merge branch '435254-work-items-add-comment-and-close-button' into 'master'

Resolve "Work items: Add comment and close button"

See merge request gitlab-org/gitlab!141025



Merged-by: default avatarNatalia Tepluhina <ntepluhina@gitlab.com>
Approved-by: Nick Leonard's avatarNick Leonard <nleonard@gitlab.com>
Approved-by: Deepika Guliani's avatarDeepika Guliani <dguliani@gitlab.com>
Approved-by: default avatarNatalia Tepluhina <ntepluhina@gitlab.com>
Reviewed-by: default avatarNatalia Tepluhina <ntepluhina@gitlab.com>
Reviewed-by: Donald Cook's avatarDonald Cook <dcook@gitlab.com>
Reviewed-by: Deepika Guliani's avatarDeepika Guliani <dguliani@gitlab.com>
Co-authored-by: Donald Cook's avatarDonald Cook <dcook@gitlab.com>
parents 032192b2 6cf5191f
No related branches found
No related tags found
1 merge request!141025Resolve "Work items: Add comment and close button"
Pipeline #1134561161 passed
......@@ -235,7 +235,9 @@ export default {
:work-item-id="workItemId"
:work-item-state="workItemState"
:work-item-type="workItemType"
:has-comment="!!commentText.length"
can-update
@submit-comment="$emit('submitForm', { commentText, isNoteInternal })"
@error="$emit('error', $event)"
/>
<gl-button
......
......@@ -38,6 +38,11 @@ export default {
required: false,
default: false,
},
hasComment: {
type: Boolean,
required: false,
default: false,
},
},
data() {
return {
......@@ -49,9 +54,15 @@ export default {
return this.workItemState === STATE_OPEN;
},
toggleWorkItemStateText() {
const baseText = this.isWorkItemOpen
let baseText = this.isWorkItemOpen
? __('Close %{workItemType}')
: __('Reopen %{workItemType}');
if (this.hasComment) {
baseText = this.isWorkItemOpen
? __('Comment & close %{workItemType}')
: __('Comment & reopen %{workItemType}');
}
return sprintfWorkItem(baseText, this.workItemType);
},
tracking() {
......@@ -96,6 +107,10 @@ export default {
Sentry.captureException(error);
}
if (this.hasComment) {
this.$emit('submit-comment');
}
this.updateInProgress = false;
},
},
......
......@@ -12286,6 +12286,12 @@ msgstr ""
msgid "Comment"
msgstr ""
 
msgid "Comment & close %{workItemType}"
msgstr ""
msgid "Comment & reopen %{workItemType}"
msgstr ""
msgid "Comment '%{label}' position"
msgstr ""
 
......@@ -208,6 +208,20 @@ describe('Work item comment form component', () => {
['Something went wrong while updating the task. Please try again.'],
]);
});
it('emits `submitForm` event on closing of work item', async () => {
createComponent({
isNewDiscussion: true,
});
findWorkItemToggleStateButton().vm.$emit('submit-comment');
await waitForPromises();
expect(wrapper.emitted('submitForm')).toEqual([
[{ commentText: draftComment, isNoteInternal: false }],
]);
});
});
describe('internal note', () => {
......@@ -239,6 +253,17 @@ describe('Work item comment form component', () => {
expect(findConfirmButton().text()).toBe(WorkItemCommentForm.i18n.addInternalNote);
});
it('emits `submitForm` event on closing of work item', async () => {
findInternalNoteCheckbox().vm.$emit('input', true);
findWorkItemToggleStateButton().vm.$emit('submit-comment');
await waitForPromises();
expect(wrapper.emitted('submitForm')).toEqual([
[{ commentText: draftComment, isNoteInternal: true }],
]);
});
});
});
});
......@@ -32,6 +32,7 @@ describe('Work Item State toggle button component', () => {
canUpdate = true,
workItemState = STATE_OPEN,
workItemType = 'Task',
hasComment = false,
} = {}) => {
wrapper = shallowMount(WorkItemStateToggle, {
apolloProvider: createMockApollo([[updateWorkItemMutation, mutationHandler]]),
......@@ -40,6 +41,7 @@ describe('Work Item State toggle button component', () => {
workItemState,
workItemType,
canUpdate,
hasComment,
},
});
};
......@@ -61,6 +63,23 @@ describe('Work Item State toggle button component', () => {
expect(findStateToggleButton().text()).toBe(buttonText);
},
);
it.each`
workItemState | workItemType | buttonText
${STATE_OPEN} | ${'Task'} | ${'Comment & close task'}
${STATE_CLOSED} | ${'Task'} | ${'Comment & reopen task'}
${STATE_OPEN} | ${'Objective'} | ${'Comment & close objective'}
${STATE_CLOSED} | ${'Objective'} | ${'Comment & reopen objective'}
${STATE_OPEN} | ${'Key result'} | ${'Comment & close key result'}
${STATE_CLOSED} | ${'Key result'} | ${'Comment & reopen key result'}
`(
'is "$buttonText" when "$workItemType" state is "$workItemState" and hasComment is true',
({ workItemState, workItemType, buttonText }) => {
createComponent({ workItemState, workItemType, hasComment: true });
expect(findStateToggleButton().text()).toBe(buttonText);
},
);
});
describe('when updating the state', () => {
......@@ -92,6 +111,15 @@ describe('Work Item State toggle button component', () => {
});
});
it('emits `submit-comment` when hasComment is true', async () => {
createComponent({ hasComment: true });
findStateToggleButton().vm.$emit('click');
await waitForPromises();
expect(wrapper.emitted('submit-comment')).toBeDefined();
});
it('emits an error message when the mutation was unsuccessful', async () => {
createComponent({ mutationHandler: jest.fn().mockRejectedValue('Error!') });
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment