Add shallow component tests

This commit is contained in:
Jonathan Bailey 2019-11-13 15:44:56 -05:00
parent 43142d5384
commit ac3afafc32
3 changed files with 123 additions and 0 deletions

View File

@ -0,0 +1,3 @@
export * from './Callback';
export * from './CallbackTitle';
export * from './CallbacksList';

View 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);
});
});
});

View 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."
}
}
}
}
}
}
}