Reduce code duplication

parent 24574e32
...@@ -9,8 +9,35 @@ import { ...@@ -9,8 +9,35 @@ import {
const localVue = createLocalVue(); const localVue = createLocalVue();
const getDefaultProps = () => ({
featureFlags: [
{
id: 1,
active: true,
name: 'flag name',
description: 'flag description',
destroy_path: 'destroy/path',
edit_path: 'edit/path',
scopes: [
{
id: 1,
active: true,
environmentScope: 'scope',
canUpdate: true,
protected: false,
rolloutStrategy: ROLLOUT_STRATEGY_ALL_USERS,
rolloutPercentage: DEFAULT_PERCENT_ROLLOUT,
shouldBeDestroyed: false,
},
],
},
],
csrfToken: 'fakeToken',
});
describe('Feature flag table', () => { describe('Feature flag table', () => {
let wrapper; let wrapper;
let props;
const createWrapper = (propsData, opts = {}) => { const createWrapper = (propsData, opts = {}) => {
wrapper = shallowMount(FeatureFlagsTable, { wrapper = shallowMount(FeatureFlagsTable, {
...@@ -21,6 +48,10 @@ describe('Feature flag table', () => { ...@@ -21,6 +48,10 @@ describe('Feature flag table', () => {
}); });
}; };
beforeEach(() => {
props = getDefaultProps();
});
afterEach(() => { afterEach(() => {
wrapper.destroy(); wrapper.destroy();
wrapper = null; wrapper = null;
...@@ -28,37 +59,10 @@ describe('Feature flag table', () => { ...@@ -28,37 +59,10 @@ describe('Feature flag table', () => {
describe('with an active scope and a standard rollout strategy', () => { describe('with an active scope and a standard rollout strategy', () => {
beforeEach(() => { beforeEach(() => {
createWrapper( props.featureFlags[0].iid = 1;
{ createWrapper(props, {
featureFlags: [ provide: { glFeatures: { featureFlagIID: true } },
{ });
id: 1,
iid: 1,
active: true,
name: 'flag name',
description: 'flag description',
destroy_path: 'destroy/path',
edit_path: 'edit/path',
scopes: [
{
id: 1,
active: true,
environmentScope: 'scope',
canUpdate: true,
protected: false,
rolloutStrategy: ROLLOUT_STRATEGY_ALL_USERS,
rolloutPercentage: DEFAULT_PERCENT_ROLLOUT,
shouldBeDestroyed: false,
},
],
},
],
csrfToken: 'fakeToken',
},
{
provide: { glFeatures: { featureFlagIID: true } },
},
);
}); });
it('Should render a table', () => { it('Should render a table', () => {
...@@ -111,31 +115,9 @@ describe('Feature flag table', () => { ...@@ -111,31 +115,9 @@ describe('Feature flag table', () => {
describe('with an active scope and a percentage rollout strategy', () => { describe('with an active scope and a percentage rollout strategy', () => {
beforeEach(() => { beforeEach(() => {
createWrapper({ props.featureFlags[0].scopes[0].rolloutStrategy = ROLLOUT_STRATEGY_PERCENT_ROLLOUT;
featureFlags: [ props.featureFlags[0].scopes[0].rolloutPercentage = '54';
{ createWrapper(props);
id: 1,
active: true,
name: 'flag name',
description: 'flag description',
destroy_path: 'destroy/path',
edit_path: 'edit/path',
scopes: [
{
id: 1,
active: true,
environmentScope: 'scope',
canUpdate: true,
protected: false,
rolloutStrategy: ROLLOUT_STRATEGY_PERCENT_ROLLOUT,
rolloutPercentage: '54',
shouldBeDestroyed: false,
},
],
},
],
csrfToken: 'fakeToken',
});
}); });
it('should render an environments specs badge with percentage', () => { it('should render an environments specs badge with percentage', () => {
...@@ -147,31 +129,8 @@ describe('Feature flag table', () => { ...@@ -147,31 +129,8 @@ describe('Feature flag table', () => {
describe('with an inactive scope', () => { describe('with an inactive scope', () => {
beforeEach(() => { beforeEach(() => {
createWrapper({ props.featureFlags[0].scopes[0].active = false;
featureFlags: [ createWrapper(props);
{
id: 1,
active: true,
name: 'flag name',
description: 'flag description',
destroy_path: 'destroy/path',
edit_path: 'edit/path',
scopes: [
{
id: 1,
active: false,
environmentScope: 'scope',
canUpdate: true,
protected: false,
rolloutStrategy: ROLLOUT_STRATEGY_ALL_USERS,
rolloutPercentage: DEFAULT_PERCENT_ROLLOUT,
shouldBeDestroyed: false,
},
],
},
],
csrfToken: 'fakeToken',
});
}); });
it('should render an environments specs badge with inactive class', () => { it('should render an environments specs badge with inactive class', () => {
......
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