Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/components/__tests__/Property.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { shallow } from 'enzyme';
import 'jest-enzyme';
import * as React from 'react';
import { SchemaNodeWithMeta } from '../../types';
import { Property, Types } from '../shared';

describe('Property component', () => {
it('should render Types with propper type and subtype', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

const node: SchemaNodeWithMeta = {
id: '1',
type: 'array',
items: {
type: 'string',
},
annotations: {
examples: {},
},
validations: {},
path: [],
};

const wrapper = shallow(<Property node={node} />);
expect(wrapper.find(Types)).toExist();
expect(wrapper.find(Types)).toHaveProp('type', 'array');
expect(wrapper.find(Types)).toHaveProp('subtype', 'string');
});
});
6 changes: 5 additions & 1 deletion src/utils/inferType.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { JSONSchema4, JSONSchema4TypeName } from 'json-schema';
import { SchemaKind } from '../types';

export function inferType(node: JSONSchema4): JSONSchema4TypeName | undefined {
export function inferType(node: JSONSchema4): JSONSchema4TypeName | JSONSchema4TypeName[] | undefined {
if ('type' in node) {
return node.type;
}

if ('properties' in node) {
return SchemaKind.Object;
}
Expand Down