diff options
Diffstat (limited to 'spec/frontend/alerts_settings/components/alerts_settings_wrapper_spec.js')
-rw-r--r-- | spec/frontend/alerts_settings/components/alerts_settings_wrapper_spec.js | 141 |
1 files changed, 84 insertions, 57 deletions
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], + }); + }); }); }); |