Commit c4b1d791 authored by Dheeraj Joshi's avatar Dheeraj Joshi Committed by Ezekiel Kigbo

Fix missing setter function for tabIndex

parent b1070678
...@@ -56,15 +56,19 @@ export default { ...@@ -56,15 +56,19 @@ export default {
return Math.max(0, activeTabIndex); return Math.max(0, activeTabIndex);
}, },
set(newTabIndex) {
const profileTypeName = Object.keys(this.profileSettings)[newTabIndex];
if (profileTypeName) {
window.location.hash = kebabCase(profileTypeName);
}
},
}, },
}, },
created() { created() {
this.addSmartQueriesForEnabledProfileTypes(); this.addSmartQueriesForEnabledProfileTypes();
}, },
methods: { methods: {
setLocationHash(profileType) {
window.location.hash = kebabCase(profileType);
},
addSmartQueriesForEnabledProfileTypes() { addSmartQueriesForEnabledProfileTypes() {
Object.values(this.profileSettings).forEach(({ profileType, graphQL: { query } }) => { Object.values(this.profileSettings).forEach(({ profileType, graphQL: { query } }) => {
this.makeProfileTypeReactive(profileType); this.makeProfileTypeReactive(profileType);
...@@ -242,11 +246,7 @@ export default { ...@@ -242,11 +246,7 @@ export default {
</header> </header>
<gl-tabs v-model="tabIndex"> <gl-tabs v-model="tabIndex">
<gl-tab <gl-tab v-for="(settings, profileType) in profileSettings" :key="profileType">
v-for="(settings, profileType) in profileSettings"
:key="profileType"
@click="setLocationHash(profileType)"
>
<template #title> <template #title>
<span>{{ settings.i18n.tabName }}</span> <span>{{ settings.i18n.tabName }}</span>
</template> </template>
......
import { mount, shallowMount, createWrapper } from '@vue/test-utils'; import { mount, shallowMount } from '@vue/test-utils';
import { within } from '@testing-library/dom'; import { within } from '@testing-library/dom';
import { merge } from 'lodash'; import { merge } from 'lodash';
import { GlDropdown } from '@gitlab/ui'; import { GlDropdown, GlTabs } from '@gitlab/ui';
import setWindowLocation from 'helpers/set_window_location_helper'; import setWindowLocation from 'helpers/set_window_location_helper';
import DastProfiles from 'ee/dast_profiles/components/dast_profiles.vue'; import DastProfiles from 'ee/dast_profiles/components/dast_profiles.vue';
...@@ -82,6 +82,7 @@ describe('EE - DastProfiles', () => { ...@@ -82,6 +82,7 @@ describe('EE - DastProfiles', () => {
const getDropdownComponent = () => wrapper.find(GlDropdown); const getDropdownComponent = () => wrapper.find(GlDropdown);
const getSiteProfilesDropdownItem = text => const getSiteProfilesDropdownItem = text =>
within(getDropdownComponent().element).queryByText(text); within(getDropdownComponent().element).queryByText(text);
const getTabsComponent = () => wrapper.find(GlTabs);
const getTab = ({ tabName, selected }) => const getTab = ({ tabName, selected }) =>
withinComponent().getByRole('tab', { withinComponent().getByRole('tab', {
name: tabName, name: tabName,
...@@ -161,10 +162,10 @@ describe('EE - DastProfiles', () => { ...@@ -161,10 +162,10 @@ describe('EE - DastProfiles', () => {
}); });
describe.each` describe.each`
tabName | givenLocationHash tabName | index | givenLocationHash
${'Site Profiles'} | ${'site-profiles'} ${'Site Profiles'} | ${0} | ${'site-profiles'}
${'Scanner Profiles'} | ${'scanner-profiles'} ${'Scanner Profiles'} | ${1} | ${'scanner-profiles'}
`('with location hash set to "$givenLocationHash"', ({ tabName, givenLocationHash }) => { `('with location hash set to "$givenLocationHash"', ({ tabName, index, givenLocationHash }) => {
beforeEach(() => { beforeEach(() => {
setWindowLocation(`http://foo.com/index#${givenLocationHash}`); setWindowLocation(`http://foo.com/index#${givenLocationHash}`);
createFullComponent(); createFullComponent();
...@@ -186,9 +187,7 @@ describe('EE - DastProfiles', () => { ...@@ -186,9 +187,7 @@ describe('EE - DastProfiles', () => {
it('updates the browsers URL to contain the selected tab', () => { it('updates the browsers URL to contain the selected tab', () => {
window.location.hash = ''; window.location.hash = '';
const tab = getTab({ tabName }); getTabsComponent().vm.$emit('input', index);
createWrapper(tab).trigger('click');
expect(window.location.hash).toBe(givenLocationHash); expect(window.location.hash).toBe(givenLocationHash);
}); });
......
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