diff --git a/app/assets/javascripts/work_items/components/work_item_description.vue b/app/assets/javascripts/work_items/components/work_item_description.vue index 25293cb5e26087a1db125aca941f6732739a469e..e5d12b7c16b9c76888a2ceb25ed0d0f7c7ef8af6 100644 --- a/app/assets/javascripts/work_items/components/work_item_description.vue +++ b/app/assets/javascripts/work_items/components/work_item_description.vue @@ -184,11 +184,17 @@ export default { return this.workItem?.namespace?.id || ''; }, markdownPreviewPath() { + const isNewWorkItemInGroup = this.isGroup && this.workItemIid === NEW_WORK_ITEM_IID; const { fullPath, workItem: { iid }, } = this; - return markdownPreviewPath({ fullPath, iid, isGroup: this.isGroupWorkItem }); + + return markdownPreviewPath({ + fullPath, + iid, + isGroup: this.isGroupWorkItem || isNewWorkItemInGroup, + }); }, autocompleteDataSources() { const isNewWorkItemInGroup = this.isGroup && this.workItemIid === NEW_WORK_ITEM_IID; diff --git a/spec/frontend/work_items/components/work_item_description_spec.js b/spec/frontend/work_items/components/work_item_description_spec.js index 687824b068af88fd7d0c99f0855398dc20d4b9ea..2deb9abf335da785bdf1081ceffa7409ca35a39f 100644 --- a/spec/frontend/work_items/components/work_item_description_spec.js +++ b/spec/frontend/work_items/components/work_item_description_spec.js @@ -16,7 +16,7 @@ import updateWorkItemMutation from '~/work_items/graphql/update_work_item.mutati import workItemByIidQuery from '~/work_items/graphql/work_item_by_iid.query.graphql'; import workItemDescriptionTemplateQuery from '~/work_items/graphql/work_item_description_template.query.graphql'; import { autocompleteDataSources, markdownPreviewPath, newWorkItemId } from '~/work_items/utils'; -import { ROUTES } from '~/work_items/constants'; +import { ROUTES, NEW_WORK_ITEM_IID, NEW_WORK_ITEM_GID } from '~/work_items/constants'; import { updateWorkItemMutationResponse, workItemByIidResponseFactory, @@ -77,6 +77,7 @@ describe('WorkItemDescription', () => { descriptionTemplateHandler = successfulTemplateHandler, routeName = '', routeQuery = {}, + fullPath = 'test-project-path', hideFullscreenMarkdownButton = false, } = {}) => { router = { @@ -90,7 +91,7 @@ describe('WorkItemDescription', () => { [workItemDescriptionTemplateQuery, descriptionTemplateHandler], ]), propsData: { - fullPath: 'test-project-path', + fullPath, workItemId, workItemIid, workItemTypeId, @@ -185,6 +186,61 @@ describe('WorkItemDescription', () => { }); }); + it('passes correct autocompletion data sources when it is a new group work item', async () => { + const workItemResponse = workItemByIidResponseFactory({ + iid: NEW_WORK_ITEM_IID, + id: NEW_WORK_ITEM_GID, + }); + + const newGroupWorkItem = { + data: { + workspace: { + __typename: 'Group', + id: 'gid://gitlab/Group/24', + workItem: { + ...workItemResponse.data.workspace.workItem, + namespace: { + id: 'gid://gitlab/Group/24', + fullPath: 'gitlab-org', + name: 'Gitlab Org', + fullName: 'Gitlab Org', + __typename: 'Namespace', + }, + }, + }, + }, + }; + + const { + namespace: { fullPath }, + } = newGroupWorkItem.data.workspace.workItem; + + createComponent({ + isEditing: true, + isGroup: true, + workItemResponse: newGroupWorkItem, + workItemIid: NEW_WORK_ITEM_IID, + fullPath, + }); + + await waitForPromises(); + + expect(findMarkdownEditor().props()).toMatchObject({ + supportsQuickActions: true, + renderMarkdownPath: markdownPreviewPath({ + fullPath, + iid: NEW_WORK_ITEM_IID, + isGroup: true, + }), + autocompleteDataSources: autocompleteDataSources({ + fullPath, + iid: NEW_WORK_ITEM_IID, + isGroup: true, + workItemTypeId: 'gid://gitlab/WorkItems::Type/5', + }), + }); + }); + it('shows edited by text', async () => { const lastEditedAt = '2022-09-21T06:18:42Z'; const lastEditedBy = {