From 2462639f76bc86a3d9d0387632c6286acb810b94 Mon Sep 17 00:00:00 2001 From: Roman Hotsiy Date: Mon, 5 Mar 2018 13:31:27 +0200 Subject: [PATCH] fix: skipReadOnly/skipWritOnly not passing down to nested OneOf --- src/components/Schema/OneOfSchema.tsx | 2 +- src/components/Schema/Schema.tsx | 2 +- .../Schema/__tests__/OneOfSchema.test.tsx | 44 +++++++++++++++++++ 3 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 src/components/Schema/__tests__/OneOfSchema.test.tsx diff --git a/src/components/Schema/OneOfSchema.tsx b/src/components/Schema/OneOfSchema.tsx index 34230dc29a..e25f888eb7 100644 --- a/src/components/Schema/OneOfSchema.tsx +++ b/src/components/Schema/OneOfSchema.tsx @@ -47,7 +47,7 @@ export class OneOfSchema extends React.Component { ))} - + ); } diff --git a/src/components/Schema/Schema.tsx b/src/components/Schema/Schema.tsx index 3d3ab17815..7994e019aa 100644 --- a/src/components/Schema/Schema.tsx +++ b/src/components/Schema/Schema.tsx @@ -52,7 +52,7 @@ export class Schema extends React.Component> { } if (oneOf !== undefined) { - return ; + return ; } switch (type) { diff --git a/src/components/Schema/__tests__/OneOfSchema.test.tsx b/src/components/Schema/__tests__/OneOfSchema.test.tsx new file mode 100644 index 0000000000..2c39ad454b --- /dev/null +++ b/src/components/Schema/__tests__/OneOfSchema.test.tsx @@ -0,0 +1,44 @@ +import * as React from 'react'; +import { shallow } from 'enzyme'; +import toJson from 'enzyme-to-json'; + +import { filterPropsDeep } from '../../../utils/test-utils'; + +import { RedocNormalizedOptions } from '../../../services/RedocNormalizedOptions'; +import { OpenAPIParser, SchemaModel } from '../../../services'; +import { Schema } from '../Schema'; +import { OneOfSchema } from '../OneOfSchema'; + +const options = new RedocNormalizedOptions({}); +describe('Components', () => { + describe('SchemaView', () => { + 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' }] }, + '', + options, + ); + let schemaViewElement = shallow( + , + ).getElement(); + expect(schemaViewElement.type).toEqual(OneOfSchema); + expect(schemaViewElement.props.skipWriteOnly).toBeTruthy(); + expect(schemaViewElement.props.skipReadOnly).toBeFalsy(); + + schemaViewElement = shallow().getElement(); + + expect(schemaViewElement.type).toEqual(OneOfSchema); + expect(schemaViewElement.props.skipWriteOnly).toBeFalsy(); + expect(schemaViewElement.props.skipReadOnly).toBeTruthy(); + }); + }); + }); +});