Commit be352be2 authored by Paul Slaughter's avatar Paul Slaughter

Use param spec in pipeline_status_badge_spec

This way we're not creating the subject twice
parent 8ded239f
import { merge } from 'lodash';
import { GlBadge, GlIcon } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import PipelineStatusBadge from 'ee/security_dashboard/components/pipeline_status_badge.vue';
......@@ -6,21 +7,15 @@ describe('Pipeline status badge', () => {
let wrapper;
const securityBuildsFailedPath = '/some/path/to/failed/jobs';
const DEFAULT_PROPS = {
pipeline: {
securityBuildsFailedCount: 5,
securityBuildsFailedPath,
},
};
const findGlBadge = () => wrapper.find(GlBadge);
const findGlIcon = () => wrapper.find(GlIcon);
const createProps = securityBuildsFailedCount => ({ pipeline: { securityBuildsFailedCount } });
const createWrapper = ({ props = {} } = {}) => {
const createWrapper = (props = {}) => {
wrapper = shallowMount(PipelineStatusBadge, {
propsData: { ...DEFAULT_PROPS, ...props },
propsData: merge({ pipeline: { securityBuildsFailedPath } }, props),
});
};
......@@ -29,34 +24,33 @@ describe('Pipeline status badge', () => {
wrapper = null;
});
describe('when there are more than 0 failed jobs', () => {
describe.each`
failedCount | expectedMessage
${7} | ${'7 failed security jobs'}
${1} | ${'1 failed security job'}
`('when there are failed jobs ($failedCount)', ({ failedCount, expectedMessage }) => {
beforeEach(() => {
createWrapper();
createWrapper(createProps(failedCount));
});
it('displays correct message for 5 failed jobs', () => {
expect(wrapper.text()).toBe('5 failed security jobs');
it('displays correct message', () => {
expect(wrapper.text()).toBe(expectedMessage);
});
it('links to the correct path', () => {
expect(findGlBadge().attributes('href')).toBe(securityBuildsFailedPath);
});
it('displays correct message for 1 failed job', () => {
createWrapper({ props: createProps(1) });
expect(wrapper.text()).toBe('1 failed security job');
});
});
describe('when there are not more than 0 failed jobs', () => {
it('does not display when there are 0 failed jobs', () => {
createWrapper({ props: createProps(0) });
createWrapper(createProps(0));
expect(findGlBadge().exists()).toBe(false);
expect(findGlIcon().exists()).toBe(false);
});
it('does not display when there is no failed jobs count', () => {
createWrapper({ props: createProps(undefined) });
createWrapper();
expect(findGlBadge().exists()).toBe(false);
expect(findGlIcon().exists()).toBe(false);
});
......
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