From 117f0ab6da930706f12516530f205fd4bb91b7f8 Mon Sep 17 00:00:00 2001 From: Olivier Leveau Date: Fri, 6 Jan 2023 13:38:03 +0100 Subject: [PATCH] Fix test / Add Tests --- .../src/diagrams/sequence/sequenceDb.js | 15 ++++-- .../diagrams/sequence/sequenceDiagram.spec.js | 47 ++++++++++++++++++- 2 files changed, 58 insertions(+), 4 deletions(-) diff --git a/packages/mermaid/src/diagrams/sequence/sequenceDb.js b/packages/mermaid/src/diagrams/sequence/sequenceDb.js index 544b46c6a..8e26c5388 100644 --- a/packages/mermaid/src/diagrams/sequence/sequenceDb.js +++ b/packages/mermaid/src/diagrams/sequence/sequenceDb.js @@ -224,9 +224,18 @@ export const parseBoxData = function (str) { let title = match != null && match[2] ? match[2].trim() : undefined; // check that the string is a color - if (!CSS.supports('color', color)) { - color = 'transparent'; - title = str.trim(); + if (window && window.CSS) { + if (!window.CSS.supports('color', color)) { + color = 'transparent'; + title = str.trim(); + } + } else { + var s = new Option().style; + s.color = color; + if (s.color !== color) { + color = 'transparent'; + title = str.trim(); + } } const boxData = { diff --git a/packages/mermaid/src/diagrams/sequence/sequenceDiagram.spec.js b/packages/mermaid/src/diagrams/sequence/sequenceDiagram.spec.js index 7f67679a7..e626042a2 100644 --- a/packages/mermaid/src/diagrams/sequence/sequenceDiagram.spec.js +++ b/packages/mermaid/src/diagrams/sequence/sequenceDiagram.spec.js @@ -1312,8 +1312,53 @@ link a: Tests @ https://tests.contoso.com/?svc=alice@contoso.com expect(boxes[0].actorKeys).toEqual(['a', 'b']); expect(boxes[0].fill).toEqual('green'); }); -}); + it('should handle box without color', function () { + const str = ` + sequenceDiagram + box Group 1 + participant a as Alice + participant b as Bob + end + participant c as Charlie + links a: { "Repo": "https://repo.contoso.com/", "Dashboard": "https://dashboard.contoso.com/" } + links b: { "Dashboard": "https://dashboard.contoso.com/" } + links a: { "On-Call": "https://oncall.contoso.com/?svc=alice" } + link a: Endpoint @ https://alice.contoso.com + link a: Swagger @ https://swagger.contoso.com + link a: Tests @ https://tests.contoso.com/?svc=alice@contoso.com + `; + + mermaidAPI.parse(str); + const boxes = diagram.db.getBoxes(); + expect(boxes[0].name).toEqual('Group 1'); + expect(boxes[0].actorKeys).toEqual(['a', 'b']); + expect(boxes[0].fill).toEqual('transparent'); + }); + + it('should handle box without description', function () { + const str = ` + sequenceDiagram + box Aqua + participant a as Alice + participant b as Bob + end + participant c as Charlie + links a: { "Repo": "https://repo.contoso.com/", "Dashboard": "https://dashboard.contoso.com/" } + links b: { "Dashboard": "https://dashboard.contoso.com/" } + links a: { "On-Call": "https://oncall.contoso.com/?svc=alice" } + link a: Endpoint @ https://alice.contoso.com + link a: Swagger @ https://swagger.contoso.com + link a: Tests @ https://tests.contoso.com/?svc=alice@contoso.com + `; + + mermaidAPI.parse(str); + const boxes = diagram.db.getBoxes(); + expect(boxes[0].name).toBeFalsy(); + expect(boxes[0].actorKeys).toEqual(['a', 'b']); + expect(boxes[0].fill).toEqual('Aqua'); + }); +}); describe('when checking the bounds in a sequenceDiagram', function () { beforeAll(() => { let conf = {