diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-21 10:08:36 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-21 10:08:36 +0300 |
commit | 48aff82709769b098321c738f3444b9bdaa694c6 (patch) | |
tree | e00c7c43e2d9b603a5a6af576b1685e400410dee /spec/frontend/feature_flags/components/strategies/flexible_rollout_spec.js | |
parent | 879f5329ee916a948223f8f43d77fba4da6cd028 (diff) |
Add latest changes from gitlab-org/gitlab@13-5-stable-eev13.5.0-rc42
Diffstat (limited to 'spec/frontend/feature_flags/components/strategies/flexible_rollout_spec.js')
-rw-r--r-- | spec/frontend/feature_flags/components/strategies/flexible_rollout_spec.js | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/spec/frontend/feature_flags/components/strategies/flexible_rollout_spec.js b/spec/frontend/feature_flags/components/strategies/flexible_rollout_spec.js new file mode 100644 index 00000000000..f3f70a325d0 --- /dev/null +++ b/spec/frontend/feature_flags/components/strategies/flexible_rollout_spec.js @@ -0,0 +1,116 @@ +import { mount } from '@vue/test-utils'; +import { GlFormInput, GlFormSelect } from '@gitlab/ui'; +import FlexibleRollout from '~/feature_flags/components/strategies/flexible_rollout.vue'; +import ParameterFormGroup from '~/feature_flags/components/strategies/parameter_form_group.vue'; +import { PERCENT_ROLLOUT_GROUP_ID } from '~/feature_flags/constants'; +import { flexibleRolloutStrategy } from '../../mock_data'; + +const DEFAULT_PROPS = { + strategy: flexibleRolloutStrategy, +}; + +describe('feature_flags/components/strategies/flexible_rollout.vue', () => { + let wrapper; + let percentageFormGroup; + let percentageInput; + let stickinessFormGroup; + let stickinessSelect; + + const factory = (props = {}) => + mount(FlexibleRollout, { propsData: { ...DEFAULT_PROPS, ...props } }); + + afterEach(() => { + if (wrapper?.destroy) { + wrapper.destroy(); + } + + wrapper = null; + }); + + describe('with valid percentage', () => { + beforeEach(() => { + wrapper = factory(); + + percentageFormGroup = wrapper + .find('[data-testid="strategy-flexible-rollout-percentage"]') + .find(ParameterFormGroup); + percentageInput = percentageFormGroup.find(GlFormInput); + stickinessFormGroup = wrapper + .find('[data-testid="strategy-flexible-rollout-stickiness"]') + .find(ParameterFormGroup); + stickinessSelect = stickinessFormGroup.find(GlFormSelect); + }); + + it('displays the current percentage value', () => { + expect(percentageInput.element.value).toBe(flexibleRolloutStrategy.parameters.rollout); + }); + + it('displays the current stickiness value', () => { + expect(stickinessSelect.element.value).toBe(flexibleRolloutStrategy.parameters.stickiness); + }); + + it('emits a change when the percentage value changes', async () => { + percentageInput.setValue('75'); + await wrapper.vm.$nextTick(); + expect(wrapper.emitted('change')).toEqual([ + [ + { + parameters: { + rollout: '75', + groupId: PERCENT_ROLLOUT_GROUP_ID, + stickiness: flexibleRolloutStrategy.parameters.stickiness, + }, + }, + ], + ]); + }); + + it('emits a change when the stickiness value changes', async () => { + stickinessSelect.setValue('USERID'); + await wrapper.vm.$nextTick(); + expect(wrapper.emitted('change')).toEqual([ + [ + { + parameters: { + rollout: flexibleRolloutStrategy.parameters.rollout, + groupId: PERCENT_ROLLOUT_GROUP_ID, + stickiness: 'USERID', + }, + }, + ], + ]); + }); + + it('does not show errors', () => { + expect(percentageFormGroup.attributes('state')).toBe('true'); + }); + }); + + describe('with percentage that is out of range', () => { + beforeEach(() => { + wrapper = factory({ strategy: { parameters: { rollout: '101' } } }); + }); + + it('shows errors', () => { + const formGroup = wrapper + .find('[data-testid="strategy-flexible-rollout-percentage"]') + .find(ParameterFormGroup); + + expect(formGroup.attributes('state')).toBeUndefined(); + }); + }); + + describe('with percentage that is not a whole number', () => { + beforeEach(() => { + wrapper = factory({ strategy: { parameters: { rollout: '3.14' } } }); + }); + + it('shows errors', () => { + const formGroup = wrapper + .find('[data-testid="strategy-flexible-rollout-percentage"]') + .find(ParameterFormGroup); + + expect(formGroup.attributes('state')).toBeUndefined(); + }); + }); +}); |