diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-06-22 09:07:26 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-06-22 09:07:26 +0300 |
commit | be3e27e39dd5c1a72fd4c296858322748db53a26 (patch) | |
tree | 900287c92f91260e3fd20c2237d018427339d821 /spec/frontend/feature_flags | |
parent | 0051266ae2e3398baa174f990fd8833b973b2b0e (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/feature_flags')
3 files changed, 57 insertions, 149 deletions
diff --git a/spec/frontend/feature_flags/components/feature_flags_table_spec.js b/spec/frontend/feature_flags/components/feature_flags_table_spec.js index 816bc9b9707..d06d60ae310 100644 --- a/spec/frontend/feature_flags/components/feature_flags_table_spec.js +++ b/spec/frontend/feature_flags/components/feature_flags_table_spec.js @@ -8,9 +8,6 @@ import { ROLLOUT_STRATEGY_PERCENT_ROLLOUT, ROLLOUT_STRATEGY_USER_ID, ROLLOUT_STRATEGY_GITLAB_USER_LIST, - NEW_VERSION_FLAG, - LEGACY_FLAG, - DEFAULT_PERCENT_ROLLOUT, } from '~/feature_flags/constants'; const getDefaultProps = () => ({ @@ -23,17 +20,28 @@ const getDefaultProps = () => ({ description: 'flag description', destroy_path: 'destroy/path', edit_path: 'edit/path', - version: LEGACY_FLAG, - scopes: [ + scopes: [], + strategies: [ { - id: 1, - active: true, - environmentScope: 'scope', - canUpdate: true, - protected: false, - rolloutStrategy: ROLLOUT_STRATEGY_ALL_USERS, - rolloutPercentage: DEFAULT_PERCENT_ROLLOUT, - shouldBeDestroyed: false, + name: ROLLOUT_STRATEGY_ALL_USERS, + parameters: {}, + scopes: [{ environment_scope: '*' }], + }, + { + name: ROLLOUT_STRATEGY_PERCENT_ROLLOUT, + parameters: { percentage: '50' }, + scopes: [{ environment_scope: 'production' }, { environment_scope: 'staging' }], + }, + { + name: ROLLOUT_STRATEGY_USER_ID, + parameters: { userIds: '1,2,3,4' }, + scopes: [{ environment_scope: 'review/*' }], + }, + { + name: ROLLOUT_STRATEGY_GITLAB_USER_LIST, + parameters: {}, + user_list: { name: 'test list' }, + scopes: [{ environment_scope: '*' }], }, ], }, @@ -43,6 +51,7 @@ const getDefaultProps = () => ({ describe('Feature flag table', () => { let wrapper; let props; + let badges; const createWrapper = (propsData, opts = {}) => { wrapper = shallowMount(FeatureFlagsTable, { @@ -56,6 +65,15 @@ describe('Feature flag table', () => { beforeEach(() => { props = getDefaultProps(); + createWrapper(props, { + provide: { csrfToken: 'fakeToken' }, + }); + + badges = wrapper.findAll('[data-testid="strategy-badge"]'); + }); + + beforeEach(() => { + props = getDefaultProps(); }); afterEach(() => { @@ -97,17 +115,10 @@ describe('Feature flag table', () => { ); }); - it('should render an environments specs column', () => { - const envColumn = wrapper.find('.js-feature-flag-environments'); - - expect(envColumn).toBeDefined(); - expect(trimText(envColumn.text())).toBe('scope'); - }); - it('should render an environments specs badge with active class', () => { const envColumn = wrapper.find('.js-feature-flag-environments'); - expect(trimText(envColumn.find(GlBadge).text())).toBe('scope'); + expect(trimText(envColumn.find(GlBadge).text())).toBe('All Users: All Environments'); }); it('should render an actions column', () => { @@ -120,11 +131,13 @@ describe('Feature flag table', () => { describe('when active and with an update toggle', () => { let toggle; + let spy; beforeEach(() => { props.featureFlags[0].update_path = props.featureFlags[0].destroy_path; createWrapper(props); toggle = wrapper.find(GlToggle); + spy = mockTracking('_category_', toggle.element, jest.spyOn); }); it('should have a toggle', () => { @@ -143,123 +156,40 @@ describe('Feature flag table', () => { expect(wrapper.emitted('toggle-flag')).toEqual([[flag]]); }); }); - }); - - describe('with an active scope and a percentage rollout strategy', () => { - beforeEach(() => { - props.featureFlags[0].scopes[0].rolloutStrategy = ROLLOUT_STRATEGY_PERCENT_ROLLOUT; - props.featureFlags[0].scopes[0].rolloutPercentage = '54'; - createWrapper(props); - }); - it('should render an environments specs badge with percentage', () => { - const envColumn = wrapper.find('.js-feature-flag-environments'); + it('tracks a click', () => { + toggle.trigger('click'); - expect(trimText(envColumn.find(GlBadge).text())).toBe('scope: 54%'); + expect(spy).toHaveBeenCalledWith('_category_', 'click_button', { + label: 'feature_flag_toggle', + }); }); }); - describe('with an inactive scope', () => { - beforeEach(() => { - props.featureFlags[0].scopes[0].active = false; - createWrapper(props); - }); - - it('should render an environments specs badge with inactive class', () => { - const envColumn = wrapper.find('.js-feature-flag-environments'); - - expect(trimText(envColumn.find(GlBadge).text())).toBe('scope'); - }); + it('shows All Environments if the environment scope is *', () => { + expect(badges.at(0).text()).toContain('All Environments'); }); - describe('with a new version flag', () => { - let toggle; - let spy; - let badges; - - beforeEach(() => { - const newVersionProps = { - ...props, - featureFlags: [ - { - id: 1, - iid: 1, - active: true, - name: 'flag name', - description: 'flag description', - destroy_path: 'destroy/path', - edit_path: 'edit/path', - update_path: 'update/path', - version: NEW_VERSION_FLAG, - scopes: [], - strategies: [ - { - name: ROLLOUT_STRATEGY_ALL_USERS, - parameters: {}, - scopes: [{ environment_scope: '*' }], - }, - { - name: ROLLOUT_STRATEGY_PERCENT_ROLLOUT, - parameters: { percentage: '50' }, - scopes: [{ environment_scope: 'production' }, { environment_scope: 'staging' }], - }, - { - name: ROLLOUT_STRATEGY_USER_ID, - parameters: { userIds: '1,2,3,4' }, - scopes: [{ environment_scope: 'review/*' }], - }, - { - name: ROLLOUT_STRATEGY_GITLAB_USER_LIST, - parameters: {}, - user_list: { name: 'test list' }, - scopes: [{ environment_scope: '*' }], - }, - ], - }, - ], - }; - createWrapper(newVersionProps, { - provide: { csrfToken: 'fakeToken', glFeatures: { featureFlagsNewVersion: true } }, - }); - - toggle = wrapper.find(GlToggle); - spy = mockTracking('_category_', toggle.element, jest.spyOn); - badges = wrapper.findAll('[data-testid="strategy-badge"]'); - }); - - it('shows All Environments if the environment scope is *', () => { - expect(badges.at(0).text()).toContain('All Environments'); - }); - - it('shows the environment scope if another is set', () => { - expect(badges.at(1).text()).toContain('production'); - expect(badges.at(1).text()).toContain('staging'); - expect(badges.at(2).text()).toContain('review/*'); - }); - - it('shows All Users for the default strategy', () => { - expect(badges.at(0).text()).toContain('All Users'); - }); - - it('shows the percent for a percent rollout', () => { - expect(badges.at(1).text()).toContain('Percent of users - 50%'); - }); + it('shows the environment scope if another is set', () => { + expect(badges.at(1).text()).toContain('production'); + expect(badges.at(1).text()).toContain('staging'); + expect(badges.at(2).text()).toContain('review/*'); + }); - it('shows the number of users for users with ID', () => { - expect(badges.at(2).text()).toContain('User IDs - 4 users'); - }); + it('shows All Users for the default strategy', () => { + expect(badges.at(0).text()).toContain('All Users'); + }); - it('shows the name of a user list for user list', () => { - expect(badges.at(3).text()).toContain('User List - test list'); - }); + it('shows the percent for a percent rollout', () => { + expect(badges.at(1).text()).toContain('Percent of users - 50%'); + }); - it('tracks a click', () => { - toggle.trigger('click'); + it('shows the number of users for users with ID', () => { + expect(badges.at(2).text()).toContain('User IDs - 4 users'); + }); - expect(spy).toHaveBeenCalledWith('_category_', 'click_button', { - label: 'feature_flag_toggle', - }); - }); + it('shows the name of a user list for user list', () => { + expect(badges.at(3).text()).toContain('User List - test list'); }); it('renders a feature flag without an iid', () => { diff --git a/spec/frontend/feature_flags/store/index/actions_spec.js b/spec/frontend/feature_flags/store/index/actions_spec.js index ec311ef92a3..a59f99f538c 100644 --- a/spec/frontend/feature_flags/store/index/actions_spec.js +++ b/spec/frontend/feature_flags/store/index/actions_spec.js @@ -1,7 +1,6 @@ import MockAdapter from 'axios-mock-adapter'; import testAction from 'helpers/vuex_action_helper'; import { TEST_HOST } from 'spec/test_constants'; -import { mapToScopesViewModel } from '~/feature_flags/store/helpers'; import { requestFeatureFlags, receiveFeatureFlagsSuccess, @@ -255,7 +254,6 @@ describe('Feature flags actions', () => { beforeEach(() => { mockedState.featureFlags = getRequestData.feature_flags.map((flag) => ({ ...flag, - scopes: mapToScopesViewModel(flag.scopes || []), })); mock = new MockAdapter(axios); }); @@ -314,7 +312,6 @@ describe('Feature flags actions', () => { beforeEach(() => { mockedState.featureFlags = getRequestData.feature_flags.map((f) => ({ ...f, - scopes: mapToScopesViewModel(f.scopes || []), })); }); @@ -338,7 +335,6 @@ describe('Feature flags actions', () => { beforeEach(() => { mockedState.featureFlags = getRequestData.feature_flags.map((f) => ({ ...f, - scopes: mapToScopesViewModel(f.scopes || []), })); }); @@ -362,7 +358,6 @@ describe('Feature flags actions', () => { beforeEach(() => { mockedState.featureFlags = getRequestData.feature_flags.map((f) => ({ ...f, - scopes: mapToScopesViewModel(f.scopes || []), })); }); diff --git a/spec/frontend/feature_flags/store/index/mutations_spec.js b/spec/frontend/feature_flags/store/index/mutations_spec.js index b9354196c68..c19f459e124 100644 --- a/spec/frontend/feature_flags/store/index/mutations_spec.js +++ b/spec/frontend/feature_flags/store/index/mutations_spec.js @@ -1,4 +1,3 @@ -import { mapToScopesViewModel } from '~/feature_flags/store/helpers'; import * as types from '~/feature_flags/store/index/mutation_types'; import mutations from '~/feature_flags/store/index/mutations'; import state from '~/feature_flags/store/index/state'; @@ -49,15 +48,6 @@ describe('Feature flags store Mutations', () => { expect(stateCopy.hasError).toEqual(false); }); - it('should set featureFlags with the transformed data', () => { - const expected = getRequestData.feature_flags.map((flag) => ({ - ...flag, - scopes: mapToScopesViewModel(flag.scopes || []), - })); - - expect(stateCopy.featureFlags).toEqual(expected); - }); - it('should set count with the given data', () => { expect(stateCopy.count).toEqual(37); }); @@ -131,13 +121,11 @@ describe('Feature flags store Mutations', () => { beforeEach(() => { stateCopy.featureFlags = getRequestData.feature_flags.map((flag) => ({ ...flag, - scopes: mapToScopesViewModel(flag.scopes || []), })); stateCopy.count = { featureFlags: 1, userLists: 0 }; mutations[types.UPDATE_FEATURE_FLAG](stateCopy, { ...featureFlag, - scopes: mapToScopesViewModel(featureFlag.scopes || []), active: false, }); }); @@ -146,7 +134,6 @@ describe('Feature flags store Mutations', () => { expect(stateCopy.featureFlags).toEqual([ { ...featureFlag, - scopes: mapToScopesViewModel(featureFlag.scopes || []), active: false, }, ]); @@ -158,7 +145,6 @@ describe('Feature flags store Mutations', () => { stateCopy.featureFlags = getRequestData.feature_flags.map((flag) => ({ ...flag, ...flagState, - scopes: mapToScopesViewModel(flag.scopes || []), })); stateCopy.count = stateCount; @@ -174,7 +160,6 @@ describe('Feature flags store Mutations', () => { expect(stateCopy.featureFlags).toEqual([ { ...featureFlag, - scopes: mapToScopesViewModel(featureFlag.scopes || []), active: false, }, ]); @@ -185,7 +170,6 @@ describe('Feature flags store Mutations', () => { beforeEach(() => { stateCopy.featureFlags = getRequestData.feature_flags.map((flag) => ({ ...flag, - scopes: mapToScopesViewModel(flag.scopes || []), })); mutations[types.RECEIVE_UPDATE_FEATURE_FLAG_ERROR](stateCopy, featureFlag.id); }); @@ -194,7 +178,6 @@ describe('Feature flags store Mutations', () => { expect(stateCopy.featureFlags).toEqual([ { ...featureFlag, - scopes: mapToScopesViewModel(featureFlag.scopes || []), active: false, }, ]); |