diff options
Diffstat (limited to 'spec/frontend/error_tracking_settings/components/app_spec.js')
-rw-r--r-- | spec/frontend/error_tracking_settings/components/app_spec.js | 80 |
1 files changed, 68 insertions, 12 deletions
diff --git a/spec/frontend/error_tracking_settings/components/app_spec.js b/spec/frontend/error_tracking_settings/components/app_spec.js index e0be81b3899..30541ba68a5 100644 --- a/spec/frontend/error_tracking_settings/components/app_spec.js +++ b/spec/frontend/error_tracking_settings/components/app_spec.js @@ -1,6 +1,9 @@ +import { GlFormRadioGroup, GlFormRadio } from '@gitlab/ui'; import { createLocalVue, shallowMount } from '@vue/test-utils'; +import { nextTick } from 'vue'; import Vuex from 'vuex'; import { TEST_HOST } from 'helpers/test_constants'; +import { extendedWrapper } from 'helpers/vue_test_utils_helper'; import ErrorTrackingSettings from '~/error_tracking_settings/components/app.vue'; import ErrorTrackingForm from '~/error_tracking_settings/components/error_tracking_form.vue'; import ProjectDropdown from '~/error_tracking_settings/components/project_dropdown.vue'; @@ -14,20 +17,31 @@ describe('error tracking settings app', () => { let wrapper; function mountComponent() { - wrapper = shallowMount(ErrorTrackingSettings, { - localVue, - store, // Override the imported store - propsData: { - initialEnabled: 'true', - initialApiHost: TEST_HOST, - initialToken: 'someToken', - initialProject: null, - listProjectsEndpoint: TEST_HOST, - operationsSettingsEndpoint: TEST_HOST, - }, - }); + wrapper = extendedWrapper( + shallowMount(ErrorTrackingSettings, { + localVue, + store, // Override the imported store + propsData: { + initialEnabled: 'true', + initialIntegrated: 'false', + initialApiHost: TEST_HOST, + initialToken: 'someToken', + initialProject: null, + listProjectsEndpoint: TEST_HOST, + operationsSettingsEndpoint: TEST_HOST, + }, + }), + ); } + const findBackendSettingsSection = () => wrapper.findByTestId('tracking-backend-settings'); + const findBackendSettingsRadioGroup = () => + findBackendSettingsSection().findComponent(GlFormRadioGroup); + const findBackendSettingsRadioButtons = () => + findBackendSettingsRadioGroup().findAllComponents(GlFormRadio); + const findElementWithText = (wrappers, text) => wrappers.filter((item) => item.text() === text); + const findSentrySettings = () => wrapper.findByTestId('sentry-setting-form'); + beforeEach(() => { store = createStore(); @@ -62,4 +76,46 @@ describe('error tracking settings app', () => { }); }); }); + + describe('tracking-backend settings', () => { + it('contains a form-group with the correct label', () => { + expect(findBackendSettingsSection().attributes('label')).toBe('Error tracking backend'); + }); + + it('contains a radio group', () => { + expect(findBackendSettingsRadioGroup().exists()).toBe(true); + }); + + it('contains the correct radio buttons', () => { + expect(findBackendSettingsRadioButtons()).toHaveLength(2); + + expect(findElementWithText(findBackendSettingsRadioButtons(), 'Sentry')).toHaveLength(1); + expect(findElementWithText(findBackendSettingsRadioButtons(), 'GitLab')).toHaveLength(1); + }); + + it('toggles the sentry-settings section when sentry is selected as a tracking-backend', async () => { + expect(findSentrySettings().exists()).toBe(true); + + // set the "integrated" setting to "true" + findBackendSettingsRadioGroup().vm.$emit('change', true); + + await nextTick(); + + expect(findSentrySettings().exists()).toBe(false); + }); + + it.each([true, false])( + 'calls the `updateIntegrated` action when the setting changes to `%s`', + (integrated) => { + jest.spyOn(store, 'dispatch').mockImplementation(); + + expect(store.dispatch).toHaveBeenCalledTimes(0); + + findBackendSettingsRadioGroup().vm.$emit('change', integrated); + + expect(store.dispatch).toHaveBeenCalledTimes(1); + expect(store.dispatch).toHaveBeenCalledWith('updateIntegrated', integrated); + }, + ); + }); }); |