Skip to content

Commit fd514b6

Browse files
committed
VueUiSparkbar add e2e component test
1 parent 829113a commit fd514b6

File tree

3 files changed

+135
-4
lines changed

3 files changed

+135
-4
lines changed

cypress/fixtures/sparkbar.json

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
{
2+
"dataset": [
3+
{
4+
"name": "KPI 1",
5+
"value": 88.88,
6+
"suffix": "%",
7+
"prefix": "v.",
8+
"rounding": 1
9+
},
10+
{
11+
"name": "KPI 2",
12+
"value": 77.77,
13+
"suffix": "%",
14+
"prefix": "v.",
15+
"rounding": 2
16+
},
17+
{
18+
"name": "KPI 3",
19+
"value": 66.66,
20+
"suffix": "%",
21+
"prefix": "v.",
22+
"rounding": 0
23+
},
24+
{
25+
"name": "KPI 4",
26+
"value": 55.55,
27+
"suffix": "%",
28+
"prefix": "v.",
29+
"rounding": 0
30+
},
31+
{
32+
"name": "KPI 5",
33+
"value": 44.44,
34+
"suffix": "%",
35+
"prefix": "v.",
36+
"rounding": 0
37+
},
38+
{
39+
"name": "KPI 6",
40+
"value": 33.33,
41+
"suffix": "%",
42+
"prefix": "v.",
43+
"rounding": 0
44+
},
45+
{
46+
"name": "KPI 7",
47+
"value": 22.22,
48+
"suffix": "%",
49+
"prefix": "v.",
50+
"rounding": 0
51+
},
52+
{
53+
"name": "KPI 8",
54+
"value": 11.11,
55+
"suffix": "%",
56+
"prefix": "v.",
57+
"rounding": 0
58+
},
59+
{
60+
"name": "KPI 9",
61+
"value": 0,
62+
"suffix": "%",
63+
"prefix": "v.",
64+
"rounding": 0
65+
}
66+
],
67+
"config": {
68+
"style": {
69+
"backgroundColor": "#FFFFFF",
70+
"fontFamily": "inherit",
71+
"layout": {
72+
"independant": true,
73+
"percentage": true,
74+
"target": 0
75+
},
76+
"gutter": {
77+
"backgroundColor": "#e1e5e8"
78+
},
79+
"bar": {
80+
"gradient": {
81+
"show": true,
82+
"intensity": 40,
83+
"underlayerColor": "#FFFFFF"
84+
}
85+
},
86+
"labels": {
87+
"fontSize": 16,
88+
"name": {
89+
"position": "top",
90+
"width": "100%",
91+
"color": "#2D353C",
92+
"bold": false
93+
},
94+
"value": {
95+
"show": true,
96+
"bold": true
97+
}
98+
},
99+
"gap": 4
100+
}
101+
}
102+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import VueUiSparkbar from './vue-ui-sparkbar.vue'
2+
3+
describe('<VueUiSparkbar />', () => {
4+
beforeEach(function () {
5+
cy.fixture('sparkbar.json').as('fixture');
6+
cy.viewport(1200, 610);
7+
});
8+
9+
it('renders with different config attributes', function () {
10+
cy.get('@fixture').then((fixture) => {
11+
cy.mount(VueUiSparkbar, {
12+
props: {
13+
dataset: fixture.dataset,
14+
config: fixture.config
15+
}
16+
});
17+
18+
for(let i = 0; i < fixture.dataset.length; i += 1) {
19+
cy.get(`[data-cy="sparkbar-svg-${i}"]`).should('exist');
20+
cy.get(`[data-cy="sparkbar-name-${i}"]`)
21+
.should('exist')
22+
.contains(fixture.dataset[i].name)
23+
24+
cy.get(`[data-cy="sparkbar-value-${i}"]`)
25+
.should('exist')
26+
.contains(`${fixture.dataset[i].prefix}${Number(fixture.dataset[i].value.toFixed(fixture.dataset[i].rounding)).toLocaleString()}${fixture.dataset[i].suffix}`)
27+
}
28+
});
29+
});
30+
})

src/components/vue-ui-sparkbar.vue

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,12 @@ function ratioTo(val) {
8585
<template v-for="(bar, i) in drawableDataset">
8686
<div :style="`display:flex !important;${['left', 'right'].includes(sparkbarConfig.style.labels.name.position) ? 'flex-direction:row !important' : 'flex-direction:column !important'};gap:${sparkbarConfig.style.gap}px !important;${sparkbarConfig.style.labels.name.position === 'right' ? 'row-reverse !important' : ''};align-items:center;${dataset.length > 0 && i !== dataset.length - 1 ? 'margin-bottom:6px' : ''}`">
8787
<div :style="`width:${sparkbarConfig.style.labels.name.width};${['right','top'].includes(sparkbarConfig.style.labels.name.position) ? 'text-align:left' : 'text-align:right'};color:${sparkbarConfig.style.labels.name.color};font-size:${sparkbarConfig.style.labels.fontSize}px;font-weight:${sparkbarConfig.style.labels.name.bold ? 'bold' : 'normal'}`">
88-
<span>{{ bar.name }}</span>
89-
<span v-if="sparkbarConfig.style.labels.value.show" :style="`font-weight:${sparkbarConfig.style.labels.value.bold ? 'bold' : 'normal'}`">
88+
<span :data-cy="`sparkbar-name-${i}`">{{ bar.name }}</span>
89+
<span :data-cy="`sparkbar-value-${i}`" v-if="sparkbarConfig.style.labels.value.show" :style="`font-weight:${sparkbarConfig.style.labels.value.bold ? 'bold' : 'normal'}`">
9090
: {{ bar.prefix ? bar.prefix : '' }}{{ Number(bar.value.toFixed(bar.rounding ? bar.rounding : 0)).toLocaleString() }}{{ bar.suffix ? bar.suffix : '' }}
9191
</span>
9292
</div>
93-
<svg :viewBox="`0 0 ${svg.width} ${svg.height}`" width="100%">
93+
<svg :data-cy="`sparkbar-svg-${i}`" :viewBox="`0 0 ${svg.width} ${svg.height}`" width="100%">
9494
<defs>
9595
<linearGradient
9696
x1="0%"
@@ -107,7 +107,6 @@ function ratioTo(val) {
107107
<rect :height="svg.height" :width="svg.width * ratioTo(bar.value)" :x="0" :y="0" :fill="sparkbarConfig.style.bar.gradient.underlayerColor" :rx="svg.height / 2" />
108108
<rect :height="svg.height" :width="svg.width * ratioTo(bar.value)" :x="0" :y="0" :fill="sparkbarConfig.style.bar.gradient.show ? `url(#sparkbar_gradient_${i}_${uid})` : bar.color" :rx="svg.height / 2" />
109109
</svg>
110-
111110
</div>
112111
</template>
113112
</div>

0 commit comments

Comments
 (0)