diff --git a/src/components/SchemaDefinition/SchemaDefinition.tsx b/src/components/SchemaDefinition/SchemaDefinition.tsx index a3c5189f39..b939891230 100644 --- a/src/components/SchemaDefinition/SchemaDefinition.tsx +++ b/src/components/SchemaDefinition/SchemaDefinition.tsx @@ -14,6 +14,7 @@ export interface ObjectDescriptionProps { exampleRef?: string; showReadOnly?: boolean; showWriteOnly?: boolean; + showExample?: boolean; parser: OpenAPIParser; options: RedocNormalizedOptions; } @@ -53,7 +54,7 @@ export class SchemaDefinition extends React.PureComponent @@ -64,11 +65,16 @@ export class SchemaDefinition extends React.PureComponent - - - - - + {showExample && ( + + + + + + )} ); diff --git a/src/components/__tests__/SchemaDefinition.test.tsx b/src/components/__tests__/SchemaDefinition.test.tsx new file mode 100644 index 0000000000..215f6ecb05 --- /dev/null +++ b/src/components/__tests__/SchemaDefinition.test.tsx @@ -0,0 +1,82 @@ +/* tslint:disable:no-implicit-dependencies */ + +import { shallow } from 'enzyme'; +import * as React from 'react'; + +import { SchemaDefinition } from '..'; +import { OpenAPIParser } from '../../services'; +import { RedocNormalizedOptions } from '../../services/RedocNormalizedOptions'; +import { withTheme } from '../testProviders'; + +const options = new RedocNormalizedOptions({}); +describe('Components', () => { + describe('SchemaDefinition', () => { + const parser = new OpenAPIParser( + { + openapi: '3.0', + info: { + title: 'test', + version: '0', + }, + paths: {}, + components: { + schemas: { + test: { + type: 'object', + properties: { + id: { + type: 'string', + }, + }, + }, + }, + }, + }, + undefined, + options, + ); + + describe('Show example constraints', () => { + it('should show the example as default', () => { + const component = shallow( + withTheme( + , + ), + ); + expect(component.html().includes('')).toBe(true); + }); + + it('should show the example if `showExample` is `true`', () => { + const component = shallow( + withTheme( + , + ), + ); + expect(component.html().includes('')).toBe(true); + }); + + it('should hide the example if `showExample` is `false`', () => { + const component = shallow( + withTheme( + , + ), + ); + expect(component.html().includes('')).toBe(false); + }); + }); + }); +});