debian-mirror-gitlab/spec/frontend/sidebar/components/severity/severity_spec.js

58 lines
1.8 KiB
JavaScript
Raw Normal View History

2020-11-24 15:15:51 +05:30
import { GlIcon } from '@gitlab/ui';
2021-03-11 19:13:27 +05:30
import { shallowMount } from '@vue/test-utils';
2020-11-24 15:15:51 +05:30
import { INCIDENT_SEVERITY } from '~/sidebar/components/severity/constants';
2021-03-11 19:13:27 +05:30
import SeverityToken from '~/sidebar/components/severity/severity.vue';
2020-11-24 15:15:51 +05:30
describe('SeverityToken', () => {
let wrapper;
function createComponent(props) {
wrapper = shallowMount(SeverityToken, {
propsData: {
...props,
},
});
}
afterEach(() => {
if (wrapper) {
wrapper.destroy();
wrapper = null;
}
});
const findIcon = () => wrapper.find(GlIcon);
it('renders severity token for each severity type', () => {
2021-03-08 18:12:59 +05:30
Object.values(INCIDENT_SEVERITY).forEach((severity) => {
2020-11-24 15:15:51 +05:30
createComponent({ severity });
expect(findIcon().classes()).toContain(`icon-${severity.icon}`);
expect(findIcon().attributes('name')).toBe(`severity-${severity.icon}`);
expect(wrapper.text()).toBe(severity.label);
});
});
it('renders only icon when `iconOnly` prop is set to `true`', () => {
const severity = INCIDENT_SEVERITY.CRITICAL;
createComponent({ severity, iconOnly: true });
expect(findIcon().classes()).toContain(`icon-${severity.icon}`);
expect(findIcon().attributes('name')).toBe(`severity-${severity.icon}`);
expect(wrapper.text()).toBe('');
});
describe('icon size', () => {
it('renders the icon in default size when other is not specified', () => {
const severity = INCIDENT_SEVERITY.HIGH;
createComponent({ severity });
expect(findIcon().attributes('size')).toBe('12');
});
it('renders the icon in provided size', () => {
const severity = INCIDENT_SEVERITY.HIGH;
const iconSize = 14;
createComponent({ severity, iconSize });
expect(findIcon().attributes('size')).toBe(`${iconSize}`);
});
});
});