Commit 08e00281 authored by Fernando's avatar Fernando

Optimize unit tests to use describe.each with parameters

- Update unit tests in rule_form_spec
- Update unit tests in project_security_rules
- Update unit tests in uncnfigured_security_rules
parent cfdf5c3b
...@@ -129,51 +129,32 @@ describe('Approvals ProjectRules', () => { ...@@ -129,51 +129,32 @@ describe('Approvals ProjectRules', () => {
}); });
}); });
describe('when the approvalSuggestions feature flag is enabled', () => { describe.each([true, false])(
beforeEach(() => { 'when the approvalSuggestions feature flag is %p',
const rules = createProjectRules(); approvalSuggestions => {
rules[0].name = 'Vulnerability-Check'; beforeEach(() => {
store.modules.approvals.state.rules = rules; const rules = createProjectRules();
store.state.settings.allowMultiRule = true; rules[0].name = 'Vulnerability-Check';
}); store.modules.approvals.state.rules = rules;
store.state.settings.allowMultiRule = true;
beforeEach(() => { });
factory(
{}, beforeEach(() => {
{ factory(
provide: { {},
glFeatures: { approvalSuggestions: true }, {
provide: {
glFeatures: { approvalSuggestions },
},
}, },
}, );
); });
});
it(`should ${
it('should render the unconfigured-security-rules component', () => { approvalSuggestions ? '' : 'not'
expect(wrapper.contains(UnconfiguredSecurityRules)).toBe(true); } render the unconfigured-security-rule component`, () => {
}); expect(wrapper.contains(UnconfiguredSecurityRules)).toBe(approvalSuggestions);
}); });
},
describe('when the approvalSuggestions feature flag is disabled', () => { );
beforeEach(() => {
const rules = createProjectRules();
rules[0].name = 'Vulnerability-Check';
store.modules.approvals.state.rules = rules;
store.state.settings.allowMultiRule = true;
});
beforeEach(() => {
factory(
{},
{
provide: {
glFeatures: { approvalSuggestions: false },
},
},
);
});
it('should not render the unconfigured-security-rule component', () => {
expect(wrapper.contains(UnconfiguredSecurityRules)).toBe(false);
});
});
}); });
...@@ -483,65 +483,35 @@ describe('EE Approvals RuleForm', () => { ...@@ -483,65 +483,35 @@ describe('EE Approvals RuleForm', () => {
}); });
describe('with approvalSuggestions enabled', () => { describe('with approvalSuggestions enabled', () => {
describe('with initRuleFieldName set to Vulnerability-Check', () => { describe.each`
beforeEach(() => { defaultRuleName | expectedDisabledAttribute
createComponent( ${'Vulnerability-Check'} | ${'disabled'}
{ ${'License-Check'} | ${'disabled'}
initRule: null, ${'Foo Bar Baz'} | ${undefined}
defaultRuleName: 'Vulnerability-Check', `(
}, 'with defaultRuleName set to $defaultRuleName',
{ ({ defaultRuleName, expectedDisabledAttribute }) => {
provide: { beforeEach(() => {
glFeatures: { approvalSuggestions: true }, createComponent(
{
initRule: null,
defaultRuleName,
}, },
}, {
); provide: {
}); glFeatures: { approvalSuggestions: true },
},
it('it disables the name text field', () => {
expect(findNameInput().attributes('disabled')).toBe('disabled');
});
});
describe('with initRuleFieldName set to License-Check', () => {
beforeEach(() => {
createComponent(
{
initRule: null,
defaultRuleName: 'License-Check',
},
{
provide: {
glFeatures: { approvalSuggestions: true },
},
},
);
});
it('it disables the name text field', () => {
expect(findNameInput().attributes('disabled')).toBe('disabled');
});
});
describe('with initRuleFieldName set to any other string', () => {
beforeEach(() => {
createComponent(
{
initRule: null,
defaultRuleName: 'Foo Bar Baz',
},
{
provide: {
glFeatures: { approvalSuggestions: true },
}, },
}, );
); });
});
it('does not disable the name text field', () => { it(`it ${
expect(findNameInput().attributes('disabled')).toBe(undefined); expectedDisabledAttribute ? 'disables' : 'does not disable'
}); } the name text field`, () => {
}); expect(findNameInput().attributes('disabled')).toBe(expectedDisabledAttribute);
});
},
);
}); });
describe('with new License-Check rule', () => { describe('with new License-Check rule', () => {
......
...@@ -47,7 +47,10 @@ describe('UnconfiguredSecurityRules component', () => { ...@@ -47,7 +47,10 @@ describe('UnconfiguredSecurityRules component', () => {
}); });
it('should fetch the security configuration', () => { it('should fetch the security configuration', () => {
expect(store.dispatch).toHaveBeenCalledWith('securityConfiguration/fetchSecurityConfiguration', undefined); expect(store.dispatch).toHaveBeenCalledWith(
'securityConfiguration/fetchSecurityConfiguration',
undefined,
);
}); });
it('should render a unconfigured-security-rule component for every security rule ', () => { it('should render a unconfigured-security-rule component for every security rule ', () => {
...@@ -56,21 +59,23 @@ describe('UnconfiguredSecurityRules component', () => { ...@@ -56,21 +59,23 @@ describe('UnconfiguredSecurityRules component', () => {
}); });
describe.each` describe.each`
approvalsLoading | securityConfigurationLoading | shouldRender approvalsLoading | securityConfigurationLoading | shouldRender
${false} | ${false} | ${false} ${false} | ${false} | ${false}
${true} | ${false} | ${true} ${true} | ${false} | ${true}
${false} | ${true} | ${true} ${false} | ${true} | ${true}
${true} | ${true} | ${true} ${true} | ${true} | ${true}
` `(
('while approvalsLoading is $approvalsLoading and securityConfigurationLoading is $securityConfigurationLoading', ({approvalsLoading, securityConfigurationLoading, shouldRender}) => { 'while approvalsLoading is $approvalsLoading and securityConfigurationLoading is $securityConfigurationLoading',
beforeEach(() => { ({ approvalsLoading, securityConfigurationLoading, shouldRender }) => {
createWrapper(); beforeEach(() => {
store.state.approvals.isLoading = approvalsLoading; createWrapper();
store.state.securityConfiguration.isLoading = securityConfigurationLoading; store.state.approvals.isLoading = approvalsLoading;
}); store.state.securityConfiguration.isLoading = securityConfigurationLoading;
});
it(`should render the loading skeleton is ${shouldRender}`, () => { it(`should ${shouldRender ? '' : 'not'} render the loading skeleton`, () => {
expect(wrapper.contains(GlSkeletonLoading)).toBe(shouldRender); expect(wrapper.contains(GlSkeletonLoading)).toBe(shouldRender);
}); });
}); },
);
}); });
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