Fix test / Add Tests

This commit is contained in:
Olivier Leveau 2023-01-06 13:38:03 +01:00
parent 64a935515c
commit 117f0ab6da
2 changed files with 58 additions and 4 deletions

View File

@ -224,10 +224,19 @@ export const parseBoxData = function (str) {
let title = match != null && match[2] ? match[2].trim() : undefined; let title = match != null && match[2] ? match[2].trim() : undefined;
// check that the string is a color // check that the string is a color
if (!CSS.supports('color', color)) { if (window && window.CSS) {
if (!window.CSS.supports('color', color)) {
color = 'transparent'; color = 'transparent';
title = str.trim(); title = str.trim();
} }
} else {
var s = new Option().style;
s.color = color;
if (s.color !== color) {
color = 'transparent';
title = str.trim();
}
}
const boxData = { const boxData = {
color: color, color: color,

View File

@ -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].actorKeys).toEqual(['a', 'b']);
expect(boxes[0].fill).toEqual('green'); 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 () { describe('when checking the bounds in a sequenceDiagram', function () {
beforeAll(() => { beforeAll(() => {
let conf = { let conf = {