debian-mirror-gitlab/spec/frontend/releases/components/issuable_stats_spec.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

112 lines
3.2 KiB
JavaScript
Raw Normal View History

2021-01-29 00:20:46 +05:30
import { GlLink } from '@gitlab/ui';
import { mount } from '@vue/test-utils';
import { trimText } from 'helpers/text_helper';
import IssuableStats from '~/releases/components/issuable_stats.vue';
describe('~/releases/components/issuable_stats.vue', () => {
let wrapper;
let defaultProps;
2021-03-08 18:12:59 +05:30
const createComponent = (propUpdates) => {
2021-01-29 00:20:46 +05:30
wrapper = mount(IssuableStats, {
propsData: {
...defaultProps,
...propUpdates,
},
});
};
2022-10-11 01:57:18 +05:30
const findOpenStatLink = () => wrapper.find('[data-testid="open-stat"]').findComponent(GlLink);
const findMergedStatLink = () =>
wrapper.find('[data-testid="merged-stat"]').findComponent(GlLink);
const findClosedStatLink = () =>
wrapper.find('[data-testid="closed-stat"]').findComponent(GlLink);
2021-01-29 00:20:46 +05:30
beforeEach(() => {
defaultProps = {
label: 'Items',
total: 10,
closed: 2,
merged: 7,
openedPath: 'path/to/opened/items',
closedPath: 'path/to/closed/items',
mergedPath: 'path/to/merged/items',
};
});
it('matches snapshot', () => {
createComponent();
expect(wrapper.html()).toMatchSnapshot();
});
describe('when only total and closed counts are provided', () => {
beforeEach(() => {
createComponent({ merged: undefined, mergedPath: undefined });
});
it('renders a label with the total count; also, the opened count and the closed count', () => {
expect(trimText(wrapper.text())).toMatchInterpolatedText('Items 10 Open: 8 • Closed: 2');
});
});
describe('when only total, merged, and closed counts are provided', () => {
beforeEach(() => {
createComponent();
});
it('renders a label with the total count; also, the opened count, the merged count, and the closed count', () => {
expect(wrapper.text()).toMatchInterpolatedText('Items 10 Open: 1 • Merged: 7 • Closed: 2');
});
});
describe('when path parameters are provided', () => {
beforeEach(() => {
createComponent();
});
it('renders the "open" stat as a link', () => {
const link = findOpenStatLink();
expect(link.exists()).toBe(true);
expect(link.attributes('href')).toBe(defaultProps.openedPath);
});
it('renders the "merged" stat as a link', () => {
const link = findMergedStatLink();
expect(link.exists()).toBe(true);
expect(link.attributes('href')).toBe(defaultProps.mergedPath);
});
it('renders the "closed" stat as a link', () => {
const link = findClosedStatLink();
expect(link.exists()).toBe(true);
expect(link.attributes('href')).toBe(defaultProps.closedPath);
});
});
describe('when path parameters are not provided', () => {
beforeEach(() => {
createComponent({
openedPath: undefined,
closedPath: undefined,
mergedPath: undefined,
});
});
it('does not render the "open" stat as a link', () => {
expect(findOpenStatLink().exists()).toBe(false);
});
it('does not render the "merged" stat as a link', () => {
expect(findMergedStatLink().exists()).toBe(false);
});
it('does not render the "closed" stat as a link', () => {
expect(findClosedStatLink().exists()).toBe(false);
});
});
});