Commit 22601902 authored by Ezekiel Kigbo's avatar Ezekiel Kigbo

Merge branch 'reset-to-all-when-last-scope-removed' into 'master'

Reset scope to all-environments when last scope removed

See merge request gitlab-org/gitlab!42287
parents 99471d01 372b13e4
......@@ -148,9 +148,8 @@ export default {
},
appliesToAllEnvironments() {
return (
this.filteredEnvironments.length === 0 ||
(this.filteredEnvironments.length === 1 &&
this.filteredEnvironments[0].environmentScope === '*')
this.filteredEnvironments.length === 1 &&
this.filteredEnvironments[0].environmentScope === '*'
);
},
filteredEnvironments() {
......@@ -203,6 +202,9 @@ export default {
} else {
this.environments = this.environments.filter(e => e !== environment);
}
if (this.filteredEnvironments.length === 0) {
this.environments.push({ environmentScope: '*' });
}
this.onStrategyChange();
},
isStrategyType(type) {
......
---
title: Reset scope to all-environments when last scope removed
merge_request: 42287
author:
type: fixed
......@@ -160,7 +160,38 @@ describe('Feature flags strategy', () => {
});
describe('with a strategy', () => {
describe('with scopes defined', () => {
describe('with a single environment scope defined', () => {
let strategy;
beforeEach(() => {
strategy = {
name: ROLLOUT_STRATEGY_PERCENT_ROLLOUT,
parameters: { percentage: '50' },
scopes: [{ environmentScope: 'production' }],
};
const propsData = { strategy, index: 0, endpoint: '' };
factory({ propsData, provide });
});
it('should revert to all-environments scope when last scope is removed', () => {
const token = wrapper.find(GlToken);
token.vm.$emit('close');
return wrapper.vm.$nextTick().then(() => {
expect(wrapper.findAll(GlToken)).toHaveLength(0);
expect(wrapper.emitted('change')).toEqual([
[
{
name: ROLLOUT_STRATEGY_PERCENT_ROLLOUT,
parameters: { percentage: '50', groupId: PERCENT_ROLLOUT_GROUP_ID },
scopes: [{ environmentScope: '*' }],
},
],
]);
});
});
});
describe('with an all-environments scope defined', () => {
let strategy;
beforeEach(() => {
......
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