🎥 Make videos programmatically with React
Elements: Register catalog headings for anchor validation
Igor Samokhovetsc8b06a55e7ec
diff --git a/packages/docs/src/components/Elements/ElementLibrary.tsx b/packages/docs/src/components/Elements/ElementLibrary.tsxindex a72732b88d..028c91f2d9 100644--- a/packages/docs/src/components/Elements/ElementLibrary.tsx+++ b/packages/docs/src/components/Elements/ElementLibrary.tsx@@ -1,4 +1,5 @@import Link from '@docusaurus/Link';+import useBrokenLinks from '@docusaurus/useBrokenLinks';import {isInsideStudio,setStudioDragData,@@ -278,6 +279,7 @@ export const ElementLibrary: React.FC<{readonly category: ElementCategory | null;readonly sourceCodeBySlug: Readonly<Record<string, string>>;}> = ({category, sourceCodeBySlug}) => {+ const brokenLinks = useBrokenLinks();const prefersReducedMotion = usePrefersReducedMotion();const [isStudioEmbed, setIsStudioEmbed] = useState(false);const [isCaptionPicker, setIsCaptionPicker] = useState(false);@@ -403,6 +405,7 @@ export const ElementLibrary: React.FC<{}const categoryHeadingId = getElementCategoryHeadingId(section.category);+ brokenLinks.collectAnchor(categoryHeadingId);return (<sectiondiff --git a/packages/docs/src/test/elements.test.ts b/packages/docs/src/test/elements.test.tsindex f5308b2f2f..425af3e034 100644--- a/packages/docs/src/test/elements.test.ts+++ b/packages/docs/src/test/elements.test.ts@@ -15,6 +15,7 @@ import remarkElementSource from '../../plugins/remark-element-source';import {elementDefinitions} from '../components/Elements/element-definitions';import {createElementPayloadFromDefinition} from '../components/Elements/element-drag-data';import {+ getElementCategoryHeadingId,getElementDocumentationUrl,getElementLibrarySections,} from '../components/Elements/element-library-data';@@ -27,12 +28,19 @@ import {import {getElementPreviewDimensions} from '../components/Elements/ElementPreviewComposition';import {Seo} from '../components/Seo';-// Docusaurus generates this alias at build time. These checks only inspect SSR markup.+// Docusaurus generates these aliases at build time.mock.module('@docusaurus/Link', () => ({default: ({to, ...props}: React.ComponentProps<'a'> & {to: string}) =>React.createElement('a', {...props, href: to}),}));+const collectedAnchors = new Set<string>();+mock.module('@docusaurus/useBrokenLinks', () => ({+ default: () => ({+ collectAnchor: (anchor: string) => collectedAnchors.add(anchor),+ }),+}));+const elementsRoot = path.join(__dirname, '..', '..', 'elements');const templateRoot = path.join(__dirname, '..', '..', 'elements-template');const staticElementsRoot = path.join(@@ -292,6 +300,7 @@ describe('Element Library', () => {const {ElementLibrary} =await import('../components/Elements/ElementLibrary');const sourceCodeBySlug = getRemotionElementSourceMap({elementsRoot});+ collectedAnchors.clear();const overviewMarkup = renderToStaticMarkup(React.createElement(ElementLibrary, {category: null,@@ -307,6 +316,10 @@ describe('Element Library', () => {}for (const section of sections) {+ const headingId = getElementCategoryHeadingId(section.category);+ expect(overviewMarkup).toContain(`id="${headingId}"`);+ expect(collectedAnchors.has(headingId)).toBe(true);+const categoryMarkup = renderToStaticMarkup(React.createElement(ElementLibrary, {category: section.category,