|
1 | 1 | import { shallow } from 'enzyme'; |
2 | 2 | import 'jest-enzyme'; |
3 | 3 | import * as React from 'react'; |
| 4 | +import { SchemaKind } from '../../types'; |
4 | 5 | import { IType, PropertyTypeColors, Type } from '../shared/Types'; |
5 | 6 |
|
6 | 7 | describe('Type component', () => { |
7 | 8 | it.each(Object.keys(PropertyTypeColors))('should handle $s type', type => { |
8 | | - const wrapper = shallow(<Type type={type as IType['type']} subtype={void 0} />); |
| 9 | + const wrapper = shallow(<Type type={type as IType['type']} subtype={void 0} title={void 0} />); |
9 | 10 |
|
10 | 11 | expect(wrapper).toHaveText(type); |
11 | 12 | }); |
12 | 13 |
|
13 | 14 | it('should handle unknown types', () => { |
14 | 15 | // @ts-ignore |
15 | | - const wrapper = shallow(<Type type="foo" subtype={void 0} />); |
| 16 | + const wrapper = shallow(<Type type="foo" subtype={void 0} title={void 0} />); |
16 | 17 |
|
17 | 18 | expect(wrapper).toHaveText('foo'); |
18 | 19 | }); |
19 | 20 |
|
20 | 21 | it('should display non-array subtype for array', () => { |
21 | | - const wrapper = shallow(<Type type="array" subtype="object" />); |
| 22 | + const wrapper = shallow(<Type type={SchemaKind.Array} subtype={SchemaKind.Object} title={void 0} />); |
22 | 23 |
|
23 | 24 | expect(wrapper).toHaveText('array[object]'); |
24 | 25 | }); |
25 | 26 |
|
26 | 27 | it('should not display array subtype for array', () => { |
27 | | - const wrapper = shallow(<Type type="array" subtype="array" />); |
| 28 | + const wrapper = shallow(<Type type={SchemaKind.Array} subtype={SchemaKind.Array} title={void 0} />); |
28 | 29 |
|
29 | 30 | expect(wrapper).toHaveText('array'); |
30 | 31 | }); |
| 32 | + |
| 33 | + describe('titles', () => { |
| 34 | + describe('when main type equals array', () => { |
| 35 | + it('given object type, should display title', () => { |
| 36 | + const wrapper = shallow(<Type type={SchemaKind.Array} subtype={SchemaKind.Object} title="foo" />); |
| 37 | + |
| 38 | + expect(wrapper).toHaveText('foo[]'); |
| 39 | + }); |
| 40 | + |
| 41 | + it('given array type, should display title', () => { |
| 42 | + const wrapper = shallow(<Type type={SchemaKind.Array} subtype={SchemaKind.Array} title="foo" />); |
| 43 | + |
| 44 | + expect(wrapper).toHaveText('foo[]'); |
| 45 | + }); |
| 46 | + |
| 47 | + it('given primitive type, should not display title', () => { |
| 48 | + const wrapper = shallow(<Type type={SchemaKind.Array} subtype={SchemaKind.String} title="foo" />); |
| 49 | + |
| 50 | + expect(wrapper).toHaveText('array[string]'); |
| 51 | + }); |
| 52 | + |
| 53 | + it('given mixed types, should not display title', () => { |
| 54 | + const wrapper = shallow( |
| 55 | + <Type type={SchemaKind.Array} subtype={[SchemaKind.String, SchemaKind.Object]} title="foo" />, |
| 56 | + ); |
| 57 | + |
| 58 | + expect(wrapper).toHaveText('array[string,object]'); |
| 59 | + }); |
| 60 | + |
| 61 | + it('given $ref type, should display title', () => { |
| 62 | + const wrapper = shallow(<Type type={SchemaKind.Array} subtype="$ref" title="foo" />); |
| 63 | + |
| 64 | + expect(wrapper).toHaveText('foo[]'); |
| 65 | + }); |
| 66 | + }); |
| 67 | + |
| 68 | + it('given object type, should always display title', () => { |
| 69 | + const wrapper = shallow(<Type type={SchemaKind.Object} subtype={void 0} title="foo" />); |
| 70 | + |
| 71 | + expect(wrapper).toHaveText('foo'); |
| 72 | + }); |
| 73 | + |
| 74 | + it('given $ref type, should always display title', () => { |
| 75 | + const wrapper = shallow(<Type type="$ref" subtype={void 0} title="foo" />); |
| 76 | + |
| 77 | + expect(wrapper).toHaveText('foo'); |
| 78 | + }); |
| 79 | + |
| 80 | + it.each([SchemaKind.Null, SchemaKind.Integer, SchemaKind.Number, SchemaKind.Boolean, SchemaKind.String])( |
| 81 | + 'given primitive %s type, should not display title', |
| 82 | + type => { |
| 83 | + const wrapper = shallow(<Type type={type} subtype={void 0} title="foo" />); |
| 84 | + |
| 85 | + expect(wrapper).toHaveText(type); |
| 86 | + }, |
| 87 | + ); |
| 88 | + }); |
31 | 89 | }); |
0 commit comments