-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add option to hide the example code when using the `SchemaDefin…
…ition` component (#2157)
- Loading branch information
1 parent
1697d2c
commit 168189b
Showing
2 changed files
with
94 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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( | ||
<SchemaDefinition | ||
schemaRef="#/components/schemas/test" | ||
parser={parser} | ||
options={options} | ||
/>, | ||
), | ||
); | ||
expect(component.html().includes('<code>')).toBe(true); | ||
}); | ||
|
||
it('should show the example if `showExample` is `true`', () => { | ||
const component = shallow( | ||
withTheme( | ||
<SchemaDefinition | ||
schemaRef="#/components/schemas/test" | ||
parser={parser} | ||
options={options} | ||
showExample={true} | ||
/>, | ||
), | ||
); | ||
expect(component.html().includes('<code>')).toBe(true); | ||
}); | ||
|
||
it('should hide the example if `showExample` is `false`', () => { | ||
const component = shallow( | ||
withTheme( | ||
<SchemaDefinition | ||
schemaRef="#/components/schemas/test" | ||
parser={parser} | ||
options={options} | ||
showExample={false} | ||
/>, | ||
), | ||
); | ||
expect(component.html().includes('<code>')).toBe(false); | ||
}); | ||
}); | ||
}); | ||
}); |