mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-17 14:29:48 +02:00
fix: review comments related to getUserDefinedConfig tests
on-behalf-of: @Mermaid-Chart <hello@mermaidchart.com>
This commit is contained in:
@@ -104,10 +104,14 @@ describe('getUserDefinedConfig', () => {
|
|||||||
configApi.addDirective(directive1);
|
configApi.addDirective(directive1);
|
||||||
configApi.addDirective(directive2);
|
configApi.addDirective(directive2);
|
||||||
|
|
||||||
const userConfig = configApi.getUserDefinedConfig();
|
expect(configApi.getUserDefinedConfig()).toMatchInlineSnapshot(`
|
||||||
expect(userConfig.layout).toBe('elk');
|
{
|
||||||
expect(userConfig.fontSize).toBe(14);
|
"fontFamily": "Arial",
|
||||||
expect(userConfig.theme).toBe('forest');
|
"fontSize": 14,
|
||||||
|
"layout": "elk",
|
||||||
|
"theme": "forest",
|
||||||
|
}
|
||||||
|
`);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should combine initialize config and directives', () => {
|
it('should combine initialize config and directives', () => {
|
||||||
@@ -120,10 +124,14 @@ describe('getUserDefinedConfig', () => {
|
|||||||
configApi.addDirective(directive2);
|
configApi.addDirective(directive2);
|
||||||
|
|
||||||
const userConfig = configApi.getUserDefinedConfig();
|
const userConfig = configApi.getUserDefinedConfig();
|
||||||
expect(userConfig.theme).toBe('forest');
|
expect(userConfig).toMatchInlineSnapshot(`
|
||||||
expect(userConfig.fontFamily).toBe('Arial');
|
{
|
||||||
expect(userConfig.layout).toBe('elk');
|
"fontFamily": "Arial",
|
||||||
expect(userConfig.fontSize).toBe(14);
|
"fontSize": 14,
|
||||||
|
"layout": "elk",
|
||||||
|
"theme": "forest",
|
||||||
|
}
|
||||||
|
`);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle nested config objects properly', () => {
|
it('should handle nested config objects properly', () => {
|
||||||
@@ -140,17 +148,19 @@ describe('getUserDefinedConfig', () => {
|
|||||||
configApi.addDirective(directive);
|
configApi.addDirective(directive);
|
||||||
|
|
||||||
const userConfig = configApi.getUserDefinedConfig();
|
const userConfig = configApi.getUserDefinedConfig();
|
||||||
expect(userConfig).toEqual({
|
expect(userConfig).toMatchInlineSnapshot(`
|
||||||
theme: 'default',
|
{
|
||||||
flowchart: {
|
"flowchart": {
|
||||||
nodeSpacing: 75,
|
"curve": "basis",
|
||||||
rankSpacing: 100,
|
"nodeSpacing": 75,
|
||||||
curve: 'basis',
|
"rankSpacing": 100,
|
||||||
},
|
},
|
||||||
mindmap: {
|
"mindmap": {
|
||||||
padding: 20,
|
"padding": 20,
|
||||||
},
|
},
|
||||||
});
|
"theme": "default",
|
||||||
|
}
|
||||||
|
`);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle complex nested overrides', () => {
|
it('should handle complex nested overrides', () => {
|
||||||
@@ -183,18 +193,20 @@ describe('getUserDefinedConfig', () => {
|
|||||||
configApi.addDirective(directive2);
|
configApi.addDirective(directive2);
|
||||||
|
|
||||||
const userConfig = configApi.getUserDefinedConfig();
|
const userConfig = configApi.getUserDefinedConfig();
|
||||||
expect(userConfig).toEqual({
|
expect(userConfig).toMatchInlineSnapshot(`
|
||||||
theme: 'default',
|
{
|
||||||
fontSize: 12,
|
"flowchart": {
|
||||||
flowchart: {
|
"curve": "basis",
|
||||||
nodeSpacing: 100,
|
"nodeSpacing": 100,
|
||||||
rankSpacing: 100,
|
"rankSpacing": 100,
|
||||||
curve: 'basis',
|
},
|
||||||
},
|
"fontSize": 12,
|
||||||
mindmap: {
|
"mindmap": {
|
||||||
padding: 15,
|
"padding": 15,
|
||||||
},
|
},
|
||||||
});
|
"theme": "default",
|
||||||
|
}
|
||||||
|
`);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return independent copies (not references)', () => {
|
it('should return independent copies (not references)', () => {
|
||||||
@@ -207,8 +219,14 @@ describe('getUserDefinedConfig', () => {
|
|||||||
userConfig1.theme = 'neutral';
|
userConfig1.theme = 'neutral';
|
||||||
userConfig1.flowchart!.nodeSpacing = 999;
|
userConfig1.flowchart!.nodeSpacing = 999;
|
||||||
|
|
||||||
expect(userConfig2.theme).toBe('dark');
|
expect(userConfig2).toMatchInlineSnapshot(`
|
||||||
expect(userConfig2.flowchart!.nodeSpacing).toBe(50);
|
{
|
||||||
|
"flowchart": {
|
||||||
|
"nodeSpacing": 50,
|
||||||
|
},
|
||||||
|
"theme": "dark",
|
||||||
|
}
|
||||||
|
`);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle edge cases with undefined values', () => {
|
it('should handle edge cases with undefined values', () => {
|
||||||
@@ -218,26 +236,29 @@ describe('getUserDefinedConfig', () => {
|
|||||||
configApi.saveConfigFromInitialize(initConfig);
|
configApi.saveConfigFromInitialize(initConfig);
|
||||||
configApi.addDirective(directive);
|
configApi.addDirective(directive);
|
||||||
|
|
||||||
const userConfig = configApi.getUserDefinedConfig();
|
expect(configApi.getUserDefinedConfig()).toMatchInlineSnapshot(`
|
||||||
expect(userConfig.theme).toBe('dark');
|
{
|
||||||
expect(userConfig.layout).toBeUndefined();
|
"fontSize": 14,
|
||||||
expect(userConfig.fontFamily).toBeUndefined();
|
"layout": undefined,
|
||||||
expect(userConfig.fontSize).toBe(14);
|
"theme": "dark",
|
||||||
|
}
|
||||||
|
`);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should work correctly after reset', () => {
|
it('should retain config from initialize after reset', () => {
|
||||||
const initConfig: MermaidConfig = { theme: 'dark' };
|
const initConfig: MermaidConfig = { theme: 'dark' };
|
||||||
const directive: MermaidConfig = { layout: 'elk' };
|
const directive: MermaidConfig = { layout: 'elk' };
|
||||||
|
|
||||||
configApi.saveConfigFromInitialize(initConfig);
|
configApi.saveConfigFromInitialize(initConfig);
|
||||||
configApi.addDirective(directive);
|
configApi.addDirective(directive);
|
||||||
|
|
||||||
let userConfig = configApi.getUserDefinedConfig();
|
expect(configApi.getUserDefinedConfig()).toMatchInlineSnapshot(`
|
||||||
expect(userConfig).toEqual({ theme: 'dark', layout: 'elk' });
|
{
|
||||||
|
"layout": "elk",
|
||||||
|
"theme": "dark",
|
||||||
|
}
|
||||||
|
`);
|
||||||
|
|
||||||
configApi.reset();
|
configApi.reset();
|
||||||
|
|
||||||
userConfig = configApi.getUserDefinedConfig();
|
|
||||||
expect(userConfig).toEqual({ theme: 'dark' });
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user