2017-04-11 22:57:57 +08:00
|
|
|
/* eslint-env jasmine */
|
2019-09-12 12:58:57 -07:00
|
|
|
import utils from './utils';
|
2015-10-17 10:39:20 +02:00
|
|
|
|
2019-09-12 12:58:57 -07:00
|
|
|
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');
|
|
|
|
});
|
2020-06-08 14:48:03 -04:00
|
|
|
it('should handle an initialize defintion', function() {
|
2020-06-11 15:31:59 -04:00
|
|
|
const str = `
|
|
|
|
%%{initialize: { 'logLevel': 0, 'theme': 'dark' }}%%
|
|
|
|
graph TB
|
|
|
|
bfs1:queue
|
|
|
|
`;
|
2020-06-08 14:48:03 -04:00
|
|
|
const init = JSON.stringify(utils.detectInit(str));
|
|
|
|
expect(init).toBe('{"logLevel":0,"theme":"dark"}');
|
|
|
|
});
|
|
|
|
it('should handle an init defintion', function() {
|
2020-06-11 15:31:59 -04:00
|
|
|
const str = `
|
|
|
|
%%{init: { 'logLevel': 0, 'theme': 'dark' }}%%
|
|
|
|
graph TB
|
|
|
|
bfs1:queue`;
|
2020-06-08 14:48:03 -04:00
|
|
|
const init = JSON.stringify(utils.detectInit(str));
|
|
|
|
expect(init).toBe('{"logLevel":0,"theme":"dark"}');
|
|
|
|
});
|
2019-09-12 12:58:57 -07:00
|
|
|
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');
|
|
|
|
});
|
2015-10-17 10:39:20 +02:00
|
|
|
|
2019-09-12 12:58:57 -07:00
|
|
|
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');
|
|
|
|
});
|
|
|
|
});
|
2015-10-17 10:39:20 +02:00
|
|
|
|
2019-09-12 12:58:57 -07:00
|
|
|
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);
|
|
|
|
});
|
|
|
|
});
|
2020-01-26 16:56:42 +01:00
|
|
|
|
|
|
|
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');
|
|
|
|
});
|
|
|
|
});
|