diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-10-04 15:17:55 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-10-04 15:17:55 +0300 |
commit | 49d36ce6e3484aea8131dd892a02f8304ee61aa1 (patch) | |
tree | ee7d8403c0ebacf5b5953ebbf1a838dd957eac6b /spec/frontend/work_items | |
parent | b68afda3299d372ef0b3745e0603a9d51369650b (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/work_items')
16 files changed, 388 insertions, 56 deletions
diff --git a/spec/frontend/work_items/components/notes/work_item_add_note_spec.js b/spec/frontend/work_items/components/notes/work_item_add_note_spec.js index 826fc2b2230..e08e954d79e 100644 --- a/spec/frontend/work_items/components/notes/work_item_add_note_spec.js +++ b/spec/frontend/work_items/components/notes/work_item_add_note_spec.js @@ -10,9 +10,11 @@ import WorkItemCommentLocked from '~/work_items/components/notes/work_item_comme import WorkItemCommentForm from '~/work_items/components/notes/work_item_comment_form.vue'; import createNoteMutation from '~/work_items/graphql/notes/create_work_item_note.mutation.graphql'; import { TRACKING_CATEGORY_SHOW } from '~/work_items/constants'; +import groupWorkItemByIidQuery from '~/work_items/graphql/group_work_item_by_iid.query.graphql'; import workItemByIidQuery from '~/work_items/graphql/work_item_by_iid.query.graphql'; import { createWorkItemNoteResponse, + groupWorkItemByIidResponseFactory, workItemByIidResponseFactory, workItemQueryResponse, } from '../../mock_data'; @@ -29,6 +31,7 @@ describe('Work item add note', () => { const mutationSuccessHandler = jest.fn().mockResolvedValue(createWorkItemNoteResponse); let workItemResponseHandler; + let groupWorkItemResponseHandler; const findCommentForm = () => wrapper.findComponent(WorkItemCommentForm); const findTextarea = () => wrapper.findByTestId('note-reply-textarea'); @@ -40,27 +43,30 @@ describe('Work item add note', () => { canCreateNote = true, workItemIid = '1', workItemResponse = workItemByIidResponseFactory({ canUpdate, canCreateNote }), + groupWorkItemResponse = groupWorkItemByIidResponseFactory({ canUpdate, canCreateNote }), signedIn = true, isEditing = true, + isGroup = false, workItemType = 'Task', isInternalThread = false, } = {}) => { workItemResponseHandler = jest.fn().mockResolvedValue(workItemResponse); + groupWorkItemResponseHandler = jest.fn().mockResolvedValue(groupWorkItemResponse); if (signedIn) { window.gon.current_user_id = '1'; window.gon.current_user_avatar_url = 'avatar.png'; } - const apolloProvider = createMockApollo([ - [workItemByIidQuery, workItemResponseHandler], - [createNoteMutation, mutationHandler], - ]); - const { id } = workItemQueryResponse.data.workItem; wrapper = shallowMountExtended(WorkItemAddNote, { - apolloProvider, + apolloProvider: createMockApollo([ + [workItemByIidQuery, workItemResponseHandler], + [groupWorkItemByIidQuery, groupWorkItemResponseHandler], + [createNoteMutation, mutationHandler], + ]), provide: { fullPath: 'test-project-path', + isGroup, }, propsData: { workItemId: id, @@ -272,16 +278,44 @@ describe('Work item add note', () => { }); }); - it('calls the work item query', async () => { - await createComponent(); + describe('when project context', () => { + it('calls the project work item query', async () => { + await createComponent(); + + expect(workItemResponseHandler).toHaveBeenCalled(); + }); + + it('skips calling the group work item query', async () => { + await createComponent(); - expect(workItemResponseHandler).toHaveBeenCalled(); + expect(groupWorkItemResponseHandler).not.toHaveBeenCalled(); + }); + + it('skips calling the project work item query when missing workItemIid', async () => { + await createComponent({ workItemIid: '', isEditing: false }); + + expect(workItemResponseHandler).not.toHaveBeenCalled(); + }); }); - it('skips calling the work item query when missing workItemIid', async () => { - await createComponent({ workItemIid: '', isEditing: false }); + describe('when group context', () => { + it('skips calling the project work item query', async () => { + await createComponent({ isGroup: true }); - expect(workItemResponseHandler).not.toHaveBeenCalled(); + expect(workItemResponseHandler).not.toHaveBeenCalled(); + }); + + it('calls the group work item query', async () => { + await createComponent({ isGroup: true }); + + expect(groupWorkItemResponseHandler).toHaveBeenCalled(); + }); + + it('skips calling the group work item query when missing workItemIid', async () => { + await createComponent({ isGroup: true, workItemIid: '', isEditing: false }); + + expect(groupWorkItemResponseHandler).not.toHaveBeenCalled(); + }); }); it('wrapper adds `internal-note` class when internal thread', async () => { diff --git a/spec/frontend/work_items/components/notes/work_item_note_spec.js b/spec/frontend/work_items/components/notes/work_item_note_spec.js index 9049a69656a..4bc58f19bd6 100644 --- a/spec/frontend/work_items/components/notes/work_item_note_spec.js +++ b/spec/frontend/work_items/components/notes/work_item_note_spec.js @@ -15,8 +15,10 @@ import NoteActions from '~/work_items/components/notes/work_item_note_actions.vu import WorkItemCommentForm from '~/work_items/components/notes/work_item_comment_form.vue'; import updateWorkItemNoteMutation from '~/work_items/graphql/notes/update_work_item_note.mutation.graphql'; import updateWorkItemMutation from '~/work_items/graphql/update_work_item.mutation.graphql'; +import groupWorkItemByIidQuery from '~/work_items/graphql/group_work_item_by_iid.query.graphql'; import workItemByIidQuery from '~/work_items/graphql/work_item_by_iid.query.graphql'; import { + groupWorkItemByIidResponseFactory, mockAssignees, mockWorkItemCommentNote, updateWorkItemMutationResponse, @@ -68,6 +70,9 @@ describe('Work Item Note', () => { }); const workItemResponseHandler = jest.fn().mockResolvedValue(workItemByIidResponseFactory()); + const groupWorkItemResponseHandler = jest + .fn() + .mockResolvedValue(groupWorkItemByIidResponseFactory()); const workItemByAuthoredByDifferentUser = jest .fn() .mockResolvedValue(mockWorkItemByDifferentUser); @@ -90,6 +95,7 @@ describe('Work Item Note', () => { const createComponent = ({ note = mockWorkItemCommentNote, isFirstNote = false, + isGroup = false, updateNoteMutationHandler = successHandler, workItemId = mockWorkItemId, updateWorkItemMutationHandler = updateWorkItemMutationSuccessHandler, @@ -99,6 +105,7 @@ describe('Work Item Note', () => { wrapper = shallowMount(WorkItemNote, { provide: { fullPath: 'test-project-path', + isGroup, }, propsData: { workItemId, @@ -112,6 +119,7 @@ describe('Work Item Note', () => { }, apolloProvider: mockApollo([ [workItemByIidQuery, workItemByIidResponseHandler], + [groupWorkItemByIidQuery, groupWorkItemResponseHandler], [updateWorkItemNoteMutation, updateNoteMutationHandler], [updateWorkItemMutation, updateWorkItemMutationHandler], ]), @@ -442,4 +450,32 @@ describe('Work Item Note', () => { expect(findAwardsList().props('workItemIid')).toBe('1'); }); }); + + describe('when project context', () => { + it('calls the project work item query', () => { + createComponent(); + + expect(workItemResponseHandler).toHaveBeenCalled(); + }); + + it('skips calling the group work item query', () => { + createComponent(); + + expect(groupWorkItemResponseHandler).not.toHaveBeenCalled(); + }); + }); + + describe('when group context', () => { + it('skips calling the project work item query', () => { + createComponent({ isGroup: true }); + + expect(workItemResponseHandler).not.toHaveBeenCalled(); + }); + + it('calls the group work item query', () => { + createComponent({ isGroup: true }); + + expect(groupWorkItemResponseHandler).toHaveBeenCalled(); + }); + }); }); 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 0098a2e0864..ab8e95e5252 100644 --- a/spec/frontend/work_items/components/work_item_actions_spec.js +++ b/spec/frontend/work_items/components/work_item_actions_spec.js @@ -132,6 +132,7 @@ describe('WorkItemActions component', () => { }, provide: { fullPath: mockFullPath, + isGroup: false, glFeatures: { workItemsMvc2: true }, }, mocks: { diff --git a/spec/frontend/work_items/components/work_item_created_updated_spec.js b/spec/frontend/work_items/components/work_item_created_updated_spec.js index f77c5481906..e4da5a68a82 100644 --- a/spec/frontend/work_items/components/work_item_created_updated_spec.js +++ b/spec/frontend/work_items/components/work_item_created_updated_spec.js @@ -7,12 +7,18 @@ import waitForPromises from 'helpers/wait_for_promises'; import WorkItemCreatedUpdated from '~/work_items/components/work_item_created_updated.vue'; import ConfidentialityBadge from '~/vue_shared/components/confidentiality_badge.vue'; import WorkItemTypeIcon from '~/work_items/components/work_item_type_icon.vue'; +import groupWorkItemByIidQuery from '~/work_items/graphql/group_work_item_by_iid.query.graphql'; import workItemByIidQuery from '~/work_items/graphql/work_item_by_iid.query.graphql'; -import { workItemByIidResponseFactory, mockAssignees } from '../mock_data'; +import { + groupWorkItemByIidResponseFactory, + mockAssignees, + workItemByIidResponseFactory, +} from '../mock_data'; describe('WorkItemCreatedUpdated component', () => { let wrapper; let successHandler; + let groupSuccessHandler; Vue.use(VueApollo); @@ -30,19 +36,26 @@ describe('WorkItemCreatedUpdated component', () => { updatedAt, confidential = false, updateInProgress = false, + isGroup = false, } = {}) => { - const workItemQueryResponse = workItemByIidResponseFactory({ + const workItemQueryResponse = workItemByIidResponseFactory({ author, updatedAt, confidential }); + const groupWorkItemQueryResponse = groupWorkItemByIidResponseFactory({ author, updatedAt, confidential, }); successHandler = jest.fn().mockResolvedValue(workItemQueryResponse); + groupSuccessHandler = jest.fn().mockResolvedValue(groupWorkItemQueryResponse); wrapper = shallowMount(WorkItemCreatedUpdated, { - apolloProvider: createMockApollo([[workItemByIidQuery, successHandler]]), + apolloProvider: createMockApollo([ + [workItemByIidQuery, successHandler], + [groupWorkItemByIidQuery, groupSuccessHandler], + ]), provide: { fullPath: '/some/project', + isGroup, }, propsData: { workItemIid, updateInProgress }, stubs: { @@ -54,10 +67,44 @@ describe('WorkItemCreatedUpdated component', () => { await waitForPromises(); }; - it('skips the work item query when workItemIid is not defined', async () => { - await createComponent({ workItemIid: null }); + describe('when project context', () => { + it('calls the project work item query', async () => { + await createComponent(); - expect(successHandler).not.toHaveBeenCalled(); + expect(successHandler).toHaveBeenCalled(); + }); + + it('skips calling the group work item query', async () => { + await createComponent(); + + expect(groupSuccessHandler).not.toHaveBeenCalled(); + }); + + it('skips calling the project work item query when workItemIid is not defined', async () => { + await createComponent({ workItemIid: null }); + + expect(successHandler).not.toHaveBeenCalled(); + }); + }); + + describe('when group context', () => { + it('skips calling the project work item query', async () => { + await createComponent({ isGroup: true }); + + expect(successHandler).not.toHaveBeenCalled(); + }); + + it('calls the group work item query', async () => { + await createComponent({ isGroup: true }); + + expect(groupSuccessHandler).toHaveBeenCalled(); + }); + + it('skips calling the group work item query when workItemIid is not defined', async () => { + await createComponent({ isGroup: true, workItemIid: null }); + + expect(groupSuccessHandler).not.toHaveBeenCalled(); + }); }); it('shows work item type metadata with type and icon', async () => { 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 8b9963b2476..98df0dc1627 100644 --- a/spec/frontend/work_items/components/work_item_description_spec.js +++ b/spec/frontend/work_items/components/work_item_description_spec.js @@ -13,9 +13,11 @@ import WorkItemDescription from '~/work_items/components/work_item_description.v import WorkItemDescriptionRendered from '~/work_items/components/work_item_description_rendered.vue'; import { TRACKING_CATEGORY_SHOW } from '~/work_items/constants'; import updateWorkItemMutation from '~/work_items/graphql/update_work_item.mutation.graphql'; +import groupWorkItemByIidQuery from '~/work_items/graphql/group_work_item_by_iid.query.graphql'; import workItemByIidQuery from '~/work_items/graphql/work_item_by_iid.query.graphql'; import { autocompleteDataSources, markdownPreviewPath } from '~/work_items/utils'; import { + groupWorkItemByIidResponseFactory, updateWorkItemMutationResponse, workItemByIidResponseFactory, workItemQueryResponse, @@ -33,6 +35,7 @@ describe('WorkItemDescription', () => { const mutationSuccessHandler = jest.fn().mockResolvedValue(updateWorkItemMutationResponse); let workItemResponseHandler; + let groupWorkItemResponseHandler; const findForm = () => wrapper.findComponent(GlForm); const findMarkdownEditor = () => wrapper.findComponent(MarkdownEditor); @@ -51,14 +54,19 @@ describe('WorkItemDescription', () => { canUpdate = true, workItemResponse = workItemByIidResponseFactory({ canUpdate }), isEditing = false, + isGroup = false, workItemIid = '1', } = {}) => { workItemResponseHandler = jest.fn().mockResolvedValue(workItemResponse); + groupWorkItemResponseHandler = jest + .fn() + .mockResolvedValue(groupWorkItemByIidResponseFactory({ canUpdate })); const { id } = workItemQueryResponse.data.workItem; wrapper = shallowMount(WorkItemDescription, { apolloProvider: createMockApollo([ [workItemByIidQuery, workItemResponseHandler], + [groupWorkItemByIidQuery, groupWorkItemResponseHandler], [updateWorkItemMutation, mutationHandler], ]), propsData: { @@ -67,6 +75,7 @@ describe('WorkItemDescription', () => { }, provide: { fullPath: 'test-project-path', + isGroup, }, }); @@ -247,9 +256,31 @@ describe('WorkItemDescription', () => { }); }); - it('calls the work item query', async () => { - await createComponent(); + describe('when project context', () => { + it('calls the project work item query', () => { + createComponent(); - expect(workItemResponseHandler).toHaveBeenCalled(); + expect(workItemResponseHandler).toHaveBeenCalled(); + }); + + it('skips calling the group work item query', () => { + createComponent(); + + expect(groupWorkItemResponseHandler).not.toHaveBeenCalled(); + }); + }); + + describe('when group context', () => { + it('skips calling the project work item query', () => { + createComponent({ isGroup: true }); + + expect(workItemResponseHandler).not.toHaveBeenCalled(); + }); + + it('calls the group work item query', () => { + createComponent({ isGroup: true }); + + expect(groupWorkItemResponseHandler).toHaveBeenCalled(); + }); }); }); 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 fec6d0673c6..28826748cb0 100644 --- a/spec/frontend/work_items/components/work_item_detail_spec.js +++ b/spec/frontend/work_items/components/work_item_detail_spec.js @@ -28,12 +28,14 @@ import WorkItemStateToggleButton from '~/work_items/components/work_item_state_t import AbuseCategorySelector from '~/abuse_reports/components/abuse_category_selector.vue'; import WorkItemTodos from '~/work_items/components/work_item_todos.vue'; import { i18n } from '~/work_items/constants'; +import groupWorkItemByIidQuery from '~/work_items/graphql/group_work_item_by_iid.query.graphql'; import workItemByIidQuery from '~/work_items/graphql/work_item_by_iid.query.graphql'; import updateWorkItemMutation from '~/work_items/graphql/update_work_item.mutation.graphql'; import updateWorkItemTaskMutation from '~/work_items/graphql/update_work_item_task.mutation.graphql'; import workItemUpdatedSubscription from '~/work_items/graphql/work_item_updated.subscription.graphql'; import { + groupWorkItemByIidResponseFactory, mockParent, workItemByIidResponseFactory, objectiveType, @@ -49,6 +51,10 @@ describe('WorkItemDetail component', () => { Vue.use(VueApollo); const workItemQueryResponse = workItemByIidResponseFactory({ canUpdate: true, canDelete: true }); + const groupWorkItemQueryResponse = groupWorkItemByIidResponseFactory({ + canUpdate: true, + canDelete: true, + }); const workItemQueryResponseWithCannotUpdate = workItemByIidResponseFactory({ canUpdate: false, canDelete: false, @@ -59,6 +65,7 @@ describe('WorkItemDetail component', () => { canDelete: true, }); const successHandler = jest.fn().mockResolvedValue(workItemQueryResponse); + const groupSuccessHandler = jest.fn().mockResolvedValue(groupWorkItemQueryResponse); const showModalHandler = jest.fn(); const { id } = workItemQueryResponse.data.workspace.workItems.nodes[0]; const workItemUpdatedSubscriptionHandler = jest @@ -92,6 +99,7 @@ describe('WorkItemDetail component', () => { const findWorkItemTypeIcon = () => wrapper.findComponent(WorkItemTypeIcon); const createComponent = ({ + isGroup = false, isModal = false, updateInProgress = false, workItemIid = '1', @@ -101,14 +109,13 @@ describe('WorkItemDetail component', () => { workItemsMvc2Enabled = false, linkedWorkItemsEnabled = false, } = {}) => { - const handlers = [ - [workItemByIidQuery, handler], - [workItemUpdatedSubscription, workItemUpdatedSubscriptionHandler], - confidentialityMock, - ]; - wrapper = shallowMountExtended(WorkItemDetail, { - apolloProvider: createMockApollo(handlers), + apolloProvider: createMockApollo([ + [workItemByIidQuery, handler], + [groupWorkItemByIidQuery, groupSuccessHandler], + [workItemUpdatedSubscription, workItemUpdatedSubscriptionHandler], + confidentialityMock, + ]), isLoggedIn: isLoggedIn(), propsData: { isModal, @@ -131,6 +138,7 @@ describe('WorkItemDetail component', () => { hasIssuableHealthStatusFeature: true, projectNamespace: 'namespace', fullPath: 'group/project', + isGroup, reportAbusePath: '/report/abuse/path', }, stubs: { @@ -484,25 +492,64 @@ describe('WorkItemDetail component', () => { expect(findAlert().text()).toBe(updateError); }); - it('calls the work item query', async () => { - createComponent(); - await waitForPromises(); + describe('when project context', () => { + it('calls the project work item query', async () => { + createComponent(); + await waitForPromises(); - expect(successHandler).toHaveBeenCalledWith({ fullPath: 'group/project', iid: '1' }); - }); + 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(); + it('skips calling the group work item query', async () => { + createComponent(); + await waitForPromises(); + + expect(groupSuccessHandler).not.toHaveBeenCalled(); + }); - expect(successHandler).not.toHaveBeenCalled(); + it('skips calling the project work item query when there is no workItemIid', async () => { + createComponent({ workItemIid: null }); + await waitForPromises(); + + expect(successHandler).not.toHaveBeenCalled(); + }); + + it('calls the project work item query when isModal=true', async () => { + createComponent({ isModal: true }); + await waitForPromises(); + + expect(successHandler).toHaveBeenCalledWith({ fullPath: 'group/project', iid: '1' }); + }); }); - it('calls the work item query when isModal=true', async () => { - createComponent({ isModal: true }); - await waitForPromises(); + describe('when group context', () => { + it('skips calling the project work item query', async () => { + createComponent({ isGroup: true }); + await waitForPromises(); + + expect(successHandler).not.toHaveBeenCalled(); + }); + + it('calls the group work item query', async () => { + createComponent({ isGroup: true }); + await waitForPromises(); + + expect(groupSuccessHandler).toHaveBeenCalledWith({ fullPath: 'group/project', iid: '1' }); + }); + + it('skips calling the group work item query when there is no workItemIid', async () => { + createComponent({ isGroup: true, workItemIid: null }); + await waitForPromises(); - expect(successHandler).toHaveBeenCalledWith({ fullPath: 'group/project', iid: '1' }); + expect(groupSuccessHandler).not.toHaveBeenCalled(); + }); + + it('calls the group work item query when isModal=true', async () => { + createComponent({ isGroup: true, isModal: true }); + await waitForPromises(); + + expect(groupSuccessHandler).toHaveBeenCalledWith({ fullPath: 'group/project', iid: '1' }); + }); }); describe('hierarchy widget', () => { diff --git a/spec/frontend/work_items/components/work_item_labels_spec.js b/spec/frontend/work_items/components/work_item_labels_spec.js index 4a20e654060..1e173776c68 100644 --- a/spec/frontend/work_items/components/work_item_labels_spec.js +++ b/spec/frontend/work_items/components/work_item_labels_spec.js @@ -7,10 +7,12 @@ import { mountExtended } from 'helpers/vue_test_utils_helper'; import { DEFAULT_DEBOUNCE_AND_THROTTLE_MS } from '~/lib/utils/constants'; import labelSearchQuery from '~/sidebar/components/labels/labels_select_widget/graphql/project_labels.query.graphql'; import updateWorkItemMutation from '~/work_items/graphql/update_work_item.mutation.graphql'; +import groupWorkItemByIidQuery from '~/work_items/graphql/group_work_item_by_iid.query.graphql'; import workItemByIidQuery from '~/work_items/graphql/work_item_by_iid.query.graphql'; import WorkItemLabels from '~/work_items/components/work_item_labels.vue'; import { i18n, I18N_WORK_ITEM_ERROR_FETCHING_LABELS } from '~/work_items/constants'; import { + groupWorkItemByIidResponseFactory, projectLabelsResponse, mockLabels, workItemByIidResponseFactory, @@ -32,6 +34,9 @@ describe('WorkItemLabels component', () => { const workItemQuerySuccess = jest .fn() .mockResolvedValue(workItemByIidResponseFactory({ labels: null })); + const groupWorkItemQuerySuccess = jest + .fn() + .mockResolvedValue(groupWorkItemByIidResponseFactory({ labels: null })); const successSearchQueryHandler = jest.fn().mockResolvedValue(projectLabelsResponse); const successUpdateWorkItemMutationHandler = jest .fn() @@ -40,6 +45,7 @@ describe('WorkItemLabels component', () => { const createComponent = ({ canUpdate = true, + isGroup = false, workItemQueryHandler = workItemQuerySuccess, searchQueryHandler = successSearchQueryHandler, updateWorkItemMutationHandler = successUpdateWorkItemMutationHandler, @@ -48,11 +54,13 @@ describe('WorkItemLabels component', () => { wrapper = mountExtended(WorkItemLabels, { apolloProvider: createMockApollo([ [workItemByIidQuery, workItemQueryHandler], + [groupWorkItemByIidQuery, groupWorkItemQuerySuccess], [labelSearchQuery, searchQueryHandler], [updateWorkItemMutation, updateWorkItemMutationHandler], ]), provide: { fullPath: 'test-project-path', + isGroup, }, propsData: { workItemId, @@ -244,17 +252,49 @@ describe('WorkItemLabels component', () => { }); }); - it('calls the work item query', async () => { - createComponent(); - await waitForPromises(); + describe('when project context', () => { + it('calls the project work item query', async () => { + createComponent(); + await waitForPromises(); + + expect(workItemQuerySuccess).toHaveBeenCalled(); + }); + + it('skips calling the group work item query', async () => { + createComponent(); + await waitForPromises(); + + expect(groupWorkItemQuerySuccess).not.toHaveBeenCalled(); + }); + + it('skips calling the project work item query when missing workItemIid', async () => { + createComponent({ workItemIid: '' }); + await waitForPromises(); - expect(workItemQuerySuccess).toHaveBeenCalled(); + expect(workItemQuerySuccess).not.toHaveBeenCalled(); + }); }); - it('skips calling the work item query when missing workItemIid', async () => { - createComponent({ workItemIid: '' }); - await waitForPromises(); + describe('when group context', () => { + it('skips calling the project work item query', async () => { + createComponent({ isGroup: true }); + await waitForPromises(); - expect(workItemQuerySuccess).not.toHaveBeenCalled(); + expect(workItemQuerySuccess).not.toHaveBeenCalled(); + }); + + it('calls the group work item query', async () => { + createComponent({ isGroup: true }); + await waitForPromises(); + + expect(groupWorkItemQuerySuccess).toHaveBeenCalled(); + }); + + it('skips calling the group work item query when missing workItemIid', async () => { + createComponent({ isGroup: true, workItemIid: '' }); + await waitForPromises(); + + expect(groupWorkItemQuerySuccess).not.toHaveBeenCalled(); + }); }); }); diff --git a/spec/frontend/work_items/components/work_item_links/work_item_children_wrapper_spec.js b/spec/frontend/work_items/components/work_item_links/work_item_children_wrapper_spec.js index cd077fbf705..be44ff7b7d9 100644 --- a/spec/frontend/work_items/components/work_item_links/work_item_children_wrapper_spec.js +++ b/spec/frontend/work_items/components/work_item_links/work_item_children_wrapper_spec.js @@ -54,6 +54,7 @@ describe('WorkItemChildrenWrapper', () => { apolloProvider: mockApollo, provide: { fullPath: 'test/project', + isGroup: false, }, propsData: { workItemType, diff --git a/spec/frontend/work_items/components/work_item_links/work_item_links_form_spec.js b/spec/frontend/work_items/components/work_item_links/work_item_links_form_spec.js index aaab22fd18d..fd068d3dd40 100644 --- a/spec/frontend/work_items/components/work_item_links/work_item_links_form_spec.js +++ b/spec/frontend/work_items/components/work_item_links/work_item_links_form_spec.js @@ -64,6 +64,7 @@ describe('WorkItemLinksForm', () => { provide: { fullPath: 'project/path', hasIterationsFeature, + isGroup: false, }, }); diff --git a/spec/frontend/work_items/components/work_item_links/work_item_links_spec.js b/spec/frontend/work_items/components/work_item_links/work_item_links_spec.js index e24cfe27616..111fb5d8458 100644 --- a/spec/frontend/work_items/components/work_item_links/work_item_links_spec.js +++ b/spec/frontend/work_items/components/work_item_links/work_item_links_spec.js @@ -13,9 +13,11 @@ import WorkItemChildrenWrapper from '~/work_items/components/work_item_links/wor import WorkItemDetailModal from '~/work_items/components/work_item_detail_modal.vue'; import AbuseCategorySelector from '~/abuse_reports/components/abuse_category_selector.vue'; import { FORM_TYPES } from '~/work_items/constants'; +import groupWorkItemByIidQuery from '~/work_items/graphql/group_work_item_by_iid.query.graphql'; import workItemByIidQuery from '~/work_items/graphql/work_item_by_iid.query.graphql'; import { getIssueDetailsResponse, + groupWorkItemByIidResponseFactory, workItemHierarchyResponse, workItemHierarchyEmptyResponse, workItemHierarchyNoUpdatePermissionResponse, @@ -32,6 +34,9 @@ describe('WorkItemLinks', () => { let mockApollo; const responseWithAddChildPermission = jest.fn().mockResolvedValue(workItemHierarchyResponse); + const groupResponseWithAddChildPermission = jest + .fn() + .mockResolvedValue(groupWorkItemByIidResponseFactory()); const responseWithoutAddChildPermission = jest .fn() .mockResolvedValue(workItemByIidResponseFactory({ adminParentLink: false })); @@ -40,10 +45,12 @@ describe('WorkItemLinks', () => { fetchHandler = responseWithAddChildPermission, issueDetailsQueryHandler = jest.fn().mockResolvedValue(getIssueDetailsResponse()), hasIterationsFeature = false, + isGroup = false, } = {}) => { mockApollo = createMockApollo( [ [workItemByIidQuery, fetchHandler], + [groupWorkItemByIidQuery, groupResponseWithAddChildPermission], [issueDetailsQuery, issueDetailsQueryHandler], ], resolvers, @@ -54,6 +61,7 @@ describe('WorkItemLinks', () => { provide: { fullPath: 'project/path', hasIterationsFeature, + isGroup, reportAbusePath: '/report/abuse/path', }, propsData: { @@ -243,4 +251,32 @@ describe('WorkItemLinks', () => { expect(findAbuseCategorySelector().exists()).toBe(false); }); }); + + describe('when project context', () => { + it('calls the project work item query', () => { + createComponent(); + + expect(responseWithAddChildPermission).toHaveBeenCalled(); + }); + + it('skips calling the group work item query', () => { + createComponent(); + + expect(groupResponseWithAddChildPermission).not.toHaveBeenCalled(); + }); + }); + + describe('when group context', () => { + it('skips calling the project work item query', () => { + createComponent({ isGroup: true }); + + expect(responseWithAddChildPermission).not.toHaveBeenCalled(); + }); + + it('calls the group work item query', () => { + createComponent({ isGroup: true }); + + expect(groupResponseWithAddChildPermission).toHaveBeenCalled(); + }); + }); }); diff --git a/spec/frontend/work_items/components/work_item_relationships/work_item_relationships_spec.js b/spec/frontend/work_items/components/work_item_relationships/work_item_relationships_spec.js index 04b6e3d8df6..83f4cf5081e 100644 --- a/spec/frontend/work_items/components/work_item_relationships/work_item_relationships_spec.js +++ b/spec/frontend/work_items/components/work_item_relationships/work_item_relationships_spec.js @@ -10,9 +10,11 @@ import WidgetWrapper from '~/work_items/components/widget_wrapper.vue'; import WorkItemRelationships from '~/work_items/components/work_item_relationships/work_item_relationships.vue'; import WorkItemRelationshipList from '~/work_items/components/work_item_relationships/work_item_relationship_list.vue'; import WorkItemAddRelationshipForm from '~/work_items/components/work_item_relationships/work_item_add_relationship_form.vue'; +import groupWorkItemByIidQuery from '~/work_items/graphql/group_work_item_by_iid.query.graphql'; import workItemByIidQuery from '~/work_items/graphql/work_item_by_iid.query.graphql'; import { + groupWorkItemByIidResponseFactory, workItemByIidResponseFactory, mockLinkedItems, mockBlockingLinkedItem, @@ -25,21 +27,29 @@ describe('WorkItemRelationships', () => { const emptyLinkedWorkItemsQueryHandler = jest .fn() .mockResolvedValue(workItemByIidResponseFactory()); + const groupWorkItemsQueryHandler = jest + .fn() + .mockResolvedValue(groupWorkItemByIidResponseFactory()); const createComponent = async ({ workItemQueryHandler = emptyLinkedWorkItemsQueryHandler, workItemType = 'Task', + isGroup = false, } = {}) => { - const mockApollo = createMockApollo([[workItemByIidQuery, workItemQueryHandler]]); - wrapper = shallowMountExtended(WorkItemRelationships, { - apolloProvider: mockApollo, + apolloProvider: createMockApollo([ + [workItemByIidQuery, workItemQueryHandler], + [groupWorkItemByIidQuery, groupWorkItemsQueryHandler], + ]), propsData: { workItemId: 'gid://gitlab/WorkItem/1', workItemIid: '1', workItemFullPath: 'test-project-path', workItemType, }, + provide: { + isGroup, + }, }); await waitForPromises(); @@ -120,4 +130,32 @@ describe('WorkItemRelationships', () => { await findWorkItemRelationshipForm().vm.$emit('cancel'); expect(findWorkItemRelationshipForm().exists()).toBe(false); }); + + describe('when project context', () => { + it('calls the project work item query', () => { + createComponent(); + + expect(emptyLinkedWorkItemsQueryHandler).toHaveBeenCalled(); + }); + + it('skips calling the group work item query', () => { + createComponent(); + + expect(groupWorkItemsQueryHandler).not.toHaveBeenCalled(); + }); + }); + + describe('when group context', () => { + it('skips calling the project work item query', () => { + createComponent({ isGroup: true }); + + expect(emptyLinkedWorkItemsQueryHandler).not.toHaveBeenCalled(); + }); + + it('calls the group work item query', () => { + createComponent({ isGroup: true }); + + expect(groupWorkItemsQueryHandler).toHaveBeenCalled(); + }); + }); }); diff --git a/spec/frontend/work_items/components/work_item_todos_spec.js b/spec/frontend/work_items/components/work_item_todos_spec.js index 454bd97bbee..c76cdbcee53 100644 --- a/spec/frontend/work_items/components/work_item_todos_spec.js +++ b/spec/frontend/work_items/components/work_item_todos_spec.js @@ -86,6 +86,9 @@ describe('WorkItemTodo component', () => { workItemFullpath: mockWorkItemFullpath, currentUserTodos, }, + provide: { + isGroup: false, + }, }); }; diff --git a/spec/frontend/work_items/graphql/cache_utils_spec.js b/spec/frontend/work_items/graphql/cache_utils_spec.js index 6d0083790d1..64ef1bdbb88 100644 --- a/spec/frontend/work_items/graphql/cache_utils_spec.js +++ b/spec/frontend/work_items/graphql/cache_utils_spec.js @@ -43,7 +43,7 @@ describe('work items graphql cache utils', () => { title: 'New child', }; - addHierarchyChild(mockCache, fullPath, iid, child); + addHierarchyChild({ cache: mockCache, fullPath, iid, workItem: child }); expect(mockCache.writeQuery).toHaveBeenCalledWith({ query: workItemByIidQuery, @@ -88,7 +88,7 @@ describe('work items graphql cache utils', () => { title: 'New child', }; - addHierarchyChild(mockCache, fullPath, iid, child); + addHierarchyChild({ cache: mockCache, fullPath, iid, workItem: child }); expect(mockCache.writeQuery).not.toHaveBeenCalled(); }); @@ -106,7 +106,7 @@ describe('work items graphql cache utils', () => { title: 'Child', }; - removeHierarchyChild(mockCache, fullPath, iid, childToRemove); + removeHierarchyChild({ cache: mockCache, fullPath, iid, workItem: childToRemove }); expect(mockCache.writeQuery).toHaveBeenCalledWith({ query: workItemByIidQuery, @@ -145,7 +145,7 @@ describe('work items graphql cache utils', () => { title: 'Child', }; - removeHierarchyChild(mockCache, fullPath, iid, childToRemove); + removeHierarchyChild({ cache: mockCache, fullPath, iid, workItem: childToRemove }); expect(mockCache.writeQuery).not.toHaveBeenCalled(); }); diff --git a/spec/frontend/work_items/mock_data.js b/spec/frontend/work_items/mock_data.js index 0250834fa85..9cd76c0651e 100644 --- a/spec/frontend/work_items/mock_data.js +++ b/spec/frontend/work_items/mock_data.js @@ -833,6 +833,21 @@ export const workItemByIidResponseFactory = (options) => { }; }; +export const groupWorkItemByIidResponseFactory = (options) => { + const response = workItemResponseFactory(options); + return { + data: { + workspace: { + __typename: 'Group', + id: 'gid://gitlab/Group/1', + workItems: { + nodes: [response.data.workItem], + }, + }, + }, + }; +}; + export const updateWorkItemMutationResponseFactory = (options) => { const response = workItemResponseFactory(options); return { diff --git a/spec/frontend/work_items/pages/create_work_item_spec.js b/spec/frontend/work_items/pages/create_work_item_spec.js index 87dbb18dcc4..527f5890338 100644 --- a/spec/frontend/work_items/pages/create_work_item_spec.js +++ b/spec/frontend/work_items/pages/create_work_item_spec.js @@ -65,6 +65,7 @@ describe('Create work item component', () => { }, provide: { fullPath: 'full-path', + isGroup: false, }, }); }; diff --git a/spec/frontend/work_items/router_spec.js b/spec/frontend/work_items/router_spec.js index 79ba31e7012..d4efcf78189 100644 --- a/spec/frontend/work_items/router_spec.js +++ b/spec/frontend/work_items/router_spec.js @@ -41,6 +41,7 @@ describe('Work items router', () => { router, provide: { fullPath: 'full-path', + isGroup: false, issuesListPath: 'full-path/-/issues', hasIssueWeightsFeature: false, hasIterationsFeature: false, |