From c74277d2fe6268f8a69bcfd49dbc998d223ff6f9 Mon Sep 17 00:00:00 2001 From: Artur Fedorov <afedorov@gitlab.com> Date: Wed, 27 Jul 2022 18:16:06 +0200 Subject: [PATCH] Applied review changes --- .../dast_profiles_configurator.vue | 22 +++++--------- .../dast_profiles_configurator_spec.js | 29 ++++--------------- 2 files changed, 14 insertions(+), 37 deletions(-) diff --git a/ee/app/assets/javascripts/security_configuration/dast_profiles/dast_profiles_configurator/dast_profiles_configurator.vue b/ee/app/assets/javascripts/security_configuration/dast_profiles/dast_profiles_configurator/dast_profiles_configurator.vue index b161ae0e31a6..3bac20f105ea 100644 --- a/ee/app/assets/javascripts/security_configuration/dast_profiles/dast_profiles_configurator/dast_profiles_configurator.vue +++ b/ee/app/assets/javascripts/security_configuration/dast_profiles/dast_profiles_configurator/dast_profiles_configurator.vue @@ -23,7 +23,7 @@ import { SITE_PROFILES_QUERY, } from 'ee/on_demand_scans_form/settings'; -const createProfilesApolloOptions = (name, field, { fetchQuery, fetchError }) => ({ +const createProfilesApolloOptions = (name, field, savedField, { fetchQuery, fetchError }) => ({ query: fetchQuery, variables() { return { @@ -35,6 +35,11 @@ const createProfilesApolloOptions = (name, field, { fetchQuery, fetchError }) => if (nodes.length === 1) { this[field] = nodes[0].id; } + + if (this[savedField] && nodes.length > 1) { + this[field] = this.findSavedProfileId(nodes, this[savedField]); + } + return nodes; }, error(e) { @@ -68,11 +73,13 @@ export default { scannerProfiles: createProfilesApolloOptions( 'scannerProfiles', 'selectedScannerProfileId', + 'savedScannerProfileName', SCANNER_PROFILES_QUERY, ), siteProfiles: createProfilesApolloOptions( 'siteProfiles', 'selectedSiteProfileId', + 'savedSiteProfileName', SITE_PROFILES_QUERY, ), }, @@ -175,19 +182,6 @@ export default { watch: { selectedScannerProfile: 'updateProfiles', selectedSiteProfile: 'updateProfiles', - scannerProfiles(profiles) { - if (this.savedScannerProfileName) { - this.selectedScannerProfileId = this.findSavedProfileId( - profiles, - this.savedScannerProfileName, - ); - } - }, - siteProfiles(profiles) { - if (this.savedSiteProfileName) { - this.selectedSiteProfileId = this.findSavedProfileId(profiles, this.savedSiteProfileName); - } - }, }, created() { const params = queryToObject(window.location.search, { legacySpacesDecode: true }); diff --git a/ee/spec/frontend/security_configuration/dast_profiles/dast_profiles_configurator/dast_profiles_configurator_spec.js b/ee/spec/frontend/security_configuration/dast_profiles/dast_profiles_configurator/dast_profiles_configurator_spec.js index 149991f17a10..bf5acae678fb 100644 --- a/ee/spec/frontend/security_configuration/dast_profiles/dast_profiles_configurator/dast_profiles_configurator_spec.js +++ b/ee/spec/frontend/security_configuration/dast_profiles/dast_profiles_configurator/dast_profiles_configurator_spec.js @@ -65,11 +65,7 @@ describe('DastProfilesConfigurator', () => { await nextTick(); }; - const createComponentFactory = (mountFn = shallowMount) => ( - options = {}, - withHandlers, - mockProfiles = true, - ) => { + const createComponentFactory = (mountFn = shallowMount) => (options = {}, withHandlers) => { localVue = createLocalVue(); let defaultMocks = { $apollo: { @@ -109,8 +105,8 @@ describe('DastProfilesConfigurator', () => { { data() { return { - scannerProfiles: mockProfiles ? scannerProfiles : [], - siteProfiles: mockProfiles ? siteProfiles : [], + scannerProfiles, + siteProfiles, ...options.data, }; }, @@ -217,30 +213,17 @@ describe('DastProfilesConfigurator', () => { const { profileName: savedScannerProfileName } = scannerProfiles[0]; const { profileName: savedSiteProfileName } = siteProfiles[0]; - beforeEach(() => { - createComponent({ savedSiteProfileName, savedScannerProfileName }, false, false); + beforeEach(async () => { + createComponent({ savedSiteProfileName, savedScannerProfileName }, true); + await nextTick(); }); it('should have saved profiles selected', async () => { - /** - * Simulate watch trigger - */ - // eslint-disable-next-line no-restricted-syntax - wrapper.setData({ scannerProfiles, siteProfiles }); - await nextTick(); - expect(findScannerProfilesSelector().find('h3').text()).toContain(savedScannerProfileName); expect(findSiteProfilesSelector().find('h3').text()).toContain(savedSiteProfileName); }); it('should mark saved profiles as in-use', async () => { - /** - * Simulate watch trigger - */ - // eslint-disable-next-line no-restricted-syntax - wrapper.setData({ scannerProfiles, siteProfiles }); - await nextTick(); - await openDrawer(); expect(findInUseLabel().exists()).toBe(true); }); -- GitLab