Repository: mermaid-js/mermaid
File: packages/mermaid/src/config.spec.ts (TypeScript)

Code before:

  it('should retain config from initialize after reset', () => {
    const initConfig: MermaidConfig = { theme: 'dark' };
    const directive: MermaidConfig = { layout: 'elk' };

    configApi.saveConfigFromInitialize(initConfig);
    configApi.addDirective(directive);

    expect(configApi.getUserDefinedConfig()).toMatchInlineSnapshot(`
      {
        "layout": "elk",
        "theme": "dark",
      }
    `);

    configApi.reset();
  });
});

describe('getEffectiveHtmlLabels', () => {
  beforeEach(() => {
    configApi.reset();
  });

  it('should return true when root-level htmlLabels is true', () => {
    configApi.saveConfigFromInitialize({ htmlLabels: true });
    configApi.setSiteConfig({ htmlLabels: true });
    const config = configApi.getConfig();
    expect(configApi.getEffectiveHtmlLabels(config)).toBe(true);
  });

  it('should return false when root-level htmlLabels is false', () => {
    configApi.saveConfigFromInitialize({ htmlLabels: false });
    configApi.setSiteConfig({ htmlLabels: false });
    const config = configApi.getConfig();
    expect(configApi.getEffectiveHtmlLabels(config)).toBe(false);
  });

  it('should return true when flowchart.htmlLabels is true and root is not set', () => {
    configApi.saveConfigFromInitialize({ flowchart: { htmlLabels: true } });
    configApi.setSiteConfig({ flowchart: { htmlLabels: true } });
    const config = configApi.getConfig();
    expect(configApi.getEffectiveHtmlLabels(config)).toBe(true);
  });

  it('should return false when flowchart.htmlLabels is false and root is not set', () => {
    configApi.saveConfigFromInitialize({ flowchart: { htmlLabels: false } });
    configApi.setSiteConfig({ flowchart: { htmlLabels: false } });
    const config = configApi.getConfig();
    expect(configApi.getEffectiveHtmlLabels(config)).toBe(false);
  });

Review comment (suggestion):
**suggestion**: Can we get rid of all these `saveConfigFromInitialize` calls you've added to the tests now that `getEffectiveHtmlLabels` doesn't actually use it?

It would make the tests much simpler to read.

Code after:

  it('should retain config from initialize after reset', () => {
    const initConfig: MermaidConfig = { theme: 'dark' };
    const directive: MermaidConfig = { layout: 'elk' };

    configApi.saveConfigFromInitialize(initConfig);
    configApi.addDirective(directive);

    expect(configApi.getUserDefinedConfig()).toMatchInlineSnapshot(`
      {
        "layout": "elk",
        "theme": "dark",
      }
    `);

    configApi.reset();
  });
});

describe('getEffectiveHtmlLabels', () => {
  beforeEach(() => {
    configApi.reset();
  });

  it('should return true when root-level htmlLabels is true', () => {
    configApi.setSiteConfig({ htmlLabels: true });
    const config = configApi.getConfig();
    expect(configApi.getEffectiveHtmlLabels(config)).toBe(true);
  });

  it('should return false when root-level htmlLabels is false', () => {
    configApi.setSiteConfig({ htmlLabels: false });
    const config = configApi.getConfig();
    expect(configApi.getEffectiveHtmlLabels(config)).toBe(false);
  });

  it('should return true when flowchart.htmlLabels is true and root is not set', () => {
    configApi.setSiteConfig({ flowchart: { htmlLabels: true } });
    const config = configApi.getConfig();
    expect(configApi.getEffectiveHtmlLabels(config)).toBe(true);
  });

  it('should return false when flowchart.htmlLabels is false and root is not set', () => {
    configApi.setSiteConfig({ flowchart: { htmlLabels: false } });
    const config = configApi.getConfig();
    expect(configApi.getEffectiveHtmlLabels(config)).toBe(false);
  });

  it('should prioritize root-level htmlLabels over flowchart.htmlLabels', () => {
    configApi.setSiteConfig({
      htmlLabels: false,