diff --git a/package.json b/package.json index d737b1e4..d4af75fe 100644 --- a/package.json +++ b/package.json @@ -191,6 +191,9 @@ "modulePathIgnorePatterns": [ "/benchmark/" ], + "snapshotSerializers": [ + "enzyme-to-json/serializer" + ], "moduleNameMapper": { "\\.(css|less)$": "/src/empty.js" } diff --git a/src/common-elements/schema.ts b/src/common-elements/schema.ts index d422ba57..6fcd2824 100644 --- a/src/common-elements/schema.ts +++ b/src/common-elements/schema.ts @@ -1,5 +1,6 @@ import styled from '../styled-components'; import { darken } from 'polished'; +import { deprecatedCss } from './mixins'; export const OneOfList = styled.div` margin: 0 0 3px 0; @@ -14,7 +15,7 @@ export const OneOfLabel = styled.span` } `; -export const OneOfButton = styled.button<{ active: boolean }>` +export const OneOfButton = styled.button<{ active: boolean; deprecated: boolean }>` display: inline-block; margin-right: 10px; margin-bottom: 5px; @@ -28,6 +29,8 @@ export const OneOfButton = styled.button<{ active: boolean }>` box-shadow: 0 0 0 1px ${props => props.theme.colors.primary.main}; } + ${({ deprecated }) => (deprecated && deprecatedCss) || ''}; + ${props => { if (props.active) { return ` diff --git a/src/components/Schema/OneOfSchema.tsx b/src/components/Schema/OneOfSchema.tsx index 8574ff40..b0864c33 100644 --- a/src/components/Schema/OneOfSchema.tsx +++ b/src/components/Schema/OneOfSchema.tsx @@ -6,6 +6,7 @@ import { OneOfLabel, OneOfList, } from '../../common-elements/schema'; +import { Badge } from '../../common-elements/shelfs'; import { SchemaModel } from '../../services/models'; import { Schema, SchemaProps } from './Schema'; @@ -20,7 +21,11 @@ export class OneOfButton extends React.Component { render() { const { idx, schema, subSchema } = this.props; return ( - + {subSchema.title || subSchema.typePrefix + subSchema.displayType} ); @@ -50,6 +55,9 @@ export class OneOfSchema extends React.Component { ))} +
+ {oneOf[schema.activeOneOf].deprecated && Deprecated} +
); diff --git a/src/components/__tests__/OneOfSchema.test.tsx b/src/components/__tests__/OneOfSchema.test.tsx index 9d178391..e9425db7 100644 --- a/src/components/__tests__/OneOfSchema.test.tsx +++ b/src/components/__tests__/OneOfSchema.test.tsx @@ -6,18 +6,19 @@ import * as React from 'react'; import { OneOfSchema, Schema } from '../'; import { OpenAPIParser, SchemaModel } from '../../services'; import { RedocNormalizedOptions } from '../../services/RedocNormalizedOptions'; +import { withTheme } from '../testProviders'; const options = new RedocNormalizedOptions({}); describe('Components', () => { describe('SchemaView', () => { + const parser = new OpenAPIParser( + { openapi: '3.0', info: { title: 'test', version: '0' }, paths: {} }, + undefined, + options, + ); + describe('OneOf', () => { it('should pass down skipReadOnly/skipReadWrite to nested oneOf', () => { - const parser = new OpenAPIParser( - { openapi: '3.0', info: { title: 'test', version: '0' }, paths: {} }, - undefined, - options, - ); - const schema = new SchemaModel( parser, { oneOf: [{ type: 'string' }, { type: 'integer' }] }, @@ -38,5 +39,19 @@ describe('Components', () => { expect(schemaViewElement.props.skipReadOnly).toBeTruthy(); }); }); + + describe('OneOf deprecated', () => { + const schema = new SchemaModel( + parser, + { oneOf: [{ type: 'string', deprecated: true }, { type: 'integer' }] }, + '', + options, + ); + + it('should match snapshot', () => { + const component = shallow(withTheme()); + expect(component.render()).toMatchSnapshot(); + }); + }); }); }); diff --git a/src/components/__tests__/__snapshots__/OneOfSchema.test.tsx.snap b/src/components/__tests__/__snapshots__/OneOfSchema.test.tsx.snap new file mode 100644 index 00000000..f8ecab88 --- /dev/null +++ b/src/components/__tests__/__snapshots__/OneOfSchema.test.tsx.snap @@ -0,0 +1,53 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Components SchemaView OneOf deprecated should match snapshot 1`] = ` +
+ + One of + +
+ + +
+
+ + Deprecated + +
+
+
+
+ + + string + +
+ +
+
+
+
+
+
+`; diff --git a/src/components/testProviders.tsx b/src/components/testProviders.tsx index 510d0db9..8f8c89dc 100644 --- a/src/components/testProviders.tsx +++ b/src/components/testProviders.tsx @@ -1,11 +1,11 @@ import * as React from 'react'; import { ThemeProvider } from 'styled-components'; -import defaultTheme from '../theme'; +import defaultTheme, { resolveTheme } from '../theme'; export default class TestThemeProvider extends React.Component { render() { return ( - + {React.Children.only(this.props.children as any)} );