diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-07-02 09:07:28 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-07-02 09:07:28 +0300 |
commit | 127ab291e2c8b66ac5502257ac9e280acf257089 (patch) | |
tree | dbc144795ae86d8035abbe9bbabc9772127ed5a6 /spec/frontend/feature_flags | |
parent | fd4360e1f532de6a23e5c79f06b3ef3d89c1511d (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/feature_flags')
5 files changed, 30 insertions, 541 deletions
diff --git a/spec/frontend/feature_flags/components/edit_feature_flag_spec.js b/spec/frontend/feature_flags/components/edit_feature_flag_spec.js index beafed2be88..799b567a2c0 100644 --- a/spec/frontend/feature_flags/components/edit_feature_flag_spec.js +++ b/spec/frontend/feature_flags/components/edit_feature_flag_spec.js @@ -1,21 +1,16 @@ import { GlToggle, GlAlert } from '@gitlab/ui'; -import { createLocalVue, shallowMount } from '@vue/test-utils'; +import { shallowMount } from '@vue/test-utils'; import MockAdapter from 'axios-mock-adapter'; +import Vue from 'vue'; import Vuex from 'vuex'; import { mockTracking } from 'helpers/tracking_helper'; import { TEST_HOST } from 'spec/test_constants'; import EditFeatureFlag from '~/feature_flags/components/edit_feature_flag.vue'; import Form from '~/feature_flags/components/form.vue'; -import { LEGACY_FLAG, NEW_VERSION_FLAG } from '~/feature_flags/constants'; import createStore from '~/feature_flags/store/edit'; import axios from '~/lib/utils/axios_utils'; -const localVue = createLocalVue(); -localVue.use(Vuex); - -const userCalloutId = 'feature_flags_new_version'; -const userCalloutsPath = `${TEST_HOST}/user_callouts`; - +Vue.use(Vuex); describe('Edit feature flag form', () => { let wrapper; let mock; @@ -25,20 +20,14 @@ describe('Edit feature flag form', () => { endpoint: `${TEST_HOST}/feature_flags.json`, }); - const factory = (opts = {}) => { + const factory = (provide = {}) => { if (wrapper) { wrapper.destroy(); wrapper = null; } wrapper = shallowMount(EditFeatureFlag, { - localVue, store, - provide: { - showUserCallout: true, - userCalloutId, - userCalloutsPath, - ...opts, - }, + provide, }); }; @@ -52,18 +41,8 @@ describe('Edit feature flag form', () => { updated_at: '2019-01-17T17:27:39.778Z', name: 'feature_flag', description: '', - version: LEGACY_FLAG, edit_path: '/h5bp/html5-boilerplate/-/feature_flags/21/edit', destroy_path: '/h5bp/html5-boilerplate/-/feature_flags/21', - scopes: [ - { - id: 21, - active: false, - environment_scope: '*', - created_at: '2019-01-17T17:27:39.778Z', - updated_at: '2019-01-17T17:27:39.778Z', - }, - ], }); factory(); setImmediate(() => done()); @@ -74,9 +53,7 @@ describe('Edit feature flag form', () => { mock.restore(); }); - const findAlert = () => wrapper.find(GlAlert); - const findWarningGlAlert = () => - wrapper.findAll(GlAlert).filter((c) => c.props('variant') === 'warning'); + const findWarningGlAlert = () => wrapper.findComponent(GlAlert); it('should display the iid', () => { expect(wrapper.find('h3').text()).toContain('^5'); @@ -86,21 +63,13 @@ describe('Edit feature flag form', () => { expect(wrapper.find(GlToggle).exists()).toBe(true); }); - it('should set the value of the toggle to whether or not the flag is active', () => { - expect(wrapper.find(GlToggle).props('value')).toBe(true); - }); - - it('should alert users the flag is read-only', () => { - expect(findAlert().text()).toContain('GitLab is moving to a new way of managing feature flags'); - }); - describe('with error', () => { it('should render the error', () => { store.dispatch('receiveUpdateFeatureFlagError', { message: ['The name is required'] }); return wrapper.vm.$nextTick(() => { const warningGlAlert = findWarningGlAlert(); - expect(warningGlAlert.at(1).exists()).toEqual(true); - expect(warningGlAlert.at(1).text()).toContain('The name is required'); + expect(warningGlAlert.exists()).toEqual(true); + expect(warningGlAlert.text()).toContain('The name is required'); }); }); }); @@ -114,32 +83,6 @@ describe('Edit feature flag form', () => { expect(wrapper.find(Form).exists()).toEqual(true); }); - it('should set the version of the form from the feature flag', () => { - expect(wrapper.find(Form).attributes('version')).toBe(LEGACY_FLAG); - - mock.resetHandlers(); - - mock.onGet(`${TEST_HOST}/feature_flags.json`).replyOnce(200, { - id: 21, - iid: 5, - active: true, - created_at: '2019-01-17T17:27:39.778Z', - updated_at: '2019-01-17T17:27:39.778Z', - name: 'feature_flag', - description: '', - version: NEW_VERSION_FLAG, - edit_path: '/h5bp/html5-boilerplate/-/feature_flags/21/edit', - destroy_path: '/h5bp/html5-boilerplate/-/feature_flags/21', - strategies: [], - }); - - factory(); - - return axios.waitForAll().then(() => { - expect(wrapper.find(Form).attributes('version')).toBe(NEW_VERSION_FLAG); - }); - }); - it('should track when the toggle is clicked', () => { const toggle = wrapper.find(GlToggle); const spy = mockTracking('_category_', toggle.element, jest.spyOn); diff --git a/spec/frontend/feature_flags/mock_data.js b/spec/frontend/feature_flags/mock_data.js index 11a91e5b2a8..b5f09ac1957 100644 --- a/spec/frontend/feature_flags/mock_data.js +++ b/spec/frontend/feature_flags/mock_data.js @@ -16,86 +16,24 @@ export const featureFlag = { destroy_path: 'feature_flags/1', update_path: 'feature_flags/1', edit_path: 'feature_flags/1/edit', - scopes: [ + strategies: [ { - id: 1, - active: true, - environment_scope: '*', - can_update: true, - protected: false, - created_at: '2019-01-14T06:41:40.987Z', - updated_at: '2019-01-14T06:41:40.987Z', - strategies: [ - { - name: ROLLOUT_STRATEGY_ALL_USERS, - parameters: {}, - }, - ], + id: 9, + name: ROLLOUT_STRATEGY_ALL_USERS, + parameters: {}, + scopes: [{ id: 17, environment_scope: '*' }], }, { - id: 2, - active: false, - environment_scope: 'production', - can_update: true, - protected: false, - created_at: '2019-01-14T06:41:40.987Z', - updated_at: '2019-01-14T06:41:40.987Z', - strategies: [ - { - name: ROLLOUT_STRATEGY_ALL_USERS, - parameters: {}, - }, - ], + id: 8, + name: ROLLOUT_STRATEGY_PERCENT_ROLLOUT, + parameters: {}, + scopes: [{ id: 18, environment_scope: 'review/*' }], }, { - id: 3, - active: false, - environment_scope: 'review/*', - can_update: true, - protected: false, - created_at: '2019-01-14T06:41:40.987Z', - updated_at: '2019-01-14T06:41:40.987Z', - strategies: [ - { - name: ROLLOUT_STRATEGY_ALL_USERS, - parameters: {}, - }, - ], - }, - { - id: 4, - active: true, - environment_scope: 'development', - can_update: true, - protected: false, - created_at: '2019-01-14T06:41:40.987Z', - updated_at: '2019-01-14T06:41:40.987Z', - strategies: [ - { - name: ROLLOUT_STRATEGY_PERCENT_ROLLOUT, - parameters: { - percentage: '86', - }, - }, - ], - }, - { - id: 5, - active: true, - environment_scope: 'development', - can_update: true, - protected: false, - created_at: '2019-01-14T06:41:40.987Z', - updated_at: '2019-01-14T06:41:40.987Z', - strategies: [ - { - name: ROLLOUT_STRATEGY_FLEXIBLE_ROLLOUT, - parameters: { - rollout: '42', - stickiness: 'DEFAULT', - }, - }, - ], + id: 7, + name: ROLLOUT_STRATEGY_USER_ID, + parameters: { userIds: '1,2,3,4' }, + scopes: [{ id: 19, environment_scope: 'production' }], }, ], }; diff --git a/spec/frontend/feature_flags/store/edit/actions_spec.js b/spec/frontend/feature_flags/store/edit/actions_spec.js index afcac53468c..12fccd79170 100644 --- a/spec/frontend/feature_flags/store/edit/actions_spec.js +++ b/spec/frontend/feature_flags/store/edit/actions_spec.js @@ -1,11 +1,7 @@ import MockAdapter from 'axios-mock-adapter'; import testAction from 'helpers/vuex_action_helper'; import { TEST_HOST } from 'spec/test_constants'; -import { - NEW_VERSION_FLAG, - LEGACY_FLAG, - ROLLOUT_STRATEGY_ALL_USERS, -} from '~/feature_flags/constants'; +import { ROLLOUT_STRATEGY_ALL_USERS } from '~/feature_flags/constants'; import { updateFeatureFlag, requestUpdateFeatureFlag, @@ -19,7 +15,7 @@ import { } from '~/feature_flags/store/edit/actions'; import * as types from '~/feature_flags/store/edit/mutation_types'; import state from '~/feature_flags/store/edit/state'; -import { mapStrategiesToRails, mapFromScopesViewModel } from '~/feature_flags/store/helpers'; +import { mapStrategiesToRails } from '~/feature_flags/store/helpers'; import axios from '~/lib/utils/axios_utils'; jest.mock('~/lib/utils/url_utility'); @@ -46,46 +42,9 @@ describe('Feature flags Edit Module actions', () => { describe('success', () => { it('dispatches requestUpdateFeatureFlag and receiveUpdateFeatureFlagSuccess ', (done) => { const featureFlag = { - name: 'feature_flag', - description: 'feature flag', - scopes: [ - { - id: '1', - environmentScope: '*', - active: true, - shouldBeDestroyed: false, - canUpdate: true, - protected: false, - rolloutStrategy: ROLLOUT_STRATEGY_ALL_USERS, - }, - ], - version: LEGACY_FLAG, - active: true, - }; - mock.onPut(mockedState.endpoint, mapFromScopesViewModel(featureFlag)).replyOnce(200); - - testAction( - updateFeatureFlag, - featureFlag, - mockedState, - [], - [ - { - type: 'requestUpdateFeatureFlag', - }, - { - type: 'receiveUpdateFeatureFlagSuccess', - }, - ], - done, - ); - }); - it('handles new version flags as well', (done) => { - const featureFlag = { name: 'name', description: 'description', active: true, - version: NEW_VERSION_FLAG, strategies: [ { name: ROLLOUT_STRATEGY_ALL_USERS, diff --git a/spec/frontend/feature_flags/store/helpers_spec.js b/spec/frontend/feature_flags/store/helpers_spec.js index 711e2a1286e..2a6211c8cc1 100644 --- a/spec/frontend/feature_flags/store/helpers_spec.js +++ b/spec/frontend/feature_flags/store/helpers_spec.js @@ -1,351 +1,7 @@ -import { uniqueId } from 'lodash'; -import { - ROLLOUT_STRATEGY_ALL_USERS, - ROLLOUT_STRATEGY_PERCENT_ROLLOUT, - ROLLOUT_STRATEGY_USER_ID, - PERCENT_ROLLOUT_GROUP_ID, - INTERNAL_ID_PREFIX, - DEFAULT_PERCENT_ROLLOUT, - LEGACY_FLAG, - NEW_VERSION_FLAG, -} from '~/feature_flags/constants'; -import { - mapToScopesViewModel, - mapFromScopesViewModel, - createNewEnvironmentScope, - mapStrategiesToViewModel, - mapStrategiesToRails, -} from '~/feature_flags/store/helpers'; +import { NEW_VERSION_FLAG } from '~/feature_flags/constants'; +import { mapStrategiesToViewModel, mapStrategiesToRails } from '~/feature_flags/store/helpers'; describe('feature flags helpers spec', () => { - describe('mapToScopesViewModel', () => { - it('converts the data object from the Rails API into something more usable by Vue', () => { - const input = [ - { - id: 3, - environment_scope: 'environment_scope', - active: true, - can_update: true, - protected: true, - strategies: [ - { - name: ROLLOUT_STRATEGY_PERCENT_ROLLOUT, - parameters: { - percentage: '56', - }, - }, - { - name: ROLLOUT_STRATEGY_USER_ID, - parameters: { - userIds: '123,234', - }, - }, - ], - - _destroy: true, - }, - ]; - - const expected = [ - expect.objectContaining({ - id: 3, - environmentScope: 'environment_scope', - active: true, - canUpdate: true, - protected: true, - rolloutStrategy: ROLLOUT_STRATEGY_PERCENT_ROLLOUT, - rolloutPercentage: '56', - rolloutUserIds: '123, 234', - shouldBeDestroyed: true, - }), - ]; - - const actual = mapToScopesViewModel(input); - - expect(actual).toEqual(expected); - }); - - it('returns Boolean properties even when their Rails counterparts were not provided (are `undefined`)', () => { - const input = [ - { - id: 3, - environment_scope: 'environment_scope', - }, - ]; - - const [result] = mapToScopesViewModel(input); - - expect(result).toEqual( - expect.objectContaining({ - active: false, - canUpdate: false, - protected: false, - shouldBeDestroyed: false, - }), - ); - }); - - it('returns an empty array if null or undefined is provided as a parameter', () => { - expect(mapToScopesViewModel(null)).toEqual([]); - expect(mapToScopesViewModel(undefined)).toEqual([]); - }); - - describe('with user IDs per environment', () => { - let oldGon; - - beforeEach(() => { - oldGon = window.gon; - window.gon = { features: { featureFlagsUsersPerEnvironment: true } }; - }); - - afterEach(() => { - window.gon = oldGon; - }); - - it('sets the user IDs as a comma separated string', () => { - const input = [ - { - id: 3, - environment_scope: 'environment_scope', - active: true, - can_update: true, - protected: true, - strategies: [ - { - name: ROLLOUT_STRATEGY_PERCENT_ROLLOUT, - parameters: { - percentage: '56', - }, - }, - { - name: ROLLOUT_STRATEGY_USER_ID, - parameters: { - userIds: '123,234', - }, - }, - ], - - _destroy: true, - }, - ]; - - const expected = [ - { - id: 3, - environmentScope: 'environment_scope', - active: true, - canUpdate: true, - protected: true, - rolloutStrategy: ROLLOUT_STRATEGY_PERCENT_ROLLOUT, - rolloutPercentage: '56', - rolloutUserIds: '123, 234', - shouldBeDestroyed: true, - shouldIncludeUserIds: true, - }, - ]; - - const actual = mapToScopesViewModel(input); - - expect(actual).toEqual(expected); - }); - }); - }); - - describe('mapFromScopesViewModel', () => { - it('converts the object emitted from the Vue component into an object than is in the right format to be submitted to the Rails API', () => { - const input = { - name: 'name', - description: 'description', - active: true, - scopes: [ - { - id: 4, - environmentScope: 'environmentScope', - active: true, - canUpdate: true, - protected: true, - shouldBeDestroyed: true, - shouldIncludeUserIds: true, - rolloutStrategy: ROLLOUT_STRATEGY_PERCENT_ROLLOUT, - rolloutPercentage: '48', - rolloutUserIds: '123, 234', - }, - ], - }; - - const expected = { - operations_feature_flag: { - name: 'name', - description: 'description', - active: true, - version: LEGACY_FLAG, - scopes_attributes: [ - { - id: 4, - environment_scope: 'environmentScope', - active: true, - can_update: true, - protected: true, - _destroy: true, - strategies: [ - { - name: ROLLOUT_STRATEGY_PERCENT_ROLLOUT, - parameters: { - groupId: PERCENT_ROLLOUT_GROUP_ID, - percentage: '48', - }, - }, - { - name: ROLLOUT_STRATEGY_USER_ID, - parameters: { - userIds: '123,234', - }, - }, - ], - }, - ], - }, - }; - - const actual = mapFromScopesViewModel(input); - - expect(actual).toEqual(expected); - }); - - it('should strip out internal IDs', () => { - const input = { - scopes: [{ id: 3 }, { id: uniqueId(INTERNAL_ID_PREFIX) }], - }; - - const result = mapFromScopesViewModel(input); - const [realId, internalId] = result.operations_feature_flag.scopes_attributes; - - expect(realId.id).toBe(3); - expect(internalId.id).toBeUndefined(); - }); - - it('returns scopes_attributes as [] if param.scopes is null or undefined', () => { - let { - operations_feature_flag: { scopes_attributes: actualScopes }, - } = mapFromScopesViewModel({ scopes: null }); - - expect(actualScopes).toEqual([]); - - ({ - operations_feature_flag: { scopes_attributes: actualScopes }, - } = mapFromScopesViewModel({ scopes: undefined })); - - expect(actualScopes).toEqual([]); - }); - describe('with user IDs per environment', () => { - it('sets the user IDs as a comma separated string', () => { - const input = { - name: 'name', - description: 'description', - active: true, - scopes: [ - { - id: 4, - environmentScope: 'environmentScope', - active: true, - canUpdate: true, - protected: true, - shouldBeDestroyed: true, - rolloutStrategy: ROLLOUT_STRATEGY_PERCENT_ROLLOUT, - rolloutPercentage: '48', - rolloutUserIds: '123, 234', - shouldIncludeUserIds: true, - }, - ], - }; - - const expected = { - operations_feature_flag: { - name: 'name', - description: 'description', - version: LEGACY_FLAG, - active: true, - scopes_attributes: [ - { - id: 4, - environment_scope: 'environmentScope', - active: true, - can_update: true, - protected: true, - _destroy: true, - strategies: [ - { - name: ROLLOUT_STRATEGY_PERCENT_ROLLOUT, - parameters: { - groupId: PERCENT_ROLLOUT_GROUP_ID, - percentage: '48', - }, - }, - { - name: ROLLOUT_STRATEGY_USER_ID, - parameters: { - userIds: '123,234', - }, - }, - ], - }, - ], - }, - }; - - const actual = mapFromScopesViewModel(input); - - expect(actual).toEqual(expected); - }); - }); - }); - - describe('createNewEnvironmentScope', () => { - it('should return a new environment scope object populated with the default options', () => { - const expected = { - environmentScope: '', - active: false, - id: expect.stringContaining(INTERNAL_ID_PREFIX), - rolloutStrategy: ROLLOUT_STRATEGY_ALL_USERS, - rolloutPercentage: DEFAULT_PERCENT_ROLLOUT, - rolloutUserIds: '', - }; - - const actual = createNewEnvironmentScope(); - - expect(actual).toEqual(expected); - }); - - it('should return a new environment scope object with overrides applied', () => { - const overrides = { - environmentScope: 'environmentScope', - active: true, - }; - - const expected = { - environmentScope: 'environmentScope', - active: true, - id: expect.stringContaining(INTERNAL_ID_PREFIX), - rolloutStrategy: ROLLOUT_STRATEGY_ALL_USERS, - rolloutPercentage: DEFAULT_PERCENT_ROLLOUT, - rolloutUserIds: '', - }; - - const actual = createNewEnvironmentScope(overrides); - - expect(actual).toEqual(expected); - }); - - it('sets canUpdate and protected when called with featureFlagPermissions=true', () => { - expect(createNewEnvironmentScope({}, true)).toEqual( - expect.objectContaining({ - canUpdate: true, - protected: false, - }), - ); - }); - }); - describe('mapStrategiesToViewModel', () => { it('should map rails casing to view model casing', () => { expect( @@ -380,14 +36,14 @@ describe('feature flags helpers spec', () => { }); it('inserts spaces between user ids', () => { - const strategy = mapStrategiesToViewModel([ + const [strategy] = mapStrategiesToViewModel([ { id: '1', name: 'userWithId', parameters: { userIds: 'user1,user2,user3' }, scopes: [], }, - ])[0]; + ]); expect(strategy.parameters).toEqual({ userIds: 'user1, user2, user3' }); }); @@ -399,7 +55,6 @@ describe('feature flags helpers spec', () => { mapStrategiesToRails({ name: 'test', description: 'test description', - version: NEW_VERSION_FLAG, active: true, strategies: [ { @@ -421,8 +76,8 @@ describe('feature flags helpers spec', () => { operations_feature_flag: { name: 'test', description: 'test description', - version: NEW_VERSION_FLAG, active: true, + version: NEW_VERSION_FLAG, strategies_attributes: [ { id: '1', @@ -447,7 +102,6 @@ describe('feature flags helpers spec', () => { mapStrategiesToRails({ name: 'test', description: 'test description', - version: NEW_VERSION_FLAG, active: true, strategies: [ { @@ -462,8 +116,8 @@ describe('feature flags helpers spec', () => { operations_feature_flag: { name: 'test', description: 'test description', - version: NEW_VERSION_FLAG, active: true, + version: NEW_VERSION_FLAG, strategies_attributes: [ { id: '1', @@ -483,7 +137,6 @@ describe('feature flags helpers spec', () => { it('removes white space between user ids', () => { const result = mapStrategiesToRails({ name: 'test', - version: NEW_VERSION_FLAG, active: true, strategies: [ { @@ -503,7 +156,6 @@ describe('feature flags helpers spec', () => { it('preserves the value of active', () => { const result = mapStrategiesToRails({ name: 'test', - version: NEW_VERSION_FLAG, active: false, strategies: [], }); diff --git a/spec/frontend/feature_flags/store/new/actions_spec.js b/spec/frontend/feature_flags/store/new/actions_spec.js index 9612d606347..7900b200eb2 100644 --- a/spec/frontend/feature_flags/store/new/actions_spec.js +++ b/spec/frontend/feature_flags/store/new/actions_spec.js @@ -1,8 +1,7 @@ import MockAdapter from 'axios-mock-adapter'; import testAction from 'helpers/vuex_action_helper'; -import { ROLLOUT_STRATEGY_ALL_USERS, NEW_VERSION_FLAG } from '~/feature_flags/constants'; +import { ROLLOUT_STRATEGY_ALL_USERS } from '~/feature_flags/constants'; import { mapStrategiesToRails } from '~/feature_flags/store/helpers'; - import { createFeatureFlag, requestCreateFeatureFlag, @@ -39,7 +38,6 @@ describe('Feature flags New Module Actions', () => { name: 'name', description: 'description', active: true, - version: NEW_VERSION_FLAG, strategies: [ { name: ROLLOUT_STRATEGY_ALL_USERS, @@ -76,7 +74,6 @@ describe('Feature flags New Module Actions', () => { name: 'name', description: 'description', active: true, - version: NEW_VERSION_FLAG, strategies: [ { name: ROLLOUT_STRATEGY_ALL_USERS, |