diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-04-26 21:19:16 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-04-26 21:19:16 +0300 |
commit | fa69a57b46f4893c488445f79d6d290463820f7d (patch) | |
tree | 4a73ccd1f8ffb4dbb47a42c6edb309238828a44e /spec/frontend/work_items/components | |
parent | 34283a71d9ac31eb4da0b59d0b25fc2be014bc9c (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/work_items/components')
3 files changed, 49 insertions, 142 deletions
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 fe31c01df36..2a5b2853b5e 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 @@ -5,14 +5,12 @@ import VueApollo from 'vue-apollo'; import createMockApollo from 'helpers/mock_apollo_helper'; import waitForPromises from 'helpers/wait_for_promises'; import WorkItemCreatedUpdated from '~/work_items/components/work_item_created_updated.vue'; -import workItemQuery from '~/work_items/graphql/work_item.query.graphql'; import workItemByIidQuery from '~/work_items/graphql/work_item_by_iid.query.graphql'; -import { workItemResponseFactory, mockAssignees } from '../mock_data'; +import { workItemByIidResponseFactory, mockAssignees } from '../mock_data'; describe('WorkItemCreatedUpdated component', () => { let wrapper; let successHandler; - let successByIidHandler; Vue.use(VueApollo); @@ -21,39 +19,17 @@ describe('WorkItemCreatedUpdated component', () => { const findCreatedAtText = () => findCreatedAt().text().replace(/\s+/g, ' '); - const createComponent = async ({ - workItemId = 'gid://gitlab/WorkItem/1', - workItemIid = '1', - fetchByIid = false, - author = null, - updatedAt, - } = {}) => { - const workItemQueryResponse = workItemResponseFactory({ + const createComponent = async ({ workItemIid = '1', author = null, updatedAt } = {}) => { + const workItemQueryResponse = workItemByIidResponseFactory({ author, updatedAt, }); - const byIidResponse = { - data: { - workspace: { - id: 'gid://gitlab/Project/1', - workItems: { - nodes: [workItemQueryResponse.data.workItem], - }, - }, - }, - }; successHandler = jest.fn().mockResolvedValue(workItemQueryResponse); - successByIidHandler = jest.fn().mockResolvedValue(byIidResponse); - - const handlers = [ - [workItemQuery, successHandler], - [workItemByIidQuery, successByIidHandler], - ]; wrapper = shallowMount(WorkItemCreatedUpdated, { - apolloProvider: createMockApollo(handlers), - propsData: { workItemId, workItemIid, fetchByIid, fullPath: '/some/project' }, + apolloProvider: createMockApollo([[workItemByIidQuery, successHandler]]), + propsData: { workItemIid, fullPath: '/some/project' }, stubs: { GlAvatarLink, GlSprintf, @@ -63,42 +39,34 @@ describe('WorkItemCreatedUpdated component', () => { await waitForPromises(); }; - describe.each([true, false])('fetchByIid is %s', (fetchByIid) => { - describe('work item id and iid undefined', () => { - beforeEach(async () => { - await createComponent({ workItemId: null, workItemIid: null, fetchByIid }); - }); - - it('skips the work item query', () => { - expect(successHandler).not.toHaveBeenCalled(); - expect(successByIidHandler).not.toHaveBeenCalled(); - }); - }); + it('skips the work item query when workItemIid is not defined', async () => { + await createComponent({ workItemIid: null }); - it('shows author name and link', async () => { - const author = mockAssignees[0]; + expect(successHandler).not.toHaveBeenCalled(); + }); - await createComponent({ fetchByIid, author }); + it('shows author name and link', async () => { + const author = mockAssignees[0]; + await createComponent({ author }); - expect(findCreatedAtText()).toEqual(`Created by ${author.name}`); - }); + expect(findCreatedAtText()).toBe(`Created by ${author.name}`); + }); - it('shows created time when author is null', async () => { - await createComponent({ fetchByIid, author: null }); + it('shows created time when author is null', async () => { + await createComponent({ author: null }); - expect(findCreatedAtText()).toEqual('Created'); - }); + expect(findCreatedAtText()).toBe('Created'); + }); - it('shows updated time', async () => { - await createComponent({ fetchByIid }); + it('shows updated time', async () => { + await createComponent(); - expect(findUpdatedAt().exists()).toBe(true); - }); + expect(findUpdatedAt().exists()).toBe(true); + }); - it('does not show updated time for new work items', async () => { - await createComponent({ fetchByIid, updatedAt: null }); + it('does not show updated time for new work items', async () => { + await createComponent({ updatedAt: null }); - expect(findUpdatedAt().exists()).toBe(false); - }); + expect(findUpdatedAt().exists()).toBe(false); }); }); 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 6d51448194b..e6f7793b43f 100644 --- a/spec/frontend/work_items/components/work_item_labels_spec.js +++ b/spec/frontend/work_items/components/work_item_labels_spec.js @@ -6,7 +6,6 @@ import waitForPromises from 'helpers/wait_for_promises'; 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 workItemQuery from '~/work_items/graphql/work_item.query.graphql'; import workItemLabelsSubscription from 'ee_else_ce/work_items/graphql/work_item_labels.subscription.graphql'; import updateWorkItemMutation from '~/work_items/graphql/update_work_item.mutation.graphql'; import workItemByIidQuery from '~/work_items/graphql/work_item_by_iid.query.graphql'; @@ -15,11 +14,9 @@ import { i18n, I18N_WORK_ITEM_ERROR_FETCHING_LABELS } from '~/work_items/constan import { projectLabelsResponse, mockLabels, - workItemQueryResponse, - workItemResponseFactory, + workItemByIidResponseFactory, updateWorkItemMutationResponse, workItemLabelsSubscriptionResponse, - projectWorkItemResponse, } from '../mock_data'; Vue.use(VueApollo); @@ -34,8 +31,9 @@ describe('WorkItemLabels component', () => { const findEmptyState = () => wrapper.findByTestId('empty-state'); const findLabelsTitle = () => wrapper.findByTestId('labels-title'); - const workItemQuerySuccess = jest.fn().mockResolvedValue(workItemQueryResponse); - const workItemByIidResponseHandler = jest.fn().mockResolvedValue(projectWorkItemResponse); + const workItemQuerySuccess = jest + .fn() + .mockResolvedValue(workItemByIidResponseFactory({ labels: null })); const successSearchQueryHandler = jest.fn().mockResolvedValue(projectLabelsResponse); const successUpdateWorkItemMutationHandler = jest .fn() @@ -48,27 +46,22 @@ describe('WorkItemLabels component', () => { workItemQueryHandler = workItemQuerySuccess, searchQueryHandler = successSearchQueryHandler, updateWorkItemMutationHandler = successUpdateWorkItemMutationHandler, - fetchByIid = false, - queryVariables = { id: workItemId }, + queryVariables = { iid: '1' }, } = {}) => { - const apolloProvider = createMockApollo([ - [workItemQuery, workItemQueryHandler], - [labelSearchQuery, searchQueryHandler], - [updateWorkItemMutation, updateWorkItemMutationHandler], - [workItemLabelsSubscription, subscriptionHandler], - [workItemByIidQuery, workItemByIidResponseHandler], - ]); - wrapper = mountExtended(WorkItemLabels, { + apolloProvider: createMockApollo([ + [workItemByIidQuery, workItemQueryHandler], + [labelSearchQuery, searchQueryHandler], + [updateWorkItemMutation, updateWorkItemMutationHandler], + [workItemLabelsSubscription, subscriptionHandler], + ]), propsData: { workItemId, canUpdate, fullPath: 'test-project-path', queryVariables, - fetchByIid, }, attachTo: document.body, - apolloProvider, }); }; @@ -186,7 +179,7 @@ describe('WorkItemLabels component', () => { }); it('adds new labels to the end', async () => { - const response = workItemResponseFactory({ labels: [mockLabels[1]] }); + const response = workItemByIidResponseFactory({ labels: [mockLabels[1]] }); const workItemQueryHandler = jest.fn().mockResolvedValue(response); createComponent({ workItemQueryHandler, @@ -263,24 +256,15 @@ describe('WorkItemLabels component', () => { }); }); - it('calls the global ID work item query when `fetchByIid` prop is false', async () => { - createComponent({ fetchByIid: false }); + it('calls the work item query', async () => { + createComponent(); await waitForPromises(); expect(workItemQuerySuccess).toHaveBeenCalled(); - expect(workItemByIidResponseHandler).not.toHaveBeenCalled(); - }); - - it('calls the IID work item query when when `fetchByIid` prop is true', async () => { - createComponent({ fetchByIid: true }); - await waitForPromises(); - - expect(workItemQuerySuccess).not.toHaveBeenCalled(); - expect(workItemByIidResponseHandler).toHaveBeenCalled(); }); - it('skips calling the handlers when missing the needed queryVariables', async () => { - createComponent({ queryVariables: {}, fetchByIid: false }); + it('skips calling the work item query when missing queryVariables', async () => { + createComponent({ queryVariables: {} }); await waitForPromises(); expect(workItemQuerySuccess).not.toHaveBeenCalled(); diff --git a/spec/frontend/work_items/components/work_item_milestone_spec.js b/spec/frontend/work_items/components/work_item_milestone_spec.js index 5997de01274..95b0aee1315 100644 --- a/spec/frontend/work_items/components/work_item_milestone_spec.js +++ b/spec/frontend/work_items/components/work_item_milestone_spec.js @@ -9,27 +9,20 @@ import { import Vue, { nextTick } from 'vue'; import VueApollo from 'vue-apollo'; import WorkItemMilestone from '~/work_items/components/work_item_milestone.vue'; -import { resolvers, config } from '~/graphql_shared/issuable_client'; import createMockApollo from 'helpers/mock_apollo_helper'; import { mockTracking } from 'helpers/tracking_helper'; import { shallowMountExtended } from 'helpers/vue_test_utils_helper'; import waitForPromises from 'helpers/wait_for_promises'; import { TRACKING_CATEGORY_SHOW } from '~/work_items/constants'; +import updateWorkItemMutation from '~/work_items/graphql/update_work_item.mutation.graphql'; import projectMilestonesQuery from '~/sidebar/queries/project_milestones.query.graphql'; import { projectMilestonesResponse, projectMilestonesResponseWithNoMilestones, mockMilestoneWidgetResponse, - workItemResponseFactory, updateWorkItemMutationErrorResponse, - workItemMilestoneSubscriptionResponse, - projectWorkItemResponse, updateWorkItemMutationResponse, -} from 'jest/work_items/mock_data'; -import workItemQuery from '~/work_items/graphql/work_item.query.graphql'; -import workItemByIidQuery from '~/work_items/graphql/work_item_by_iid.query.graphql'; -import workItemMilestoneSubscription from '~/work_items/graphql/work_item_milestone.subscription.graphql'; -import updateWorkItemMutation from '~/work_items/graphql/update_work_item.mutation.graphql'; +} from '../mock_data'; describe('WorkItemMilestone component', () => { Vue.use(VueApollo); @@ -52,72 +45,34 @@ describe('WorkItemMilestone component', () => { const findDropdownTextAtIndex = (index) => findDropdownTexts().at(index); const findInputGroup = () => wrapper.findComponent(GlFormGroup); - const workItemQueryResponse = workItemResponseFactory({ canUpdate: true, canDelete: true }); - const workItemQueryHandler = jest.fn().mockResolvedValue(workItemQueryResponse); - const workItemByIidResponseHandler = jest.fn().mockResolvedValue(projectWorkItemResponse); - - const networkResolvedValue = new Error(); - const successSearchQueryHandler = jest.fn().mockResolvedValue(projectMilestonesResponse); const successSearchWithNoMatchingMilestones = jest .fn() .mockResolvedValue(projectMilestonesResponseWithNoMilestones); - const milestoneSubscriptionHandler = jest - .fn() - .mockResolvedValue(workItemMilestoneSubscriptionResponse); const successUpdateWorkItemMutationHandler = jest .fn() .mockResolvedValue(updateWorkItemMutationResponse); - const showDropdown = () => { - findDropdown().vm.$emit('shown'); - }; - - const hideDropdown = () => { - findDropdown().vm.$emit('hide'); - }; + const showDropdown = () => findDropdown().vm.$emit('shown'); + const hideDropdown = () => findDropdown().vm.$emit('hide'); const createComponent = ({ canUpdate = true, milestone = mockMilestoneWidgetResponse, searchQueryHandler = successSearchQueryHandler, - fetchByIid = false, mutationHandler = successUpdateWorkItemMutationHandler, } = {}) => { - const apolloProvider = createMockApollo( - [ - [workItemQuery, workItemQueryHandler], - [workItemMilestoneSubscription, milestoneSubscriptionHandler], + wrapper = shallowMountExtended(WorkItemMilestone, { + apolloProvider: createMockApollo([ [projectMilestonesQuery, searchQueryHandler], [updateWorkItemMutation, mutationHandler], - [workItemByIidQuery, workItemByIidResponseHandler], - ], - resolvers, - { - typePolicies: config.cacheConfig.typePolicies, - }, - ); - - apolloProvider.clients.defaultClient.writeQuery({ - query: workItemQuery, - variables: { - id: workItemId, - }, - data: workItemQueryResponse.data, - }); - - wrapper = shallowMountExtended(WorkItemMilestone, { - apolloProvider, + ]), propsData: { canUpdate, workItemMilestone: milestone, workItemId, workItemType, fullPath, - queryVariables: { - id: workItemId, - }, - fetchByIid, }, stubs: { GlDropdown, @@ -244,7 +199,7 @@ describe('WorkItemMilestone component', () => { it.each` errorType | expectedErrorMessage | mockValue | resolveFunction ${'graphql error'} | ${'Something went wrong while updating the task. Please try again.'} | ${updateWorkItemMutationErrorResponse} | ${'mockResolvedValue'} - ${'network error'} | ${'Something went wrong while updating the task. Please try again.'} | ${networkResolvedValue} | ${'mockRejectedValue'} + ${'network error'} | ${'Something went wrong while updating the task. Please try again.'} | ${new Error()} | ${'mockRejectedValue'} `( 'emits an error when there is a $errorType', async ({ mockValue, expectedErrorMessage, resolveFunction }) => { |