Skip to content

Commit

Permalink
chore: add tests for cover field default crash (#2389)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexVarchuk authored Aug 31, 2023
1 parent c86fd7f commit 2eff85a
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 5 deletions.
1 change: 1 addition & 0 deletions demo/openapi-3-1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1139,6 +1139,7 @@ components:
type: [string, integer, 'null']
minItems: 1
maxItems: 10
default: []
xml:
name: photoUrl
wrapped: true
Expand Down
2 changes: 2 additions & 0 deletions demo/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1047,6 +1047,7 @@ components:
photoUrls:
description: The list of URL to a cute photos featuring pet
type: array
default: []
maxItems: 20
xml:
name: photoUrl
Expand Down Expand Up @@ -1176,6 +1177,7 @@ components:
name:
type: string
description: hooray
default: []
description: Pet object that needs to be added to the store
required: true
UserArray:
Expand Down
1 change: 1 addition & 0 deletions demo/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,7 @@ definitions:
photoUrls:
description: The list of URL to a cute photos featuring pet
type: array
default: []
xml:
name: photoUrl
wrapped: true
Expand Down
2 changes: 1 addition & 1 deletion src/components/Markdown/SanitizedMdBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { StylingMarkdownProps } from './Markdown';
import { StyledMarkdownBlock } from './styled.elements';
import styled from 'styled-components';

const StyledMarkdownSpan = styled(StyledMarkdownBlock)`
const StyledMarkdownSpan = styled(props => <StyledMarkdownBlock {...props} />)`
display: inline;
`;

Expand Down
47 changes: 47 additions & 0 deletions src/components/__tests__/FieldDetails.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import * as React from 'react';
import { shallow } from 'enzyme';

import { FieldDetails } from '../Fields/FieldDetails';
import { SchemaModel } from '../../services/models/Schema';
import { withTheme } from '../testProviders';

jest.mock('../ExternalDocumentation/ExternalDocumentation', () => ({
ExternalDocumentation: () => {
return <div />;
},
}));

describe('FieldDetailsComponent', () => {
it('renders correctly', () => {
const mockFieldProps = {
showExamples: true,
field: {
schema: {
type: 'array',
default: [],
typePrefix: 'test type prefix',
displayType: 'array',
title: 'test title',
externalDocs: undefined,
constraints: [''],
} as SchemaModel,
example: 'example',
name: 'name',
expanded: false,
required: false,
kind: '',
deprecated: false,
collapse: jest.fn(),
toggle: jest.fn(),
explode: false,
expand: jest.fn(),
description: 'test description',
},
renderDiscriminatorSwitch: jest.fn(),
};

const wrapper = shallow(withTheme(<FieldDetails {...mockFieldProps} />));

expect(wrapper.render()).toMatchSnapshot();
});
});
69 changes: 69 additions & 0 deletions src/components/__tests__/__snapshots__/FieldDetails.test.tsx.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`FieldDetailsComponent renders correctly 1`] = `
<div>
<div>
<span
class="sc-kpDqfm sc-dAlyuH cGRfjn gHomYR"
>
test type prefix
</span>
<span
class="sc-kpDqfm sc-jlZhew cGRfjn dYtiIA"
>
array
</span>
<span
class="sc-kpDqfm sc-cwHptR cGRfjn gyVIPr"
>
(test title)
</span>
<span>
<span
class="sc-kpDqfm sc-gFqAkR cGRfjn fYEICH"
>
</span>
</span>
</div>
<div>
<span
class="sc-kpDqfm cGRfjn"
>
Default:
</span>
<span
class="sc-kpDqfm sc-eldPxv cGRfjn ehWiAn"
>
""
</span>
</div>
<div>
<span
class="sc-kpDqfm cGRfjn"
>
Example:
</span>
<span
class="sc-kpDqfm sc-eldPxv cGRfjn ehWiAn"
>
"example"
</span>
</div>
<div>
<div
class="sc-lcIPJg sc-hknOHE gBHqkN eigFbs"
>
<p>
test description
</p>
</div>
</div>
</div>
`;
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
exports[`SecurityRequirement should render SecurityDefs 1`] = `
"<div id=\\"section/Authentication/petstore_auth\\" data-section-id=\\"section/Authentication/petstore_auth\\" class=\\"sc-dcJsrY bBkGhy\\"><div class=\\"sc-kAyceB hBQWIZ\\"><div class=\\"sc-fqkvVR oJKYx\\"><h2 class=\\"sc-jXbUNg fWnwAh\\">petstore_auth</h2><div class=\\"sc-eeDRCY sc-eBMEME gTGgei hvaraW\\"><p>Get access to data while protecting your account credentials.
OAuth2 is also a safer and more secure way to give you access.</p>
</div><div class=\\"sc-ejfMa-d a-DjBE\\"><div class=\\"sc-dkmUuB hFwAIA\\"><b>Security Scheme Type: </b><span>OAuth2</span></div><div class=\\"sc-eeDRCY sc-eBMEME gTGgei hvaraW\\"><div class=\\"sc-dkmUuB hFwAIA\\"><b>Flow type: </b><code>implicit </code></div><div class=\\"sc-dkmUuB hFwAIA\\"><strong> Authorization URL: </strong><code><a target=\\"_blank\\" rel=\\"noopener noreferrer\\" href=\\"http://petstore.swagger.io/api/oauth/dialog\\">http://petstore.swagger.io/api/oauth/dialog</a></code></div><div class=\\"sc-dkmUuB hFwAIA\\"><b> Scopes: </b></div><div class=\\"sc-iEXKAA blExNw container\\" style=\\"height: 4em;\\"><ul><li><code>write:pets</code> - <div class=\\"sc-eeDRCY sc-eBMEME sc-fhzFiK gTGgei dNjZhe hXtrri redoc-markdown\\"><p>modify pets in your account</p>
</div></li><li><code>read:pets</code> - <div class=\\"sc-eeDRCY sc-eBMEME sc-fhzFiK gTGgei dNjZhe hXtrri redoc-markdown\\"><p>read your pets</p>
</div><div class=\\"sc-ejfMa-d a-DjBE\\"><div class=\\"sc-dkmUuB hFwAIA\\"><b>Security Scheme Type: </b><span>OAuth2</span></div><div class=\\"sc-eeDRCY sc-eBMEME gTGgei hvaraW\\"><div class=\\"sc-dkmUuB hFwAIA\\"><b>Flow type: </b><code>implicit </code></div><div class=\\"sc-dkmUuB hFwAIA\\"><strong> Authorization URL: </strong><code><a target=\\"_blank\\" rel=\\"noopener noreferrer\\" href=\\"http://petstore.swagger.io/api/oauth/dialog\\">http://petstore.swagger.io/api/oauth/dialog</a></code></div><div class=\\"sc-dkmUuB hFwAIA\\"><b> Scopes: </b></div><div class=\\"sc-iEXKAA blExNw container\\" style=\\"height: 4em;\\"><ul><li><code>write:pets</code> - <div class=\\"sc-eeDRCY sc-eBMEME gTGgei dNjZhe sc-fhzFiK hXtrri redoc-markdown\\"><p>modify pets in your account</p>
</div></li><li><code>read:pets</code> - <div class=\\"sc-eeDRCY sc-eBMEME gTGgei dNjZhe sc-fhzFiK hXtrri redoc-markdown\\"><p>read your pets</p>
</div></li></ul></div><div class=\\"sc-EgOXT bNSpXO\\"></div></div></div></div></div></div><div id=\\"section/Authentication/GitLab_PersonalAccessToken\\" data-section-id=\\"section/Authentication/GitLab_PersonalAccessToken\\" class=\\"sc-dcJsrY bBkGhy\\"><div class=\\"sc-kAyceB hBQWIZ\\"><div class=\\"sc-fqkvVR oJKYx\\"><h2 class=\\"sc-jXbUNg fWnwAh\\">GitLab_PersonalAccessToken</h2><div class=\\"sc-eeDRCY sc-eBMEME gTGgei hvaraW\\"><p>GitLab Personal Access Token description</p>
</div><div class=\\"sc-ejfMa-d a-DjBE\\"><div class=\\"sc-dkmUuB hFwAIA\\"><b>Security Scheme Type: </b><span>API Key</span></div><div class=\\"sc-eeDRCY sc-eBMEME gTGgei hvaraW\\"><div class=\\"sc-dkmUuB hFwAIA\\"><b>Header parameter name: </b><code>PRIVATE-TOKEN</code></div></div></div></div></div></div><div id=\\"section/Authentication/GitLab_OpenIdConnect\\" data-section-id=\\"section/Authentication/GitLab_OpenIdConnect\\" class=\\"sc-dcJsrY bBkGhy\\"><div class=\\"sc-kAyceB hBQWIZ\\"><div class=\\"sc-fqkvVR oJKYx\\"><h2 class=\\"sc-jXbUNg fWnwAh\\">GitLab_OpenIdConnect</h2><div class=\\"sc-eeDRCY sc-eBMEME gTGgei hvaraW\\"><p>GitLab OpenIdConnect description</p>
</div><div class=\\"sc-ejfMa-d a-DjBE\\"><div class=\\"sc-dkmUuB hFwAIA\\"><b>Security Scheme Type: </b><span>OpenID Connect</span></div><div class=\\"sc-eeDRCY sc-eBMEME gTGgei hvaraW\\"><div class=\\"sc-dkmUuB hFwAIA\\"><b>Connect URL: </b><code><a target=\\"_blank\\" rel=\\"noopener noreferrer\\" href=\\"https://gitlab.com/.well-known/openid-configuration\\">https://gitlab.com/.well-known/openid-configuration</a></code></div></div></div></div></div></div><div id=\\"section/Authentication/basicAuth\\" data-section-id=\\"section/Authentication/basicAuth\\" class=\\"sc-dcJsrY bBkGhy\\"><div class=\\"sc-kAyceB hBQWIZ\\"><div class=\\"sc-fqkvVR oJKYx\\"><h2 class=\\"sc-jXbUNg fWnwAh\\">basicAuth</h2><div class=\\"sc-eeDRCY sc-eBMEME gTGgei hvaraW\\"></div><div class=\\"sc-ejfMa-d a-DjBE\\"><div class=\\"sc-dkmUuB hFwAIA\\"><b>Security Scheme Type: </b><span>HTTP</span></div><div class=\\"sc-eeDRCY sc-eBMEME gTGgei hvaraW\\"><div class=\\"sc-dkmUuB hFwAIA\\"><b>HTTP Authorization Scheme: </b><code>basic</code></div><div class=\\"sc-dkmUuB hFwAIA\\"></div></div></div></div></div></div>"
Expand All @@ -15,8 +15,8 @@ exports[`SecurityRequirement should render authDefinition 1`] = `"<div class=\\"
exports[`SecurityRequirement should render authDefinition 2`] = `
"<div class=\\"sc-bDumWk gtsPcy\\"><div class=\\"sc-sLsrZ hgeUJn\\"><h5 class=\\"sc-dAlyuH sc-fifgRP jbQuod kWJur\\">Authorizations:</h5><svg class=\\"sc-cwHptR dSJqIk\\" version=\\"1.1\\" viewBox=\\"0 0 24 24\\" x=\\"0\\" xmlns=\\"http://www.w3.org/2000/svg\\" y=\\"0\\" aria-hidden=\\"true\\"><polygon points=\\"17.3 8.3 12 13.6 6.7 8.3 5.3 9.7 12 16.4 18.7 9.7 \\"></polygon></svg></div><div class=\\"sc-dBmzty llvZdI\\"><span class=\\"sc-kbousE dOwJQz\\">(<span class=\\"sc-gfoqjT kbvnry\\">API Key: <i>GitLab_PersonalAccessToken</i></span><span class=\\"sc-gfoqjT kbvnry\\">OpenID Connect: <i>GitLab_OpenIdConnect</i></span><span class=\\"sc-gfoqjT kbvnry\\">HTTP: <i>basicAuth</i></span>) </span><span class=\\"sc-kbousE dOwJQz\\"><span class=\\"sc-gfoqjT kbvnry\\">OAuth2: <i>petstore_auth</i> (<code class=\\"sc-eyvILC bzHwfc\\">write:pets</code><code class=\\"sc-eyvILC bzHwfc\\">read:pets</code>) </span></span></div></div><div class=\\"sc-ejfMa-d a-DjBE\\"><h5><svg xmlns=\\"http://www.w3.org/2000/svg\\" viewBox=\\"0 0 24 24\\" width=\\"11\\" height=\\"11\\"><path fill=\\"currentColor\\" d=\\"M18 10V6A6 6 0 0 0 6 6v4H3v14h18V10h-3zM8 6c0-2.206 1.794-4 4-4s4 1.794 4 4v4H8V6zm11 16H5V12h14v10z\\"></path></svg> OAuth2: petstore_auth</h5><div class=\\"sc-eeDRCY sc-eBMEME gTGgei hvaraW\\"><p>Get access to data while protecting your account credentials.
OAuth2 is also a safer and more secure way to give you access.</p>
</div><div class=\\"sc-eeDRCY sc-eBMEME gTGgei hvaraW\\"><div class=\\"sc-dkmUuB hFwAIA\\"><b>Flow type: </b><code>implicit </code></div><div class=\\"sc-dkmUuB hFwAIA\\"><strong> Authorization URL: </strong><code><a target=\\"_blank\\" rel=\\"noopener noreferrer\\" href=\\"http://petstore.swagger.io/api/oauth/dialog\\">http://petstore.swagger.io/api/oauth/dialog</a></code></div><div><b>Required scopes: </b><code>write:pets</code> <code>read:pets</code> </div><div class=\\"sc-dkmUuB hFwAIA\\"><b> Scopes: </b></div><div class=\\"sc-iEXKAA blExNw container\\" style=\\"height: 4em;\\"><ul><li><code>write:pets</code> - <div class=\\"sc-eeDRCY sc-eBMEME sc-fhzFiK gTGgei dNjZhe hXtrri redoc-markdown\\"><p>modify pets in your account</p>
</div></li><li><code>read:pets</code> - <div class=\\"sc-eeDRCY sc-eBMEME sc-fhzFiK gTGgei dNjZhe hXtrri redoc-markdown\\"><p>read your pets</p>
</div><div class=\\"sc-eeDRCY sc-eBMEME gTGgei hvaraW\\"><div class=\\"sc-dkmUuB hFwAIA\\"><b>Flow type: </b><code>implicit </code></div><div class=\\"sc-dkmUuB hFwAIA\\"><strong> Authorization URL: </strong><code><a target=\\"_blank\\" rel=\\"noopener noreferrer\\" href=\\"http://petstore.swagger.io/api/oauth/dialog\\">http://petstore.swagger.io/api/oauth/dialog</a></code></div><div><b>Required scopes: </b><code>write:pets</code> <code>read:pets</code> </div><div class=\\"sc-dkmUuB hFwAIA\\"><b> Scopes: </b></div><div class=\\"sc-iEXKAA blExNw container\\" style=\\"height: 4em;\\"><ul><li><code>write:pets</code> - <div class=\\"sc-eeDRCY sc-eBMEME gTGgei dNjZhe sc-fhzFiK hXtrri redoc-markdown\\"><p>modify pets in your account</p>
</div></li><li><code>read:pets</code> - <div class=\\"sc-eeDRCY sc-eBMEME gTGgei dNjZhe sc-fhzFiK hXtrri redoc-markdown\\"><p>read your pets</p>
</div></li></ul></div><div class=\\"sc-EgOXT bNSpXO\\"></div></div></div><div class=\\"sc-ejfMa-d a-DjBE\\"><h5><svg xmlns=\\"http://www.w3.org/2000/svg\\" viewBox=\\"0 0 24 24\\" width=\\"11\\" height=\\"11\\"><path fill=\\"currentColor\\" d=\\"M18 10V6A6 6 0 0 0 6 6v4H3v14h18V10h-3zM8 6c0-2.206 1.794-4 4-4s4 1.794 4 4v4H8V6zm11 16H5V12h14v10z\\"></path></svg> API Key: GitLab_PersonalAccessToken</h5><div class=\\"sc-eeDRCY sc-eBMEME gTGgei hvaraW\\"><p>GitLab Personal Access Token description</p>
</div><div class=\\"sc-eeDRCY sc-eBMEME gTGgei hvaraW\\"><div class=\\"sc-dkmUuB hFwAIA\\"><b>Header parameter name: </b><code>PRIVATE-TOKEN</code></div></div></div><div class=\\"sc-ejfMa-d a-DjBE\\"><h5><svg xmlns=\\"http://www.w3.org/2000/svg\\" viewBox=\\"0 0 24 24\\" width=\\"11\\" height=\\"11\\"><path fill=\\"currentColor\\" d=\\"M18 10V6A6 6 0 0 0 6 6v4H3v14h18V10h-3zM8 6c0-2.206 1.794-4 4-4s4 1.794 4 4v4H8V6zm11 16H5V12h14v10z\\"></path></svg> OpenID Connect: GitLab_OpenIdConnect</h5><div class=\\"sc-eeDRCY sc-eBMEME gTGgei hvaraW\\"><p>GitLab OpenIdConnect description</p>
</div><div class=\\"sc-eeDRCY sc-eBMEME gTGgei hvaraW\\"><div class=\\"sc-dkmUuB hFwAIA\\"><b>Connect URL: </b><code><a target=\\"_blank\\" rel=\\"noopener noreferrer\\" href=\\"https://gitlab.com/.well-known/openid-configuration\\">https://gitlab.com/.well-known/openid-configuration</a></code></div></div></div><div class=\\"sc-ejfMa-d a-DjBE\\"><h5><svg xmlns=\\"http://www.w3.org/2000/svg\\" viewBox=\\"0 0 24 24\\" width=\\"11\\" height=\\"11\\"><path fill=\\"currentColor\\" d=\\"M18 10V6A6 6 0 0 0 6 6v4H3v14h18V10h-3zM8 6c0-2.206 1.794-4 4-4s4 1.794 4 4v4H8V6zm11 16H5V12h14v10z\\"></path></svg> HTTP: basicAuth</h5><div class=\\"sc-eeDRCY sc-eBMEME gTGgei hvaraW\\"></div><div class=\\"sc-eeDRCY sc-eBMEME gTGgei hvaraW\\"><div class=\\"sc-dkmUuB hFwAIA\\"><b>HTTP Authorization Scheme: </b><code>basic</code></div><div class=\\"sc-dkmUuB hFwAIA\\"></div></div></div>,"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Object {
"schema": Object {
"properties": Object {
"name": Object {
"default": Array [],
"description": "hooray",
"type": "string",
},
Expand Down Expand Up @@ -289,6 +290,7 @@ Object {
"type": "string",
},
"photoUrls": Object {
"default": Array [],
"description": "The list of URL to a cute photos featuring pet",
"items": Object {
"format": "url",
Expand Down Expand Up @@ -2195,6 +2197,7 @@ Object {
"type": "string",
},
"photoUrls": Object {
"default": Array [],
"description": "The list of URL to a cute photos featuring pet",
"else": Object {
"maxItems": 20,
Expand Down Expand Up @@ -4085,6 +4088,7 @@ Object {
"type": "string",
},
"photoUrls": Object {
"default": Array [],
"description": "The list of URL to a cute photos featuring pet",
"items": Object {
"format": "url",
Expand Down

0 comments on commit 2eff85a

Please sign in to comment.