mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-01-21 06:53:17 +08:00
bd11663e0a
Added inline config and init(ialization) grammar Added reinitialize functionality to mermaidAPI (not to be confused with initialize) Added actorFontWeight, noteFontWeight, messageFontWeight, wrapEnabled, wrapPadding Added wrapLabel and breakWord functions to intelligently wrap text based on a pixel-based width instead of column-based - The implementation is largely from Carys Mills: https://medium.com/@CarysMills/wrapping-svg-text-without-svg-2-ecbfb58f7ba4 - Made slight modifications for mermaid-js Fixed dark theme color inconsistencies for sequence diagrams Removed !important from sequence scss as this prevents any client overrides Fixed various invalid css values in sequence scss which prevented proper rendering of various elements Added detectInit to utils for initialization json detection Updated detectType to support the existence or absence of the intialization configuration Updated calculateTextWidth to include fontWeight
108 lines
3.6 KiB
JavaScript
108 lines
3.6 KiB
JavaScript
/* eslint-env jasmine */
|
|
import utils from './utils';
|
|
|
|
describe('when detecting chart type ', function() {
|
|
it('should handle a graph defintion', function() {
|
|
const str = 'graph TB\nbfs1:queue';
|
|
const type = utils.detectType(str);
|
|
expect(type).toBe('flowchart');
|
|
});
|
|
it('should handle an initialize defintion', function() {
|
|
const str = 'initialize: { "logLevel": 0, "theme": "dark" }\ngraph TB\nbfs1:queue';
|
|
const init = JSON.stringify(utils.detectInit(str));
|
|
expect(init).toBe('{"logLevel":0,"theme":"dark"}');
|
|
});
|
|
it('should handle an init defintion', function() {
|
|
const str = 'init: { "logLevel": 0, "theme": "dark" }\ngraph TB\nbfs1:queue';
|
|
const init = JSON.stringify(utils.detectInit(str));
|
|
expect(init).toBe('{"logLevel":0,"theme":"dark"}');
|
|
});
|
|
it('should handle a graph defintion with leading spaces', function() {
|
|
const str = ' graph TB\nbfs1:queue';
|
|
const type = utils.detectType(str);
|
|
expect(type).toBe('flowchart');
|
|
});
|
|
|
|
it('should handle a graph defintion with leading spaces and newline', function() {
|
|
const str = ' \n graph TB\nbfs1:queue';
|
|
const type = utils.detectType(str);
|
|
expect(type).toBe('flowchart');
|
|
});
|
|
it('should handle a graph defintion for gitGraph', function() {
|
|
const str = ' \n gitGraph TB:\nbfs1:queue';
|
|
const type = utils.detectType(str);
|
|
expect(type).toBe('git');
|
|
});
|
|
});
|
|
|
|
describe('when finding substring in array ', function() {
|
|
it('should return the array index that contains the substring', function() {
|
|
const arr = ['stroke:val1', 'fill:val2'];
|
|
const result = utils.isSubstringInArray('fill', arr);
|
|
expect(result).toEqual(1);
|
|
});
|
|
it('should return -1 if the substring is not found in the array', function() {
|
|
const arr = ['stroke:val1', 'stroke-width:val2'];
|
|
const result = utils.isSubstringInArray('fill', arr);
|
|
expect(result).toEqual(-1);
|
|
});
|
|
});
|
|
|
|
describe('when formatting urls', function() {
|
|
it('should handle links', function() {
|
|
const url = 'https://mermaid-js.github.io/mermaid/#/';
|
|
|
|
let config = { securityLevel: 'loose' };
|
|
let result = utils.formatUrl(url, config);
|
|
expect(result).toEqual(url);
|
|
|
|
config.securityLevel = 'strict';
|
|
result = utils.formatUrl(url, config);
|
|
expect(result).toEqual(url);
|
|
});
|
|
it('should handle anchors', function() {
|
|
const url = '#interaction';
|
|
|
|
let config = { securityLevel: 'loose' };
|
|
let result = utils.formatUrl(url, config);
|
|
expect(result).toEqual(url);
|
|
|
|
config.securityLevel = 'strict';
|
|
result = utils.formatUrl(url, config);
|
|
expect(result).toEqual('about:blank');
|
|
});
|
|
it('should handle mailto', function() {
|
|
const url = 'mailto:user@user.user';
|
|
|
|
let config = { securityLevel: 'loose' };
|
|
let result = utils.formatUrl(url, config);
|
|
expect(result).toEqual(url);
|
|
|
|
config.securityLevel = 'strict';
|
|
result = utils.formatUrl(url, config);
|
|
expect(result).toEqual(url);
|
|
});
|
|
it('should handle other protocols', function() {
|
|
const url = 'notes://do-your-thing/id';
|
|
|
|
let config = { securityLevel: 'loose' };
|
|
let result = utils.formatUrl(url, config);
|
|
expect(result).toEqual(url);
|
|
|
|
config.securityLevel = 'strict';
|
|
result = utils.formatUrl(url, config);
|
|
expect(result).toEqual(url);
|
|
});
|
|
it('should handle scripts', function() {
|
|
const url = 'javascript:alert("test")';
|
|
|
|
let config = { securityLevel: 'loose' };
|
|
let result = utils.formatUrl(url, config);
|
|
expect(result).toEqual(url);
|
|
|
|
config.securityLevel = 'strict';
|
|
result = utils.formatUrl(url, config);
|
|
expect(result).toEqual('about:blank');
|
|
});
|
|
});
|