Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/frontend')
-rw-r--r--spec/frontend/feature_highlight/feature_highlight_helper_spec.js42
-rw-r--r--spec/frontend/feature_highlight/feature_highlight_popover_spec.js75
-rw-r--r--spec/frontend/vue_merge_request_widget/components/states/mr_widget_ready_to_merge_spec.js79
3 files changed, 76 insertions, 120 deletions
diff --git a/spec/frontend/feature_highlight/feature_highlight_helper_spec.js b/spec/frontend/feature_highlight/feature_highlight_helper_spec.js
deleted file mode 100644
index 4609bfc23d7..00000000000
--- a/spec/frontend/feature_highlight/feature_highlight_helper_spec.js
+++ /dev/null
@@ -1,42 +0,0 @@
-import MockAdapter from 'axios-mock-adapter';
-import { dismiss } from '~/feature_highlight/feature_highlight_helper';
-import { createAlert } from '~/alert';
-import axios from '~/lib/utils/axios_utils';
-import { HTTP_STATUS_CREATED, HTTP_STATUS_INTERNAL_SERVER_ERROR } from '~/lib/utils/http_status';
-
-jest.mock('~/alert');
-
-describe('feature highlight helper', () => {
- describe('dismiss', () => {
- let mockAxios;
- const endpoint = '/-/callouts/dismiss';
- const highlightId = '123';
-
- beforeEach(() => {
- mockAxios = new MockAdapter(axios);
- });
-
- afterEach(() => {
- mockAxios.reset();
- });
-
- it('calls persistent dismissal endpoint with highlightId', async () => {
- mockAxios.onPost(endpoint, { feature_name: highlightId }).replyOnce(HTTP_STATUS_CREATED);
-
- await expect(dismiss(endpoint, highlightId)).resolves.toEqual(expect.anything());
- });
-
- it('triggers an alert when dismiss request fails', async () => {
- mockAxios
- .onPost(endpoint, { feature_name: highlightId })
- .replyOnce(HTTP_STATUS_INTERNAL_SERVER_ERROR);
-
- await dismiss(endpoint, highlightId);
-
- expect(createAlert).toHaveBeenCalledWith({
- message:
- 'An error occurred while dismissing the feature highlight. Refresh the page and try dismissing again.',
- });
- });
- });
-});
diff --git a/spec/frontend/feature_highlight/feature_highlight_popover_spec.js b/spec/frontend/feature_highlight/feature_highlight_popover_spec.js
deleted file mode 100644
index 66ea22cece3..00000000000
--- a/spec/frontend/feature_highlight/feature_highlight_popover_spec.js
+++ /dev/null
@@ -1,75 +0,0 @@
-import { GlPopover, GlLink, GlButton } from '@gitlab/ui';
-import { mount } from '@vue/test-utils';
-import { nextTick } from 'vue';
-import { POPOVER_TARGET_ID } from '~/feature_highlight/constants';
-import { dismiss } from '~/feature_highlight/feature_highlight_helper';
-import FeatureHighlightPopover from '~/feature_highlight/feature_highlight_popover.vue';
-
-jest.mock('~/feature_highlight/feature_highlight_helper');
-
-describe('feature_highlight/feature_highlight_popover', () => {
- let wrapper;
- const props = {
- autoDevopsHelpPath: '/help/autodevops',
- highlightId: '123',
- dismissEndpoint: '/api/dismiss',
- };
-
- const buildWrapper = (propsData = props) => {
- wrapper = mount(FeatureHighlightPopover, {
- propsData,
- });
- };
- const findPopoverTarget = () => wrapper.find(`#${POPOVER_TARGET_ID}`);
- const findPopover = () => wrapper.findComponent(GlPopover);
- const findAutoDevopsHelpLink = () => wrapper.findComponent(GlLink);
- const findDismissButton = () => wrapper.findComponent(GlButton);
-
- beforeEach(() => {
- buildWrapper();
- });
-
- it('renders popover target', () => {
- expect(findPopoverTarget().exists()).toBe(true);
- });
-
- it('renders popover', () => {
- expect(findPopover().props()).toMatchObject({
- target: POPOVER_TARGET_ID,
- cssClasses: ['feature-highlight-popover'],
- container: 'body',
- placement: 'right',
- boundary: 'viewport',
- });
- });
-
- it('renders link that points to the autodevops help page', () => {
- expect(findAutoDevopsHelpLink().attributes().href).toBe(props.autoDevopsHelpPath);
- expect(findAutoDevopsHelpLink().text()).toBe('Auto DevOps');
- });
-
- it('renders dismiss button', () => {
- expect(findDismissButton().props()).toMatchObject({
- size: 'small',
- icon: 'thumb-up',
- variant: 'confirm',
- });
- });
-
- it('dismisses popover when dismiss button is clicked', async () => {
- await findDismissButton().trigger('click');
-
- expect(findPopover().emitted('close')).toHaveLength(1);
- expect(dismiss).toHaveBeenCalledWith(props.dismissEndpoint, props.highlightId);
- });
-
- describe('when popover is dismissed and hidden', () => {
- it('hides the popover target', async () => {
- await findDismissButton().trigger('click');
- findPopover().vm.$emit('hidden');
- await nextTick();
-
- expect(findPopoverTarget().exists()).toBe(false);
- });
- });
-});
diff --git a/spec/frontend/vue_merge_request_widget/components/states/mr_widget_ready_to_merge_spec.js b/spec/frontend/vue_merge_request_widget/components/states/mr_widget_ready_to_merge_spec.js
index dbfd3cec76c..1b7338744e8 100644
--- a/spec/frontend/vue_merge_request_widget/components/states/mr_widget_ready_to_merge_spec.js
+++ b/spec/frontend/vue_merge_request_widget/components/states/mr_widget_ready_to_merge_spec.js
@@ -1,9 +1,10 @@
-import { shallowMount } from '@vue/test-utils';
import Vue, { nextTick } from 'vue';
import { GlSprintf } from '@gitlab/ui';
import VueApollo from 'vue-apollo';
import produce from 'immer';
+import { createMockSubscription as createMockApolloSubscription } from 'mock-apollo-client';
import readyToMergeResponse from 'test_fixtures/graphql/merge_requests/states/ready_to_merge.query.graphql.json';
+import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import waitForPromises from 'helpers/wait_for_promises';
import createMockApollo from 'helpers/mock_apollo_helper';
import readyToMergeQuery from 'ee_else_ce/vue_merge_request_widget/queries/states/ready_to_merge.query.graphql';
@@ -15,6 +16,7 @@ import SquashBeforeMerge from '~/vue_merge_request_widget/components/states/squa
import MergeFailedPipelineConfirmationDialog from '~/vue_merge_request_widget/components/states/merge_failed_pipeline_confirmation_dialog.vue';
import { MWPS_MERGE_STRATEGY } from '~/vue_merge_request_widget/constants';
import eventHub from '~/vue_merge_request_widget/event_hub';
+import readyToMergeSubscription from '~/vue_merge_request_widget/queries/states/ready_to_merge.subscription.graphql';
jest.mock('~/lib/utils/simple_poll', () =>
jest.fn().mockImplementation(jest.requireActual('~/lib/utils/simple_poll').default),
@@ -79,6 +81,7 @@ Vue.use(VueApollo);
let service;
let wrapper;
let readyToMergeResponseSpy;
+let mockedSubscription;
const createReadyToMergeResponse = (customMr) => {
return produce(readyToMergeResponse, (draft) => {
@@ -87,7 +90,21 @@ const createReadyToMergeResponse = (customMr) => {
};
const createComponent = (customConfig = {}, createState = true) => {
- wrapper = shallowMount(ReadyToMerge, {
+ mockedSubscription = createMockApolloSubscription();
+ const apolloProvider = createMockApollo([[readyToMergeQuery, readyToMergeResponseSpy]]);
+ const subscriptionResponse = {
+ data: { mergeRequestMergeStatusUpdated: { ...readyToMergeResponse.data.project.mergeRequest } },
+ };
+ subscriptionResponse.data.mergeRequestMergeStatusUpdated.defaultMergeCommitMessage =
+ 'New default merge commit message';
+
+ const subscriptionHandlers = [[readyToMergeSubscription, () => mockedSubscription]];
+
+ subscriptionHandlers.forEach(([query, stream]) => {
+ apolloProvider.defaultClient.setRequestHandler(query, stream);
+ });
+
+ wrapper = shallowMountExtended(ReadyToMerge, {
propsData: {
mr: createTestMr(customConfig),
service,
@@ -109,7 +126,7 @@ const createComponent = (customConfig = {}, createState = true) => {
CommitEdit,
GlSprintf,
},
- apolloProvider: createMockApollo([[readyToMergeQuery, readyToMergeResponseSpy]]),
+ apolloProvider,
});
};
@@ -840,4 +857,60 @@ describe('ReadyToMerge', () => {
expect(wrapper.text()).not.toContain('Auto-merge enabled');
});
});
+
+ describe('commit message', () => {
+ it('updates commit message from subscription', async () => {
+ createComponent({ mr: { id: 1 } });
+
+ await waitForPromises();
+
+ await wrapper.findByTestId('widget_edit_commit_message').vm.$emit('input', true);
+
+ expect(wrapper.findByTestId('merge-commit-message').props('value')).not.toEqual(
+ 'Updated commit message',
+ );
+
+ mockedSubscription.next({
+ data: {
+ mergeRequestMergeStatusUpdated: {
+ ...readyToMergeResponse.data.project.mergeRequest,
+ defaultMergeCommitMessage: 'Updated commit message',
+ },
+ },
+ });
+
+ await waitForPromises();
+
+ expect(wrapper.findByTestId('merge-commit-message').props('value')).toEqual(
+ 'Updated commit message',
+ );
+ });
+
+ it('does not update commit message from subscription if commit message has been manually changed', async () => {
+ createComponent({ mr: { id: 1 } });
+
+ await waitForPromises();
+
+ await wrapper.findByTestId('widget_edit_commit_message').vm.$emit('input', true);
+
+ await wrapper
+ .findByTestId('merge-commit-message')
+ .vm.$emit('input', 'Manually updated commit message');
+
+ mockedSubscription.next({
+ data: {
+ mergeRequestMergeStatusUpdated: {
+ ...readyToMergeResponse.data.project.mergeRequest,
+ defaultMergeCommitMessage: 'Updated commit message',
+ },
+ },
+ });
+
+ await waitForPromises();
+
+ expect(wrapper.findByTestId('merge-commit-message').props('value')).toEqual(
+ 'Manually updated commit message',
+ );
+ });
+ });
});