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

Code before:
    configApi.saveConfigFromInitialize({
      htmlLabels: false,
      flowchart: { htmlLabels: true },
    });
    configApi.setSiteConfig({
      htmlLabels: false,
      flowchart: { htmlLabels: true },
    });
    const config = configApi.getConfig();
    expect(configApi.getEffectiveHtmlLabels(config)).toBe(false);
  });

  it('should default to true when neither root nor flowchart htmlLabels is explicitly set', () => {
    configApi.setSiteConfig({});
    const config = configApi.getConfig();
    // flowchart.htmlLabels has a default of true in the schema
    expect(configApi.getEffectiveHtmlLabels(config)).toBe(true);
  });

  it('should handle directives with flowchart.htmlLabels set to false', () => {
    // Ensure clean state - reset clears directives but not configFromInitialize
    configApi.reset();
    configApi.saveConfigFromInitialize({});
    configApi.setSiteConfig({});
    // Add a directive that sets flowchart.htmlLabels to false
    configApi.addDirective({ flowchart: { htmlLabels: false } });
    const config = configApi.getConfig();
    // Since flowchart.htmlLabels was explicitly set via directive, it should be false
    expect(configApi.getEffectiveHtmlLabels(config)).toBe(false);
  });

  it('should handle directives with root htmlLabels taking precedence', () => {
    configApi.saveConfigFromInitialize({ flowchart: { htmlLabels: true } });
    configApi.setSiteConfig({ flowchart: { htmlLabels: true } });
    configApi.addDirective({ htmlLabels: false });
    const config = configApi.getConfig();
    expect(configApi.getEffectiveHtmlLabels(config)).toBe(false);
  });
});


Review comment (suggestion):
Please also test the opposite of this! (e.g. what happens if `flowchart: {htmlLabels: true}, htmlLabels: false`).

Code after:
    const config = configApi.getConfig();
    expect(configApi.getEffectiveHtmlLabels(config)).toBe(false);
  });

  it('should default to true when neither root nor flowchart htmlLabels is explicitly set', () => {
    configApi.setSiteConfig({});
    const config = configApi.getConfig();
    // flowchart.htmlLabels has a default of true in the schema
    expect(configApi.getEffectiveHtmlLabels(config)).toBe(true);
  });

  it('should handle directives with flowchart.htmlLabels set to false', () => {
    configApi.setSiteConfig({});
    // Add a directive that sets flowchart.htmlLabels to false
    configApi.addDirective({ flowchart: { htmlLabels: false } });
    const config = configApi.getConfig();
    // Since flowchart.htmlLabels was explicitly set via directive, it should be false
    expect(configApi.getEffectiveHtmlLabels(config)).toBe(false);
  });

  it('should handle directives with root htmlLabels taking precedence', () => {
    configApi.setSiteConfig({ flowchart: { htmlLabels: true } });
    configApi.addDirective({ htmlLabels: false });
    const config = configApi.getConfig();
    expect(configApi.getEffectiveHtmlLabels(config)).toBe(false);
  });

  it('should handle directives with root htmlLabels true overriding flowchart htmlLabels false', () => {
    configApi.setSiteConfig({ flowchart: { htmlLabels: false } });
    configApi.addDirective({ htmlLabels: true });
    const config = configApi.getConfig();
    expect(configApi.getEffectiveHtmlLabels(config)).toBe(true);
  });
});