diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-06-14 21:08:38 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-06-14 21:08:38 +0300 |
commit | 14160fad80415337f8c08755af53ee994b4a7518 (patch) | |
tree | bfe1bf6bad8cda3e3bbf905c9d8ac742420dd8a3 /spec/frontend/work_items | |
parent | 7a33080fff9a735cbe77968d67b13ffa92c0ffae (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/work_items')
3 files changed, 166 insertions, 23 deletions
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 bbd114c124d..cd077fbf705 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 @@ -39,17 +39,26 @@ describe('WorkItemChildrenWrapper', () => { children = childrenWorkItems, mutationHandler = updateWorkItemMutationHandler, } = {}) => { + const mockApollo = createMockApollo([ + [workItemByIidQuery, getWorkItemQueryHandler], + [updateWorkItemMutation, mutationHandler], + ]); + + mockApollo.clients.defaultClient.cache.writeQuery({ + query: workItemByIidQuery, + variables: { fullPath: 'test/project', iid: '1' }, + data: workItemByIidResponseFactory().data, + }); + wrapper = shallowMountExtended(WorkItemChildrenWrapper, { - apolloProvider: createMockApollo([ - [workItemByIidQuery, getWorkItemQueryHandler], - [updateWorkItemMutation, mutationHandler], - ]), + apolloProvider: mockApollo, provide: { fullPath: 'test/project', }, propsData: { workItemType, workItemId: 'gid://gitlab/WorkItem/515', + workItemIid: '1', confidential, children, }, 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 c3a98dcffb1..dd46505bd65 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 @@ -20,7 +20,6 @@ import { workItemHierarchyEmptyResponse, workItemHierarchyNoUpdatePermissionResponse, workItemByIidResponseFactory, - workItemQueryResponse, mockWorkItemCommentNote, } from '../../mock_data'; @@ -136,24 +135,6 @@ describe('WorkItemLinks', () => { expect(findAddLinksForm().exists()).toBe(false); }); - - it('adds work item child from the form', async () => { - const workItem = { - ...workItemQueryResponse.data.workItem, - id: 'gid://gitlab/WorkItem/11', - }; - await createComponent(); - findToggleFormDropdown().vm.$emit('click'); - findToggleCreateFormButton().vm.$emit('click'); - await nextTick(); - - expect(findWorkItemLinkChildrenWrapper().props().children).toHaveLength(4); - - findAddLinksForm().vm.$emit('addWorkItemChild', workItem); - await waitForPromises(); - - expect(findWorkItemLinkChildrenWrapper().props().children).toHaveLength(5); - }); }); describe('when no child links', () => { diff --git a/spec/frontend/work_items/graphql/cache_utils_spec.js b/spec/frontend/work_items/graphql/cache_utils_spec.js new file mode 100644 index 00000000000..6d0083790d1 --- /dev/null +++ b/spec/frontend/work_items/graphql/cache_utils_spec.js @@ -0,0 +1,153 @@ +import { WIDGET_TYPE_HIERARCHY } from '~/work_items/constants'; +import { addHierarchyChild, removeHierarchyChild } from '~/work_items/graphql/cache_utils'; +import workItemByIidQuery from '~/work_items/graphql/work_item_by_iid.query.graphql'; + +describe('work items graphql cache utils', () => { + const fullPath = 'full/path'; + const iid = '10'; + const mockCacheData = { + workspace: { + workItems: { + nodes: [ + { + id: 'gid://gitlab/WorkItem/10', + title: 'Work item', + widgets: [ + { + type: WIDGET_TYPE_HIERARCHY, + children: { + nodes: [ + { + id: 'gid://gitlab/WorkItem/20', + title: 'Child', + }, + ], + }, + }, + ], + }, + ], + }, + }, + }; + + describe('addHierarchyChild', () => { + it('updates the work item with a new child', () => { + const mockCache = { + readQuery: () => mockCacheData, + writeQuery: jest.fn(), + }; + + const child = { + id: 'gid://gitlab/WorkItem/30', + title: 'New child', + }; + + addHierarchyChild(mockCache, fullPath, iid, child); + + expect(mockCache.writeQuery).toHaveBeenCalledWith({ + query: workItemByIidQuery, + variables: { fullPath, iid }, + data: { + workspace: { + workItems: { + nodes: [ + { + id: 'gid://gitlab/WorkItem/10', + title: 'Work item', + widgets: [ + { + type: WIDGET_TYPE_HIERARCHY, + children: { + nodes: [ + { + id: 'gid://gitlab/WorkItem/20', + title: 'Child', + }, + child, + ], + }, + }, + ], + }, + ], + }, + }, + }, + }); + }); + + it('does not update the work item when there is no cache data', () => { + const mockCache = { + readQuery: () => {}, + writeQuery: jest.fn(), + }; + + const child = { + id: 'gid://gitlab/WorkItem/30', + title: 'New child', + }; + + addHierarchyChild(mockCache, fullPath, iid, child); + + expect(mockCache.writeQuery).not.toHaveBeenCalled(); + }); + }); + + describe('removeHierarchyChild', () => { + it('updates the work item with a new child', () => { + const mockCache = { + readQuery: () => mockCacheData, + writeQuery: jest.fn(), + }; + + const childToRemove = { + id: 'gid://gitlab/WorkItem/20', + title: 'Child', + }; + + removeHierarchyChild(mockCache, fullPath, iid, childToRemove); + + expect(mockCache.writeQuery).toHaveBeenCalledWith({ + query: workItemByIidQuery, + variables: { fullPath, iid }, + data: { + workspace: { + workItems: { + nodes: [ + { + id: 'gid://gitlab/WorkItem/10', + title: 'Work item', + widgets: [ + { + type: WIDGET_TYPE_HIERARCHY, + children: { + nodes: [], + }, + }, + ], + }, + ], + }, + }, + }, + }); + }); + + it('does not update the work item when there is no cache data', () => { + const mockCache = { + readQuery: () => {}, + writeQuery: jest.fn(), + }; + + const childToRemove = { + id: 'gid://gitlab/WorkItem/20', + title: 'Child', + }; + + removeHierarchyChild(mockCache, fullPath, iid, childToRemove); + + expect(mockCache.writeQuery).not.toHaveBeenCalled(); + }); + }); +}); |