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/alerts_settings')
-rw-r--r--spec/frontend/alerts_settings/components/alerts_settings_form_spec.js3
-rw-r--r--spec/frontend/alerts_settings/components/alerts_settings_wrapper_spec.js141
-rw-r--r--spec/frontend/alerts_settings/components/util.js24
-rw-r--r--spec/frontend/alerts_settings/utils/mapping_transformations_spec.js35
4 files changed, 118 insertions, 85 deletions
diff --git a/spec/frontend/alerts_settings/components/alerts_settings_form_spec.js b/spec/frontend/alerts_settings/components/alerts_settings_form_spec.js
index 9912ac433a5..298596085ef 100644
--- a/spec/frontend/alerts_settings/components/alerts_settings_form_spec.js
+++ b/spec/frontend/alerts_settings/components/alerts_settings_form_spec.js
@@ -8,7 +8,6 @@ import AlertsSettingsForm from '~/alerts_settings/components/alerts_settings_for
import { typeSet } from '~/alerts_settings/constants';
import alertFields from '../mocks/alert_fields.json';
import parsedMapping from '../mocks/parsed_mapping.json';
-import { defaultAlertSettingsConfig } from './util';
const scrollIntoViewMock = jest.fn();
HTMLElement.prototype.scrollIntoView = scrollIntoViewMock;
@@ -29,7 +28,6 @@ describe('AlertsSettingsForm', () => {
...props,
},
provide: {
- ...defaultAlertSettingsConfig,
multiIntegrations,
},
mocks: {
@@ -50,7 +48,6 @@ describe('AlertsSettingsForm', () => {
const findFormToggle = () => wrapper.findComponent(GlToggle);
const findSamplePayloadSection = () => wrapper.findByTestId('sample-payload-section');
const findMappingBuilder = () => wrapper.findComponent(MappingBuilder);
-
const findSubmitButton = () => wrapper.findByTestId('integration-form-submit');
const findMultiSupportText = () => wrapper.findByTestId('multi-integrations-not-supported');
const findJsonTestSubmit = () => wrapper.findByTestId('send-test-alert');
diff --git a/spec/frontend/alerts_settings/components/alerts_settings_wrapper_spec.js b/spec/frontend/alerts_settings/components/alerts_settings_wrapper_spec.js
index dd8ce838dfd..595c3f1a289 100644
--- a/spec/frontend/alerts_settings/components/alerts_settings_wrapper_spec.js
+++ b/spec/frontend/alerts_settings/components/alerts_settings_wrapper_spec.js
@@ -20,6 +20,7 @@ import resetPrometheusTokenMutation from '~/alerts_settings/graphql/mutations/re
import updateCurrentHttpIntegrationMutation from '~/alerts_settings/graphql/mutations/update_current_http_integration.mutation.graphql';
import updateCurrentPrometheusIntegrationMutation from '~/alerts_settings/graphql/mutations/update_current_prometheus_integration.mutation.graphql';
import updatePrometheusIntegrationMutation from '~/alerts_settings/graphql/mutations/update_prometheus_integration.mutation.graphql';
+import getHttpIntegrationQuery from '~/alerts_settings/graphql/queries/get_http_integration.query.graphql';
import getIntegrationsQuery from '~/alerts_settings/graphql/queries/get_integrations.query.graphql';
import alertsUpdateService from '~/alerts_settings/services';
import {
@@ -47,7 +48,6 @@ import {
destroyIntegrationResponseWithErrors,
} from './mocks/apollo_mock';
import mockIntegrations from './mocks/integrations.json';
-import { defaultAlertSettingsConfig } from './util';
jest.mock('~/flash');
@@ -58,27 +58,12 @@ describe('AlertsSettingsWrapper', () => {
let fakeApollo;
let destroyIntegrationHandler;
useMockIntersectionObserver();
+
const httpMappingData = {
payloadExample: '{"test: : "field"}',
payloadAttributeMappings: [],
payloadAlertFields: [],
};
- const httpIntegrations = {
- list: [
- {
- id: mockIntegrations[0].id,
- ...httpMappingData,
- },
- {
- id: mockIntegrations[1].id,
- ...httpMappingData,
- },
- {
- id: mockIntegrations[2].id,
- httpMappingData,
- },
- ],
- };
const findLoader = () => wrapper.findComponent(IntegrationsList).findComponent(GlLoadingIcon);
const findIntegrationsList = () => wrapper.findComponent(IntegrationsList);
@@ -109,13 +94,14 @@ describe('AlertsSettingsWrapper', () => {
return { ...data };
},
provide: {
- ...defaultAlertSettingsConfig,
...provide,
},
mocks: {
$apollo: {
mutate: jest.fn(),
- query: jest.fn(),
+ addSmartQuery: jest.fn((_, options) => {
+ options.result.call(wrapper.vm);
+ }),
queries: {
integrations: {
loading,
@@ -143,9 +129,6 @@ describe('AlertsSettingsWrapper', () => {
wrapper = mount(AlertsSettingsWrapper, {
localVue,
apolloProvider: fakeApollo,
- provide: {
- ...defaultAlertSettingsConfig,
- },
});
}
@@ -158,17 +141,29 @@ describe('AlertsSettingsWrapper', () => {
beforeEach(() => {
createComponent({
data: {
- integrations: { list: mockIntegrations },
- httpIntegrations: { list: [] },
+ integrations: mockIntegrations,
currentIntegration: mockIntegrations[0],
},
loading: false,
});
});
- it('renders alerts integrations list and add new integration button by default', () => {
+ it('renders alerts integrations list', () => {
expect(findLoader().exists()).toBe(false);
expect(findIntegrations()).toHaveLength(mockIntegrations.length);
+ });
+
+ it('renders `Add new integration` button when multiple integrations are supported ', () => {
+ createComponent({
+ data: {
+ integrations: mockIntegrations,
+ currentIntegration: mockIntegrations[0],
+ },
+ provide: {
+ multiIntegrations: true,
+ },
+ loading: false,
+ });
expect(findAddIntegrationBtn().exists()).toBe(true);
});
@@ -177,6 +172,16 @@ describe('AlertsSettingsWrapper', () => {
});
it('hides `add new integration` button and displays setting form on btn click', async () => {
+ createComponent({
+ data: {
+ integrations: mockIntegrations,
+ currentIntegration: mockIntegrations[0],
+ },
+ provide: {
+ multiIntegrations: true,
+ },
+ loading: false,
+ });
const addNewIntegrationBtn = findAddIntegrationBtn();
expect(addNewIntegrationBtn.exists()).toBe(true);
await addNewIntegrationBtn.trigger('click');
@@ -186,7 +191,7 @@ describe('AlertsSettingsWrapper', () => {
it('shows loading indicator inside the IntegrationsList table', () => {
createComponent({
- data: { integrations: {} },
+ data: { integrations: [] },
loading: true,
});
expect(wrapper.find(IntegrationsList).exists()).toBe(true);
@@ -198,7 +203,7 @@ describe('AlertsSettingsWrapper', () => {
beforeEach(() => {
createComponent({
data: {
- integrations: { list: mockIntegrations },
+ integrations: mockIntegrations,
currentIntegration: mockIntegrations[0],
formVisible: true,
},
@@ -283,7 +288,7 @@ describe('AlertsSettingsWrapper', () => {
it('calls `$apollo.mutate` with `updatePrometheusIntegrationMutation`', () => {
createComponent({
data: {
- integrations: { list: mockIntegrations },
+ integrations: mockIntegrations,
currentIntegration: mockIntegrations[3],
formVisible: true,
},
@@ -374,39 +379,61 @@ describe('AlertsSettingsWrapper', () => {
});
});
- it('calls `$apollo.mutate` with `updateCurrentHttpIntegrationMutation` on HTTP integration edit', () => {
- createComponent({
- data: {
- integrations: { list: mockIntegrations },
- currentIntegration: mockIntegrations[0],
- httpIntegrations,
- },
- loading: false,
- });
+ describe('Edit integration', () => {
+ describe('HTTP', () => {
+ beforeEach(() => {
+ createComponent({
+ data: {
+ integrations: mockIntegrations,
+ currentIntegration: mockIntegrations[0],
+ currentHttpIntegration: { id: mockIntegrations[0].id, ...httpMappingData },
+ },
+ provide: {
+ multiIntegrations: true,
+ },
+ loading: false,
+ });
+ jest.spyOn(wrapper.vm.$apollo, 'mutate').mockResolvedValueOnce({});
+ findIntegrationsList().vm.$emit('edit-integration', updateHttpVariables);
+ });
- jest.spyOn(wrapper.vm.$apollo, 'mutate').mockResolvedValueOnce({});
- findIntegrationsList().vm.$emit('edit-integration', updateHttpVariables);
- expect(wrapper.vm.$apollo.mutate).toHaveBeenCalledWith({
- mutation: updateCurrentHttpIntegrationMutation,
- variables: { ...mockIntegrations[0], ...httpMappingData },
- });
- });
+ it('requests `currentHttpIntegration`', () => {
+ expect(wrapper.vm.$apollo.addSmartQuery).toHaveBeenCalledWith(
+ 'currentHttpIntegration',
+ expect.objectContaining({
+ query: getHttpIntegrationQuery,
+ result: expect.any(Function),
+ update: expect.any(Function),
+ variables: expect.any(Function),
+ }),
+ );
+ });
- it('calls `$apollo.mutate` with `updateCurrentPrometheusIntegrationMutation` on PROMETHEUS integration edit', () => {
- createComponent({
- data: {
- integrations: { list: mockIntegrations },
- currentIntegration: mockIntegrations[3],
- httpIntegrations,
- },
- loading: false,
+ it('calls `$apollo.mutate` with `updateCurrentHttpIntegrationMutation`', () => {
+ expect(wrapper.vm.$apollo.mutate).toHaveBeenCalledWith({
+ mutation: updateCurrentHttpIntegrationMutation,
+ variables: { ...mockIntegrations[0], ...httpMappingData },
+ });
+ });
});
- jest.spyOn(wrapper.vm.$apollo, 'mutate').mockResolvedValue();
- findIntegrationsList().vm.$emit('edit-integration', updatePrometheusVariables);
- expect(wrapper.vm.$apollo.mutate).toHaveBeenCalledWith({
- mutation: updateCurrentPrometheusIntegrationMutation,
- variables: mockIntegrations[3],
+ describe('Prometheus', () => {
+ it('calls `$apollo.mutate` with `updateCurrentPrometheusIntegrationMutation`', () => {
+ createComponent({
+ data: {
+ integrations: mockIntegrations,
+ currentIntegration: mockIntegrations[3],
+ },
+ loading: false,
+ });
+
+ jest.spyOn(wrapper.vm.$apollo, 'mutate').mockResolvedValue();
+ findIntegrationsList().vm.$emit('edit-integration', updatePrometheusVariables);
+ expect(wrapper.vm.$apollo.mutate).toHaveBeenCalledWith({
+ mutation: updateCurrentPrometheusIntegrationMutation,
+ variables: mockIntegrations[3],
+ });
+ });
});
});
diff --git a/spec/frontend/alerts_settings/components/util.js b/spec/frontend/alerts_settings/components/util.js
deleted file mode 100644
index 5c07f22f1c9..00000000000
--- a/spec/frontend/alerts_settings/components/util.js
+++ /dev/null
@@ -1,24 +0,0 @@
-const PROMETHEUS_URL = '/prometheus/alerts/notify.json';
-const GENERIC_URL = '/alerts/notify.json';
-const KEY = 'abcedfg123';
-const INVALID_URL = 'http://invalid';
-const ACTIVE = false;
-
-export const defaultAlertSettingsConfig = {
- generic: {
- authorizationKey: KEY,
- formPath: INVALID_URL,
- url: GENERIC_URL,
- alertsSetupUrl: INVALID_URL,
- alertsUsageUrl: INVALID_URL,
- active: ACTIVE,
- },
- prometheus: {
- authorizationKey: KEY,
- prometheusFormPath: INVALID_URL,
- url: PROMETHEUS_URL,
- active: ACTIVE,
- },
- projectPath: '',
- multiIntegrations: true,
-};
diff --git a/spec/frontend/alerts_settings/utils/mapping_transformations_spec.js b/spec/frontend/alerts_settings/utils/mapping_transformations_spec.js
index 62b95c6078b..8a0800457c6 100644
--- a/spec/frontend/alerts_settings/utils/mapping_transformations_spec.js
+++ b/spec/frontend/alerts_settings/utils/mapping_transformations_spec.js
@@ -1,4 +1,8 @@
-import { getMappingData, transformForSave } from '~/alerts_settings/utils/mapping_transformations';
+import {
+ getMappingData,
+ setFieldsLabels,
+ transformForSave,
+} from '~/alerts_settings/utils/mapping_transformations';
import alertFields from '../mocks/alert_fields.json';
import parsedMapping from '../mocks/parsed_mapping.json';
@@ -64,4 +68,33 @@ describe('Mapping Transformation Utilities', () => {
expect(result).toEqual([]);
});
});
+
+ describe('setFieldsLabels', () => {
+ const nonNestedFields = [{ label: 'title' }];
+ const nonNestedFieldsResult = { displayLabel: 'Title', tooltip: undefined };
+
+ const nestedFields = [
+ {
+ label: 'field/subfield',
+ },
+ ];
+ const nestedFieldsResult = { displayLabel: '...Subfield', tooltip: 'field.subfield' };
+
+ const nestedArrayFields = [
+ {
+ label: 'fields[1]/subfield',
+ },
+ ];
+
+ const nestedArrayFieldsResult = { displayLabel: '...Subfield', tooltip: 'fields[1].subfield' };
+
+ it.each`
+ type | fields | result
+ ${'not nested field'} | ${nonNestedFields} | ${nonNestedFieldsResult}
+ ${'nested field'} | ${nestedFields} | ${nestedFieldsResult}
+ ${'nested inside array'} | ${nestedArrayFields} | ${nestedArrayFieldsResult}
+ `('adds correct displayLabel and tooltip for $type', ({ fields, result }) => {
+ expect(setFieldsLabels(fields)[0]).toMatchObject(result);
+ });
+ });
});