diff options
Diffstat (limited to 'spec/frontend/vue_merge_request_widget/components/merge_checks_spec.js')
-rw-r--r-- | spec/frontend/vue_merge_request_widget/components/merge_checks_spec.js | 103 |
1 files changed, 88 insertions, 15 deletions
diff --git a/spec/frontend/vue_merge_request_widget/components/merge_checks_spec.js b/spec/frontend/vue_merge_request_widget/components/merge_checks_spec.js index c86fe6d0a10..d39098b27c2 100644 --- a/spec/frontend/vue_merge_request_widget/components/merge_checks_spec.js +++ b/spec/frontend/vue_merge_request_widget/components/merge_checks_spec.js @@ -1,18 +1,22 @@ import VueApollo from 'vue-apollo'; import Vue from 'vue'; -import { mountExtended } from 'helpers/vue_test_utils_helper'; +import { shallowMountExtended, mountExtended } from 'helpers/vue_test_utils_helper'; import createMockApollo from 'helpers/mock_apollo_helper'; import waitForPromises from 'helpers/wait_for_promises'; import MergeChecksComponent from '~/vue_merge_request_widget/components/merge_checks.vue'; import mergeChecksQuery from '~/vue_merge_request_widget/queries/merge_checks.query.graphql'; import StatusIcon from '~/vue_merge_request_widget/components/extensions/status_icon.vue'; +import StateContainer from '~/vue_merge_request_widget/components/state_container.vue'; +import { COMPONENTS } from '~/vue_merge_request_widget/components/checks/constants'; +import conflictsStateQuery from '~/vue_merge_request_widget/queries/states/conflicts.query.graphql'; +import rebaseStateQuery from '~/vue_merge_request_widget/queries/states/rebase.query.graphql'; Vue.use(VueApollo); let wrapper; let apolloProvider; -function factory({ canMerge = true, mergeChecks = [] } = {}) { +function factory(mountFn, { canMerge = true, mergeabilityChecks = [] } = {}) { apolloProvider = createMockApollo([ [ mergeChecksQuery, @@ -20,28 +24,79 @@ function factory({ canMerge = true, mergeChecks = [] } = {}) { data: { project: { id: 1, - mergeRequest: { id: 1, userPermissions: { canMerge }, mergeChecks }, + mergeRequest: { id: 1, userPermissions: { canMerge }, mergeabilityChecks }, }, }, }), ], + [ + conflictsStateQuery, + () => + Promise.resolve({ + data: { + project: { + id: 1, + mergeRequest: { + id: 1, + shouldBeRebased: false, + sourceBranchProtected: false, + userPermissions: { pushToSourceBranch: true }, + }, + }, + }, + }), + ], + [ + rebaseStateQuery, + () => + Promise.resolve({ + data: { + project: { + id: '1', + mergeRequest: { + id: '2', + rebaseInProgress: false, + targetBranch: 'main', + userPermissions: { + pushToSourceBranch: true, + }, + pipelines: { + nodes: [ + { + id: '1', + project: { + id: '2', + fullPath: 'gitlab/gitlab', + }, + }, + ], + }, + }, + }, + }, + }), + ], ]); - wrapper = mountExtended(MergeChecksComponent, { + wrapper = mountFn(MergeChecksComponent, { apolloProvider, propsData: { mr: {}, + service: {}, }, }); } +const mountComponent = factory.bind(null, mountExtended); +const shallowMountComponent = factory.bind(null, shallowMountExtended); + describe('Merge request merge checks component', () => { afterEach(() => { apolloProvider = null; }); it('renders ready to merge text if user can merge', async () => { - factory({ canMerge: true }); + mountComponent({ canMerge: true }); await waitForPromises(); @@ -49,7 +104,7 @@ describe('Merge request merge checks component', () => { }); it('renders ready to merge by members text if user can not merge', async () => { - factory({ canMerge: false }); + mountComponent({ canMerge: false }); await waitForPromises(); @@ -57,11 +112,11 @@ describe('Merge request merge checks component', () => { }); it.each` - mergeChecks | text - ${[{ identifier: 'discussions', result: 'failed' }]} | ${'Merge blocked: 1 check failed'} - ${[{ identifier: 'discussions', result: 'failed' }, { identifier: 'rebase', result: 'failed' }]} | ${'Merge blocked: 2 checks failed'} - `('renders $text for $mergeChecks', async ({ mergeChecks, text }) => { - factory({ mergeChecks }); + mergeabilityChecks | text + ${[{ identifier: 'discussions', status: 'failed' }]} | ${'Merge blocked: 1 check failed'} + ${[{ identifier: 'discussions', status: 'failed' }, { identifier: 'rebase', status: 'failed' }]} | ${'Merge blocked: 2 checks failed'} + `('renders $text for $mergeabilityChecks', async ({ mergeabilityChecks, text }) => { + mountComponent({ mergeabilityChecks }); await waitForPromises(); @@ -69,19 +124,37 @@ describe('Merge request merge checks component', () => { }); it.each` - result | statusIcon + status | statusIcon ${'failed'} | ${'failed'} ${'passed'} | ${'success'} - `('renders $statusIcon for $result result', async ({ result, statusIcon }) => { - factory({ mergeChecks: [{ result, identifier: 'discussions' }] }); + `('renders $statusIcon for $status result', async ({ status, statusIcon }) => { + mountComponent({ mergeabilityChecks: [{ status, identifier: 'discussions' }] }); await waitForPromises(); expect(wrapper.findComponent(StatusIcon).props('iconName')).toBe(statusIcon); }); + it.each` + identifier + ${'conflict'} + ${'unresolved_discussions'} + ${'need_rebase'} + ${'default'} + `('renders $identifier merge check', async ({ identifier }) => { + shallowMountComponent({ mergeabilityChecks: [{ status: 'failed', identifier }] }); + + wrapper.findComponent(StateContainer).vm.$emit('toggle'); + + await waitForPromises(); + + const { default: component } = await COMPONENTS[identifier](); + + expect(wrapper.findComponent(component).exists()).toBe(true); + }); + it('expands collapsed area', async () => { - factory(); + mountComponent(); await waitForPromises(); |