2021-12-11 22:18:48 +05:30
|
|
|
import { GlLink, GlIcon } from '@gitlab/ui';
|
|
|
|
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
|
2022-04-04 11:22:00 +05:30
|
|
|
import MetricPopover from '~/analytics/shared/components/metric_popover.vue';
|
2023-04-23 21:23:45 +05:30
|
|
|
import { METRIC_POPOVER_LABEL } from '~/analytics/shared/constants';
|
2021-12-11 22:18:48 +05:30
|
|
|
|
|
|
|
const MOCK_METRIC = {
|
|
|
|
key: 'deployment-frequency',
|
|
|
|
label: 'Deployment Frequency',
|
|
|
|
value: '10.0',
|
2022-07-16 23:28:13 +05:30
|
|
|
unit: '/day',
|
2021-12-11 22:18:48 +05:30
|
|
|
description: 'Average number of deployments to production per day.',
|
|
|
|
links: [],
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('MetricPopover', () => {
|
|
|
|
let wrapper;
|
|
|
|
|
|
|
|
const createComponent = (props = {}) => {
|
|
|
|
return shallowMountExtended(MetricPopover, {
|
|
|
|
propsData: {
|
|
|
|
target: 'deployment-frequency',
|
|
|
|
...props,
|
|
|
|
},
|
|
|
|
stubs: {
|
|
|
|
'gl-popover': { template: '<div><slot name="title"></slot><slot></slot></div>' },
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const findMetricLabel = () => wrapper.findByTestId('metric-label');
|
2023-04-23 21:23:45 +05:30
|
|
|
const findMetricLink = () => wrapper.find('[data-testid="metric-link"]');
|
2021-12-11 22:18:48 +05:30
|
|
|
const findMetricDescription = () => wrapper.findByTestId('metric-description');
|
|
|
|
const findMetricDocsLink = () => wrapper.findByTestId('metric-docs-link');
|
2022-10-11 01:57:18 +05:30
|
|
|
const findMetricDocsLinkIcon = () => findMetricDocsLink().findComponent(GlIcon);
|
2023-04-23 21:23:45 +05:30
|
|
|
const findMetricDetailsIcon = () => findMetricLink().findComponent(GlIcon);
|
2021-12-11 22:18:48 +05:30
|
|
|
|
|
|
|
it('renders the metric label', () => {
|
|
|
|
wrapper = createComponent({ metric: MOCK_METRIC });
|
|
|
|
expect(findMetricLabel().text()).toBe(MOCK_METRIC.label);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders the metric description', () => {
|
|
|
|
wrapper = createComponent({ metric: MOCK_METRIC });
|
|
|
|
expect(findMetricDescription().text()).toBe(MOCK_METRIC.description);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('with links', () => {
|
2023-04-23 21:23:45 +05:30
|
|
|
const METRIC_NAME = 'Deployment frequency';
|
|
|
|
const LINK_URL = '/groups/gitlab-org/-/analytics/ci_cd?tab=deployment-frequency';
|
2021-12-11 22:18:48 +05:30
|
|
|
const links = [
|
|
|
|
{
|
2023-04-23 21:23:45 +05:30
|
|
|
name: METRIC_NAME,
|
|
|
|
url: LINK_URL,
|
2021-12-11 22:18:48 +05:30
|
|
|
label: 'Dashboard',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
const docsLink = {
|
|
|
|
name: 'Deployment frequency',
|
|
|
|
url: '/help/user/analytics/index#definitions',
|
|
|
|
label: 'Go to docs',
|
|
|
|
docs_link: true,
|
|
|
|
};
|
|
|
|
const linksWithDocs = [...links, docsLink];
|
|
|
|
|
|
|
|
describe.each`
|
2023-04-23 21:23:45 +05:30
|
|
|
hasDocsLink | allLinks
|
|
|
|
${true} | ${linksWithDocs}
|
|
|
|
${false} | ${links}
|
|
|
|
`('when one link has docs_link=$hasDocsLink', ({ hasDocsLink, allLinks }) => {
|
|
|
|
beforeEach(() => {
|
|
|
|
wrapper = createComponent({ metric: { ...MOCK_METRIC, links: allLinks } });
|
|
|
|
});
|
2021-12-11 22:18:48 +05:30
|
|
|
|
2023-04-23 21:23:45 +05:30
|
|
|
describe('Metric title row', () => {
|
|
|
|
it(`renders a link for "${METRIC_NAME}"`, () => {
|
|
|
|
expect(findMetricLink().text()).toContain(METRIC_POPOVER_LABEL);
|
|
|
|
expect(findMetricLink().findComponent(GlLink).attributes('href')).toBe(LINK_URL);
|
|
|
|
});
|
2021-12-11 22:18:48 +05:30
|
|
|
|
2023-04-23 21:23:45 +05:30
|
|
|
it('renders the chart icon', () => {
|
|
|
|
expect(findMetricDetailsIcon().attributes('name')).toBe('chart');
|
2021-12-11 22:18:48 +05:30
|
|
|
});
|
2023-04-23 21:23:45 +05:30
|
|
|
});
|
2021-12-11 22:18:48 +05:30
|
|
|
|
2023-04-23 21:23:45 +05:30
|
|
|
it(`${hasDocsLink ? 'renders' : "doesn't render"} a docs link`, () => {
|
|
|
|
expect(findMetricDocsLink().exists()).toBe(hasDocsLink);
|
2021-12-11 22:18:48 +05:30
|
|
|
|
2023-04-23 21:23:45 +05:30
|
|
|
if (hasDocsLink) {
|
|
|
|
expect(findMetricDocsLink().attributes('href')).toBe(docsLink.url);
|
|
|
|
expect(findMetricDocsLink().text()).toBe(docsLink.label);
|
|
|
|
expect(findMetricDocsLinkIcon().attributes('name')).toBe('external-link');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2021-12-11 22:18:48 +05:30
|
|
|
});
|
|
|
|
});
|