Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

6262 - Fixed faces positioning in journey diagram #6263

Draft
wants to merge 8 commits into
base: develop
Choose a base branch
from
99 changes: 98 additions & 1 deletion cypress/integration/rendering/journey.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { imgSnapshotTest, renderGraph } from '../../helpers/util.ts';

describe('User journey diagram', () => {
describe('User journey diagram simple tests', () => {
it('Simple test', () => {
imgSnapshotTest(
`journey
Expand Down Expand Up @@ -64,3 +64,100 @@ section Checkout from website
);
});
});

describe('User journey diagram task score behavior validation', () => {
it('should throw an error if the task score is non-integer', () => {
let errorCaught = false;

cy.once('uncaught:exception', () => {
errorCaught = true;
return false;
});

renderGraph(`
journey
accTitle: simple journey demo
accDescr: 2 main sections: work and home, each with just a few tasks

section Go to work
Make tea: Hello: Me
Go upstairs: 3: Me
section Go home
Go downstairs: 5: Me
Sit down: 2: Me
`);

cy.wait(500).then(() => {
expect(errorCaught, 'Error should be thrown for a non-integer score').to.equal(true);
});
});

it('should throw an error if the task score is less than 0', () => {
let errorCaught = false;

cy.once('uncaught:exception', () => {
errorCaught = true;
return false;
});

renderGraph(`
journey
section Go to work
Make tea: -10: Me
Go upstairs: 3: Me
section Go home
Go downstairs: 5: Me
Sit down: 2: Me
`);

cy.wait(500).then(() => {
expect(errorCaught, 'Error should be thrown for a score less than 0').to.equal(true);
});
});

it('should throw an error if the task score is greater than 5', () => {
let errorCaught = false;

cy.once('uncaught:exception', () => {
errorCaught = true;
return false;
});

renderGraph(`
journey
section Go to work
Make tea: 23: Me
Go upstairs: 3: Me
section Go home
Go downstairs: 5: Me
Sit down: 2: Me
`);

cy.wait(500).then(() => {
expect(errorCaught, 'Error should be thrown for a score greater than 5').to.equal(true);
});
});

it('should NOT throw an error if the task score is valid (e.g., 4)', () => {
let errorCaught = false;

cy.once('uncaught:exception', () => {
errorCaught = true;
return false;
});

renderGraph(`
journey
section Go to work
Make tea: 4: Me
Go upstairs: 3: Me
section Go home
Go downstairs: 5: Me
Sit down: 2: Me
`);

cy.wait(500).then(() => {
expect(errorCaught, 'No error should be thrown for a valid score').to.equal(false);
});
});
});
5 changes: 5 additions & 0 deletions packages/mermaid/src/diagrams/user-journey/svgDraw.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,11 @@ export const drawTask = function (elem, task, conf) {
.attr('stroke-dasharray', '4 2')
.attr('stroke', '#666');

// Check if the score exceeds the max limit and show alert
if (!Number.isInteger(task.score) || task.score > 5 || task.score < 0) {
throw new Error('Score must be an integer between 0 and 5');
}

drawFace(g, {
cx: center,
cy: 300 + (5 - task.score) * 30,
Expand Down
Loading