diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-06-20 14:10:13 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-06-20 14:10:13 +0300 |
commit | 0ea3fcec397b69815975647f5e2aa5fe944a8486 (patch) | |
tree | 7979381b89d26011bcf9bdc989a40fcc2f1ed4ff /spec/frontend/issuable/popover/components | |
parent | 72123183a20411a36d607d70b12d57c484394c8e (diff) |
Add latest changes from gitlab-org/gitlab@15-1-stable-eev15.1.0-rc42
Diffstat (limited to 'spec/frontend/issuable/popover/components')
-rw-r--r-- | spec/frontend/issuable/popover/components/issue_popover_spec.js | 81 | ||||
-rw-r--r-- | spec/frontend/issuable/popover/components/mr_popover_spec.js | 119 |
2 files changed, 200 insertions, 0 deletions
diff --git a/spec/frontend/issuable/popover/components/issue_popover_spec.js b/spec/frontend/issuable/popover/components/issue_popover_spec.js new file mode 100644 index 00000000000..3e77e750f3a --- /dev/null +++ b/spec/frontend/issuable/popover/components/issue_popover_spec.js @@ -0,0 +1,81 @@ +import { GlSkeletonLoader } from '@gitlab/ui'; +import { shallowMount } from '@vue/test-utils'; +import Vue from 'vue'; +import VueApollo from 'vue-apollo'; +import createMockApollo from 'helpers/mock_apollo_helper'; +import waitForPromises from 'helpers/wait_for_promises'; +import StatusBox from '~/issuable/components/status_box.vue'; +import IssuePopover from '~/issuable/popover/components/issue_popover.vue'; +import issueQuery from '~/issuable/popover/queries/issue.query.graphql'; + +describe('Issue Popover', () => { + let wrapper; + + Vue.use(VueApollo); + + const issueQueryResponse = { + data: { + project: { + __typename: 'Project', + id: '1', + issue: { + __typename: 'Issue', + id: 'gid://gitlab/Issue/1', + createdAt: '2020-07-01T04:08:01Z', + state: 'opened', + title: 'Issue title', + }, + }, + }, + }; + + const mountComponent = ({ + queryResponse = jest.fn().mockResolvedValue(issueQueryResponse), + } = {}) => { + wrapper = shallowMount(IssuePopover, { + apolloProvider: createMockApollo([[issueQuery, queryResponse]]), + propsData: { + target: document.createElement('a'), + projectPath: 'foo/bar', + iid: '1', + cachedTitle: 'Cached title', + }, + }); + }; + + afterEach(() => { + wrapper.destroy(); + }); + + it('shows skeleton-loader while apollo is loading', () => { + mountComponent(); + + expect(wrapper.findComponent(GlSkeletonLoader).exists()).toBe(true); + }); + + describe('when loaded', () => { + beforeEach(() => { + mountComponent(); + return waitForPromises(); + }); + + it('shows status badge', () => { + expect(wrapper.findComponent(StatusBox).props()).toEqual({ + issuableType: 'issue', + initialState: issueQueryResponse.data.project.issue.state, + }); + }); + + it('shows opened time', () => { + expect(wrapper.text()).toContain('Opened 4 days ago'); + }); + + it('shows title', () => { + expect(wrapper.find('h5').text()).toBe(issueQueryResponse.data.project.issue.title); + }); + + it('shows reference', () => { + expect(wrapper.text()).toContain('foo/bar#1'); + }); + }); +}); diff --git a/spec/frontend/issuable/popover/components/mr_popover_spec.js b/spec/frontend/issuable/popover/components/mr_popover_spec.js new file mode 100644 index 00000000000..5fdd1e6e8fc --- /dev/null +++ b/spec/frontend/issuable/popover/components/mr_popover_spec.js @@ -0,0 +1,119 @@ +import { GlSkeletonLoader } from '@gitlab/ui'; +import { shallowMount } from '@vue/test-utils'; +import Vue from 'vue'; +import VueApollo from 'vue-apollo'; +import createMockApollo from 'helpers/mock_apollo_helper'; +import waitForPromises from 'helpers/wait_for_promises'; +import MRPopover from '~/issuable/popover/components/mr_popover.vue'; +import mergeRequestQuery from '~/issuable/popover/queries/merge_request.query.graphql'; +import CiIcon from '~/vue_shared/components/ci_icon.vue'; + +describe('MR Popover', () => { + let wrapper; + + Vue.use(VueApollo); + + const mrQueryResponse = { + data: { + project: { + __typename: 'Project', + id: '1', + mergeRequest: { + __typename: 'Merge Request', + id: 'gid://gitlab/Merge_Request/1', + createdAt: '2020-07-01T04:08:01Z', + state: 'opened', + title: 'MR title', + headPipeline: { + id: '1', + detailedStatus: { + id: '1', + icon: 'status_success', + group: 'success', + }, + }, + }, + }, + }, + }; + + const mrQueryResponseWithoutDetailedStatus = { + data: { + project: { + __typename: 'Project', + id: '1', + mergeRequest: { + __typename: 'Merge Request', + id: 'gid://gitlab/Merge_Request/1', + createdAt: '2020-07-01T04:08:01Z', + state: 'opened', + title: 'MR title', + headPipeline: { + id: '1', + detailedStatus: null, + }, + }, + }, + }, + }; + + const mountComponent = ({ + queryResponse = jest.fn().mockResolvedValue(mrQueryResponse), + } = {}) => { + wrapper = shallowMount(MRPopover, { + apolloProvider: createMockApollo([[mergeRequestQuery, queryResponse]]), + propsData: { + target: document.createElement('a'), + projectPath: 'foo/bar', + iid: '1', + cachedTitle: 'Cached Title', + }, + }); + }; + + afterEach(() => { + wrapper.destroy(); + }); + + it('shows skeleton-loader while apollo is loading', () => { + mountComponent(); + + expect(wrapper.findComponent(GlSkeletonLoader).exists()).toBe(true); + }); + + describe('when loaded', () => { + beforeEach(() => { + mountComponent(); + return waitForPromises(); + }); + + it('shows opened time', () => { + expect(wrapper.text()).toContain('Opened 4 days ago'); + }); + + it('shows title', () => { + expect(wrapper.find('h5').text()).toBe(mrQueryResponse.data.project.mergeRequest.title); + }); + + it('shows reference', () => { + expect(wrapper.text()).toContain('foo/bar!1'); + }); + + it('shows CI Icon if there is pipeline data', async () => { + expect(wrapper.findComponent(CiIcon).exists()).toBe(true); + }); + }); + + describe('without detailed status', () => { + beforeEach(() => { + mountComponent({ + queryResponse: jest.fn().mockResolvedValue(mrQueryResponseWithoutDetailedStatus), + }); + return waitForPromises(); + }); + + it('does not show CI icon if there is no pipeline data', async () => { + expect(wrapper.findComponent(CiIcon).exists()).toBe(false); + }); + }); +}); |