mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-02-04 07:13:25 +08:00
test: rewrite some config
vals to tighten types
We're planning on limiting some of MermaidConfig's types to specific values (e.g. `0 | 1` instead of `number`).
This commit is contained in:
parent
6e51f8fd98
commit
77ba7c987a
@ -563,7 +563,7 @@ describe('mermaidAPI', () => {
|
|||||||
const config = {
|
const config = {
|
||||||
logLevel: 0,
|
logLevel: 0,
|
||||||
securityLevel: 'loose',
|
securityLevel: 'loose',
|
||||||
};
|
} as const;
|
||||||
mermaidAPI.initialize(config);
|
mermaidAPI.initialize(config);
|
||||||
mermaidAPI.setConfig({ securityLevel: 'strict', logLevel: 1 });
|
mermaidAPI.setConfig({ securityLevel: 'strict', logLevel: 1 });
|
||||||
expect(mermaidAPI.getConfig().logLevel).toBe(1);
|
expect(mermaidAPI.getConfig().logLevel).toBe(1);
|
||||||
|
@ -260,56 +260,46 @@ describe('when formatting urls', function () {
|
|||||||
it('should handle links', function () {
|
it('should handle links', function () {
|
||||||
const url = 'https://mermaid-js.github.io/mermaid/#/';
|
const url = 'https://mermaid-js.github.io/mermaid/#/';
|
||||||
|
|
||||||
const config = { securityLevel: 'loose' };
|
let result = utils.formatUrl(url, { securityLevel: 'loose' });
|
||||||
let result = utils.formatUrl(url, config);
|
|
||||||
expect(result).toEqual(url);
|
expect(result).toEqual(url);
|
||||||
|
|
||||||
config.securityLevel = 'strict';
|
result = utils.formatUrl(url, { securityLevel: 'strict' });
|
||||||
result = utils.formatUrl(url, config);
|
|
||||||
expect(result).toEqual(url);
|
expect(result).toEqual(url);
|
||||||
});
|
});
|
||||||
it('should handle anchors', function () {
|
it('should handle anchors', function () {
|
||||||
const url = '#interaction';
|
const url = '#interaction';
|
||||||
|
|
||||||
const config = { securityLevel: 'loose' };
|
let result = utils.formatUrl(url, { securityLevel: 'loose' });
|
||||||
let result = utils.formatUrl(url, config);
|
|
||||||
expect(result).toEqual(url);
|
expect(result).toEqual(url);
|
||||||
|
|
||||||
config.securityLevel = 'strict';
|
result = utils.formatUrl(url, { securityLevel: 'strict' });
|
||||||
result = utils.formatUrl(url, config);
|
|
||||||
expect(result).toEqual(url);
|
expect(result).toEqual(url);
|
||||||
});
|
});
|
||||||
it('should handle mailto', function () {
|
it('should handle mailto', function () {
|
||||||
const url = 'mailto:user@user.user';
|
const url = 'mailto:user@user.user';
|
||||||
|
|
||||||
const config = { securityLevel: 'loose' };
|
let result = utils.formatUrl(url, { securityLevel: 'loose' });
|
||||||
let result = utils.formatUrl(url, config);
|
|
||||||
expect(result).toEqual(url);
|
expect(result).toEqual(url);
|
||||||
|
|
||||||
config.securityLevel = 'strict';
|
result = utils.formatUrl(url, { securityLevel: 'strict' });
|
||||||
result = utils.formatUrl(url, config);
|
|
||||||
expect(result).toEqual(url);
|
expect(result).toEqual(url);
|
||||||
});
|
});
|
||||||
it('should handle other protocols', function () {
|
it('should handle other protocols', function () {
|
||||||
const url = 'notes://do-your-thing/id';
|
const url = 'notes://do-your-thing/id';
|
||||||
|
|
||||||
const config = { securityLevel: 'loose' };
|
let result = utils.formatUrl(url, { securityLevel: 'loose' });
|
||||||
let result = utils.formatUrl(url, config);
|
|
||||||
expect(result).toEqual(url);
|
expect(result).toEqual(url);
|
||||||
|
|
||||||
config.securityLevel = 'strict';
|
result = utils.formatUrl(url, { securityLevel: 'strict' });
|
||||||
result = utils.formatUrl(url, config);
|
|
||||||
expect(result).toEqual(url);
|
expect(result).toEqual(url);
|
||||||
});
|
});
|
||||||
it('should handle scripts', function () {
|
it('should handle scripts', function () {
|
||||||
const url = 'javascript:alert("test")';
|
const url = 'javascript:alert("test")';
|
||||||
|
|
||||||
const config = { securityLevel: 'loose' };
|
let result = utils.formatUrl(url, { securityLevel: 'loose' });
|
||||||
let result = utils.formatUrl(url, config);
|
|
||||||
expect(result).toEqual(url);
|
expect(result).toEqual(url);
|
||||||
|
|
||||||
config.securityLevel = 'strict';
|
result = utils.formatUrl(url, { securityLevel: 'strict' });
|
||||||
result = utils.formatUrl(url, config);
|
|
||||||
expect(result).toEqual('about:blank');
|
expect(result).toEqual('about:blank');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user