1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
import { GlSingleStat } from '@gitlab/ui/dist/charts';
import { shallowMount } from '@vue/test-utils';
import MetricTile from '~/cycle_analytics/components/metric_tile.vue';
import MetricPopover from '~/cycle_analytics/components/metric_popover.vue';
import { redirectTo } from '~/lib/utils/url_utility';
jest.mock('~/lib/utils/url_utility');
describe('MetricTile', () => {
let wrapper;
const createComponent = (props = {}) => {
return shallowMount(MetricTile, {
propsData: {
metric: {},
...props,
},
});
};
const findSingleStat = () => wrapper.findComponent(GlSingleStat);
const findPopover = () => wrapper.findComponent(MetricPopover);
afterEach(() => {
wrapper.destroy();
});
describe('template', () => {
describe('links', () => {
it('when the metric has links, it redirects the user on click', () => {
const metric = {
identifier: 'deploys',
value: '10',
label: 'Deploys',
links: [{ url: 'foo/bar' }],
};
wrapper = createComponent({ metric });
const singleStat = findSingleStat();
singleStat.vm.$emit('click');
expect(redirectTo).toHaveBeenCalledWith('foo/bar');
});
it("when the metric doesn't have links, it won't the user on click", () => {
const metric = { identifier: 'deploys', value: '10', label: 'Deploys' };
wrapper = createComponent({ metric });
const singleStat = findSingleStat();
singleStat.vm.$emit('click');
expect(redirectTo).not.toHaveBeenCalled();
});
});
describe('decimal places', () => {
it(`will render 0 decimal places for an integer value`, () => {
const metric = { identifier: 'deploys', value: '10', label: 'Deploys' };
wrapper = createComponent({ metric });
const singleStat = findSingleStat();
expect(singleStat.props('animationDecimalPlaces')).toBe(0);
});
it(`will render 1 decimal place for a float value`, () => {
const metric = { identifier: 'deploys', value: '10.5', label: 'Deploys' };
wrapper = createComponent({ metric });
const singleStat = findSingleStat();
expect(singleStat.props('animationDecimalPlaces')).toBe(1);
});
});
it('renders a metric popover', () => {
const metric = { identifier: 'deploys', value: '10', label: 'Deploys' };
wrapper = createComponent({ metric });
const popover = findPopover();
expect(popover.exists()).toBe(true);
expect(popover.props()).toMatchObject({ metric, target: metric.identifier });
});
});
});
|