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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
import { mount } from '@vue/test-utils';
import StackedProgressBarComponent from '~/vue_shared/components/stacked_progress_bar.vue';
describe('StackedProgressBarComponent', () => {
let wrapper;
const createComponent = (config) => {
const defaultConfig = {
successLabel: 'Synced',
failureLabel: 'Failed',
neutralLabel: 'Out of sync',
successCount: 25,
failureCount: 10,
totalCount: 5000,
...config,
};
wrapper = mount(StackedProgressBarComponent, { propsData: defaultConfig });
};
const findSuccessBar = () => wrapper.find('.status-green');
const findNeutralBar = () => wrapper.find('.status-neutral');
const findFailureBar = () => wrapper.find('.status-red');
const findUnavailableBar = () => wrapper.find('.status-unavailable');
describe('template', () => {
it('renders container element', () => {
createComponent();
expect(wrapper.classes()).toContain('stacked-progress-bar');
});
it('renders empty state when count is unavailable', () => {
createComponent({ totalCount: 0, successCount: 0, failureCount: 0 });
expect(findUnavailableBar()).not.toBeUndefined();
});
it('renders bar elements when count is available', () => {
createComponent();
expect(findSuccessBar().exists()).toBe(true);
expect(findNeutralBar().exists()).toBe(true);
expect(findFailureBar().exists()).toBe(true);
});
describe('getPercent', () => {
it('returns correct percentages from provided count based on `totalCount`', () => {
createComponent({ totalCount: 100, successCount: 25, failureCount: 10 });
expect(findSuccessBar().text()).toBe('25%');
expect(findNeutralBar().text()).toBe('65%');
expect(findFailureBar().text()).toBe('10%');
});
it('returns percentage with decimal place when decimal is greater than 1', () => {
createComponent({ successCount: 67 });
expect(findSuccessBar().text()).toBe('1.3%');
});
it('returns percentage as `< 1%` from provided count based on `totalCount` when evaluated value is less than 1', () => {
createComponent({ successCount: 10 });
expect(findSuccessBar().text()).toBe('< 1%');
});
it('returns not available if totalCount is falsy', () => {
createComponent({ totalCount: 0 });
expect(findUnavailableBar().text()).toBe('Not available');
});
it('returns 99.9% when numbers are extreme decimals', () => {
createComponent({ totalCount: 1000000 });
expect(findNeutralBar().text()).toBe('99.9%');
});
});
describe('bar style', () => {
it('renders width based on percentage provided', () => {
createComponent({ totalCount: 100, successCount: 25 });
expect(findSuccessBar().element.style.width).toBe('25%');
});
});
describe('tooltip', () => {
describe('when hideTooltips is false', () => {
it('returns label string based on label and count provided', () => {
createComponent({ successCount: 10, successLabel: 'Synced', hideTooltips: false });
expect(findSuccessBar().attributes('title')).toBe('Synced: 10');
});
});
describe('when hideTooltips is true', () => {
it('returns an empty string', () => {
createComponent({ successCount: 10, successLabel: 'Synced', hideTooltips: true });
expect(findSuccessBar().attributes('title')).toBe('');
});
});
});
});
});
|