collab/mermaid/cypress/integration/rendering/journey.spec.jsblame
View source
6dd74de1import { imgSnapshotTest, renderGraph } from '../../helpers/util.ts';
6dd74de2
6dd74de3describe('User journey diagram', () => {
6dd74de4 it('Simple test', () => {
6dd74de5 imgSnapshotTest(
6dd74de6 `journey
6dd74de7title Adding journey diagram functionality to mermaid
6dd74de8section Order from website
6dd74de9 `,
6dd74de10 {}
6dd74de11 );
6dd74de12 });
6dd74de13
6dd74de14 it('should render a user journey chart', () => {
6dd74de15 imgSnapshotTest(
6dd74de16 `
6dd74de17 journey
6dd74de18 title My working day
6dd74de19 section Go to work
6dd74de20 Make tea: 5: Me
6dd74de21 Go upstairs: 3: Me
6dd74de22 Do work: 1: Me, Cat
6dd74de23 section Go home
6dd74de24 Go downstairs: 5: Me
6dd74de25 Sit down: 3: Me
6dd74de26 `,
6dd74de27 {}
6dd74de28 );
6dd74de29 });
6dd74de30
6dd74de31 it('should render a user journey diagram when useMaxWidth is true (default)', () => {
6dd74de32 renderGraph(
6dd74de33 `journey
6dd74de34title E-Commerce
6dd74de35section Order from website
6dd74de36 Add to cart: 5: Me
6dd74de37section Checkout from website
6dd74de38 Add payment details: 5: Me
6dd74de39 `,
6dd74de40 { journey: { useMaxWidth: true } }
6dd74de41 );
6dd74de42 cy.get('svg').should((svg) => {
6dd74de43 expect(svg).to.have.attr('width', '100%');
6dd74de44 expect(svg).to.have.attr('height');
6dd74de45 // const height = parseFloat(svg.attr('height'));
6dd74de46 // expect(height).to.eq(565);
6dd74de47 const style = svg.attr('style');
6dd74de48 expect(style).to.match(/^max-width: [\d.]+px;$/);
6dd74de49 const maxWidthValue = parseFloat(style.match(/[\d.]+/g).join(''));
6dd74de50 expect(maxWidthValue).to.eq(700);
6dd74de51 });
6dd74de52 });
6dd74de53
6dd74de54 it('should render a user journey diagram when useMaxWidth is false', () => {
6dd74de55 imgSnapshotTest(
6dd74de56 `journey
6dd74de57title E-Commerce
6dd74de58section Order from website
6dd74de59 Add to cart: 5: Me
6dd74de60section Checkout from website
6dd74de61 Add payment details: 5: Me
6dd74de62 `,
6dd74de63 { journey: { useMaxWidth: false } }
6dd74de64 );
6dd74de65 });
6dd74de66
6dd74de67 it('should initialize with a left margin of 150px for user journeys', () => {
6dd74de68 renderGraph(
6dd74de69 `
6dd74de70 ---
6dd74de71 config:
6dd74de72 journey:
6dd74de73 maxLabelWidth: 320
6dd74de74 ---
6dd74de75 journey
6dd74de76 title User Journey Example
6dd74de77 section Onboarding
6dd74de78 Sign Up: 5:
6dd74de79 Browse Features: 3:
6dd74de80 Use Core Functionality: 4:
6dd74de81 section Engagement
6dd74de82 Browse Features: 3
6dd74de83 Use Core Functionality: 4
6dd74de84 `,
6dd74de85 { journey: { useMaxWidth: true } }
6dd74de86 );
6dd74de87
6dd74de88 let diagramStartX;
6dd74de89
6dd74de90 cy.contains('foreignobject', 'Sign Up').then(($diagram) => {
6dd74de91 diagramStartX = parseFloat($diagram.attr('x'));
6dd74de92 expect(diagramStartX).to.be.closeTo(150, 2);
6dd74de93 });
6dd74de94 });
6dd74de95
6dd74de96 it('should maintain sufficient space between legend and diagram when legend labels are longer', () => {
6dd74de97 renderGraph(
6dd74de98 `journey
6dd74de99 title Web hook life cycle
6dd74de100 section Darkoob
6dd74de101 Make preBuilt:5: Darkoob user
6dd74de102 register slug : 5: Darkoob userf deliberately increasing the size of this label to check if distance between legend and diagram is maintained
6dd74de103 Map slug to a Prebuilt Job:5: Darkoob user
6dd74de104 section External Service
6dd74de105 set Darkoob slug as hook for an Event : 5 : admin Exjjjnjjjj qwerty
6dd74de106 listen to the events : 5 : External Service
6dd74de107 call darkoob endpoint : 5 : External Service
6dd74de108 section Darkoob
6dd74de109 check for inputs : 5 : DarkoobAPI
6dd74de110 run the prebuilt job : 5 : DarkoobAPI
6dd74de111 `,
6dd74de112 { journey: { useMaxWidth: true } }
6dd74de113 );
6dd74de114
6dd74de115 let LabelEndX, diagramStartX;
6dd74de116
6dd74de117 // Get right edge of the legend
6dd74de118 cy.contains('tspan', 'Darkoob userf').then((textBox) => {
6dd74de119 const bbox = textBox[0].getBBox();
6dd74de120 LabelEndX = bbox.x + bbox.width;
6dd74de121 });
6dd74de122
6dd74de123 // Get left edge of the diagram
6dd74de124 cy.contains('foreignobject', 'Make preBuilt').then((rect) => {
6dd74de125 diagramStartX = parseFloat(rect.attr('x'));
6dd74de126 });
6dd74de127
6dd74de128 // Assert right edge of the diagram is greater than or equal to the right edge of the label
6dd74de129 cy.then(() => {
6dd74de130 expect(diagramStartX).to.be.gte(LabelEndX);
6dd74de131 });
6dd74de132 });
6dd74de133
6dd74de134 it('should wrap a single long word with hyphenation', () => {
6dd74de135 renderGraph(
6dd74de136 `
6dd74de137 ---
6dd74de138 config:
6dd74de139 journey:
6dd74de140 maxLabelWidth: 100
6dd74de141 ---
6dd74de142 journey
6dd74de143 title Long Word Test
6dd74de144 section Test
6dd74de145 VeryLongWord: 5: Supercalifragilisticexpialidocious
6dd74de146 `,
6dd74de147 { journey: { useMaxWidth: true } }
6dd74de148 );
6dd74de149
6dd74de150 // Verify that the line ends with a hyphen, indicating proper hyphenation for words exceeding maxLabelWidth.
6dd74de151 cy.get('tspan').then((tspans) => {
6dd74de152 const hasHyphen = [...tspans].some((t) => t.textContent.trim().endsWith('-'));
6dd74de153 return expect(hasHyphen).to.be.true;
6dd74de154 });
6dd74de155 });
6dd74de156
6dd74de157 it('should wrap text on whitespace without adding hyphens', () => {
6dd74de158 renderGraph(
6dd74de159 `
6dd74de160 ---
6dd74de161 config:
6dd74de162 journey:
6dd74de163 maxLabelWidth: 200
6dd74de164 ---
6dd74de165 journey
6dd74de166 title Whitespace Test
6dd74de167 section Test
6dd74de168 TextWithSpaces: 5: Gustavo Fring is played by Giancarlo Esposito and is a character in Breaking Bad.
6dd74de169 `,
6dd74de170 { journey: { useMaxWidth: true } }
6dd74de171 );
6dd74de172
6dd74de173 // Verify that none of the text spans end with a hyphen.
6dd74de174 cy.get('tspan').each(($el) => {
6dd74de175 const text = $el.text();
6dd74de176 expect(text.trim()).not.to.match(/-$/);
6dd74de177 });
6dd74de178 });
6dd74de179
6dd74de180 it('should wrap long labels into multiple lines, keep them under max width, and maintain margins', () => {
6dd74de181 renderGraph(
6dd74de182 `
6dd74de183 ---
6dd74de184 config:
6dd74de185 journey:
6dd74de186 maxLabelWidth: 320
6dd74de187 ---
6dd74de188 journey
6dd74de189 title User Journey Example
6dd74de190 section Onboarding
6dd74de191 Sign Up: 5: This is a long label that will be split into multiple lines to test the wrapping functionality
6dd74de192 Browse Features: 3: This is another long label that will be split into multiple lines to test the wrapping functionality
6dd74de193 Use Core Functionality: 4: This is yet another long label that will be split into multiple lines to test the wrapping functionality
6dd74de194 section Engagement
6dd74de195 Browse Features: 3
6dd74de196 Use Core Functionality: 4
6dd74de197 `,
6dd74de198 { journey: { useMaxWidth: true } }
6dd74de199 );
6dd74de200
6dd74de201 let diagramStartX, maxLineWidth;
6dd74de202
6dd74de203 // Get the diagram's left edge x-coordinate
6dd74de204 cy.contains('foreignobject', 'Sign Up')
6dd74de205 .then(($diagram) => {
6dd74de206 diagramStartX = parseFloat($diagram.attr('x'));
6dd74de207 })
6dd74de208 .then(() => {
6dd74de209 cy.get('text.legend').then(($lines) => {
6dd74de210 // Check that there are multiple lines
6dd74de211 expect($lines.length).to.be.equal(9);
6dd74de212
6dd74de213 // Check that all lines are under the maxLabelWidth
6dd74de214 $lines.each((index, el) => {
6dd74de215 const bbox = el.getBBox();
6dd74de216 expect(bbox.width).to.be.lte(320);
6dd74de217 maxLineWidth = Math.max(maxLineWidth || 0, bbox.width);
6dd74de218 });
6dd74de219
6dd74de220 /** The expected margin between the diagram and the legend is 150px, as defined by
6dd74de221 * conf.leftMargin in user-journey-config.js
6dd74de222 */
6dd74de223 expect(diagramStartX - maxLineWidth).to.be.closeTo(150, 2);
6dd74de224 });
6dd74de225 });
6dd74de226 });
6dd74de227
6dd74de228 it('should correctly render the user journey diagram title with the specified styling', () => {
6dd74de229 renderGraph(
6dd74de230 `---
6dd74de231config:
6dd74de232 journey:
6dd74de233 titleColor: "#2900A5"
6dd74de234 titleFontFamily: "Times New Roman"
6dd74de235 titleFontSize: "5rem"
6dd74de236---
6dd74de237
6dd74de238journey
6dd74de239 title User Journey Example
6dd74de240 section Onboarding
6dd74de241 Sign Up: 5: John, Shahir
6dd74de242 Complete Profile: 4: John
6dd74de243 section Engagement
6dd74de244 Browse Features: 3: John
6dd74de245 Use Core Functionality: 4: John
6dd74de246 section Retention
6dd74de247 Revisit Application: 5: John
6dd74de248 Invite Friends: 3: John
6dd74de249
6dd74de250 size: 2rem
6dd74de251 `
6dd74de252 );
6dd74de253
6dd74de254 cy.get('text').contains('User Journey Example').as('title');
6dd74de255 cy.get('@title').then(($title) => {
6dd74de256 expect($title).to.have.attr('fill', '#2900A5');
6dd74de257 expect($title).to.have.attr('font-family', 'Times New Roman');
6dd74de258 expect($title).to.have.attr('font-size', '5rem');
6dd74de259 });
6dd74de260 });
6dd74de261});