Merge pull request #12588 from phated/guard-duplicate-in-createSummaryValue

Addon-docs: Move summary & detail equality check to createSummaryValue
This commit is contained in:
Michael Shilman 2020-10-03 21:21:28 +08:00 committed by GitHub
commit e98574cd9f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 26 additions and 6 deletions

View File

@ -47,10 +47,7 @@ function generateElement(
inferredType as InspectionIdentifiableInferedType
);
return createSummaryValue(
prettyIdentifier,
prettyIdentifier !== defaultValue ? defaultValue : undefined
);
return createSummaryValue(prettyIdentifier, defaultValue);
}
}

View File

@ -50,7 +50,7 @@ function generateReactObject(rawDefaultProp: any) {
if (displayName != null) {
const prettyIdentifier = getPrettyElementIdentifier(displayName);
return createSummaryValue(prettyIdentifier, prettyIdentifier !== jsx ? jsx : undefined);
return createSummaryValue(prettyIdentifier, jsx);
}
if (isString(type)) {

View File

@ -381,7 +381,7 @@ export function createType(extractedProp: ExtractedProp): PropType {
}
}
return createSummaryValue(short, short !== full ? full : undefined);
return createSummaryValue(short, full);
}
case PropTypesType.FUNC: {
const { short, full } = generateType(type, extractedProp);

View File

@ -0,0 +1,20 @@
import { createSummaryValue } from './utils';
describe('createSummaryValue', () => {
it('creates an object with just summary if detail is not passed', () => {
const summary = 'boolean';
expect(createSummaryValue(summary)).toEqual({ summary });
});
it('creates an object with summary & detail if passed', () => {
const summary = 'MyType';
const detail = 'boolean | string';
expect(createSummaryValue(summary, detail)).toEqual({ summary, detail });
});
it('creates an object with just summary if details are equal', () => {
const summary = 'boolean';
const detail = 'boolean';
expect(createSummaryValue(summary, detail)).toEqual({ summary });
});
});

View File

@ -12,6 +12,9 @@ export function isTooLongForDefaultValueSummary(value: string): boolean {
}
export function createSummaryValue(summary: string, detail?: string): PropSummaryValue {
if (summary === detail) {
return { summary };
}
return { summary, detail };
}