Commit 79b2ffc3 authored by David O'Regan's avatar David O'Regan Committed by Olena Horal-Koretska

Add support for HTTP Create

Add support for alert HTTP
create supported via GraphQL
parent d14f9d9f
...@@ -58,6 +58,11 @@ export default { ...@@ -58,6 +58,11 @@ export default {
required: false, required: false,
default: false, default: false,
}, },
currentIntegration: {
type: Object,
required: false,
default: null,
},
}, },
fields: [ fields: [
{ {
...@@ -82,17 +87,16 @@ export default { ...@@ -82,17 +87,16 @@ export default {
integrationToDelete: integrationToDeleteDefault, integrationToDelete: integrationToDeleteDefault,
}; };
}, },
computed: {
tbodyTrClass() {
return {
[bodyTrClass]: this.integrations.length,
};
},
},
mounted() { mounted() {
this.trackPageViews(); this.trackPageViews();
}, },
methods: { methods: {
tbodyTrClass(item) {
return {
[bodyTrClass]: this.integrations.length,
'gl-bg-blue-50': item?.id === this.currentIntegration?.id,
};
},
trackPageViews() { trackPageViews() {
const { category, action } = trackAlertIntegrationsViewsOptions; const { category, action } = trackAlertIntegrationsViewsOptions;
Tracking.event(category, action); Tracking.event(category, action);
......
...@@ -23,6 +23,7 @@ import { ...@@ -23,6 +23,7 @@ import {
DELETE_INTEGRATION_ERROR, DELETE_INTEGRATION_ERROR,
ADD_INTEGRATION_ERROR, ADD_INTEGRATION_ERROR,
RESET_INTEGRATION_TOKEN_ERROR, RESET_INTEGRATION_TOKEN_ERROR,
UPDATE_INTEGRATION_ERROR,
} from '../utils/error_messages'; } from '../utils/error_messages';
export default { export default {
...@@ -162,8 +163,8 @@ export default { ...@@ -162,8 +163,8 @@ export default {
type: FLASH_TYPES.SUCCESS, type: FLASH_TYPES.SUCCESS,
}); });
}) })
.catch(err => { .catch(() => {
createFlash({ message: err }); createFlash({ message: UPDATE_INTEGRATION_ERROR });
}) })
.finally(() => { .finally(() => {
this.isUpdating = false; this.isUpdating = false;
...@@ -234,7 +235,6 @@ export default { ...@@ -234,7 +235,6 @@ export default {
}); });
}) })
.catch(() => { .catch(() => {
this.errored = true;
createFlash({ message: DELETE_INTEGRATION_ERROR }); createFlash({ message: DELETE_INTEGRATION_ERROR });
}) })
.finally(() => { .finally(() => {
...@@ -253,6 +253,7 @@ export default { ...@@ -253,6 +253,7 @@ export default {
<integrations-list <integrations-list
:integrations="glFeatures.httpIntegrationsList ? integrations.list : intergrationsOptionsOld" :integrations="glFeatures.httpIntegrationsList ? integrations.list : intergrationsOptionsOld"
:loading="loading" :loading="loading"
:current-integration="currentIntegration"
@edit-integration="editIntegration" @edit-integration="editIntegration"
@delete-integration="deleteIntegration" @delete-integration="deleteIntegration"
/> />
......
...@@ -57,15 +57,6 @@ export const typeSet = { ...@@ -57,15 +57,6 @@ export const typeSet = {
prometheus: 'PROMETHEUS', prometheus: 'PROMETHEUS',
}; };
export const defaultFormState = {
name: '',
active: false,
token: '',
url: '',
apiUrl: '',
integrationTestPayload: { json: null, error: null },
};
export const integrationToDeleteDefault = { id: null, name: '' }; export const integrationToDeleteDefault = { id: null, name: '' };
export const JSON_VALIDATE_DELAY = 250; export const JSON_VALIDATE_DELAY = 250;
......
...@@ -8,6 +8,10 @@ export const ADD_INTEGRATION_ERROR = s__( ...@@ -8,6 +8,10 @@ export const ADD_INTEGRATION_ERROR = s__(
'AlertsIntegrations|The integration could not be added. Please try again.', 'AlertsIntegrations|The integration could not be added. Please try again.',
); );
export const UPDATE_INTEGRATION_ERROR = s__(
'AlertsIntegrations|The current integration could not be updated. Please try again.',
);
export const RESET_INTEGRATION_TOKEN_ERROR = s__( export const RESET_INTEGRATION_TOKEN_ERROR = s__(
'AlertsIntegrations|The integration token could not be reset. Please try again.', 'AlertsIntegrations|The integration token could not be reset. Please try again.',
); );
...@@ -2671,6 +2671,9 @@ msgstr "" ...@@ -2671,6 +2671,9 @@ msgstr ""
msgid "AlertsIntegrations|Prometheus" msgid "AlertsIntegrations|Prometheus"
msgstr "" msgstr ""
msgid "AlertsIntegrations|The current integration could not be updated. Please try again."
msgstr ""
msgid "AlertsIntegrations|The integration could not be added. Please try again." msgid "AlertsIntegrations|The integration could not be added. Please try again."
msgstr "" msgstr ""
......
import { GlTable, GlIcon } from '@gitlab/ui'; import { GlTable, GlIcon, GlButton } from '@gitlab/ui';
import { mount } from '@vue/test-utils'; import { mount } from '@vue/test-utils';
import Tracking from '~/tracking'; import Tracking from '~/tracking';
import AlertIntegrationsList, { import AlertIntegrationsList, {
...@@ -8,11 +8,13 @@ import { trackAlertIntegrationsViewsOptions } from '~/alerts_settings/constants' ...@@ -8,11 +8,13 @@ import { trackAlertIntegrationsViewsOptions } from '~/alerts_settings/constants'
const mockIntegrations = [ const mockIntegrations = [
{ {
id: '1',
active: true, active: true,
name: 'Integration 1', name: 'Integration 1',
type: 'HTTP endpoint', type: 'HTTP endpoint',
}, },
{ {
id: '2',
active: false, active: false,
name: 'Integration 2', name: 'Integration 2',
type: 'HTTP endpoint', type: 'HTTP endpoint',
...@@ -30,6 +32,7 @@ describe('AlertIntegrationsList', () => { ...@@ -30,6 +32,7 @@ describe('AlertIntegrationsList', () => {
}, },
stubs: { stubs: {
GlIcon: true, GlIcon: true,
GlButton: true,
}, },
}); });
} }
...@@ -46,6 +49,7 @@ describe('AlertIntegrationsList', () => { ...@@ -46,6 +49,7 @@ describe('AlertIntegrationsList', () => {
}); });
const findTableComponent = () => wrapper.find(GlTable); const findTableComponent = () => wrapper.find(GlTable);
const findTableComponentRows = () => wrapper.find(GlTable).findAll('table tbody tr');
const finsStatusCell = () => wrapper.findAll('[data-testid="integration-activated-status"]'); const finsStatusCell = () => wrapper.findAll('[data-testid="integration-activated-status"]');
it('renders a table', () => { it('renders a table', () => {
...@@ -57,6 +61,19 @@ describe('AlertIntegrationsList', () => { ...@@ -57,6 +61,19 @@ describe('AlertIntegrationsList', () => {
expect(findTableComponent().text()).toContain(i18n.emptyState); expect(findTableComponent().text()).toContain(i18n.emptyState);
}); });
it('renders an an edit and delete button for each integration', () => {
expect(findTableComponent().findAll(GlButton).length).toBe(4);
});
it('renders an highlighted row when a current integration is selected to edit', () => {
mountComponent({ currentIntegration: { id: '1' } });
expect(
findTableComponentRows()
.at(0)
.classes(),
).toContain('gl-bg-blue-50');
});
describe('integration status', () => { describe('integration status', () => {
it('enabled', () => { it('enabled', () => {
const cell = finsStatusCell().at(0); const cell = finsStatusCell().at(0);
......
...@@ -19,6 +19,7 @@ import { typeSet } from '~/alerts_settings/constants'; ...@@ -19,6 +19,7 @@ import { typeSet } from '~/alerts_settings/constants';
import { import {
ADD_INTEGRATION_ERROR, ADD_INTEGRATION_ERROR,
RESET_INTEGRATION_TOKEN_ERROR, RESET_INTEGRATION_TOKEN_ERROR,
UPDATE_INTEGRATION_ERROR,
} from '~/alerts_settings/utils/error_messages'; } from '~/alerts_settings/utils/error_messages';
import createFlash from '~/flash'; import createFlash from '~/flash';
import { defaultAlertSettingsConfig } from './util'; import { defaultAlertSettingsConfig } from './util';
...@@ -148,16 +149,6 @@ describe('AlertsSettingsWrapper', () => { ...@@ -148,16 +149,6 @@ describe('AlertsSettingsWrapper', () => {
expect(findIntegrations()).toHaveLength(mockIntegrations.length); expect(findIntegrations()).toHaveLength(mockIntegrations.length);
}); });
it('shows an error message when a user cannot create a new integration', () => {
createComponent({
data: { integrations: { list: mockIntegrations } },
provide: { glFeatures: { httpIntegrationsList: true } },
loading: false,
});
expect(findLoader().exists()).toBe(false);
expect(findIntegrations()).toHaveLength(mockIntegrations.length);
});
it('calls `$apollo.mutate` with `createHttpIntegrationMutation`', () => { it('calls `$apollo.mutate` with `createHttpIntegrationMutation`', () => {
createComponent({ createComponent({
data: { integrations: { list: mockIntegrations }, currentIntegration: mockIntegrations[0] }, data: { integrations: { list: mockIntegrations }, currentIntegration: mockIntegrations[0] },
...@@ -292,7 +283,7 @@ describe('AlertsSettingsWrapper', () => { ...@@ -292,7 +283,7 @@ describe('AlertsSettingsWrapper', () => {
}); });
}); });
it('shows error alert when integration creation fails ', async () => { it('shows an error alert when integration creation fails ', async () => {
createComponent({ createComponent({
data: { integrations: { list: mockIntegrations }, currentIntegration: mockIntegrations[0] }, data: { integrations: { list: mockIntegrations }, currentIntegration: mockIntegrations[0] },
provide: { glFeatures: { httpIntegrationsList: true } }, provide: { glFeatures: { httpIntegrationsList: true } },
...@@ -307,7 +298,7 @@ describe('AlertsSettingsWrapper', () => { ...@@ -307,7 +298,7 @@ describe('AlertsSettingsWrapper', () => {
expect(createFlash).toHaveBeenCalledWith({ message: ADD_INTEGRATION_ERROR }); expect(createFlash).toHaveBeenCalledWith({ message: ADD_INTEGRATION_ERROR });
}); });
it('shows error alert when integration token reset fails ', async () => { it('shows an error alert when integration token reset fails ', async () => {
createComponent({ createComponent({
data: { integrations: { list: mockIntegrations }, currentIntegration: mockIntegrations[0] }, data: { integrations: { list: mockIntegrations }, currentIntegration: mockIntegrations[0] },
provide: { glFeatures: { httpIntegrationsList: true } }, provide: { glFeatures: { httpIntegrationsList: true } },
...@@ -322,7 +313,7 @@ describe('AlertsSettingsWrapper', () => { ...@@ -322,7 +313,7 @@ describe('AlertsSettingsWrapper', () => {
expect(createFlash).toHaveBeenCalledWith({ message: RESET_INTEGRATION_TOKEN_ERROR }); expect(createFlash).toHaveBeenCalledWith({ message: RESET_INTEGRATION_TOKEN_ERROR });
}); });
it('shows error alert when integration update fails ', async () => { it('shows an error alert when integration update fails ', async () => {
createComponent({ createComponent({
data: { integrations: { list: mockIntegrations }, currentIntegration: mockIntegrations[0] }, data: { integrations: { list: mockIntegrations }, currentIntegration: mockIntegrations[0] },
provide: { glFeatures: { httpIntegrationsList: true } }, provide: { glFeatures: { httpIntegrationsList: true } },
...@@ -334,7 +325,7 @@ describe('AlertsSettingsWrapper', () => { ...@@ -334,7 +325,7 @@ describe('AlertsSettingsWrapper', () => {
wrapper.find(AlertsSettingsFormNew).vm.$emit('update-integration', {}); wrapper.find(AlertsSettingsFormNew).vm.$emit('update-integration', {});
await waitForPromises(); await waitForPromises();
expect(createFlash).toHaveBeenCalledWith({ message: errorMsg }); expect(createFlash).toHaveBeenCalledWith({ message: UPDATE_INTEGRATION_ERROR });
}); });
}); });
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment