debian-mirror-gitlab/spec/frontend/vue_shared/components/ci_badge_link_spec.js

101 lines
2.5 KiB
JavaScript
Raw Normal View History

2021-03-11 19:13:27 +05:30
import { shallowMount } from '@vue/test-utils';
import CiBadge from '~/vue_shared/components/ci_badge_link.vue';
import CiIcon from '~/vue_shared/components/ci_icon.vue';
2017-08-17 22:00:37 +05:30
describe('CI Badge Link Component', () => {
2021-03-11 19:13:27 +05:30
let wrapper;
2017-08-17 22:00:37 +05:30
const statuses = {
canceled: {
text: 'canceled',
label: 'canceled',
group: 'canceled',
2018-03-17 18:26:18 +05:30
icon: 'status_canceled',
2017-08-17 22:00:37 +05:30
details_path: 'status/canceled',
},
created: {
text: 'created',
label: 'created',
group: 'created',
2018-03-17 18:26:18 +05:30
icon: 'status_created',
2017-08-17 22:00:37 +05:30
details_path: 'status/created',
},
failed: {
text: 'failed',
label: 'failed',
group: 'failed',
2018-03-17 18:26:18 +05:30
icon: 'status_failed',
2017-08-17 22:00:37 +05:30
details_path: 'status/failed',
},
manual: {
text: 'manual',
label: 'manual action',
group: 'manual',
2018-03-17 18:26:18 +05:30
icon: 'status_manual',
2017-08-17 22:00:37 +05:30
details_path: 'status/manual',
},
pending: {
text: 'pending',
label: 'pending',
group: 'pending',
2018-03-17 18:26:18 +05:30
icon: 'status_pending',
2017-08-17 22:00:37 +05:30
details_path: 'status/pending',
},
running: {
text: 'running',
label: 'running',
group: 'running',
2018-03-17 18:26:18 +05:30
icon: 'status_running',
2017-08-17 22:00:37 +05:30
details_path: 'status/running',
},
skipped: {
text: 'skipped',
label: 'skipped',
group: 'skipped',
2018-03-17 18:26:18 +05:30
icon: 'status_skipped',
2017-08-17 22:00:37 +05:30
details_path: 'status/skipped',
},
success_warining: {
text: 'passed',
label: 'passed',
2019-07-31 22:56:46 +05:30
group: 'success-with-warnings',
2018-03-17 18:26:18 +05:30
icon: 'status_warning',
2017-08-17 22:00:37 +05:30
details_path: 'status/warning',
},
success: {
text: 'passed',
label: 'passed',
group: 'passed',
2018-03-17 18:26:18 +05:30
icon: 'status_success',
2017-08-17 22:00:37 +05:30
details_path: 'status/passed',
},
};
2021-03-11 19:13:27 +05:30
const findIcon = () => wrapper.findComponent(CiIcon);
const createComponent = (propsData) => {
wrapper = shallowMount(CiBadge, { propsData });
};
2018-03-17 18:26:18 +05:30
afterEach(() => {
2021-03-11 19:13:27 +05:30
wrapper.destroy();
wrapper = null;
2018-03-17 18:26:18 +05:30
});
2017-08-17 22:00:37 +05:30
2021-03-11 19:13:27 +05:30
it.each(Object.keys(statuses))('should render badge for status: %s', (status) => {
createComponent({ status: statuses[status] });
2018-12-13 13:39:08 +05:30
2021-03-11 19:13:27 +05:30
expect(wrapper.attributes('href')).toBe(statuses[status].details_path);
expect(wrapper.text()).toBe(statuses[status].text);
expect(wrapper.classes()).toContain('ci-status');
expect(wrapper.classes()).toContain(`ci-${statuses[status].group}`);
expect(findIcon().exists()).toBe(true);
2017-08-17 22:00:37 +05:30
});
2018-03-17 18:26:18 +05:30
it('should not render label', () => {
2021-03-11 19:13:27 +05:30
createComponent({ status: statuses.canceled, showText: false });
2018-12-13 13:39:08 +05:30
2021-03-11 19:13:27 +05:30
expect(wrapper.text()).toBe('');
2018-03-17 18:26:18 +05:30
});
2017-08-17 22:00:37 +05:30
});