forked from EnergySage/es-ds
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEsSlider.spec.js
87 lines (78 loc) · 2.53 KB
/
EsSlider.spec.js
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
import { mount } from '@vue/test-utils';
import EsSlider from '@/src/lib-components/EsSlider.vue';
import jestVue from '@/tests/jest.vue.config';
describe('EsSlider', () => {
// Basic test; should exist for most components
test(`<EsSlider
:startingValue="100"
:data="[0,100,500]"
:marks="[0,500]"
:min="100"
:max="500"
ariaLabel="Select a number" />`, async () => {
const wrapper = mount(EsSlider, {
...jestVue,
propsData: {
startingValue: 300,
data: [100, 300, 500],
marks: [100, 500],
min: 100,
max: 500,
ariaLabel: 'Select a number',
},
});
const a11y = await axe(wrapper.element);
expect(wrapper.vm).toBeTruthy();
expect(wrapper.html()).toMatchSnapshot();
expect(a11y).toHaveNoViolations();
});
test('<EsSlider :startingValue="50" />', async () => {
const wrapper = mount(EsSlider, {
...jestVue,
propsData: {
startingValue: 50,
data: [],
marks: [],
min: 0,
max: 100,
ariaLabel: 'Select a number',
},
});
expect(wrapper.html()).toMatchSnapshot();
const tooltip = wrapper.find('div.slider-tooltip');
expect(tooltip.text()).toContain('50');
expect(wrapper.vm.sliderValue).toBe(50);
});
test('<EsSlider variant="secondary" />', async () => {
const wrapper = mount(EsSlider, {
...jestVue,
propsData: {
startingValue: 50,
data: [],
marks: [],
min: 0,
max: 100,
ariaLabel: 'Select a number',
variant: 'secondary',
},
});
expect(wrapper.html()).toMatchSnapshot();
});
test('<EsSlider /> tooltipFormatter works', async () => {
const wrapper = mount(EsSlider, {
...jestVue,
propsData: {
startingValue: 50,
data: [],
marks: [],
min: 0,
max: 100,
ariaLabel: 'Select a number',
tooltipFormatter: (v) => `$${v}`,
},
});
expect(wrapper.html()).toMatchSnapshot();
const tooltip = wrapper.find('div.slider-tooltip');
expect(tooltip.text()).toContain('$');
});
});