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/work_item_created_updated_spec.js | |
parent | 34283a71d9ac31eb4da0b59d0b25fc2be014bc9c (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/work_items/components/work_item_created_updated_spec.js')
-rw-r--r-- | spec/frontend/work_items/components/work_item_created_updated_spec.js | 82 |
1 files changed, 25 insertions, 57 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); }); }); |