collab/mermaid/cypress/integration/rendering/sankey.spec.tsblame
View source
6dd74de1import { imgSnapshotTest, renderGraph } from '../../helpers/util.ts';
6dd74de2
6dd74de3describe('Sankey Diagram', () => {
6dd74de4 it('should render a simple example', () => {
6dd74de5 imgSnapshotTest(
6dd74de6 `
6dd74de7 sankey-beta
6dd74de8
6dd74de9 sourceNode,targetNode,10
6dd74de10 `,
6dd74de11 {}
6dd74de12 );
6dd74de13 });
6dd74de14
6dd74de15 describe('when given a linkColor', function () {
6dd74de16 this.beforeAll(() => {
6dd74de17 cy.wrap(
6dd74de18 `sankey
6dd74de19 a,b,10
6dd74de20 `
6dd74de21 ).as('graph');
6dd74de22 });
6dd74de23
6dd74de24 it('links should use hex color', function () {
6dd74de25 renderGraph(this.graph, { sankey: { linkColor: '#636465' } });
6dd74de26
6dd74de27 cy.get('.link path').should((link) => {
6dd74de28 expect(link.attr('stroke')).to.equal('#636465');
6dd74de29 });
6dd74de30 });
6dd74de31
6dd74de32 it('links should be the same color as source node', function () {
6dd74de33 renderGraph(this.graph, { sankey: { linkColor: 'source' } });
6dd74de34
6dd74de35 cy.get('.link path').then((link) => {
6dd74de36 cy.get('.node[id="node-1"] rect').should((node) =>
6dd74de37 expect(link.attr('stroke')).to.equal(node.attr('fill'))
6dd74de38 );
6dd74de39 });
6dd74de40 });
6dd74de41
6dd74de42 it('links should be the same color as target node', function () {
6dd74de43 renderGraph(this.graph, { sankey: { linkColor: 'target' } });
6dd74de44
6dd74de45 cy.get('.link path').then((link) => {
6dd74de46 cy.get('.node[id="node-2"] rect').should((node) =>
6dd74de47 expect(link.attr('stroke')).to.equal(node.attr('fill'))
6dd74de48 );
6dd74de49 });
6dd74de50 });
6dd74de51
6dd74de52 it('links must be gradient', function () {
6dd74de53 renderGraph(this.graph, { sankey: { linkColor: 'gradient' } });
6dd74de54
6dd74de55 cy.get('.link path').should((link) => {
6dd74de56 expect(link.attr('stroke')).to.equal('url(#linearGradient-3)');
6dd74de57 });
6dd74de58 });
6dd74de59 });
6dd74de60
6dd74de61 describe('when given a nodeAlignment', function () {
6dd74de62 this.beforeAll(() => {
6dd74de63 cy.wrap(
6dd74de64 `
6dd74de65 sankey
6dd74de66
6dd74de67 a,b,8
6dd74de68 b,c,8
6dd74de69 c,d,8
6dd74de70 d,e,8
6dd74de71
6dd74de72 x,c,4
6dd74de73 c,y,4
6dd74de74 `
6dd74de75 ).as('graph');
6dd74de76 });
6dd74de77
6dd74de78 this.afterEach(() => {
6dd74de79 cy.get('.node[id="node-1"]').should((node) => {
6dd74de80 expect(node.attr('x')).to.equal('0');
6dd74de81 });
6dd74de82 cy.get('.node[id="node-2"]').should((node) => {
6dd74de83 expect(node.attr('x')).to.equal('100');
6dd74de84 });
6dd74de85 cy.get('.node[id="node-3"]').should((node) => {
6dd74de86 expect(node.attr('x')).to.equal('200');
6dd74de87 });
6dd74de88 cy.get('.node[id="node-4"]').should((node) => {
6dd74de89 expect(node.attr('x')).to.equal('300');
6dd74de90 });
6dd74de91 cy.get('.node[id="node-5"]').should((node) => {
6dd74de92 expect(node.attr('x')).to.equal('400');
6dd74de93 });
6dd74de94 });
6dd74de95
6dd74de96 it('should justify nodes', function () {
6dd74de97 renderGraph(this.graph, {
6dd74de98 sankey: { nodeAlignment: 'justify', width: 410, useMaxWidth: false },
6dd74de99 });
6dd74de100 cy.get('.node[id="node-6"]').should((node) => {
6dd74de101 expect(node.attr('x')).to.equal('0');
6dd74de102 });
6dd74de103 cy.get('.node[id="node-7"]').should((node) => {
6dd74de104 expect(node.attr('x')).to.equal('400');
6dd74de105 });
6dd74de106 });
6dd74de107
6dd74de108 it('should align nodes left', function () {
6dd74de109 renderGraph(this.graph, {
6dd74de110 sankey: { nodeAlignment: 'left', width: 410, useMaxWidth: false },
6dd74de111 });
6dd74de112 cy.get('.node[id="node-6"]').should((node) => {
6dd74de113 expect(node.attr('x')).to.equal('0');
6dd74de114 });
6dd74de115 cy.get('.node[id="node-7"]').should((node) => {
6dd74de116 expect(node.attr('x')).to.equal('300');
6dd74de117 });
6dd74de118 });
6dd74de119
6dd74de120 it('should align nodes right', function () {
6dd74de121 renderGraph(this.graph, {
6dd74de122 sankey: { nodeAlignment: 'right', width: 410, useMaxWidth: false },
6dd74de123 });
6dd74de124 cy.get('.node[id="node-6"]').should((node) => {
6dd74de125 expect(node.attr('x')).to.equal('100');
6dd74de126 });
6dd74de127 cy.get('.node[id="node-7"]').should((node) => {
6dd74de128 expect(node.attr('x')).to.equal('400');
6dd74de129 });
6dd74de130 });
6dd74de131
6dd74de132 it('should center nodes', function () {
6dd74de133 renderGraph(this.graph, {
6dd74de134 sankey: { nodeAlignment: 'center', width: 410, useMaxWidth: false },
6dd74de135 });
6dd74de136 cy.get('.node[id="node-6"]').should((node) => {
6dd74de137 expect(node.attr('x')).to.equal('100');
6dd74de138 });
6dd74de139 cy.get('.node[id="node-7"]').should((node) => {
6dd74de140 expect(node.attr('x')).to.equal('300');
6dd74de141 });
6dd74de142 });
6dd74de143 });
6dd74de144});