Commit ceb448d9 authored by Kushal Pandya's avatar Kushal Pandya

Merge branch 'cngo-migrate-feature-flag-toggles-to-gl-toggle' into 'master'

Migrate feature flags page toggles to GlToggle

See merge request gitlab-org/gitlab!52728
parents a8c61b1e 96f4c089
...@@ -10,11 +10,11 @@ import { ...@@ -10,11 +10,11 @@ import {
GlFormCheckbox, GlFormCheckbox,
GlSprintf, GlSprintf,
GlIcon, GlIcon,
GlToggle,
} from '@gitlab/ui'; } from '@gitlab/ui';
import RelatedIssuesRoot from '~/related_issues/components/related_issues_root.vue'; import RelatedIssuesRoot from '~/related_issues/components/related_issues_root.vue';
import { s__ } from '~/locale'; import { s__ } from '~/locale';
import featureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin'; import featureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
import ToggleButton from '~/vue_shared/components/toggle_button.vue';
import EnvironmentsDropdown from './environments_dropdown.vue'; import EnvironmentsDropdown from './environments_dropdown.vue';
import Strategy from './strategy.vue'; import Strategy from './strategy.vue';
import { import {
...@@ -37,7 +37,7 @@ export default { ...@@ -37,7 +37,7 @@ export default {
GlTooltip, GlTooltip,
GlSprintf, GlSprintf,
GlIcon, GlIcon,
ToggleButton, GlToggle,
EnvironmentsDropdown, EnvironmentsDropdown,
Strategy, Strategy,
RelatedIssuesRoot, RelatedIssuesRoot,
...@@ -372,7 +372,7 @@ export default { ...@@ -372,7 +372,7 @@ export default {
{{ s__('FeatureFlags|Environment Spec') }} {{ s__('FeatureFlags|Environment Spec') }}
</div> </div>
<div <div
class="table-mobile-content js-feature-flag-status d-flex align-items-center justify-content-start" class="table-mobile-content gl-display-flex gl-align-items-center gl-justify-content-start"
> >
<p v-if="isAllEnvironment(scope.environmentScope)" class="js-scope-all pl-3"> <p v-if="isAllEnvironment(scope.environmentScope)" class="js-scope-all pl-3">
{{ $options.translations.allEnvironmentsText }} {{ $options.translations.allEnvironmentsText }}
...@@ -398,10 +398,10 @@ export default { ...@@ -398,10 +398,10 @@ export default {
<div class="table-mobile-header" role="rowheader"> <div class="table-mobile-header" role="rowheader">
{{ s__('FeatureFlags|Status') }} {{ s__('FeatureFlags|Status') }}
</div> </div>
<div class="table-mobile-content js-feature-flag-status"> <div class="table-mobile-content gl-display-flex gl-justify-content-center">
<toggle-button <gl-toggle
:value="scope.active" :value="scope.active"
:disabled-input="!active || !canUpdateScope(scope)" :disabled="!active || !canUpdateScope(scope)"
@change="(status) => (scope.active = status)" @change="(status) => (scope.active = status)"
/> />
</div> </div>
...@@ -498,25 +498,26 @@ export default { ...@@ -498,25 +498,26 @@ export default {
<div class="table-mobile-header" role="rowheader"> <div class="table-mobile-header" role="rowheader">
{{ s__('FeatureFlags|Remove') }} {{ s__('FeatureFlags|Remove') }}
</div> </div>
<div class="table-mobile-content js-feature-flag-delete"> <div class="table-mobile-content">
<gl-button <gl-button
v-if="!isAllEnvironment(scope.environmentScope) && canUpdateScope(scope)" v-if="!isAllEnvironment(scope.environmentScope) && canUpdateScope(scope)"
v-gl-tooltip v-gl-tooltip
:title="s__('FeatureFlags|Remove')" :title="s__('FeatureFlags|Remove')"
class="js-delete-scope btn-transparent pr-3 pl-3" class="js-delete-scope btn-transparent pr-3 pl-3"
icon="clear" icon="clear"
data-testid="feature-flag-delete"
@click="removeScope(scope)" @click="removeScope(scope)"
/> />
</div> </div>
</div> </div>
</div> </div>
<div class="js-add-new-scope gl-responsive-table-row" role="row"> <div class="gl-responsive-table-row" role="row" data-testid="add-new-scope">
<div class="table-section section-30" role="gridcell"> <div class="table-section section-30" role="gridcell">
<div class="table-mobile-header" role="rowheader"> <div class="table-mobile-header" role="rowheader">
{{ s__('FeatureFlags|Environment Spec') }} {{ s__('FeatureFlags|Environment Spec') }}
</div> </div>
<div class="table-mobile-content js-feature-flag-status"> <div class="table-mobile-content">
<environments-dropdown <environments-dropdown
class="js-new-scope-name col-12" class="js-new-scope-name col-12"
:value="newScope" :value="newScope"
...@@ -530,9 +531,9 @@ export default { ...@@ -530,9 +531,9 @@ export default {
<div class="table-mobile-header" role="rowheader"> <div class="table-mobile-header" role="rowheader">
{{ s__('FeatureFlags|Status') }} {{ s__('FeatureFlags|Status') }}
</div> </div>
<div class="table-mobile-content js-feature-flag-status"> <div class="table-mobile-content gl-display-flex gl-justify-content-center">
<toggle-button <gl-toggle
:disabled-input="!active" :disabled="!active"
:value="false" :value="false"
@change="createNewScope({ active: true })" @change="createNewScope({ active: true })"
/> />
......
---
title: Migrate feature flags page toggles to GlToggle
merge_request: 52728
author:
type: changed
import { uniqueId } from 'lodash'; import { uniqueId } from 'lodash';
import { shallowMount } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import { GlFormTextarea, GlFormCheckbox, GlButton } from '@gitlab/ui'; import { GlFormTextarea, GlFormCheckbox, GlButton, GlToggle } from '@gitlab/ui';
import { extendedWrapper } from 'helpers/vue_test_utils_helper';
import Api from '~/api'; import Api from '~/api';
import Form from '~/feature_flags/components/form.vue'; import Form from '~/feature_flags/components/form.vue';
import EnvironmentsDropdown from '~/feature_flags/components/environments_dropdown.vue'; import EnvironmentsDropdown from '~/feature_flags/components/environments_dropdown.vue';
...@@ -14,7 +15,6 @@ import { ...@@ -14,7 +15,6 @@ import {
NEW_VERSION_FLAG, NEW_VERSION_FLAG,
} from '~/feature_flags/constants'; } from '~/feature_flags/constants';
import RelatedIssuesRoot from '~/related_issues/components/related_issues_root.vue'; import RelatedIssuesRoot from '~/related_issues/components/related_issues_root.vue';
import ToggleButton from '~/vue_shared/components/toggle_button.vue';
import { featureFlag, userList, allUsersStrategy } from '../mock_data'; import { featureFlag, userList, allUsersStrategy } from '../mock_data';
jest.mock('~/api.js'); jest.mock('~/api.js');
...@@ -35,14 +35,19 @@ describe('feature flag form', () => { ...@@ -35,14 +35,19 @@ describe('feature flag form', () => {
}, },
}; };
const findAddNewScopeRow = () => wrapper.findByTestId('add-new-scope');
const findGlToggle = () => wrapper.find(GlToggle);
const factory = (props = {}, provide = {}) => { const factory = (props = {}, provide = {}) => {
wrapper = shallowMount(Form, { wrapper = extendedWrapper(
propsData: { ...requiredProps, ...props }, shallowMount(Form, {
provide: { propsData: { ...requiredProps, ...props },
...requiredInjections, provide: {
...provide, ...requiredInjections,
}, ...provide,
}); },
}),
);
}; };
beforeEach(() => { beforeEach(() => {
...@@ -102,13 +107,13 @@ describe('feature flag form', () => { ...@@ -102,13 +107,13 @@ describe('feature flag form', () => {
}); });
it('should render scopes table with a new row ', () => { it('should render scopes table with a new row ', () => {
expect(wrapper.find('.js-add-new-scope').exists()).toBe(true); expect(findAddNewScopeRow().exists()).toBe(true);
}); });
describe('status toggle', () => { describe('status toggle', () => {
describe('without filled text input', () => { describe('without filled text input', () => {
it('should add a new scope with the text value empty and the status', () => { it('should add a new scope with the text value empty and the status', () => {
wrapper.find(ToggleButton).vm.$emit('change', true); findGlToggle().vm.$emit('change', true);
expect(wrapper.vm.formScopes).toHaveLength(1); expect(wrapper.vm.formScopes).toHaveLength(1);
expect(wrapper.vm.formScopes[0].active).toEqual(true); expect(wrapper.vm.formScopes[0].active).toEqual(true);
...@@ -121,7 +126,7 @@ describe('feature flag form', () => { ...@@ -121,7 +126,7 @@ describe('feature flag form', () => {
it('should be disabled if the feature flag is not active', (done) => { it('should be disabled if the feature flag is not active', (done) => {
wrapper.setProps({ active: false }); wrapper.setProps({ active: false });
wrapper.vm.$nextTick(() => { wrapper.vm.$nextTick(() => {
expect(wrapper.find(ToggleButton).props('disabledInput')).toBe(true); expect(findGlToggle().props('disabled')).toBe(true);
done(); done();
}); });
}); });
...@@ -166,11 +171,11 @@ describe('feature flag form', () => { ...@@ -166,11 +171,11 @@ describe('feature flag form', () => {
describe('scopes', () => { describe('scopes', () => {
it('should be possible to remove a scope', () => { it('should be possible to remove a scope', () => {
expect(wrapper.find('.js-feature-flag-delete').exists()).toEqual(true); expect(wrapper.findByTestId('feature-flag-delete').exists()).toEqual(true);
}); });
it('renders empty row to add a new scope', () => { it('renders empty row to add a new scope', () => {
expect(wrapper.find('.js-add-new-scope').exists()).toEqual(true); expect(findAddNewScopeRow().exists()).toEqual(true);
}); });
it('renders the user id checkbox', () => { it('renders the user id checkbox', () => {
...@@ -186,7 +191,7 @@ describe('feature flag form', () => { ...@@ -186,7 +191,7 @@ describe('feature flag form', () => {
describe('update scope', () => { describe('update scope', () => {
describe('on click on toggle', () => { describe('on click on toggle', () => {
it('should update the scope', () => { it('should update the scope', () => {
wrapper.find(ToggleButton).vm.$emit('change', false); findGlToggle().vm.$emit('change', false);
expect(wrapper.vm.formScopes[0].active).toBe(false); expect(wrapper.vm.formScopes[0].active).toBe(false);
}); });
...@@ -195,7 +200,7 @@ describe('feature flag form', () => { ...@@ -195,7 +200,7 @@ describe('feature flag form', () => {
wrapper.setProps({ active: false }); wrapper.setProps({ active: false });
wrapper.vm.$nextTick(() => { wrapper.vm.$nextTick(() => {
expect(wrapper.find(ToggleButton).props('disabledInput')).toBe(true); expect(findGlToggle().props('disabled')).toBe(true);
done(); done();
}); });
}); });
...@@ -294,7 +299,7 @@ describe('feature flag form', () => { ...@@ -294,7 +299,7 @@ describe('feature flag form', () => {
const row = wrapper.findAll('.gl-responsive-table-row').at(2); const row = wrapper.findAll('.gl-responsive-table-row').at(2);
expect(row.find(EnvironmentsDropdown).vm.disabled).toBe(true); expect(row.find(EnvironmentsDropdown).vm.disabled).toBe(true);
expect(row.find(ToggleButton).vm.disabledInput).toBe(true); expect(row.find(GlToggle).props('disabled')).toBe(true);
expect(row.find('.js-delete-scope').exists()).toBe(false); expect(row.find('.js-delete-scope').exists()).toBe(false);
}); });
}); });
...@@ -347,10 +352,10 @@ describe('feature flag form', () => { ...@@ -347,10 +352,10 @@ describe('feature flag form', () => {
return wrapper.vm.$nextTick(); return wrapper.vm.$nextTick();
}) })
.then(() => { .then(() => {
wrapper.find('.js-add-new-scope').find(ToggleButton).vm.$emit('change', true); findAddNewScopeRow().find(GlToggle).vm.$emit('change', true);
}) })
.then(() => { .then(() => {
wrapper.find(ToggleButton).vm.$emit('change', true); findGlToggle().vm.$emit('change', true);
return wrapper.vm.$nextTick(); return wrapper.vm.$nextTick();
}) })
......
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