From 408bb3eb2820e0377ec3cda24a9ef71205c0dac2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ro=C5=BCek?= Date: Wed, 26 Jun 2019 22:59:21 +0200 Subject: [PATCH 1/2] fix: render falsy validation values --- src/components/SchemaRow.tsx | 2 +- src/components/__tests__/SchemaRow.spec.tsx | 36 +++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 src/components/__tests__/SchemaRow.spec.tsx diff --git a/src/components/SchemaRow.tsx b/src/components/SchemaRow.tsx index 524f4d59..d9a0ea88 100644 --- a/src/components/SchemaRow.tsx +++ b/src/components/SchemaRow.tsx @@ -140,7 +140,7 @@ export const SchemaRow: React.FunctionComponent = ({ node, treeStore if (Array.isArray(validation)) { elem = validation.map((v, i) => (
-
{v}
+
{String(v)}
{i < validation.length - 1 ?
,
: null}
)); diff --git a/src/components/__tests__/SchemaRow.spec.tsx b/src/components/__tests__/SchemaRow.spec.tsx new file mode 100644 index 00000000..0f362567 --- /dev/null +++ b/src/components/__tests__/SchemaRow.spec.tsx @@ -0,0 +1,36 @@ +import { Popover } from '@stoplight/ui-kit'; +import { shallow } from 'enzyme'; +import 'jest-enzyme'; +import * as React from 'react'; +import { SchemaTreeListNode } from '../../types'; +import { SchemaRow } from '../SchemaRow'; + +describe('SchemaRow component', () => { + test('should render falsy validations', () => { + const node: SchemaTreeListNode = { + id: '0.n1f7tvhzoj', + level: 0, + name: '', + metadata: { + type: 'object', + validations: { + enum: [null, 0, false], + }, + annotations: {}, + enum: [null, 0, false], + path: [], + } as any, + }; + + const rowOptions = { + isEdited: false, + isExpanded: true, + }; + + const wrapper = shallow(shallow() + .find(Popover) + .prop('content') as React.ReactElement); + + expect(wrapper).toHaveText('enum:null,0,false'); + }); +}); From dcbf0fae985c40d94c7310c0de0cfb6805af4375 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ro=C5=BCek?= Date: Wed, 26 Jun 2019 23:05:03 +0200 Subject: [PATCH 2/2] refactor: don't pass treeStore down --- src/components/SchemaRow.tsx | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/components/SchemaRow.tsx b/src/components/SchemaRow.tsx index d9a0ea88..900647f6 100644 --- a/src/components/SchemaRow.tsx +++ b/src/components/SchemaRow.tsx @@ -1,5 +1,5 @@ import { MarkdownViewer } from '@stoplight/markdown-viewer'; -import { IRowRendererOptions, TreeStore } from '@stoplight/tree-list'; +import { IRowRendererOptions } from '@stoplight/tree-list'; import { Icon, Popover } from '@stoplight/ui-kit'; import * as cn from 'classnames'; import * as React from 'react'; @@ -15,7 +15,6 @@ import { Types } from './'; export interface ISchemaRow { node: SchemaTreeListNode; rowOptions: IRowRendererOptions; - treeStore: TreeStore; onGoToRef?: GoToRefHandler; } @@ -23,7 +22,7 @@ const ICON_SIZE = 12; const ICON_DIMENSION = 20; const ROW_OFFSET = 7; -export const SchemaRow: React.FunctionComponent = ({ node, treeStore, onGoToRef }) => { +export const SchemaRow: React.FunctionComponent = ({ node, rowOptions, onGoToRef }) => { const schemaNode = node.metadata as SchemaNodeWithMeta; const { name, $ref, subtype, required } = schemaNode; @@ -79,7 +78,7 @@ export const SchemaRow: React.FunctionComponent = ({ node, treeStore >