Skip to content

Commit

Permalink
Merge pull request #12588 from phated/guard-duplicate-in-createSummar…
Browse files Browse the repository at this point in the history
…yValue

Addon-docs: Move summary & detail equality check to createSummaryValue
  • Loading branch information
shilman committed Oct 3, 2020
2 parents 5aab5b2 + ed59bcb commit e98574c
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 6 deletions.
Expand Up @@ -47,10 +47,7 @@ function generateElement(
inferredType as InspectionIdentifiableInferedType
);

return createSummaryValue(
prettyIdentifier,
prettyIdentifier !== defaultValue ? defaultValue : undefined
);
return createSummaryValue(prettyIdentifier, defaultValue);
}
}

Expand Down
Expand Up @@ -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)) {
Expand Down
2 changes: 1 addition & 1 deletion addons/docs/src/frameworks/react/propTypes/createType.ts
Expand Up @@ -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);
Expand Down
20 changes: 20 additions & 0 deletions addons/docs/src/lib/utils.test.ts
@@ -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 });
});
});
3 changes: 3 additions & 0 deletions addons/docs/src/lib/utils.ts
Expand Up @@ -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 };
}

Expand Down

0 comments on commit e98574c

Please sign in to comment.