diff options
Diffstat (limited to 'spec/frontend/vue_mr_widget/components/states')
14 files changed, 116 insertions, 51 deletions
diff --git a/spec/frontend/vue_mr_widget/components/states/__snapshots__/mr_widget_pipeline_failed_spec.js.snap b/spec/frontend/vue_mr_widget/components/states/__snapshots__/mr_widget_pipeline_failed_spec.js.snap new file mode 100644 index 00000000000..a124008b36a --- /dev/null +++ b/spec/frontend/vue_mr_widget/components/states/__snapshots__/mr_widget_pipeline_failed_spec.js.snap @@ -0,0 +1,24 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`PipelineFailed should render error message with a disabled merge button 1`] = ` +<div + class="mr-widget-body media" +> + <status-icon-stub + showdisabledbutton="true" + status="warning" + /> + + <div + class="media-body space-children" + > + <span + class="bold" + > + <gl-sprintf-stub + message="The pipeline for this merge request did not complete. Push a new commit to fix the failure, or check the %{linkStart}troubleshooting documentation%{linkEnd} to see other possible actions." + /> + </span> + </div> +</div> +`; diff --git a/spec/frontend/vue_mr_widget/components/states/mr_widget_auto_merge_enabled_spec.js b/spec/frontend/vue_mr_widget/components/states/mr_widget_auto_merge_enabled_spec.js index 850bbd93df5..4dd1bd2aa9c 100644 --- a/spec/frontend/vue_mr_widget/components/states/mr_widget_auto_merge_enabled_spec.js +++ b/spec/frontend/vue_mr_widget/components/states/mr_widget_auto_merge_enabled_spec.js @@ -1,11 +1,11 @@ -import { nextTick } from 'vue'; import { shallowMount } from '@vue/test-utils'; +import { nextTick } from 'vue'; import { trimText } from 'helpers/text_helper'; import { extendedWrapper } from 'helpers/vue_test_utils_helper'; import autoMergeEnabledComponent from '~/vue_merge_request_widget/components/states/mr_widget_auto_merge_enabled.vue'; -import MRWidgetService from '~/vue_merge_request_widget/services/mr_widget_service'; -import eventHub from '~/vue_merge_request_widget/event_hub'; import { MWPS_MERGE_STRATEGY } from '~/vue_merge_request_widget/constants'; +import eventHub from '~/vue_merge_request_widget/event_hub'; +import MRWidgetService from '~/vue_merge_request_widget/services/mr_widget_service'; let wrapper; let mergeRequestWidgetGraphqlEnabled = false; @@ -202,7 +202,11 @@ describe('MRWidgetAutoMergeEnabled', () => { wrapper.vm.cancelAutomaticMerge(); setImmediate(() => { expect(wrapper.vm.isCancellingAutoMerge).toBeTruthy(); - expect(eventHub.$emit).toHaveBeenCalledWith('UpdateWidgetData', mrObj); + if (mergeRequestWidgetGraphql) { + expect(eventHub.$emit).toHaveBeenCalledWith('MRWidgetUpdateRequested'); + } else { + expect(eventHub.$emit).toHaveBeenCalledWith('UpdateWidgetData', mrObj); + } done(); }); }); diff --git a/spec/frontend/vue_mr_widget/components/states/mr_widget_auto_merge_failed_spec.js b/spec/frontend/vue_mr_widget/components/states/mr_widget_auto_merge_failed_spec.js index dca3798f7ea..24198096564 100644 --- a/spec/frontend/vue_mr_widget/components/states/mr_widget_auto_merge_failed_spec.js +++ b/spec/frontend/vue_mr_widget/components/states/mr_widget_auto_merge_failed_spec.js @@ -1,6 +1,6 @@ -import { nextTick } from 'vue'; -import { shallowMount } from '@vue/test-utils'; import { GlLoadingIcon, GlButton } from '@gitlab/ui'; +import { shallowMount } from '@vue/test-utils'; +import { nextTick } from 'vue'; import AutoMergeFailedComponent from '~/vue_merge_request_widget/components/states/mr_widget_auto_merge_failed.vue'; import eventHub from '~/vue_merge_request_widget/event_hub'; diff --git a/spec/frontend/vue_mr_widget/components/states/mr_widget_commit_message_dropdown_spec.js b/spec/frontend/vue_mr_widget/components/states/mr_widget_commit_message_dropdown_spec.js index 706d60368b5..4c763f40cbe 100644 --- a/spec/frontend/vue_mr_widget/components/states/mr_widget_commit_message_dropdown_spec.js +++ b/spec/frontend/vue_mr_widget/components/states/mr_widget_commit_message_dropdown_spec.js @@ -1,5 +1,5 @@ -import { shallowMount } from '@vue/test-utils'; import { GlDropdownItem } from '@gitlab/ui'; +import { shallowMount } from '@vue/test-utils'; import CommitMessageDropdown from '~/vue_merge_request_widget/components/states/commit_message_dropdown.vue'; const commits = [ diff --git a/spec/frontend/vue_mr_widget/components/states/mr_widget_conflicts_spec.js b/spec/frontend/vue_mr_widget/components/states/mr_widget_conflicts_spec.js index f5a059698b6..d3fc1e0e05b 100644 --- a/spec/frontend/vue_mr_widget/components/states/mr_widget_conflicts_spec.js +++ b/spec/frontend/vue_mr_widget/components/states/mr_widget_conflicts_spec.js @@ -1,7 +1,7 @@ -import $ from 'jquery'; import { createLocalVue, shallowMount } from '@vue/test-utils'; -import { removeBreakLine } from 'helpers/text_helper'; +import $ from 'jquery'; import { TEST_HOST } from 'helpers/test_constants'; +import { removeBreakLine } from 'helpers/text_helper'; import ConflictsComponent from '~/vue_merge_request_widget/components/states/mr_widget_conflicts.vue'; describe('MRWidgetConflicts', () => { diff --git a/spec/frontend/vue_mr_widget/components/states/mr_widget_failed_to_merge_spec.js b/spec/frontend/vue_mr_widget/components/states/mr_widget_failed_to_merge_spec.js index 48c1a9eedf9..c1471314c4a 100644 --- a/spec/frontend/vue_mr_widget/components/states/mr_widget_failed_to_merge_spec.js +++ b/spec/frontend/vue_mr_widget/components/states/mr_widget_failed_to_merge_spec.js @@ -54,7 +54,7 @@ describe('MRWidgetFailedToMerge', () => { Vue.nextTick() .then(() => { - expect(vm.mergeError).toBe('contains line breaks'); + expect(vm.mergeError).toBe('contains line breaks.'); }) .then(done) .catch(done.fail); @@ -113,14 +113,14 @@ describe('MRWidgetFailedToMerge', () => { describe('while it is not regresing', () => { it('renders warning icon and disabled merge button', () => { expect(vm.$el.querySelector('.js-ci-status-icon-warning')).not.toBeNull(); - expect(vm.$el.querySelector('.js-disabled-merge-button').getAttribute('disabled')).toEqual( - 'disabled', - ); + expect( + vm.$el.querySelector('[data-testid="disabled-merge-button"]').getAttribute('disabled'), + ).toEqual('disabled'); }); it('renders given error', () => { expect(vm.$el.querySelector('.has-error-message').textContent.trim()).toEqual( - 'Merge error happened', + 'Merge error happened.', ); }); diff --git a/spec/frontend/vue_mr_widget/components/states/mr_widget_merged_spec.js b/spec/frontend/vue_mr_widget/components/states/mr_widget_merged_spec.js index 36c4174c03d..6af8ac9e18e 100644 --- a/spec/frontend/vue_mr_widget/components/states/mr_widget_merged_spec.js +++ b/spec/frontend/vue_mr_widget/components/states/mr_widget_merged_spec.js @@ -1,5 +1,8 @@ +import { getByRole } from '@testing-library/dom'; import Vue from 'vue'; import mountComponent from 'helpers/vue_mount_component_helper'; +import { OPEN_REVERT_MODAL, OPEN_CHERRY_PICK_MODAL } from '~/projects/commit/constants'; +import modalEventHub from '~/projects/commit/event_hub'; import mergedComponent from '~/vue_merge_request_widget/components/states/mr_widget_merged.vue'; import eventHub from '~/vue_merge_request_widget/event_hub'; @@ -16,6 +19,7 @@ describe('MRWidgetMerged', () => { }; beforeEach(() => { + jest.spyOn(document, 'dispatchEvent'); const Component = Vue.extend(mergedComponent); const mr = { isRemovingSourceBranch: false, @@ -147,6 +151,26 @@ describe('MRWidgetMerged', () => { }); }); + it('calls dispatchDocumentEvent to load in the modal component', () => { + expect(document.dispatchEvent).toHaveBeenCalledWith(new CustomEvent('merged:UpdateActions')); + }); + + it('emits event to open the revert modal on revert button click', () => { + const eventHubSpy = jest.spyOn(modalEventHub, '$emit'); + + getByRole(vm.$el, 'button', { name: /Revert/i }).click(); + + expect(eventHubSpy).toHaveBeenCalledWith(OPEN_REVERT_MODAL); + }); + + it('emits event to open the cherry-pick modal on cherry-pick button click', () => { + const eventHubSpy = jest.spyOn(modalEventHub, '$emit'); + + getByRole(vm.$el, 'button', { name: /Cherry-pick/i }).click(); + + expect(eventHubSpy).toHaveBeenCalledWith(OPEN_CHERRY_PICK_MODAL); + }); + it('has merged by information', () => { expect(vm.$el.textContent).toContain('Merged by'); expect(vm.$el.textContent).toContain('Administrator'); diff --git a/spec/frontend/vue_mr_widget/components/states/mr_widget_pipeline_blocked_spec.js b/spec/frontend/vue_mr_widget/components/states/mr_widget_pipeline_blocked_spec.js index 8847e4e6bdd..bd77a1d657e 100644 --- a/spec/frontend/vue_mr_widget/components/states/mr_widget_pipeline_blocked_spec.js +++ b/spec/frontend/vue_mr_widget/components/states/mr_widget_pipeline_blocked_spec.js @@ -1,25 +1,27 @@ -import Vue from 'vue'; -import mountComponent from 'helpers/vue_mount_component_helper'; -import { removeBreakLine } from 'helpers/text_helper'; -import pipelineBlockedComponent from '~/vue_merge_request_widget/components/states/mr_widget_pipeline_blocked.vue'; +import { shallowMount, mount } from '@vue/test-utils'; +import PipelineBlockedComponent from '~/vue_merge_request_widget/components/states/mr_widget_pipeline_blocked.vue'; describe('MRWidgetPipelineBlocked', () => { - let vm; - beforeEach(() => { - const Component = Vue.extend(pipelineBlockedComponent); - vm = mountComponent(Component); - }); + let wrapper; + + const createWrapper = (mountFn = shallowMount) => { + wrapper = mountFn(PipelineBlockedComponent); + }; afterEach(() => { - vm.$destroy(); + wrapper.destroy(); }); it('renders warning icon', () => { - expect(vm.$el.querySelector('.ci-status-icon-warning')).not.toBe(null); + createWrapper(mount); + + expect(wrapper.find('.ci-status-icon-warning').exists()).toBe(true); }); it('renders information text', () => { - expect(removeBreakLine(vm.$el.textContent).trim()).toContain( + createWrapper(); + + expect(wrapper.text()).toBe( 'Pipeline blocked. The pipeline for this merge request requires a manual action to proceed', ); }); diff --git a/spec/frontend/vue_mr_widget/components/states/mr_widget_pipeline_failed_spec.js b/spec/frontend/vue_mr_widget/components/states/mr_widget_pipeline_failed_spec.js index 179adef12d9..3e0840fef4e 100644 --- a/spec/frontend/vue_mr_widget/components/states/mr_widget_pipeline_failed_spec.js +++ b/spec/frontend/vue_mr_widget/components/states/mr_widget_pipeline_failed_spec.js @@ -1,19 +1,30 @@ -import Vue from 'vue'; -import { removeBreakLine } from 'helpers/text_helper'; +import { shallowMount } from '@vue/test-utils'; +import statusIcon from '~/vue_merge_request_widget/components/mr_widget_status_icon.vue'; import PipelineFailed from '~/vue_merge_request_widget/components/states/pipeline_failed.vue'; describe('PipelineFailed', () => { - describe('template', () => { - const Component = Vue.extend(PipelineFailed); - const vm = new Component({ - el: document.createElement('div'), - }); - it('should have correct elements', () => { - expect(vm.$el.classList.contains('mr-widget-body')).toBeTruthy(); - expect(vm.$el.querySelector('button').getAttribute('disabled')).toBeTruthy(); - expect(removeBreakLine(vm.$el.innerText).trim()).toContain( - 'The pipeline for this merge request failed. Please retry the job or push a new commit to fix the failure', - ); - }); + let wrapper; + + const createComponent = () => { + wrapper = shallowMount(PipelineFailed); + }; + + const findStatusIcon = () => wrapper.find(statusIcon); + + beforeEach(() => { + createComponent(); + }); + + afterEach(() => { + wrapper.destroy(); + wrapper = null; + }); + + it('should render error message with a disabled merge button', () => { + expect(wrapper.element).toMatchSnapshot(); + }); + + it('merge button should be disabled', () => { + expect(findStatusIcon().props('showDisabledButton')).toBe(true); }); }); diff --git a/spec/frontend/vue_mr_widget/components/states/mr_widget_ready_to_merge_spec.js b/spec/frontend/vue_mr_widget/components/states/mr_widget_ready_to_merge_spec.js index 8eddf59820c..983e4a35078 100644 --- a/spec/frontend/vue_mr_widget/components/states/mr_widget_ready_to_merge_spec.js +++ b/spec/frontend/vue_mr_widget/components/states/mr_widget_ready_to_merge_spec.js @@ -1,14 +1,14 @@ -import Vue from 'vue'; import { createLocalVue, shallowMount } from '@vue/test-utils'; -import ReadyToMerge from '~/vue_merge_request_widget/components/states/ready_to_merge.vue'; -import SquashBeforeMerge from '~/vue_merge_request_widget/components/states/squash_before_merge.vue'; -import CommitsHeader from '~/vue_merge_request_widget/components/states/commits_header.vue'; +import Vue from 'vue'; +import { refreshUserMergeRequestCounts } from '~/commons/nav/user_merge_requests'; +import simplePoll from '~/lib/utils/simple_poll'; import CommitEdit from '~/vue_merge_request_widget/components/states/commit_edit.vue'; import CommitMessageDropdown from '~/vue_merge_request_widget/components/states/commit_message_dropdown.vue'; -import eventHub from '~/vue_merge_request_widget/event_hub'; +import CommitsHeader from '~/vue_merge_request_widget/components/states/commits_header.vue'; +import ReadyToMerge from '~/vue_merge_request_widget/components/states/ready_to_merge.vue'; +import SquashBeforeMerge from '~/vue_merge_request_widget/components/states/squash_before_merge.vue'; import { MWPS_MERGE_STRATEGY, MTWPS_MERGE_STRATEGY } from '~/vue_merge_request_widget/constants'; -import { refreshUserMergeRequestCounts } from '~/commons/nav/user_merge_requests'; -import simplePoll from '~/lib/utils/simple_poll'; +import eventHub from '~/vue_merge_request_widget/event_hub'; jest.mock('~/lib/utils/simple_poll', () => jest.fn().mockImplementation(jest.requireActual('~/lib/utils/simple_poll').default), diff --git a/spec/frontend/vue_mr_widget/components/states/mr_widget_sha_mismatch_spec.js b/spec/frontend/vue_mr_widget/components/states/mr_widget_sha_mismatch_spec.js index 38920846a50..ef6a9b1e8fc 100644 --- a/spec/frontend/vue_mr_widget/components/states/mr_widget_sha_mismatch_spec.js +++ b/spec/frontend/vue_mr_widget/components/states/mr_widget_sha_mismatch_spec.js @@ -1,6 +1,6 @@ import Vue from 'vue'; -import mountComponent from 'helpers/vue_mount_component_helper'; import { removeBreakLine } from 'helpers/text_helper'; +import mountComponent from 'helpers/vue_mount_component_helper'; import ShaMismatch from '~/vue_merge_request_widget/components/states/sha_mismatch.vue'; describe('ShaMismatch', () => { diff --git a/spec/frontend/vue_mr_widget/components/states/mr_widget_squash_before_merge_spec.js b/spec/frontend/vue_mr_widget/components/states/mr_widget_squash_before_merge_spec.js index cc160f6182d..8ead0002950 100644 --- a/spec/frontend/vue_mr_widget/components/states/mr_widget_squash_before_merge_spec.js +++ b/spec/frontend/vue_mr_widget/components/states/mr_widget_squash_before_merge_spec.js @@ -1,5 +1,5 @@ -import { createLocalVue, shallowMount } from '@vue/test-utils'; import { GlFormCheckbox } from '@gitlab/ui'; +import { createLocalVue, shallowMount } from '@vue/test-utils'; import SquashBeforeMerge from '~/vue_merge_request_widget/components/states/squash_before_merge.vue'; import { SQUASH_BEFORE_MERGE } from '~/vue_merge_request_widget/i18n'; diff --git a/spec/frontend/vue_mr_widget/components/states/mr_widget_unresolved_discussions_spec.js b/spec/frontend/vue_mr_widget/components/states/mr_widget_unresolved_discussions_spec.js index a5531577a8c..6c0d69ea109 100644 --- a/spec/frontend/vue_mr_widget/components/states/mr_widget_unresolved_discussions_spec.js +++ b/spec/frontend/vue_mr_widget/components/states/mr_widget_unresolved_discussions_spec.js @@ -1,7 +1,7 @@ import { mount } from '@vue/test-utils'; import { TEST_HOST } from 'helpers/test_constants'; -import UnresolvedDiscussions from '~/vue_merge_request_widget/components/states/unresolved_discussions.vue'; import notesEventHub from '~/notes/event_hub'; +import UnresolvedDiscussions from '~/vue_merge_request_widget/components/states/unresolved_discussions.vue'; function createComponent({ path = '' } = {}) { return mount(UnresolvedDiscussions, { diff --git a/spec/frontend/vue_mr_widget/components/states/mr_widget_wip_spec.js b/spec/frontend/vue_mr_widget/components/states/mr_widget_wip_spec.js index 6d63d4b1be3..e0077a008a2 100644 --- a/spec/frontend/vue_mr_widget/components/states/mr_widget_wip_spec.js +++ b/spec/frontend/vue_mr_widget/components/states/mr_widget_wip_spec.js @@ -1,7 +1,7 @@ import Vue from 'vue'; +import { deprecatedCreateFlash as createFlash } from '~/flash'; import WorkInProgress from '~/vue_merge_request_widget/components/states/work_in_progress.vue'; import eventHub from '~/vue_merge_request_widget/event_hub'; -import { deprecatedCreateFlash as createFlash } from '~/flash'; jest.mock('~/flash'); |