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', () => {
});
});
describe('when the approvalSuggestions feature flag is enabled', () => {
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: true },
describe.each([true, false])(
'when the approvalSuggestions feature flag is %p',
approvalSuggestions => {
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 },
},
},
},
);
});
it('should render the unconfigured-security-rules component', () => {
expect(wrapper.contains(UnconfiguredSecurityRules)).toBe(true);
});
});
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);
});
});
);
});
it(`should ${
approvalSuggestions ? '' : 'not'
} render the unconfigured-security-rule component`, () => {
expect(wrapper.contains(UnconfiguredSecurityRules)).toBe(approvalSuggestions);
});
},
);
});
......@@ -483,65 +483,35 @@ describe('EE Approvals RuleForm', () => {
});
describe('with approvalSuggestions enabled', () => {
describe('with initRuleFieldName set to Vulnerability-Check', () => {
beforeEach(() => {
createComponent(
{
initRule: null,
defaultRuleName: 'Vulnerability-Check',
},
{
provide: {
glFeatures: { approvalSuggestions: true },
describe.each`
defaultRuleName | expectedDisabledAttribute
${'Vulnerability-Check'} | ${'disabled'}
${'License-Check'} | ${'disabled'}
${'Foo Bar Baz'} | ${undefined}
`(
'with defaultRuleName set to $defaultRuleName',
({ defaultRuleName, expectedDisabledAttribute }) => {
beforeEach(() => {
createComponent(
{
initRule: null,
defaultRuleName,
},
},
);
});
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 },
{
provide: {
glFeatures: { approvalSuggestions: true },
},
},
},
);
});
);
});
it('does not disable the name text field', () => {
expect(findNameInput().attributes('disabled')).toBe(undefined);
});
});
it(`it ${
expectedDisabledAttribute ? 'disables' : 'does not disable'
} the name text field`, () => {
expect(findNameInput().attributes('disabled')).toBe(expectedDisabledAttribute);
});
},
);
});
describe('with new License-Check rule', () => {
......
......@@ -47,7 +47,10 @@ describe('UnconfiguredSecurityRules component', () => {
});
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 ', () => {
......@@ -56,21 +59,23 @@ describe('UnconfiguredSecurityRules component', () => {
});
describe.each`
approvalsLoading | securityConfigurationLoading | shouldRender
${false} | ${false} | ${false}
${true} | ${false} | ${true}
${false} | ${true} | ${true}
${true} | ${true} | ${true}
`
('while approvalsLoading is $approvalsLoading and securityConfigurationLoading is $securityConfigurationLoading', ({approvalsLoading, securityConfigurationLoading, shouldRender}) => {
beforeEach(() => {
createWrapper();
store.state.approvals.isLoading = approvalsLoading;
store.state.securityConfiguration.isLoading = securityConfigurationLoading;
});
approvalsLoading | securityConfigurationLoading | shouldRender
${false} | ${false} | ${false}
${true} | ${false} | ${true}
${false} | ${true} | ${true}
${true} | ${true} | ${true}
`(
'while approvalsLoading is $approvalsLoading and securityConfigurationLoading is $securityConfigurationLoading',
({ approvalsLoading, securityConfigurationLoading, shouldRender }) => {
beforeEach(() => {
createWrapper();
store.state.approvals.isLoading = approvalsLoading;
store.state.securityConfiguration.isLoading = securityConfigurationLoading;
});
it(`should render the loading skeleton is ${shouldRender}`, () => {
expect(wrapper.contains(GlSkeletonLoading)).toBe(shouldRender);
});
});
it(`should ${shouldRender ? '' : 'not'} render the loading skeleton`, () => {
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