-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: consume schema title property (#76)
* feat: pretty titles * fix: pr feedback
- Loading branch information
Showing
12 changed files
with
559 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,6 @@ | ||
@import "~@stoplight/tree-list/styles/_tree-list.scss"; | ||
@import "~@stoplight/ui-kit/styles/_ui-kit.scss"; | ||
|
||
.JsonSchemaViewer { | ||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', system-ui, sans-serif, | ||
'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji';} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,89 @@ | ||
import { shallow } from 'enzyme'; | ||
import 'jest-enzyme'; | ||
import * as React from 'react'; | ||
import { SchemaKind } from '../../types'; | ||
import { IType, PropertyTypeColors, Type } from '../shared/Types'; | ||
|
||
describe('Type component', () => { | ||
it.each(Object.keys(PropertyTypeColors))('should handle $s type', type => { | ||
const wrapper = shallow(<Type type={type as IType['type']} subtype={void 0} />); | ||
const wrapper = shallow(<Type type={type as IType['type']} subtype={void 0} title={void 0} />); | ||
|
||
expect(wrapper).toHaveText(type); | ||
}); | ||
|
||
it('should handle unknown types', () => { | ||
// @ts-ignore | ||
const wrapper = shallow(<Type type="foo" subtype={void 0} />); | ||
const wrapper = shallow(<Type type="foo" subtype={void 0} title={void 0} />); | ||
|
||
expect(wrapper).toHaveText('foo'); | ||
}); | ||
|
||
it('should display non-array subtype for array', () => { | ||
const wrapper = shallow(<Type type="array" subtype="object" />); | ||
const wrapper = shallow(<Type type={SchemaKind.Array} subtype={SchemaKind.Object} title={void 0} />); | ||
|
||
expect(wrapper).toHaveText('array[object]'); | ||
}); | ||
|
||
it('should not display array subtype for array', () => { | ||
const wrapper = shallow(<Type type="array" subtype="array" />); | ||
const wrapper = shallow(<Type type={SchemaKind.Array} subtype={SchemaKind.Array} title={void 0} />); | ||
|
||
expect(wrapper).toHaveText('array'); | ||
}); | ||
|
||
describe('titles', () => { | ||
describe('when main type equals array', () => { | ||
it('given object type, should display title', () => { | ||
const wrapper = shallow(<Type type={SchemaKind.Array} subtype={SchemaKind.Object} title="foo" />); | ||
|
||
expect(wrapper).toHaveText('foo[]'); | ||
}); | ||
|
||
it('given array type, should display title', () => { | ||
const wrapper = shallow(<Type type={SchemaKind.Array} subtype={SchemaKind.Array} title="foo" />); | ||
|
||
expect(wrapper).toHaveText('foo[]'); | ||
}); | ||
|
||
it('given primitive type, should not display title', () => { | ||
const wrapper = shallow(<Type type={SchemaKind.Array} subtype={SchemaKind.String} title="foo" />); | ||
|
||
expect(wrapper).toHaveText('array[string]'); | ||
}); | ||
|
||
it('given mixed types, should not display title', () => { | ||
const wrapper = shallow( | ||
<Type type={SchemaKind.Array} subtype={[SchemaKind.String, SchemaKind.Object]} title="foo" />, | ||
); | ||
|
||
expect(wrapper).toHaveText('array[string,object]'); | ||
}); | ||
|
||
it('given $ref type, should display title', () => { | ||
const wrapper = shallow(<Type type={SchemaKind.Array} subtype="$ref" title="foo" />); | ||
|
||
expect(wrapper).toHaveText('foo[]'); | ||
}); | ||
}); | ||
|
||
it('given object type, should always display title', () => { | ||
const wrapper = shallow(<Type type={SchemaKind.Object} subtype={void 0} title="foo" />); | ||
|
||
expect(wrapper).toHaveText('foo'); | ||
}); | ||
|
||
it('given $ref type, should always display title', () => { | ||
const wrapper = shallow(<Type type="$ref" subtype={void 0} title="foo" />); | ||
|
||
expect(wrapper).toHaveText('foo'); | ||
}); | ||
|
||
it.each([SchemaKind.Null, SchemaKind.Integer, SchemaKind.Number, SchemaKind.Boolean, SchemaKind.String])( | ||
'given primitive %s type, should not display title', | ||
type => { | ||
const wrapper = shallow(<Type type={type} subtype={void 0} title="foo" />); | ||
|
||
expect(wrapper).toHaveText(type); | ||
}, | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.