summaryrefslogtreecommitdiff
path: root/spec/frontend/feature_flags/components/strategies
diff options
context:
space:
mode:
Diffstat (limited to 'spec/frontend/feature_flags/components/strategies')
-rw-r--r--spec/frontend/feature_flags/components/strategies/default_spec.js10
-rw-r--r--spec/frontend/feature_flags/components/strategies/flexible_rollout_spec.js116
-rw-r--r--spec/frontend/feature_flags/components/strategies/gitlab_user_list_spec.js51
-rw-r--r--spec/frontend/feature_flags/components/strategies/parameter_form_group_spec.js50
-rw-r--r--spec/frontend/feature_flags/components/strategies/percent_rollout_spec.js78
-rw-r--r--spec/frontend/feature_flags/components/strategies/users_with_id_spec.js38
6 files changed, 343 insertions, 0 deletions
diff --git a/spec/frontend/feature_flags/components/strategies/default_spec.js b/spec/frontend/feature_flags/components/strategies/default_spec.js
new file mode 100644
index 00000000000..1315cd7d735
--- /dev/null
+++ b/spec/frontend/feature_flags/components/strategies/default_spec.js
@@ -0,0 +1,10 @@
+import { shallowMount } from '@vue/test-utils';
+import Default from '~/feature_flags/components/strategies/default.vue';
+
+describe('~/feature_flags/components/strategies/default.vue', () => {
+ it('should emit an empty parameter object on mount', () => {
+ const wrapper = shallowMount(Default);
+
+ expect(wrapper.emitted('change')).toEqual([[{ parameters: {} }]]);
+ });
+});
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();
+ });
+ });
+});
diff --git a/spec/frontend/feature_flags/components/strategies/gitlab_user_list_spec.js b/spec/frontend/feature_flags/components/strategies/gitlab_user_list_spec.js
new file mode 100644
index 00000000000..014c6dd98b9
--- /dev/null
+++ b/spec/frontend/feature_flags/components/strategies/gitlab_user_list_spec.js
@@ -0,0 +1,51 @@
+import { mount } from '@vue/test-utils';
+import { GlFormSelect } from '@gitlab/ui';
+import GitlabUserList from '~/feature_flags/components/strategies/gitlab_user_list.vue';
+import { userListStrategy, userList } from '../../mock_data';
+
+const DEFAULT_PROPS = {
+ strategy: userListStrategy,
+ userLists: [userList],
+};
+
+describe('~/feature_flags/components/strategies/gitlab_user_list.vue', () => {
+ let wrapper;
+
+ const factory = (props = {}) =>
+ mount(GitlabUserList, { propsData: { ...DEFAULT_PROPS, ...props } });
+
+ describe('with user lists', () => {
+ beforeEach(() => {
+ wrapper = factory();
+ });
+
+ it('should show the input for userListId with the correct value', () => {
+ const inputWrapper = wrapper.find(GlFormSelect);
+ expect(inputWrapper.exists()).toBe(true);
+ expect(inputWrapper.element.value).toBe('2');
+ });
+
+ it('should emit a change event when altering the userListId', () => {
+ const inputWrapper = wrapper.find(GitlabUserList);
+ inputWrapper.vm.$emit('change', {
+ userListId: '3',
+ });
+ expect(wrapper.emitted('change')).toEqual([
+ [
+ {
+ userListId: '3',
+ },
+ ],
+ ]);
+ });
+ });
+ describe('without user lists', () => {
+ beforeEach(() => {
+ wrapper = factory({ userLists: [] });
+ });
+
+ it('should display a message that there are no user lists', () => {
+ expect(wrapper.text()).toContain('There are no configured user lists');
+ });
+ });
+});
diff --git a/spec/frontend/feature_flags/components/strategies/parameter_form_group_spec.js b/spec/frontend/feature_flags/components/strategies/parameter_form_group_spec.js
new file mode 100644
index 00000000000..a0ffdb1fca0
--- /dev/null
+++ b/spec/frontend/feature_flags/components/strategies/parameter_form_group_spec.js
@@ -0,0 +1,50 @@
+import { mount } from '@vue/test-utils';
+import { GlFormGroup, GlFormInput } from '@gitlab/ui';
+import ParameterFormGroup from '~/feature_flags/components/strategies/parameter_form_group.vue';
+
+describe('~/feature_flags/strategies/parameter_form_group.vue', () => {
+ let wrapper;
+ let formGroup;
+ let slot;
+
+ beforeEach(() => {
+ wrapper = mount(ParameterFormGroup, {
+ propsData: { inputId: 'test-id', label: 'test' },
+ attrs: { description: 'test description' },
+ scopedSlots: {
+ default(props) {
+ return this.$createElement(GlFormInput, {
+ attrs: { id: props.inputId, 'data-testid': 'slot' },
+ });
+ },
+ },
+ });
+
+ formGroup = wrapper.find(GlFormGroup);
+ slot = wrapper.find('[data-testid="slot"]');
+ });
+
+ afterEach(() => {
+ if (wrapper?.destroy) {
+ wrapper.destroy();
+ }
+
+ wrapper = null;
+ });
+
+ it('should display the default slot', () => {
+ expect(slot.exists()).toBe(true);
+ });
+
+ it('should bind the input id to the slot', () => {
+ expect(slot.attributes('id')).toBe('test-id');
+ });
+
+ it('should bind the label-for to the input id', () => {
+ expect(formGroup.find('[for="test-id"]').exists()).toBe(true);
+ });
+
+ it('should bind extra attributes to the form group', () => {
+ expect(formGroup.attributes('description')).toBe('test description');
+ });
+});
diff --git a/spec/frontend/feature_flags/components/strategies/percent_rollout_spec.js b/spec/frontend/feature_flags/components/strategies/percent_rollout_spec.js
new file mode 100644
index 00000000000..de0b439f1c5
--- /dev/null
+++ b/spec/frontend/feature_flags/components/strategies/percent_rollout_spec.js
@@ -0,0 +1,78 @@
+import { mount } from '@vue/test-utils';
+import { GlFormInput } from '@gitlab/ui';
+import PercentRollout from '~/feature_flags/components/strategies/percent_rollout.vue';
+import ParameterFormGroup from '~/feature_flags/components/strategies/parameter_form_group.vue';
+import { PERCENT_ROLLOUT_GROUP_ID } from '~/feature_flags/constants';
+import { percentRolloutStrategy } from '../../mock_data';
+
+const DEFAULT_PROPS = {
+ strategy: percentRolloutStrategy,
+};
+
+describe('~/feature_flags/components/strategies/percent_rollout.vue', () => {
+ let wrapper;
+ let input;
+ let formGroup;
+
+ const factory = (props = {}) =>
+ mount(PercentRollout, { propsData: { ...DEFAULT_PROPS, ...props } });
+
+ afterEach(() => {
+ if (wrapper?.destroy) {
+ wrapper.destroy();
+ }
+
+ wrapper = null;
+ });
+
+ describe('with valid percentage', () => {
+ beforeEach(() => {
+ wrapper = factory();
+
+ input = wrapper.find(GlFormInput);
+ formGroup = wrapper.find(ParameterFormGroup);
+ });
+
+ it('displays the current value', () => {
+ expect(input.element.value).toBe(percentRolloutStrategy.parameters.percentage);
+ });
+
+ it('emits a change when the value changes', async () => {
+ input.setValue('75');
+ await wrapper.vm.$nextTick();
+ expect(wrapper.emitted('change')).toEqual([
+ [{ parameters: { percentage: '75', groupId: PERCENT_ROLLOUT_GROUP_ID } }],
+ ]);
+ });
+
+ it('does not show errors', () => {
+ expect(formGroup.attributes('state')).toBe('true');
+ });
+ });
+
+ describe('with percentage that is out of range', () => {
+ beforeEach(() => {
+ wrapper = factory({ strategy: { parameters: { percentage: '101' } } });
+
+ input = wrapper.find(GlFormInput);
+ formGroup = wrapper.find(ParameterFormGroup);
+ });
+
+ it('shows errors', () => {
+ expect(formGroup.attributes('state')).toBeUndefined();
+ });
+ });
+
+ describe('with percentage that is not a whole number', () => {
+ beforeEach(() => {
+ wrapper = factory({ strategy: { parameters: { percentage: '3.14' } } });
+
+ input = wrapper.find(GlFormInput);
+ formGroup = wrapper.find(ParameterFormGroup);
+ });
+
+ it('shows errors', () => {
+ expect(formGroup.attributes('state')).toBeUndefined();
+ });
+ });
+});
diff --git a/spec/frontend/feature_flags/components/strategies/users_with_id_spec.js b/spec/frontend/feature_flags/components/strategies/users_with_id_spec.js
new file mode 100644
index 00000000000..460df6ef2ec
--- /dev/null
+++ b/spec/frontend/feature_flags/components/strategies/users_with_id_spec.js
@@ -0,0 +1,38 @@
+import { mount } from '@vue/test-utils';
+import { GlFormTextarea } from '@gitlab/ui';
+import UsersWithId from '~/feature_flags/components/strategies/users_with_id.vue';
+import { usersWithIdStrategy } from '../../mock_data';
+
+const DEFAULT_PROPS = {
+ strategy: usersWithIdStrategy,
+};
+
+describe('~/feature_flags/components/users_with_id.vue', () => {
+ let wrapper;
+ let textarea;
+
+ const factory = (props = {}) => mount(UsersWithId, { propsData: { ...DEFAULT_PROPS, ...props } });
+
+ beforeEach(() => {
+ wrapper = factory();
+ textarea = wrapper.find(GlFormTextarea);
+ });
+
+ afterEach(() => {
+ if (wrapper?.destroy) {
+ wrapper.destroy();
+ }
+
+ wrapper = null;
+ });
+
+ it('should display the current value of the parameters', () => {
+ expect(textarea.element.value).toBe(usersWithIdStrategy.parameters.userIds);
+ });
+
+ it('should emit a change event when the IDs change', () => {
+ textarea.setValue('4,5,6');
+
+ expect(wrapper.emitted('change')).toEqual([[{ parameters: { userIds: '4,5,6' } }]]);
+ });
+});