Skip to content

Commit ad29f0f

Browse files
committed
VueUiXy VueUiDonut e2e test for pdf & xlsx downloads
1 parent 5d4872a commit ad29f0f

File tree

8 files changed

+57
-9
lines changed

8 files changed

+57
-9
lines changed

cypress.config.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,31 @@
11
import { defineConfig } from "cypress";
22

3+
import fs from "fs";
4+
35
export default defineConfig({
46
component: {
57
devServer: {
68
framework: "vue",
79
bundler: "vite",
810
},
11+
setupNodeEvents(on, config) {
12+
on('task', {
13+
clearDownloads() {
14+
const downloadsFolder = 'cypress/downloads';
15+
16+
try {
17+
fs.readdirSync(downloadsFolder).forEach((file) => {
18+
const filePath = `${downloadsFolder}/${file}`;
19+
fs.unlinkSync(filePath);
20+
});
21+
console.log('Downloads folder cleared.');
22+
return null;
23+
} catch (err) {
24+
console.error(`Error clearing downloads folder: ${err}`);
25+
return err;
26+
}
27+
},
28+
});
29+
}
930
},
1031
});

cypress/support/commands.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,8 @@
2222
//
2323
//
2424
// -- This will overwrite an existing command --
25-
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
25+
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
26+
27+
Cypress.Commands.add('clearDownloads', () => {
28+
cy.task('clearDownloads');
29+
});

cypress/support/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import '../plugins';

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@
5858
"preview": "vite preview",
5959
"test": "vitest"
6060
},
61-
"dependencies": {
62-
},
6361
"devDependencies": {
6462
"@vitejs/plugin-vue": "^4.2.3",
6563
"cypress": "^13.5.1",

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import VueUiDonut from './vue-ui-donut.vue'
1+
import VueUiDonut from './vue-ui-donut.vue';
22

33
describe('<VueUiDonut />', () => {
44
beforeEach(function () {
@@ -298,6 +298,17 @@ describe('<VueUiDonut />', () => {
298298
});
299299
}
300300
});
301+
302+
cy.get(`[data-cy="donut-pdf"]`).click();
303+
cy.wait(5000);
304+
cy.readFile('cypress\\Downloads\\Title.pdf');
305+
306+
cy.get(`[data-cy="donut-xls"]`).click();
307+
cy.wait(3000);
308+
cy.readFile('cypress\\Downloads\\Title.xlsx');
309+
310+
cy.clearDownloads();
311+
301312
});
302313
});
303314
})

