mirror of
https://github.com/Redocly/redoc.git
synced 2025-08-08 06:04:56 +03:00
Add shallow component tests
This commit is contained in:
parent
43142d5384
commit
ac3afafc32
3
src/components/Callbacks/index.ts
Normal file
3
src/components/Callbacks/index.ts
Normal file
|
@ -0,0 +1,3 @@
|
|||
export * from './Callback';
|
||||
export * from './CallbackTitle';
|
||||
export * from './CallbacksList';
|
56
src/components/__tests__/Callbacks.test.tsx
Normal file
56
src/components/__tests__/Callbacks.test.tsx
Normal file
|
@ -0,0 +1,56 @@
|
|||
/* tslint:disable:no-implicit-dependencies */
|
||||
|
||||
import { shallow } from 'enzyme';
|
||||
import * as React from 'react';
|
||||
|
||||
import { OpenAPIParser } from '../../services';
|
||||
import { CallbackModel } from '../../services/models/Callback';
|
||||
import { CallbackView, CallbacksList, CallbackTitle } from '../Callbacks';
|
||||
import { RedocNormalizedOptions } from '../../services/RedocNormalizedOptions';
|
||||
import * as simpleCallbackFixture from './fixtures/simple-callback.json';
|
||||
|
||||
const options = new RedocNormalizedOptions({});
|
||||
describe('Components', () => {
|
||||
describe('Callbacks', () => {
|
||||
it('should correctly render CallbackView', () => {
|
||||
const parser = new OpenAPIParser(simpleCallbackFixture, undefined, options);
|
||||
const callback = new CallbackModel(
|
||||
parser,
|
||||
'Test.Callback',
|
||||
{ $ref: '#/components/callbacks/Test' },
|
||||
options,
|
||||
);
|
||||
const callbackViewElement = shallow(
|
||||
<CallbackView key={callback.name} callback={callback} />,
|
||||
).getElement();
|
||||
expect(callbackViewElement.props).toBeDefined();
|
||||
expect(callbackViewElement.props.children).toBeDefined();
|
||||
expect(callbackViewElement.props.children.length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it('should correctly render CallbackTitle', () => {
|
||||
const callbackTitleViewElement = shallow(
|
||||
<CallbackTitle name={'Test'} className={'.test'} onClick={undefined} />,
|
||||
).getElement();
|
||||
expect(callbackTitleViewElement.props).toBeDefined();
|
||||
expect(callbackTitleViewElement.props.className).toEqual('.test');
|
||||
expect(callbackTitleViewElement.props.onClick).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should correctly render CallbacksList', () => {
|
||||
const parser = new OpenAPIParser(simpleCallbackFixture, undefined, options);
|
||||
const callback = new CallbackModel(
|
||||
parser,
|
||||
'Test.Callback',
|
||||
{ $ref: '#/components/callbacks/Test' },
|
||||
options,
|
||||
);
|
||||
const callbacksListViewElement = shallow(
|
||||
<CallbacksList callbacks={[callback]} />,
|
||||
).getElement();
|
||||
expect(callbacksListViewElement.props).toBeDefined();
|
||||
expect(callbacksListViewElement.props.children).toBeDefined();
|
||||
expect(callbacksListViewElement.props.children.length).toBeGreaterThan(0);
|
||||
});
|
||||
});
|
||||
});
|
64
src/components/__tests__/fixtures/simple-callback.json
Normal file
64
src/components/__tests__/fixtures/simple-callback.json
Normal file
|
@ -0,0 +1,64 @@
|
|||
{
|
||||
"openapi": "3.0.0",
|
||||
"info": {
|
||||
"version": "1.0",
|
||||
"title": "Foo"
|
||||
},
|
||||
"components": {
|
||||
"callbacks": {
|
||||
"Test": {
|
||||
"post": {
|
||||
"operationId": "testCallback",
|
||||
"description": "Test callback.",
|
||||
"requestBody": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"title": "TestTitle",
|
||||
"type": "object",
|
||||
"description": "Test description",
|
||||
"properties": {
|
||||
"type": {
|
||||
"type": "string",
|
||||
"description": "The type of response.",
|
||||
"enum": [
|
||||
"TestResponse.Complete"
|
||||
]
|
||||
},
|
||||
"status": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"FAILURE",
|
||||
"SUCCESS"
|
||||
]
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"status"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"parameters": [
|
||||
{
|
||||
"name": "X-Test-Header",
|
||||
"in": "header",
|
||||
"required": true,
|
||||
"example": "1",
|
||||
"description": "This is a test header parameter",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"204": {
|
||||
"description": "Test response."
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user