Skip to content

Commit 8c91994

Browse files
P0lipmarbemac
authored andcommitted
fix: render falsy validation values (#32)
* fix: render falsy validation values * refactor: don't pass treeStore down
1 parent 62cbd5e commit 8c91994

File tree

2 files changed

+40
-5
lines changed

2 files changed

+40
-5
lines changed

src/components/SchemaRow.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { MarkdownViewer } from '@stoplight/markdown-viewer';
2-
import { IRowRendererOptions, TreeStore } from '@stoplight/tree-list';
2+
import { IRowRendererOptions } from '@stoplight/tree-list';
33
import { Icon, Popover } from '@stoplight/ui-kit';
44
import * as cn from 'classnames';
55
import * as React from 'react';
@@ -15,15 +15,14 @@ import { Types } from './';
1515
export interface ISchemaRow {
1616
node: SchemaTreeListNode;
1717
rowOptions: IRowRendererOptions;
18-
treeStore: TreeStore;
1918
onGoToRef?: GoToRefHandler;
2019
}
2120

2221
const ICON_SIZE = 12;
2322
const ICON_DIMENSION = 20;
2423
const ROW_OFFSET = 7;
2524

26-
export const SchemaRow: React.FunctionComponent<ISchemaRow> = ({ node, treeStore, onGoToRef }) => {
25+
export const SchemaRow: React.FunctionComponent<ISchemaRow> = ({ node, rowOptions, onGoToRef }) => {
2726
const schemaNode = node.metadata as SchemaNodeWithMeta;
2827
const { name, $ref, subtype, required } = schemaNode;
2928

@@ -79,7 +78,7 @@ export const SchemaRow: React.FunctionComponent<ISchemaRow> = ({ node, treeStore
7978
>
8079
<Icon
8180
iconSize={ICON_SIZE}
82-
icon={treeStore.isNodeExpanded(node) ? 'caret-down' : 'caret-right'}
81+
icon={rowOptions.isExpanded ? 'caret-down' : 'caret-right'}
8382
className="text-darken-9 dark:text-lighten-9"
8483
/>
8584
</div>
@@ -140,7 +139,7 @@ export const SchemaRow: React.FunctionComponent<ISchemaRow> = ({ node, treeStore
140139
if (Array.isArray(validation)) {
141140
elem = validation.map((v, i) => (
142141
<div key={i} className="mt-1 mr-1 flex items-center">
143-
<div className="px-1 bg-gray-2 dark:bg-gray-8 font-bold text-sm rounded">{v}</div>
142+
<div className="px-1 bg-gray-2 dark:bg-gray-8 font-bold text-sm rounded">{String(v)}</div>
144143
{i < validation.length - 1 ? <div>,</div> : null}
145144
</div>
146145
));
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { Popover } from '@stoplight/ui-kit';
2+
import { shallow } from 'enzyme';
3+
import 'jest-enzyme';
4+
import * as React from 'react';
5+
import { SchemaTreeListNode } from '../../types';
6+
import { SchemaRow } from '../SchemaRow';
7+
8+
describe('SchemaRow component', () => {
9+
test('should render falsy validations', () => {
10+
const node: SchemaTreeListNode = {
11+
id: '0.n1f7tvhzoj',
12+
level: 0,
13+
name: '',
14+
metadata: {
15+
type: 'object',
16+
validations: {
17+
enum: [null, 0, false],
18+
},
19+
annotations: {},
20+
enum: [null, 0, false],
21+
path: [],
22+
} as any,
23+
};
24+
25+
const rowOptions = {
26+
isEdited: false,
27+
isExpanded: true,
28+
};
29+
30+
const wrapper = shallow(shallow(<SchemaRow node={node as SchemaTreeListNode} rowOptions={rowOptions} />)
31+
.find(Popover)
32+
.prop('content') as React.ReactElement);
33+
34+
expect(wrapper).toHaveText('enum:null,0,false');
35+
});
36+
});

0 commit comments

Comments
 (0)