src/components/vue-ui-donut.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ defineExpose({
272272
v-model="mutableConfig.showTable">
273273
<label :for="`vue-ui-donut-option-table_${uid}`">{{ donutConfig.userOptions.labels.showTable }}</label>
274274
</div>
275-
<button class="vue-ui-donut-button" @click="generatePdf" :disabled="isPrinting" style="margin-top:12px" :style="`background:${donutConfig.style.chart.backgroundColor};color:${donutConfig.style.chart.color}`">
275+
<button data-cy="donut-pdf" class="vue-ui-donut-button" @click="generatePdf" :disabled="isPrinting" style="margin-top:12px" :style="`background:${donutConfig.style.chart.backgroundColor};color:${donutConfig.style.chart.color}`">
276276
<svg class="vue-ui-donut-print-icon" xmlns="http://www.w3.org/2000/svg" v-if="isPrinting" width="20" height="20" viewBox="0 0 24 24" stroke-width="1.5" :stroke="donutConfig.style.chart.color" fill="none" stroke-linecap="round" stroke-linejoin="round">
277277
<path stroke="none" d="M0 0h24v24H0z" fill="none"/>
278278
<path d="M18 16v.01" />
@@ -283,7 +283,7 @@ defineExpose({
283283
</svg>
284284
<span v-else>PDF</span>
285285
</button>
286-
<button class="vue-ui-donut-button" @click="generateXls" :style="`background:${donutConfig.style.chart.backgroundColor};color:${donutConfig.style.chart.color}`">
286+
<button data-cy="donut-xls" class="vue-ui-donut-button" @click="generateXls" :style="`background:${donutConfig.style.chart.backgroundColor};color:${donutConfig.style.chart.color}`">
287287
XLSX
288288
</button>
289289
</div>

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,19 @@ describe('<VueUiXy />', () => {
174174
cy.get(`[data-cy="xy-tooltip"]`).should('not.exist');
175175
cy.get(`[data-cy="xy-tooltip-trap-6"]`).trigger("mouseenter");
176176
cy.get(`[data-cy="xy-tooltip"]`).should('exist');
177+
cy.get(`[data-cy="xy-tooltip-trap-6"]`).trigger("mouseleave");
178+
179+
cy.get(`[data-cy="xy-summary"]`).click({force:true});
180+
181+
cy.get(`[data-cy="xy-pdf"]`).click();
182+
cy.wait(5000);
183+
cy.readFile('cypress\\Downloads\\Title.pdf');
184+
185+
cy.get(`[data-cy="xy-xls"]`).click();
186+
cy.wait(3000);
187+
cy.readFile('cypress\\Downloads\\Title.xlsx');
188+
189+
cy.clearDownloads();
177190

178191
});
179192
});

src/components/vue-ui-xy.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
</div>
1313

1414
<details class="vue-ui-xy-user-options" :style="`background:${chartConfig.chart.backgroundColor};color:${chartConfig.chart.color}`" data-html2canvas-ignore v-if="chartConfig.chart.userOptions.show" ref="details">
15-
<summary :style="`background:${chartConfig.chart.backgroundColor};color:${chartConfig.chart.color}`">{{ chartConfig.chart.userOptions.title }}</summary>
15+
<summary data-cy="xy-summary" :style="`background:${chartConfig.chart.backgroundColor};color:${chartConfig.chart.color}`">{{ chartConfig.chart.userOptions.title }}</summary>
1616
<div class="vue-ui-xy-user-options-items" :style="`background:${chartConfig.chart.backgroundColor};color:${chartConfig.chart.color}`">
1717
<div class="vue-ui-xy-user-option-item">
1818
<input type="checkbox" :id="`vue-ui-xy-option-datalabels_${uniqueId}`" :name="`vue-ui-xy-option-datalabels_${uniqueId}`"
@@ -34,7 +34,7 @@
3434
v-model="mutableConfig.showTable">
3535
<label :for="`vue-ui-xy-option-table_${uniqueId}`">{{ chartConfig.chart.userOptions.labels.showTable }}</label>
3636
</div>
37-
<button class="vue-ui-xy-button" @click="generatePdf" :disabled="isPrinting" :style="`margin-top: 12px; background:${chartConfig.chart.backgroundColor};color:${chartConfig.chart.color}`">
37+
<button data-cy="xy-pdf" class="vue-ui-xy-button" @click="generatePdf" :disabled="isPrinting" :style="`margin-top: 12px; background:${chartConfig.chart.backgroundColor};color:${chartConfig.chart.color}`">
3838
<svg class="vue-ui-xy-print-icon" xmlns="http://www.w3.org/2000/svg" v-if="isPrinting" width="20" height="20" viewBox="0 0 24 24" stroke-width="1.5" :stroke="chartConfig.chart.color" fill="none" stroke-linecap="round" stroke-linejoin="round">
3939
<path stroke="none" d="M0 0h24v24H0z" fill="none"/>
4040
<path d="M18 16v.01" />
@@ -45,7 +45,7 @@
4545
</svg>
4646
<span v-else>PDF</span>
4747
</button>
48-
<button class="vue-ui-xy-button" @click="generateXls" :style="`background:${chartConfig.chart.backgroundColor};color:${chartConfig.chart.color}`">
48+
<button data-cy="xy-xls" class="vue-ui-xy-button" @click="generateXls" :style="`background:${chartConfig.chart.backgroundColor};color:${chartConfig.chart.color}`">
4949
XLSX
5050
</button>
5151
</div>

0 commit comments

Comments
 (0)