Skip to content

Commit ef11548

Browse files
committed
Tests - Improve VueUiDonut component test
1 parent f5c312a commit ef11548

File tree

2 files changed

+41
-4
lines changed

2 files changed

+41
-4
lines changed

src/components/vue-ui-donut.cy.js

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,41 @@ describe('<VueUiDonut />', () => {
4444
})
4545
}
4646

47+
function testEmits(wrapper) {
48+
cy.log('@selectLegend');
49+
cy.get('[data-cy="legend-item"]').first().click({ force: true }).then(() => {
50+
expect(wrapper.emitted('selectLegend')).to.exist;
51+
});
52+
53+
cy.log('selectDatapoint');
54+
cy.get('[data-cy="tooltip-trap"]').first().click({ force: true }).then(() => {
55+
expect(wrapper.emitted('selectDatapoint')[0][0]).to.have.keys('datapoint', 'index');
56+
expect(wrapper.emitted('selectDatapoint')[0][0].index).to.equal(0);
57+
expect(wrapper.emitted('selectDatapoint')[0][0].datapoint).to.have.keys(
58+
'absoluteValues',
59+
'arcSlice',
60+
'center',
61+
'color',
62+
'comment',
63+
'cx',
64+
'cy',
65+
'endX',
66+
'endY',
67+
'firstSeparator',
68+
'name',
69+
'path',
70+
'patternIndex',
71+
'proportion',
72+
'ratio',
73+
'separator',
74+
'seriesIndex',
75+
'startX',
76+
'startY',
77+
'value'
78+
);
79+
});
80+
}
81+
4782
it('renders donut default variation', () => {
4883
cy.mount(VueUiDonut, {
4984
props: {
@@ -55,7 +90,7 @@ describe('<VueUiDonut />', () => {
5590
'data-cy': 'slot-plot-comment'
5691
}, plot.comment)
5792
}
58-
}).then(() => {
93+
}).then(({ wrapper }) => {
5994
commonTest();
6095

6196
cy.get('[data-cy="donut-arc"]').should('exist').and('be.visible').and('have.length', dataset.length);
@@ -68,6 +103,7 @@ describe('<VueUiDonut />', () => {
68103
cy.get('[data-cy="hollow-average-value"]').should('exist').and('be.visible').contains(average.toFixed(0));
69104

70105
testDataLabels('donut');
106+
testEmits(wrapper);
71107
});
72108
});
73109

@@ -85,13 +121,14 @@ describe('<VueUiDonut />', () => {
85121
'data-cy': 'slot-plot-comment'
86122
}, plot.comment)
87123
}
88-
}).then(() => {
124+
}).then(({ wrapper }) => {
89125
commonTest();
90126

91127
cy.get('[data-cy="polar-datapoint"]').should('exist').and('be.visible').and('have.length', dataset.length);
92128
cy.get('[data-cy="polar-shadow"]').should('exist').and('be.visible').and('have.length', dataset.length);
93129

94130
testDataLabels('polar');
131+
testEmits(wrapper);
95132
});
96133
});
97134
});

src/components/vue-ui-donut.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,11 +1002,11 @@ defineExpose({
10021002
</g>
10031003
<g v-else>
10041004
<circle
1005+
data-cy="tooltip-trap"
10051006
:cx="svg.width / 2"
10061007
:cy="svg.height / 2"
10071008
:r="minSize"
10081009
:fill="selectedSerie === i ? 'rgba(0,0,0,0.1)' : 'transparent'"
1009-
data-cy-donut-trap
10101010
@mouseenter="useTooltip({
10111011
datapoint: currentDonut[0],
10121012
relativeIndex: 0,
@@ -1288,7 +1288,7 @@ defineExpose({
12881288

12891289
<template #item="{ legend, index }">
12901290
<div
1291-
:data-cy="`legend-item-${index}`"
1291+
data-cy="legend-item"
12921292
:style="`opacity:${segregated.includes(index) ? 0.5 : 1}`"
12931293
@click="legend.segregate()"
12941294
>

0 commit comments

Comments
 (0)