angular/adev/shared-docs/pipeline/shared/test/heading.spec.mts
Suguru Inatomi 30e486a41c fix(docs-infra): use shared heading ID generation logic
This commit extracts the heading ID generation logic into a shared utility
and updates both the route generation script and the markdown pipeline to use it.

This ensures consistency between the generated routes and the rendered
documentation, and fixes an issue where custom heading IDs (`{#id}`)
were ignored during route generation.

Fixes #67200

(cherry picked from commit bedfcb5644)
2026-02-23 23:16:55 +00:00

31 lines
1,021 B
TypeScript

/*!
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {getIdFromHeading} from '../heading.mjs';
describe('getIdFromHeading', () => {
it('should generate id from simple text', () => {
expect(getIdFromHeading('My Heading')).toBe('my-heading');
});
it('should generate id from text with special characters', () => {
expect(getIdFromHeading('Step 2 - Add component')).toBe('step-2---add-component');
});
it('should extract custom id when present', () => {
expect(getIdFromHeading('My Heading {#custom-id}')).toBe('custom-id');
});
it('should extract custom id ignoring surrounding spaces', () => {
expect(getIdFromHeading('My Heading {# custom-id }')).toBe('custom-id');
});
it('should prioritize custom id over text content', () => {
expect(getIdFromHeading('Duplicate Heading {#unique-id}')).toBe('unique-id');
});
});