Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

test(core): drop the tautological #4163 doc-contract tests (#5382)

Cindy Zhang63f398dfa3ae
diff --git a/packages/core/src/__tests__/apiContractDrift.test.tsx b/packages/core/src/__tests__/apiContractDrift.test.tsx
deleted file mode 100644
index 0f9462bf8a..0000000000
--- a/packages/core/src/__tests__/apiContractDrift.test.tsx
+++ /dev/null
@@ -1,80 +0,0 @@
-// Copyright (c) Meta Platforms, Inc. and affiliates.
-
-import {describe, it, expect} from 'vitest';
-
-import {docs as ButtonDocs} from '../Button/Button.doc.mjs';
-import {docs as ContextMenuDocs} from '../ContextMenu/ContextMenu.doc.mjs';
-import {docs as DialogDocs} from '../Dialog/Dialog.doc.mjs';
-import {docs as LinkDocs} from '../Link/Link.doc.mjs';
-import {docs as MoreMenuDocs} from '../MoreMenu/MoreMenu.doc.mjs';
-import {docs as NumberInputDocs} from '../NumberInput/NumberInput.doc.mjs';
-import {docs as PowerSearchDocs} from '../PowerSearch/PowerSearch.doc.mjs';
-import {docs as SelectorDocs} from '../Selector/Selector.doc.mjs';
-import {docs as TextInputDocs} from '../TextInput/TextInput.doc.mjs';
-import {docs as ToastDocs} from '../Toast/Toast.doc.mjs';
-import {docs as TokenizerDocs} from '../Tokenizer/Tokenizer.doc.mjs';
-
-// `docs` is the ComponentDoc union (single vs multi component); narrow it
-// for structural access to either the top-level props or the first
-// sub-component's props.
-function getProps(docs: unknown): {name: string}[] {
- const doc = docs as {
- props?: {name: string}[];
- components?: {props?: {name: string}[]}[];
- };
- return doc.props || doc.components?.[0]?.props || [];
-}
-
-describe('API Contract Drift Audit (#4163)', () => {
- it('documents Button link mode props', () => {
- const props = getProps(ButtonDocs).map(p => p.name);
- expect(props).toContain('href');
- expect(props).toContain('as');
- expect(props).toContain('target');
- expect(props).toContain('rel');
- });
-
- it('documents Toast onDismiss callback', () => {
- const props = getProps(ToastDocs).map(p => p.name);
- expect(props).toContain('onDismiss');
- });
-
- it('documents ContextMenu and MoreMenu onOpenChange callback', () => {
- const contextProps = getProps(ContextMenuDocs).map(p => p.name);
- const moreProps = getProps(MoreMenuDocs).map(p => p.name);
- expect(contextProps).toContain('onOpenChange');
- expect(moreProps).toContain('onOpenChange');
- });
-
- it('documents Selector startIcon and isLoading props', () => {
- const props = getProps(SelectorDocs).map(p => p.name);
- expect(props).toContain('startIcon');
- expect(props).toContain('isLoading');
- });
-
- it('documents TextInput and NumberInput onEnter / onKeyDown callbacks', () => {
- const textProps = getProps(TextInputDocs).map(p => p.name);
- const numProps = getProps(NumberInputDocs).map(p => p.name);
- expect(textProps).toContain('onEnter');
- expect(textProps).toContain('onKeyDown');
- expect(numProps).toContain('onEnter');
- expect(numProps).toContain('onKeyDown');
- });
-
- it('documents PowerSearch and Tokenizer onFocus / onBlur callbacks', () => {
- const powerProps = getProps(PowerSearchDocs).map(p => p.name);
- const tokProps = getProps(TokenizerDocs).map(p => p.name);
- expect(powerProps).toContain('onFocus');
- expect(powerProps).toContain('onBlur');
- expect(tokProps).toContain('onFocus');
- expect(tokProps).toContain('onBlur');
- });
-
- it('documents Link download / referrerPolicy and Dialog padding props', () => {
- const linkProps = getProps(LinkDocs).map(p => p.name);
- const dialogProps = getProps(DialogDocs).map(p => p.name);
- expect(linkProps).toContain('download');
- expect(linkProps).toContain('referrerPolicy');
- expect(dialogProps).toContain('padding');
- });
-});
diff --git a/packages/core/src/__tests__/fieldContract.test.tsx b/packages/core/src/__tests__/fieldContract.test.tsx
deleted file mode 100644
index 947ef0f900..0000000000
--- a/packages/core/src/__tests__/fieldContract.test.tsx
+++ /dev/null
@@ -1,24 +0,0 @@
-// Copyright (c) Meta Platforms, Inc. and affiliates.
-
-import {describe, it, expect} from 'vitest';
-
-import {docs as FieldDocs} from '../Field/Field.doc.mjs';
-
-// `docs` is the ComponentDoc union (single vs multi component); narrow it
-// for structural access to either the top-level props or the first
-// sub-component's props.
-function getProps(docs: unknown): {name: string}[] {
- const doc = docs as {
- props?: {name: string}[];
- components?: {props?: {name: string}[]}[];
- };
- return doc.props || doc.components?.[0]?.props || [];
-}
-
-describe('Field Component API Contract Drift (#4163)', () => {
- it('documents Field labelID and isGroupLabel props', () => {
- const props = getProps(FieldDocs).map(p => p.name);
- expect(props).toContain('labelID');
- expect(props).toContain('isGroupLabel');
- });
-});
diff --git a/packages/core/src/__tests__/inputWidthContract.test.tsx b/packages/core/src/__tests__/inputWidthContract.test.tsx
deleted file mode 100644
index edf40a5c9c..0000000000
--- a/packages/core/src/__tests__/inputWidthContract.test.tsx
+++ /dev/null
@@ -1,69 +0,0 @@
-// Copyright (c) Meta Platforms, Inc. and affiliates.
-
-import {describe, it, expect} from 'vitest';
-
-import {docs as CheckboxInputDocs} from '../CheckboxInput/CheckboxInput.doc.mjs';
-import {docs as CheckboxListDocs} from '../CheckboxList/CheckboxList.doc.mjs';
-import {docs as DateInputDocs} from '../DateInput/DateInput.doc.mjs';
-import {docs as DateRangeInputDocs} from '../DateRangeInput/DateRangeInput.doc.mjs';
-import {docs as DateTimeInputDocs} from '../DateTimeInput/DateTimeInput.doc.mjs';
-import {docs as FileInputDocs} from '../FileInput/FileInput.doc.mjs';
-import {docs as MultiSelectorDocs} from '../MultiSelector/MultiSelector.doc.mjs';
-import {docs as NumberInputDocs} from '../NumberInput/NumberInput.doc.mjs';
-import {docs as RadioListDocs} from '../RadioList/RadioList.doc.mjs';
-import {docs as SelectorDocs} from '../Selector/Selector.doc.mjs';
-import {docs as SliderDocs} from '../Slider/Slider.doc.mjs';
-import {docs as SwitchDocs} from '../Switch/Switch.doc.mjs';
-import {docs as TextAreaDocs} from '../TextArea/TextArea.doc.mjs';
-import {docs as TextInputDocs} from '../TextInput/TextInput.doc.mjs';
-import {docs as TimeInputDocs} from '../TimeInput/TimeInput.doc.mjs';
-import {docs as TokenizerDocs} from '../Tokenizer/Tokenizer.doc.mjs';
-import {docs as TypeaheadDocs} from '../Typeahead/Typeahead.doc.mjs';
-
-const inputDocsSuite = [
- {name: 'CheckboxInput', docs: CheckboxInputDocs},
- {name: 'CheckboxList', docs: CheckboxListDocs},
- {name: 'DateInput', docs: DateInputDocs},
- {name: 'DateRangeInput', docs: DateRangeInputDocs},
- {name: 'DateTimeInput', docs: DateTimeInputDocs},
- {name: 'FileInput', docs: FileInputDocs},
- {name: 'MultiSelector', docs: MultiSelectorDocs},
- {name: 'NumberInput', docs: NumberInputDocs},
- {name: 'RadioList', docs: RadioListDocs},
- {name: 'Selector', docs: SelectorDocs},
- {name: 'Slider', docs: SliderDocs},
- {name: 'Switch', docs: SwitchDocs},
- {name: 'TextArea', docs: TextAreaDocs},
- {name: 'TextInput', docs: TextInputDocs},
- {name: 'TimeInput', docs: TimeInputDocs},
- {name: 'Tokenizer', docs: TokenizerDocs},
- {name: 'Typeahead', docs: TypeaheadDocs},
-];
-
-describe('Input Family width Prop Contract (#4163)', () => {
- inputDocsSuite.forEach(({name, docs}) => {
- it(`documents the width prop for ${name}`, () => {
- // `docs` is the ComponentDoc union (single vs multi component); narrow it
- // for structural access to either the top-level props or the first
- // sub-component's props.
- const doc = docs as {
- props?: {name: string; type: string}[];
- components?: {props?: {name: string; type: string}[]}[];
- };
- const propsList = (doc.props || doc.components?.[0]?.props) as {
- name: string;
- type: string;
- }[];
- expect(
- propsList,
- `${name}.doc.mjs must expose a props array`,
- ).toBeDefined();
- const widthProp = propsList.find(p => p.name === 'width');
- expect(
- widthProp,
- `${name}.doc.mjs must document the width prop`,
- ).toBeDefined();
- expect(widthProp?.type).toBe('SizeValue');
- });
- });
-});
diff --git a/packages/core/src/__tests__/structuralComponentContract.test.tsx b/packages/core/src/__tests__/structuralComponentContract.test.tsx
deleted file mode 100644
index 3c20f5a3cd..0000000000
--- a/packages/core/src/__tests__/structuralComponentContract.test.tsx
+++ /dev/null
@@ -1,39 +0,0 @@
-// Copyright (c) Meta Platforms, Inc. and affiliates.
-
-import {describe, it, expect} from 'vitest';
-
-import {docs as CodeBlockDocs} from '../CodeBlock/CodeBlock.doc.mjs';
-import {docs as StackDocs} from '../Stack/Stack.doc.mjs';
-import {docs as ToolbarDocs} from '../Toolbar/Toolbar.doc.mjs';
-
-// `docs` is the ComponentDoc union (single vs multi component); narrow it
-// for structural access to either the top-level props or the first
-// sub-component's props.
-function getProps(docs: unknown): {name: string}[] {
- const doc = docs as {
- props?: {name: string}[];
- components?: {props?: {name: string}[]}[];
- };
- return doc.props || doc.components?.[0]?.props || [];
-}
-
-describe('Structural Component API Contract Drift (#4163)', () => {
- it('documents CodeBlock highlightMode prop', () => {
- const props = getProps(CodeBlockDocs).map(p => p.name);
- expect(props).toContain('highlightMode');
- });
-
- it('documents Toolbar dividers prop', () => {
- const props = getProps(ToolbarDocs).map(p => p.name);
- expect(props).toContain('dividers');
- });
-
- it('documents Stack direction and base props', () => {
- const props = getProps(StackDocs).map(p => p.name);
- expect(props).toContain('direction');
- expect(props).toContain('gap');
- expect(props).toContain('padding');
- expect(props).toContain('width');
- expect(props).toContain('height');
- });
-});
diff --git a/packages/lab/src/__tests__/labApiContractDrift.test.tsx b/packages/lab/src/__tests__/labApiContractDrift.test.tsx
deleted file mode 100644
index 4293f8916e..0000000000
--- a/packages/lab/src/__tests__/labApiContractDrift.test.tsx
+++ /dev/null
@@ -1,51 +0,0 @@
-// Copyright (c) Meta Platforms, Inc. and affiliates.
-
-import {describe, it, expect} from 'vitest';
-
-import {docs as ChatReasoningDocs} from '../ChatReasoning/ChatReasoning.doc.mjs';
-import {docs as CodeEditorDocs} from '../CodeEditor/CodeEditor.doc.mjs';
-import {docs as LogStreamDocs} from '../LogStream/LogStream.doc.mjs';
-
-function getProps(docs: Record<string, unknown>): Array<{name: string}> {
- return (
- (docs.props as Array<{name: string}>) ||
- (
- docs.components as Array<{
- props: Array<{name: string}>;
- }>
- )?.[0]?.props ||
- []
- );
-}
-
-describe('Lab API Contract Drift (#4163)', () => {
- it('documents ChatReasoning props', () => {
- const props = getProps(ChatReasoningDocs).map(p => p.name);
- expect(props).toContain('duration');
- expect(props).toContain('isStreaming');
- expect(props).toContain('isExpanded');
- expect(props).toContain('defaultIsExpanded');
- expect(props).toContain('onExpandedChange');
- });
-
- it('documents CodeEditor props', () => {
- const props = getProps(CodeEditorDocs).map(p => p.name);
- expect(props).toContain('language');
- expect(props).toContain('hasLineNumbers');
- expect(props).toContain('isReadOnly');
- expect(props).toContain('placeholder');
- expect(props).toContain('maxHeight');
- expect(props).toContain('size');
- expect(props).toContain('tokenizer');
- });
-
- it('documents LogStream props', () => {
- const props = getProps(LogStreamDocs).map(p => p.name);
- expect(props).toContain('variant');
- expect(props).toContain('isFollowing');
- expect(props).toContain('onFollowChange');
- expect(props).toContain('maxHeight');
- expect(props).toContain('hasTimestamps');
- expect(props).toContain('renderEntry');
- });
-});