diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-09-16 00:11:12 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-09-16 00:11:12 +0300 |
commit | a7aff3e0e4deb15c0902e0f948eb300ba77f3e47 (patch) | |
tree | c294fb9c39d5619fb3cac6f4a8d520deb8403dca /spec/frontend/error_tracking_settings | |
parent | 27d1ed4ddff6c2649544a968c2842140272d9c9d (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/error_tracking_settings')
5 files changed, 88 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); + }, + ); + }); }); diff --git a/spec/frontend/error_tracking_settings/mock.js b/spec/frontend/error_tracking_settings/mock.js index e64a6d1fe14..b2d7a912518 100644 --- a/spec/frontend/error_tracking_settings/mock.js +++ b/spec/frontend/error_tracking_settings/mock.js @@ -42,6 +42,7 @@ export const sampleBackendProject = { export const sampleFrontendSettings = { apiHost: 'apiHost', enabled: false, + integrated: false, token: 'token', selectedProject: { slug: normalizedProject.slug, @@ -54,6 +55,7 @@ export const sampleFrontendSettings = { export const transformedSettings = { api_host: 'apiHost', enabled: false, + integrated: false, token: 'token', project: { slug: normalizedProject.slug, @@ -71,6 +73,7 @@ export const defaultProps = { export const initialEmptyState = { apiHost: '', enabled: false, + integrated: false, project: null, token: '', listProjectsEndpoint: TEST_HOST, @@ -80,6 +83,7 @@ export const initialEmptyState = { export const initialPopulatedState = { apiHost: 'apiHost', enabled: true, + integrated: true, project: JSON.stringify(projectList[0]), token: 'token', listProjectsEndpoint: TEST_HOST, diff --git a/spec/frontend/error_tracking_settings/store/actions_spec.js b/spec/frontend/error_tracking_settings/store/actions_spec.js index 281db7d9686..1b9be042dd4 100644 --- a/spec/frontend/error_tracking_settings/store/actions_spec.js +++ b/spec/frontend/error_tracking_settings/store/actions_spec.js @@ -202,5 +202,11 @@ describe('error tracking settings actions', () => { done, ); }); + + it.each([true, false])('should set the `integrated` flag to `%s`', async (payload) => { + await testAction(actions.updateIntegrated, payload, state, [ + { type: types.UPDATE_INTEGRATED, payload }, + ]); + }); }); }); diff --git a/spec/frontend/error_tracking_settings/store/mutation_spec.js b/spec/frontend/error_tracking_settings/store/mutation_spec.js index 78fd56904b3..ecf1c91c08a 100644 --- a/spec/frontend/error_tracking_settings/store/mutation_spec.js +++ b/spec/frontend/error_tracking_settings/store/mutation_spec.js @@ -25,6 +25,7 @@ describe('error tracking settings mutations', () => { expect(state.apiHost).toEqual(''); expect(state.enabled).toEqual(false); + expect(state.integrated).toEqual(false); expect(state.selectedProject).toEqual(null); expect(state.token).toEqual(''); expect(state.listProjectsEndpoint).toEqual(TEST_HOST); @@ -38,6 +39,7 @@ describe('error tracking settings mutations', () => { expect(state.apiHost).toEqual('apiHost'); expect(state.enabled).toEqual(true); + expect(state.integrated).toEqual(true); expect(state.selectedProject).toEqual(projectList[0]); expect(state.token).toEqual('token'); expect(state.listProjectsEndpoint).toEqual(TEST_HOST); @@ -78,5 +80,11 @@ describe('error tracking settings mutations', () => { expect(state.connectSuccessful).toBe(false); expect(state.connectError).toBe(false); }); + + it.each([true, false])('should update `integrated` to `%s`', (integrated) => { + mutations[types.UPDATE_INTEGRATED](state, integrated); + + expect(state.integrated).toBe(integrated); + }); }); }); diff --git a/spec/frontend/error_tracking_settings/utils_spec.js b/spec/frontend/error_tracking_settings/utils_spec.js index 4b144f7daf1..61e75cdc45e 100644 --- a/spec/frontend/error_tracking_settings/utils_spec.js +++ b/spec/frontend/error_tracking_settings/utils_spec.js @@ -11,12 +11,14 @@ describe('error tracking settings utils', () => { const emptyFrontendSettingsObject = { apiHost: '', enabled: false, + integrated: false, token: '', selectedProject: null, }; const transformedEmptySettingsObject = { api_host: null, enabled: false, + integrated: false, token: null, project: null, }; |