From ac3afafc32c27ad702bf8557d8993384a4c28b5d Mon Sep 17 00:00:00 2001 From: Jonathan Bailey Date: Wed, 13 Nov 2019 15:44:56 -0500 Subject: [PATCH] Add shallow component tests --- src/components/Callbacks/index.ts | 3 + src/components/__tests__/Callbacks.test.tsx | 56 ++++++++++++++++ .../__tests__/fixtures/simple-callback.json | 64 +++++++++++++++++++ 3 files changed, 123 insertions(+) create mode 100644 src/components/Callbacks/index.ts create mode 100644 src/components/__tests__/Callbacks.test.tsx create mode 100644 src/components/__tests__/fixtures/simple-callback.json diff --git a/src/components/Callbacks/index.ts b/src/components/Callbacks/index.ts new file mode 100644 index 00000000..9a73da92 --- /dev/null +++ b/src/components/Callbacks/index.ts @@ -0,0 +1,3 @@ +export * from './Callback'; +export * from './CallbackTitle'; +export * from './CallbacksList'; diff --git a/src/components/__tests__/Callbacks.test.tsx b/src/components/__tests__/Callbacks.test.tsx new file mode 100644 index 00000000..6b62ade7 --- /dev/null +++ b/src/components/__tests__/Callbacks.test.tsx @@ -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( + , + ).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( + , + ).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( + , + ).getElement(); + expect(callbacksListViewElement.props).toBeDefined(); + expect(callbacksListViewElement.props.children).toBeDefined(); + expect(callbacksListViewElement.props.children.length).toBeGreaterThan(0); + }); + }); +}); diff --git a/src/components/__tests__/fixtures/simple-callback.json b/src/components/__tests__/fixtures/simple-callback.json new file mode 100644 index 00000000..5ca4af74 --- /dev/null +++ b/src/components/__tests__/fixtures/simple-callback.json @@ -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." + } + } + } + } + } + } + } \ No newline at end of file