diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-05-05 21:17:47 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-05-05 21:17:47 +0300 |
commit | bc4cd6ffb93ae695f20ea54f4e4803d50c78a69e (patch) | |
tree | 2364d0f880af998b70356628f79cda64f13a11e7 /spec/frontend/work_items | |
parent | 6634288474d2a83cac7b4205f3ffc736cc6b36db (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/work_items')
5 files changed, 36 insertions, 139 deletions
diff --git a/spec/frontend/work_items/components/work_item_actions_spec.js b/spec/frontend/work_items/components/work_item_actions_spec.js index 6e8f6defb17..0045abe50d0 100644 --- a/spec/frontend/work_items/components/work_item_actions_spec.js +++ b/spec/frontend/work_items/components/work_item_actions_spec.js @@ -18,10 +18,10 @@ import updateWorkItemNotificationsMutation from '~/work_items/graphql/update_wor import projectWorkItemTypesQuery from '~/work_items/graphql/project_work_item_types.query.graphql'; import convertWorkItemMutation from '~/work_items/graphql/work_item_convert.mutation.graphql'; import { - workItemResponseFactory, convertWorkItemMutationResponse, projectWorkItemTypesQueryResponse, convertWorkItemMutationErrorResponse, + workItemByIidResponseFactory, } from '../mock_data'; jest.mock('~/lib/utils/common_utils'); @@ -211,45 +211,45 @@ describe('WorkItemActions component', () => { describe('notifications action', () => { const errorMessage = 'Failed to subscribe'; + const id = 'gid://gitlab/WorkItem/1'; const notificationToggledOffMessage = 'Notifications turned off.'; const notificationToggledOnMessage = 'Notifications turned on.'; - const workItemQueryResponse = workItemResponseFactory({ canUpdate: true, canDelete: true }); const inputVariablesOff = { - id: workItemQueryResponse.data.workItem.id, + id, notificationsWidget: { subscribed: false, }, }; const inputVariablesOn = { - id: workItemQueryResponse.data.workItem.id, + id, notificationsWidget: { subscribed: true, }, }; - const notificationsOffExpectedResponse = workItemResponseFactory({ + const notificationsOffExpectedResponse = workItemByIidResponseFactory({ subscribed: false, }); const toggleNotificationsOffHandler = jest.fn().mockResolvedValue({ data: { workItemUpdate: { - workItem: notificationsOffExpectedResponse.data.workItem, + workItem: notificationsOffExpectedResponse.data.workspace.workItems.nodes[0], errors: [], }, }, }); - const notificationsOnExpectedResponse = workItemResponseFactory({ + const notificationsOnExpectedResponse = workItemByIidResponseFactory({ subscribed: true, }); const toggleNotificationsOnHandler = jest.fn().mockResolvedValue({ data: { workItemUpdate: { - workItem: notificationsOnExpectedResponse.data.workItem, + workItem: notificationsOnExpectedResponse.data.workspace.workItems.nodes[0], errors: [], }, }, diff --git a/spec/frontend/work_items/components/work_item_assignees_spec.js b/spec/frontend/work_items/components/work_item_assignees_spec.js index af97b3680f9..1e336a928a0 100644 --- a/spec/frontend/work_items/components/work_item_assignees_spec.js +++ b/spec/frontend/work_items/components/work_item_assignees_spec.js @@ -8,9 +8,7 @@ import { mockTracking } from 'helpers/tracking_helper'; import { DEFAULT_DEBOUNCE_AND_THROTTLE_MS } from '~/lib/utils/constants'; import userSearchQuery from '~/graphql_shared/queries/users_search.query.graphql'; import currentUserQuery from '~/graphql_shared/queries/current_user.query.graphql'; -import { config } from '~/graphql_shared/issuable_client'; import InviteMembersTrigger from '~/invite_members/components/invite_members_trigger.vue'; -import workItemQuery from '~/work_items/graphql/work_item.query.graphql'; import updateWorkItemMutation from '~/work_items/graphql/update_work_item.mutation.graphql'; import WorkItemAssignees from '~/work_items/components/work_item_assignees.vue'; import { @@ -22,7 +20,6 @@ import { import { projectMembersResponseWithCurrentUser, mockAssignees, - workItemQueryResponse, currentUserResponse, currentUserNullResponse, projectMembersResponseWithoutCurrentUser, @@ -78,25 +75,11 @@ describe('WorkItemAssignees component', () => { canInviteMembers = false, canUpdate = true, } = {}) => { - const apolloProvider = createMockApollo( - [ - [userSearchQuery, searchQueryHandler], - [currentUserQuery, currentUserQueryHandler], - [updateWorkItemMutation, updateWorkItemMutationHandler], - ], - {}, - { - typePolicies: config.cacheConfig.typePolicies, - }, - ); - - apolloProvider.clients.defaultClient.writeQuery({ - query: workItemQuery, - variables: { - id: workItemId, - }, - data: workItemQueryResponse.data, - }); + const apolloProvider = createMockApollo([ + [userSearchQuery, searchQueryHandler], + [currentUserQuery, currentUserQueryHandler], + [updateWorkItemMutation, updateWorkItemMutationHandler], + ]); wrapper = mountExtended(WorkItemAssignees, { propsData: { diff --git a/spec/frontend/work_items/components/work_item_detail_spec.js b/spec/frontend/work_items/components/work_item_detail_spec.js index 291dacfd844..630eb78d5c0 100644 --- a/spec/frontend/work_items/components/work_item_detail_spec.js +++ b/spec/frontend/work_items/components/work_item_detail_spec.js @@ -39,7 +39,7 @@ import updateWorkItemTaskMutation from '~/work_items/graphql/update_work_item_ta import { mockParent, workItemDatesSubscriptionResponse, - workItemByIidResponseFactory as workItemResponseFactory, + workItemByIidResponseFactory, workItemTitleSubscriptionResponse, workItemAssigneesSubscriptionResponse, workItemMilestoneSubscriptionResponse, @@ -52,8 +52,8 @@ describe('WorkItemDetail component', () => { Vue.use(VueApollo); - const workItemQueryResponse = workItemResponseFactory({ canUpdate: true, canDelete: true }); - const workItemQueryResponseWithoutParent = workItemResponseFactory({ + const workItemQueryResponse = workItemByIidResponseFactory({ canUpdate: true, canDelete: true }); + const workItemQueryResponseWithoutParent = workItemByIidResponseFactory({ parent: null, canUpdate: true, canDelete: true, @@ -221,7 +221,7 @@ describe('WorkItemDetail component', () => { describe('confidentiality', () => { const errorMessage = 'Mutation failed'; - const confidentialWorkItem = workItemResponseFactory({ + const confidentialWorkItem = workItemByIidResponseFactory({ confidential: true, }); const workItem = confidentialWorkItem.data.workspace.workItems.nodes[0]; @@ -398,7 +398,7 @@ describe('WorkItemDetail component', () => { describe('with parent', () => { beforeEach(() => { - const parentResponse = workItemResponseFactory(mockParent); + const parentResponse = workItemByIidResponseFactory(mockParent); createComponent({ handler: jest.fn().mockResolvedValue(parentResponse) }); return waitForPromises(); @@ -437,7 +437,7 @@ describe('WorkItemDetail component', () => { }, }, }; - const parentResponse = workItemResponseFactory(mockParentObjective); + const parentResponse = workItemByIidResponseFactory(mockParentObjective); createComponent({ handler: jest.fn().mockResolvedValue(parentResponse) }); await waitForPromises(); @@ -492,7 +492,7 @@ describe('WorkItemDetail component', () => { describe('when the assignees widget does not exist', () => { it('does not call the assignees subscription', async () => { - const response = workItemResponseFactory({ assigneesWidgetPresent: false }); + const response = workItemByIidResponseFactory({ assigneesWidgetPresent: false }); const handler = jest.fn().mockResolvedValue(response); createComponent({ handler }); await waitForPromises(); @@ -514,7 +514,7 @@ describe('WorkItemDetail component', () => { describe('when the due date widget does not exist', () => { it('does not call the dates subscription', async () => { - const response = workItemResponseFactory({ datesWidgetPresent: false }); + const response = workItemByIidResponseFactory({ datesWidgetPresent: false }); const handler = jest.fn().mockResolvedValue(response); createComponent({ handler }); await waitForPromises(); @@ -537,7 +537,7 @@ describe('WorkItemDetail component', () => { createComponent({ handler: jest .fn() - .mockResolvedValue(workItemResponseFactory({ assigneesWidgetPresent: false })), + .mockResolvedValue(workItemByIidResponseFactory({ assigneesWidgetPresent: false })), }); await waitForPromises(); @@ -551,7 +551,7 @@ describe('WorkItemDetail component', () => { ${'renders when widget is returned from API'} | ${true} | ${true} ${'does not render when widget is not returned from API'} | ${false} | ${false} `('$description', async ({ labelsWidgetPresent, exists }) => { - const response = workItemResponseFactory({ labelsWidgetPresent }); + const response = workItemByIidResponseFactory({ labelsWidgetPresent }); const handler = jest.fn().mockResolvedValue(response); createComponent({ handler }); await waitForPromises(); @@ -567,7 +567,7 @@ describe('WorkItemDetail component', () => { ${'when widget is not returned from API'} | ${false} | ${false} `('$description', ({ datesWidgetPresent, exists }) => { it(`${datesWidgetPresent ? 'renders' : 'does not render'} due date component`, async () => { - const response = workItemResponseFactory({ datesWidgetPresent }); + const response = workItemByIidResponseFactory({ datesWidgetPresent }); const handler = jest.fn().mockResolvedValue(response); createComponent({ handler }); await waitForPromises(); @@ -594,7 +594,7 @@ describe('WorkItemDetail component', () => { ${'renders when widget is returned from API'} | ${true} | ${true} ${'does not render when widget is not returned from API'} | ${false} | ${false} `('$description', async ({ milestoneWidgetPresent, exists }) => { - const response = workItemResponseFactory({ milestoneWidgetPresent }); + const response = workItemByIidResponseFactory({ milestoneWidgetPresent }); const handler = jest.fn().mockResolvedValue(response); createComponent({ handler }); await waitForPromises(); @@ -614,7 +614,7 @@ describe('WorkItemDetail component', () => { describe('when the assignees widget does not exist', () => { it('does not call the milestone subscription', async () => { - const response = workItemResponseFactory({ milestoneWidgetPresent: false }); + const response = workItemByIidResponseFactory({ milestoneWidgetPresent: false }); const handler = jest.fn().mockResolvedValue(response); createComponent({ handler }); await waitForPromises(); @@ -632,6 +632,13 @@ describe('WorkItemDetail component', () => { expect(successHandler).toHaveBeenCalledWith({ fullPath: 'group/project', iid: '1' }); }); + it('skips the work item query when there is no workItemIid', async () => { + createComponent({ workItemIid: null }); + await waitForPromises(); + + expect(successHandler).not.toHaveBeenCalled(); + }); + it('calls the work item query when isModal=true', async () => { createComponent({ isModal: true }); await waitForPromises(); @@ -648,7 +655,7 @@ describe('WorkItemDetail component', () => { }); describe('work item has children', () => { - const objectiveWorkItem = workItemResponseFactory({ + const objectiveWorkItem = workItemByIidResponseFactory({ workItemType: objectiveType, confidential: true, }); diff --git a/spec/frontend/work_items/mock_data.js b/spec/frontend/work_items/mock_data.js index 2ab31908577..1c319844af3 100644 --- a/spec/frontend/work_items/mock_data.js +++ b/spec/frontend/work_items/mock_data.js @@ -684,87 +684,6 @@ export const createWorkItemMutationErrorResponse = { }, }; -export const createWorkItemFromTaskMutationResponse = { - data: { - workItemCreateFromTask: { - __typename: 'WorkItemCreateFromTaskPayload', - errors: [], - workItem: { - __typename: 'WorkItem', - description: 'New description', - id: 'gid://gitlab/WorkItem/1', - iid: '1', - title: 'Updated title', - state: 'OPEN', - confidential: false, - createdAt: '2022-08-03T12:41:54Z', - closedAt: null, - project: { - __typename: 'Project', - id: '1', - fullPath: 'test-project-path', - archived: false, - }, - workItemType: { - __typename: 'WorkItemType', - id: 'gid://gitlab/WorkItems::Type/5', - name: 'Task', - iconName: 'issue-type-task', - }, - userPermissions: { - deleteWorkItem: false, - updateWorkItem: false, - setWorkItemMetadata: false, - __typename: 'WorkItemPermissions', - }, - widgets: [ - { - __typename: 'WorkItemWidgetDescription', - type: 'DESCRIPTION', - description: 'New description', - descriptionHtml: '<p>New description</p>', - lastEditedAt: '2022-09-21T06:18:42Z', - lastEditedBy: { - name: 'Administrator', - webPath: '/root', - }, - }, - ], - }, - newWorkItem: { - __typename: 'WorkItem', - id: 'gid://gitlab/WorkItem/1000000', - iid: '100', - title: 'Updated title', - state: 'OPEN', - createdAt: '2022-08-03T12:41:54Z', - closedAt: null, - description: '', - confidential: false, - project: { - __typename: 'Project', - id: '1', - fullPath: 'test-project-path', - archived: false, - }, - workItemType: { - __typename: 'WorkItemType', - id: 'gid://gitlab/WorkItems::Type/5', - name: 'Task', - iconName: 'issue-type-task', - }, - userPermissions: { - deleteWorkItem: false, - updateWorkItem: false, - setWorkItemMetadata: false, - __typename: 'WorkItemPermissions', - }, - widgets: [], - }, - }, - }, -}; - export const deleteWorkItemResponse = { data: { workItemDelete: { errors: [], __typename: 'WorkItemDeletePayload' } }, }; @@ -1831,18 +1750,6 @@ export const projectMilestonesResponseWithNoMilestones = { }, }; -export const projectWorkItemResponse = { - data: { - workspace: { - id: 'gid://gitlab/Project/1', - workItems: { - nodes: [workItemQueryResponse.data.workItem], - }, - __typename: 'Project', - }, - }, -}; - export const mockWorkItemNotesResponse = { data: { workItem: { diff --git a/spec/frontend/work_items/router_spec.js b/spec/frontend/work_items/router_spec.js index 86e890ea809..b5d54a7c319 100644 --- a/spec/frontend/work_items/router_spec.js +++ b/spec/frontend/work_items/router_spec.js @@ -6,7 +6,7 @@ import { currentUserResponse, workItemAssigneesSubscriptionResponse, workItemDatesSubscriptionResponse, - workItemByIidResponseFactory as workItemResponseFactory, + workItemByIidResponseFactory, workItemTitleSubscriptionResponse, workItemLabelsSubscriptionResponse, workItemMilestoneSubscriptionResponse, @@ -32,7 +32,7 @@ describe('Work items router', () => { Vue.use(VueApollo); - const workItemQueryHandler = jest.fn().mockResolvedValue(workItemResponseFactory()); + const workItemQueryHandler = jest.fn().mockResolvedValue(workItemByIidResponseFactory()); const currentUserQueryHandler = jest.fn().mockResolvedValue(currentUserResponse); const datesSubscriptionHandler = jest.fn().mockResolvedValue(workItemDatesSubscriptionResponse); const titleSubscriptionHandler = jest.fn().mockResolvedValue(workItemTitleSubscriptionResponse); |