This repository has been archived by the owner on Nov 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix linting errors, add component for better testing, fix current bug…
…s, implement $ref lookups for schemas
- Loading branch information
Showing
5 changed files
with
231 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
packages/api-explorer/__tests__/ResponseSchemaBody.test.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
const React = require('react'); | ||
const { shallow } = require('enzyme'); | ||
|
||
const ResponseSchemaBody = require('../src/ResponseSchemaBody'); | ||
const Oas = require('../src/lib/Oas'); | ||
const petstore = require('./fixtures/petstore/oas.json'); | ||
|
||
const oas = new Oas(petstore); | ||
|
||
test('display object properties in the table', () => { | ||
const schema = { | ||
type: 'object', | ||
properties: { | ||
a: { | ||
type: 'string', | ||
}, | ||
}, | ||
}; | ||
const responseSchemaBody = shallow(<ResponseSchemaBody oas={oas} schema={schema} />); | ||
|
||
expect(responseSchemaBody.find('th').text()).toContain('a'); | ||
expect(responseSchemaBody.find('td').text()).toEqual('string'); | ||
}); | ||
|
||
test('display object properties in the table', () => { | ||
const schema = { | ||
type: 'object', | ||
properties: { | ||
a: { | ||
type: 'string', | ||
}, | ||
}, | ||
}; | ||
const responseSchemaBody = shallow(<ResponseSchemaBody oas={oas} schema={schema} />); | ||
|
||
expect(responseSchemaBody.find('th').text()).toContain('a'); | ||
expect(responseSchemaBody.find('td').text()).toEqual('string'); | ||
}); | ||
|
||
test('display properties if object contains $ref type', () => { | ||
const schema = { | ||
type: 'object', | ||
required: ['name', 'photoUrls'], | ||
properties: { | ||
id: { | ||
type: 'integer', | ||
format: 'int64', | ||
readOnly: true, | ||
}, | ||
category: { | ||
$ref: '#/components/schemas/Category', | ||
}, | ||
name: { | ||
type: 'string', | ||
example: 'doggie', | ||
}, | ||
photoUrls: { | ||
type: 'array', | ||
xml: { | ||
name: 'photoUrl', | ||
wrapped: true, | ||
}, | ||
items: { | ||
type: 'string', | ||
}, | ||
}, | ||
tags: { | ||
type: 'array', | ||
xml: { | ||
name: 'tag', | ||
wrapped: true, | ||
}, | ||
items: { | ||
$ref: '#/components/schemas/Tag', | ||
}, | ||
}, | ||
status: { | ||
type: 'string', | ||
description: 'pet status in the store', | ||
enum: ['available', 'pending', 'sold'], | ||
}, | ||
}, | ||
xml: { | ||
name: 'Pet', | ||
}, | ||
}; | ||
const responseSchemaBody = shallow(<ResponseSchemaBody oas={oas} schema={schema} />); | ||
expect( | ||
responseSchemaBody | ||
.find('th') | ||
.map(a => a.text()) | ||
.filter(a => a === 'category.name').length, | ||
).toBe(1); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.