diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-02-17 21:07:50 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-02-17 21:07:50 +0000 |
commit | 360ee1db0bf3bba2fc7aad7f230ec80829561227 (patch) | |
tree | ca7484ad394da3eb719c8070857e6f20eb1d9f51 /spec/frontend | |
parent | ec76d14980534d45d25ef65134a756c733fe4877 (diff) | |
download | gitlab-ce-360ee1db0bf3bba2fc7aad7f230ec80829561227.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend')
-rw-r--r-- | spec/frontend/issues/show/components/description_spec.js | 392 |
1 files changed, 185 insertions, 207 deletions
diff --git a/spec/frontend/issues/show/components/description_spec.js b/spec/frontend/issues/show/components/description_spec.js index 3f4513e6bfa..da51372dd3d 100644 --- a/spec/frontend/issues/show/components/description_spec.js +++ b/spec/frontend/issues/show/components/description_spec.js @@ -310,69 +310,58 @@ describe('Description component', () => { }); }); - describe('with work_items_mvc feature flag enabled', () => { - describe('empty description', () => { - beforeEach(() => { - createComponent({ - props: { - descriptionHtml: '', - }, - provide: { - glFeatures: { - workItemsMvc: true, - }, - }, - }); - return nextTick(); + describe('empty description', () => { + beforeEach(() => { + createComponent({ + props: { + descriptionHtml: '', + }, }); + return nextTick(); + }); - it('renders without error', () => { - expect(findTaskActionButtons()).toHaveLength(0); - }); + it('renders without error', () => { + expect(findTaskActionButtons()).toHaveLength(0); }); + }); - describe('description with checkboxes', () => { - beforeEach(() => { - createComponent({ - props: { - descriptionHtml: descriptionHtmlWithCheckboxes, - }, - provide: { - glFeatures: { - workItemsMvc: true, - }, - }, - }); - return nextTick(); + describe('description with checkboxes', () => { + beforeEach(() => { + createComponent({ + props: { + descriptionHtml: descriptionHtmlWithCheckboxes, + }, }); + return nextTick(); + }); - it('renders a list of hidden buttons corresponding to checkboxes in description HTML', () => { - expect(findTaskActionButtons()).toHaveLength(3); - }); + it('renders a list of hidden buttons corresponding to checkboxes in description HTML', () => { + expect(findTaskActionButtons()).toHaveLength(3); + }); - it('does not show a modal by default', () => { - expect(findModal().exists()).toBe(false); - }); + it('does not show a modal by default', () => { + expect(findModal().exists()).toBe(false); + }); - it('shows toast after delete success', async () => { - const newDesc = 'description'; - findWorkItemDetailModal().vm.$emit('workItemDeleted', newDesc); + it('shows toast after delete success', async () => { + const newDesc = 'description'; + findWorkItemDetailModal().vm.$emit('workItemDeleted', newDesc); - expect(wrapper.emitted('updateDescription')).toEqual([[newDesc]]); - expect($toast.show).toHaveBeenCalledWith('Task deleted'); - }); + expect(wrapper.emitted('updateDescription')).toEqual([[newDesc]]); + expect($toast.show).toHaveBeenCalledWith('Task deleted'); }); + }); - describe('task list item actions', () => { - describe('converting the task list item to a task', () => { - describe('when successful', () => { - let createWorkItemMutationHandler; + describe('task list item actions', () => { + describe('converting the task list item to a task', () => { + describe('when successful', () => { + let createWorkItemMutationHandler; - beforeEach(async () => { - createWorkItemMutationHandler = jest - .fn() - .mockResolvedValue(createWorkItemMutationResponse); - const descriptionText = `Tasks + beforeEach(async () => { + createWorkItemMutationHandler = jest + .fn() + .mockResolvedValue(createWorkItemMutationResponse); + const descriptionText = `Tasks 1. [ ] item 1 1. [ ] item 2 @@ -381,218 +370,207 @@ describe('Description component', () => { 1. [ ] item 3 1. [ ] item 4;`; - createComponent({ - props: { descriptionText }, - provide: { glFeatures: { workItemsMvc: true } }, - createWorkItemMutationHandler, - }); - await waitForPromises(); - - eventHub.$emit('convert-task-list-item', '4:4-8:19'); - await waitForPromises(); + createComponent({ + props: { descriptionText }, + createWorkItemMutationHandler, }); + await waitForPromises(); - it('emits an event to update the description with the deleted task list item omitted', () => { - const newDescriptionText = `Tasks + eventHub.$emit('convert-task-list-item', '4:4-8:19'); + await waitForPromises(); + }); + + it('emits an event to update the description with the deleted task list item omitted', () => { + const newDescriptionText = `Tasks 1. [ ] item 1 1. [ ] item 3 1. [ ] item 4;`; - expect(wrapper.emitted('saveDescription')).toEqual([[newDescriptionText]]); - }); + expect(wrapper.emitted('saveDescription')).toEqual([[newDescriptionText]]); + }); - it('calls a mutation to create a task', () => { - const { + it('calls a mutation to create a task', () => { + const { + confidential, + iteration, + milestone, + } = issueDetailsResponse.data.workspace.issuable; + expect(createWorkItemMutationHandler).toHaveBeenCalledWith({ + input: { confidential, - iteration, - milestone, - } = issueDetailsResponse.data.workspace.issuable; - expect(createWorkItemMutationHandler).toHaveBeenCalledWith({ - input: { - confidential, - description: '\nparagraph text\n', - hierarchyWidget: { - parentId: 'gid://gitlab/WorkItem/1', - }, - iterationWidget: { - iterationId: IS_EE ? iteration.id : null, - }, - milestoneWidget: { - milestoneId: milestone.id, - }, - projectPath: 'gitlab-org/gitlab-test', - title: 'item 2', - workItemTypeId: 'gid://gitlab/WorkItems::Type/3', + description: '\nparagraph text\n', + hierarchyWidget: { + parentId: 'gid://gitlab/WorkItem/1', + }, + iterationWidget: { + iterationId: IS_EE ? iteration.id : null, + }, + milestoneWidget: { + milestoneId: milestone.id, }, - }); + projectPath: 'gitlab-org/gitlab-test', + title: 'item 2', + workItemTypeId: 'gid://gitlab/WorkItems::Type/3', + }, }); + }); - it('shows a toast to confirm the creation of the task', () => { - expect($toast.show).toHaveBeenCalledWith('Converted to task', expect.any(Object)); - }); + it('shows a toast to confirm the creation of the task', () => { + expect($toast.show).toHaveBeenCalledWith('Converted to task', expect.any(Object)); }); + }); - describe('when unsuccessful', () => { - beforeEach(async () => { - createComponent({ - props: { descriptionText: 'description' }, - provide: { glFeatures: { workItemsMvc: true } }, - createWorkItemMutationHandler: jest - .fn() - .mockResolvedValue(createWorkItemMutationErrorResponse), - }); - await waitForPromises(); - - eventHub.$emit('convert-task-list-item', '1:1-1:11'); - await waitForPromises(); + describe('when unsuccessful', () => { + beforeEach(async () => { + createComponent({ + props: { descriptionText: 'description' }, + createWorkItemMutationHandler: jest + .fn() + .mockResolvedValue(createWorkItemMutationErrorResponse), }); + await waitForPromises(); - it('shows an alert with an error message', () => { - expect(createAlert).toHaveBeenCalledWith({ - message: 'Something went wrong when creating task. Please try again.', - error: new Error('an error'), - captureError: true, - }); + eventHub.$emit('convert-task-list-item', '1:1-1:11'); + await waitForPromises(); + }); + + it('shows an alert with an error message', () => { + expect(createAlert).toHaveBeenCalledWith({ + message: 'Something went wrong when creating task. Please try again.', + error: new Error('an error'), + captureError: true, }); }); }); + }); - describe('deleting the task list item', () => { - it('emits an event to update the description with the deleted task list item', () => { - const descriptionText = `Tasks + describe('deleting the task list item', () => { + it('emits an event to update the description with the deleted task list item', () => { + const descriptionText = `Tasks 1. [ ] item 1 1. [ ] item 2 1. [ ] item 3 1. [ ] item 4;`; - const newDescriptionText = `Tasks + const newDescriptionText = `Tasks 1. [ ] item 1 1. [ ] item 3 1. [ ] item 4;`; - createComponent({ - props: { descriptionText }, - provide: { glFeatures: { workItemsMvc: true } }, - }); + createComponent({ + props: { descriptionText }, + }); - eventHub.$emit('delete-task-list-item', '4:4-5:19'); + eventHub.$emit('delete-task-list-item', '4:4-5:19'); - expect(wrapper.emitted('saveDescription')).toEqual([[newDescriptionText]]); - }); + expect(wrapper.emitted('saveDescription')).toEqual([[newDescriptionText]]); }); }); + }); - describe('work items detail', () => { - describe('when opening and closing', () => { - beforeEach(() => { - createComponent({ - props: { - descriptionHtml: descriptionHtmlWithTask, - }, - provide: { - glFeatures: { workItemsMvc: true }, - }, - }); - return nextTick(); + describe('work items detail', () => { + describe('when opening and closing', () => { + beforeEach(() => { + createComponent({ + props: { + descriptionHtml: descriptionHtmlWithTask, + }, }); + return nextTick(); + }); - it('opens when task button is clicked', async () => { - await findTaskLink().trigger('click'); + it('opens when task button is clicked', async () => { + await findTaskLink().trigger('click'); - expect(showDetailsModal).toHaveBeenCalled(); - expect(updateHistory).toHaveBeenCalledWith({ - url: `${TEST_HOST}/?work_item_id=2`, - replace: true, - }); + expect(showDetailsModal).toHaveBeenCalled(); + expect(updateHistory).toHaveBeenCalledWith({ + url: `${TEST_HOST}/?work_item_id=2`, + replace: true, }); + }); - it('closes from an open state', async () => { - await findTaskLink().trigger('click'); + it('closes from an open state', async () => { + await findTaskLink().trigger('click'); - findWorkItemDetailModal().vm.$emit('close'); - await nextTick(); + findWorkItemDetailModal().vm.$emit('close'); + await nextTick(); - expect(updateHistory).toHaveBeenLastCalledWith({ - url: `${TEST_HOST}/`, - replace: true, - }); + expect(updateHistory).toHaveBeenLastCalledWith({ + url: `${TEST_HOST}/`, + replace: true, }); + }); - it('tracks when opened', async () => { - const trackingSpy = mockTracking(undefined, wrapper.element, jest.spyOn); - - await findTaskLink().trigger('click'); + it('tracks when opened', async () => { + const trackingSpy = mockTracking(undefined, wrapper.element, jest.spyOn); - expect(trackingSpy).toHaveBeenCalledWith( - TRACKING_CATEGORY_SHOW, - 'viewed_work_item_from_modal', - { - category: TRACKING_CATEGORY_SHOW, - label: 'work_item_view', - property: 'type_task', - }, - ); - }); - }); + await findTaskLink().trigger('click'); - describe('when url query `work_item_id` exists', () => { - it.each` - behavior | workItemId | modalOpened - ${'opens'} | ${'2'} | ${1} - ${'does not open'} | ${'123'} | ${0} - ${'does not open'} | ${'123e'} | ${0} - ${'does not open'} | ${'12e3'} | ${0} - ${'does not open'} | ${'1e23'} | ${0} - ${'does not open'} | ${'x'} | ${0} - ${'does not open'} | ${'undefined'} | ${0} - `( - '$behavior when url contains `work_item_id=$workItemId`', - async ({ workItemId, modalOpened }) => { - setWindowLocation(`?work_item_id=${workItemId}`); - - createComponent({ - props: { descriptionHtml: descriptionHtmlWithTask }, - provide: { glFeatures: { workItemsMvc: true } }, - }); - - expect(showDetailsModal).toHaveBeenCalledTimes(modalOpened); + expect(trackingSpy).toHaveBeenCalledWith( + TRACKING_CATEGORY_SHOW, + 'viewed_work_item_from_modal', + { + category: TRACKING_CATEGORY_SHOW, + label: 'work_item_view', + property: 'type_task', }, ); }); }); - describe('when hovering task links', () => { - beforeEach(() => { - createComponent({ - props: { - descriptionHtml: descriptionHtmlWithTask, - }, - provide: { - glFeatures: { workItemsMvc: true }, - }, - }); - return nextTick(); - }); + describe('when url query `work_item_id` exists', () => { + it.each` + behavior | workItemId | modalOpened + ${'opens'} | ${'2'} | ${1} + ${'does not open'} | ${'123'} | ${0} + ${'does not open'} | ${'123e'} | ${0} + ${'does not open'} | ${'12e3'} | ${0} + ${'does not open'} | ${'1e23'} | ${0} + ${'does not open'} | ${'x'} | ${0} + ${'does not open'} | ${'undefined'} | ${0} + `( + '$behavior when url contains `work_item_id=$workItemId`', + async ({ workItemId, modalOpened }) => { + setWindowLocation(`?work_item_id=${workItemId}`); - it('prefetches work item detail after work item link is hovered for 150ms', async () => { - await findTaskLink().trigger('mouseover'); - jest.advanceTimersByTime(150); - await waitForPromises(); + createComponent({ + props: { descriptionHtml: descriptionHtmlWithTask }, + }); - expect(queryHandler).toHaveBeenCalledWith({ - id: 'gid://gitlab/WorkItem/2', - }); + expect(showDetailsModal).toHaveBeenCalledTimes(modalOpened); + }, + ); + }); + }); + + describe('when hovering task links', () => { + beforeEach(() => { + createComponent({ + props: { + descriptionHtml: descriptionHtmlWithTask, + }, }); + return nextTick(); + }); - it('does not work item detail after work item link is hovered for less than 150ms', async () => { - await findTaskLink().trigger('mouseover'); - await findTaskLink().trigger('mouseout'); - jest.advanceTimersByTime(150); - await waitForPromises(); + it('prefetches work item detail after work item link is hovered for 150ms', async () => { + await findTaskLink().trigger('mouseover'); + jest.advanceTimersByTime(150); + await waitForPromises(); - expect(queryHandler).not.toHaveBeenCalled(); + expect(queryHandler).toHaveBeenCalledWith({ + id: 'gid://gitlab/WorkItem/2', }); }); + + it('does not work item detail after work item link is hovered for less than 150ms', async () => { + await findTaskLink().trigger('mouseover'); + await findTaskLink().trigger('mouseout'); + jest.advanceTimersByTime(150); + await waitForPromises(); + + expect(queryHandler).not.toHaveBeenCalled(); + }); }); }); |