-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
OneOfSchema.test.tsx
82 lines (72 loc) · 2.55 KB
/
OneOfSchema.test.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/* tslint:disable:no-implicit-dependencies */
import { shallow } from 'enzyme';
import * as React from 'react';
import { OneOfSchema, Schema } from '../';
import { OpenAPIParser, SchemaModel } from '../../services';
import { RedocNormalizedOptions } from '../../services/RedocNormalizedOptions';
import { withTheme } from '../testProviders';
const options = new RedocNormalizedOptions({});
describe('Components', () => {
describe('SchemaView', () => {
const parser = new OpenAPIParser(
{ openapi: '3.0', info: { title: 'test', version: '0' }, paths: {} },
undefined,
options,
);
describe('OneOf', () => {
it('should pass down skipReadOnly/skipReadWrite to nested oneOf', () => {
const schema = new SchemaModel(
parser,
{ oneOf: [{ type: 'string' }, { type: 'integer' }] },
'',
options,
);
let schemaViewElement = shallow(
<Schema schema={schema} skipWriteOnly={true} />,
).getElement();
expect(schemaViewElement.type).toEqual(OneOfSchema);
expect(schemaViewElement.props.skipWriteOnly).toBeTruthy();
expect(schemaViewElement.props.skipReadOnly).toBeFalsy();
schemaViewElement = shallow(<Schema schema={schema} skipReadOnly={true} />).getElement();
expect(schemaViewElement.type).toEqual(OneOfSchema);
expect(schemaViewElement.props.skipWriteOnly).toBeFalsy();
expect(schemaViewElement.props.skipReadOnly).toBeTruthy();
});
});
describe('OneOf deprecated', () => {
const schema = new SchemaModel(
parser,
{ oneOf: [{ type: 'string', deprecated: true }, { type: 'integer' }] },
'',
options,
);
it('should match snapshot', () => {
const component = shallow(withTheme(<Schema schema={schema} />));
expect(component.render()).toMatchSnapshot();
});
});
describe('Show minProperties/maxProperties constraints oneOf', () => {
const schema = new SchemaModel(
parser,
{
oneOf: [
{
type: 'object',
description: 'Test description',
minProperties: 1,
maxProperties: 1,
additionalProperties: {
type: 'string',
description: 'The name and value o',
},
},
],
},
'',
options,
);
const component = shallow(withTheme(<Schema schema={schema} />));
expect(component.html().includes('= 1 properties')).toBe(true);
});
});
});