Skip to content

Commit 53acfe8

Browse files
committed
Tests - Add tests for VueUiDag
1 parent b6e6b15 commit 53acfe8

File tree

4 files changed

+89
-2
lines changed

4 files changed

+89
-2
lines changed

cypress/fixtures/vdui-components.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,41 @@
55
*
66
*/
77
export const components = [
8+
{
9+
name: 'VueUiDag',
10+
dataset: {
11+
nodes: [
12+
{ id: 'A', label: 'AAA' },
13+
{ id: 'B', label: 'BBB' },
14+
{ id: 'C', label: 'CCC' },
15+
],
16+
edges: [
17+
{ from: 'A', to: 'B' },
18+
{ from: 'A', to: 'C' },
19+
]
20+
},
21+
config: {
22+
style: {
23+
chart: {
24+
nodes: {
25+
tooltip: {
26+
showOnClick: true
27+
}
28+
},
29+
midpoints: {
30+
show: true
31+
},
32+
title: {
33+
text: 'Title',
34+
subtitle: {
35+
text: 'Subtitle'
36+
}
37+
}
38+
}
39+
}
40+
},
41+
wrapperClass: '.vue-ui-dag'
42+
},
843
{
944
name: 'VueUiChord',
1045
dataset: {

src/atoms/BaseZoomControls.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ const emit = defineEmits(['zoomIn', 'zoomOut', 'resetZoom', 'switchDirection']);
4444
<button
4545
@click="emit('zoomOut')"
4646
class="vue-data-ui-zoom-controls-button"
47+
data-cy-zoom-out
4748
>
4849
<BaseIcon
4950
name="zoomMinus"
@@ -54,6 +55,7 @@ const emit = defineEmits(['zoomIn', 'zoomOut', 'resetZoom', 'switchDirection']);
5455
<button
5556
class="vue-data-ui-zoom-controls-button-zoom"
5657
@click="emit('resetZoom')"
58+
data-cy-zoom-reset
5759
:style="{
5860
color: config.style.chart.controls.color,
5961
width: config.style.chart.controls.fontSize * 4 + 'px',
@@ -65,6 +67,7 @@ const emit = defineEmits(['zoomIn', 'zoomOut', 'resetZoom', 'switchDirection']);
6567
<button
6668
@click="emit('zoomIn')"
6769
class="vue-data-ui-zoom-controls-button"
70+
data-cy-zoom-in
6871
>
6972
<BaseIcon
7073
name="zoomPlus"

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import VueUiDag from "./vue-ui-dag.vue";
2+
import { components } from '../../cypress/fixtures/vdui-components';
3+
import { testCommonFeatures } from '../../cypress/fixtures';
4+
import { h } from "vue";
5+
6+
const { config, dataset } = components.find(c => c.name === 'VueUiDag');
7+
8+
describe('<VueUiDag />', () => {
9+
it('renders', () => {
10+
cy.mount(VueUiDag, {
11+
props: {
12+
dataset,
13+
config
14+
}
15+
}).then(() => {
16+
testCommonFeatures({
17+
userOptions: true,
18+
title: true,
19+
subtitle: true,
20+
legend: false,
21+
dataTable: false,
22+
});
23+
24+
cy.get('[data-cy-node]').first().click({ force: true});
25+
cy.get('[data-cy-tooltip-node]').should('be.visible').and('contain', 'AAA')
26+
27+
cy.get('[data-cy-midpoint]').first().trigger('mouseenter')
28+
cy.get('[data-cy-tooltip-midpoint]').should('exist').and('contain', 'AAA → BBB')
29+
30+
cy.get('[data-cy-zoom-in]').click()
31+
cy.wait(300)
32+
cy.get('[data-cy-zoom-reset]').should('contain', '150%')
33+
cy.get('[data-cy-zoom-out]').click()
34+
cy.wait(300)
35+
cy.get('[data-cy-zoom-reset]').should('contain', '100%')
36+
cy.get('[data-cy-zoom-out]').click()
37+
cy.wait(300)
38+
cy.get('[data-cy-zoom-reset]').should('contain', '67%').click()
39+
cy.wait(300)
40+
cy.get('[data-cy-zoom-reset]').should('contain', '100%')
41+
})
42+
})
43+
})

src/components/vue-ui-dag.vue

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,8 @@ defineExpose({
812812
<!-- Edges -->
813813
<g class="vue-ui-dag-edges">
814814
<template v-for="edge in layoutData.edges" :key="edge.id">
815-
<path
815+
<path
816+
data-cy-edge
816817
:d="edge.pathData"
817818
fill="none"
818819
:stroke="edge.original.color ?? FINAL_CONFIG.style.chart.edges.stroke"
@@ -822,6 +823,7 @@ defineExpose({
822823
style="pointer-events: none; transition: stroke-width 0.2s ease-in-out"
823824
/>
824825
<circle
826+
data-cy-midpoint
825827
class="vue-ui-dag-edge-midpoint"
826828
v-if="FINAL_CONFIG.style.chart.midpoints.show"
827829
:cx="edge.midpoint.x"
@@ -848,7 +850,8 @@ defineExpose({
848850
@mouseleave="highlightedNodeId = null"
849851
>
850852
<template v-if="!$slots.node">
851-
<rect
853+
<rect
854+
data-cy-node
852855
:x="node.x - node.width / 2"
853856
:y="node.y - node.height / 2"
854857
:width="node.width"
@@ -879,6 +882,7 @@ defineExpose({
879882
880883
<!-- default label, multiline when provided with /n -->
881884
<text
885+
data-cy-node-label
882886
v-else
883887
:x="node.x"
884888
:y="node.y"
@@ -940,6 +944,7 @@ defineExpose({
940944
<Transition name="fade">
941945
<Teleport :to="isFullscreen ? dagChart : 'body'" v-if="isTooltip">
942946
<div
947+
data-cy-tooltip-midpoint
943948
ref="tooltipRef"
944949
class="vue-ui-dag-tooltip"
945950
:style="{
@@ -963,6 +968,7 @@ defineExpose({
963968
<Transition name="fade">
964969
<Teleport :to="isFullscreen ? dagChart : 'body'" v-if="isNodeTooltip">
965970
<div
971+
data-cy-tooltip-node
966972
ref="nodeTooltipRef"
967973
class="vue-ui-dag-node-tooltip"
968974
:style="{

0 commit comments

Comments
 (0)