From 5c2317c4aee5a8bf0343dfa013d279834f3c2ba2 Mon Sep 17 00:00:00 2001 From: Alex Varchuk Date: Thu, 31 Aug 2023 10:43:53 +0300 Subject: [PATCH] chore: add tests for cover field default crash (#2389) --- demo/openapi-3-1.yaml | 1 + demo/openapi.yaml | 2 + demo/swagger.yaml | 1 + src/components/Markdown/SanitizedMdBlock.tsx | 2 +- .../__tests__/FieldDetails.test.tsx | 47 +++++++++++++ .../__snapshots__/FieldDetails.test.tsx.snap | 69 +++++++++++++++++++ .../SecurityRequirement.test.tsx.snap | 14 ++-- .../loadAndBundleSpec.test.ts.snap | 4 ++ 8 files changed, 132 insertions(+), 8 deletions(-) create mode 100644 src/components/__tests__/FieldDetails.test.tsx create mode 100644 src/components/__tests__/__snapshots__/FieldDetails.test.tsx.snap diff --git a/demo/openapi-3-1.yaml b/demo/openapi-3-1.yaml index 7cd6178f..f50af26c 100644 --- a/demo/openapi-3-1.yaml +++ b/demo/openapi-3-1.yaml @@ -1139,6 +1139,7 @@ components: type: [string, integer, 'null'] minItems: 1 maxItems: 10 + default: [] xml: name: photoUrl wrapped: true diff --git a/demo/openapi.yaml b/demo/openapi.yaml index 0bfb6bae..093695a0 100644 --- a/demo/openapi.yaml +++ b/demo/openapi.yaml @@ -1646,6 +1646,7 @@ components: photoUrls: description: The list of URL to a cute photos featuring pet type: array + default: [] maxItems: 20 xml: name: photoUrl @@ -1775,6 +1776,7 @@ components: name: type: string description: hooray + default: [] description: Pet object that needs to be added to the store required: true UserArray: diff --git a/demo/swagger.yaml b/demo/swagger.yaml index a7552d59..5aaa19b6 100644 --- a/demo/swagger.yaml +++ b/demo/swagger.yaml @@ -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 diff --git a/src/components/Markdown/SanitizedMdBlock.tsx b/src/components/Markdown/SanitizedMdBlock.tsx index 44b1d8d4..33a54bd0 100644 --- a/src/components/Markdown/SanitizedMdBlock.tsx +++ b/src/components/Markdown/SanitizedMdBlock.tsx @@ -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 => )` display: inline; `; diff --git a/src/components/__tests__/FieldDetails.test.tsx b/src/components/__tests__/FieldDetails.test.tsx new file mode 100644 index 00000000..703dc3ea --- /dev/null +++ b/src/components/__tests__/FieldDetails.test.tsx @@ -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
; + }, +})); + +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()); + + expect(wrapper.render()).toMatchSnapshot(); + }); +}); diff --git a/src/components/__tests__/__snapshots__/FieldDetails.test.tsx.snap b/src/components/__tests__/__snapshots__/FieldDetails.test.tsx.snap new file mode 100644 index 00000000..828cdc84 --- /dev/null +++ b/src/components/__tests__/__snapshots__/FieldDetails.test.tsx.snap @@ -0,0 +1,69 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`FieldDetailsComponent renders correctly 1`] = ` +
+
+ + test type prefix + + + array + + + (test title) + + + + + + + +
+
+ + Default: + + + + "" + +
+ +
+ + Example: + + + + "example" + +
+
+
+

+ test description +

+ + +
+
+
+`; diff --git a/src/components/__tests__/__snapshots__/SecurityRequirement.test.tsx.snap b/src/components/__tests__/__snapshots__/SecurityRequirement.test.tsx.snap index df84599e..55665970 100644 --- a/src/components/__tests__/__snapshots__/SecurityRequirement.test.tsx.snap +++ b/src/components/__tests__/__snapshots__/SecurityRequirement.test.tsx.snap @@ -3,8 +3,8 @@ exports[`SecurityRequirement should render SecurityDefs 1`] = ` "

petstore_auth

Get access to data while protecting your account credentials. OAuth2 is also a safer and more secure way to give you access.

-
Security Scheme Type: OAuth2
Flow type: implicit
Scopes:
  • write:pets -

    modify pets in your account

    -
  • read:pets -

    read your pets

    +
    Security Scheme Type: OAuth2
    Flow type: implicit
    Scopes:
    • write:pets -

      modify pets in your account

      +
    • read:pets -

      read your pets

GitLab_PersonalAccessToken

GitLab Personal Access Token description

Security Scheme Type: API Key
Header parameter name: PRIVATE-TOKEN

GitLab_OpenIdConnect

GitLab OpenIdConnect description

Security Scheme Type: OpenID Connect

basicAuth

Security Scheme Type: HTTP
HTTP Authorization Scheme: basic
" @@ -15,9 +15,9 @@ exports[`SecurityRequirement should render authDefinition 1`] = `"
Authorizations:
(API Key: GitLab_PersonalAccessTokenOpenID Connect: GitLab_OpenIdConnectHTTP: basicAuth) OAuth2: petstore_auth (write:petsread:pets)
OAuth2: petstore_auth

Get access to data while protecting your account credentials. OAuth2 is also a safer and more secure way to give you access.

-
Flow type: implicit
Required scopes: write:pets read:pets
Scopes:
  • write:pets -

    modify pets in your account

    -
  • read:pets -

    read your pets

    -
API Key: GitLab_PersonalAccessToken

GitLab Personal Access Token description

-
Header parameter name: PRIVATE-TOKEN
OpenID Connect: GitLab_OpenIdConnect

GitLab OpenIdConnect description

-
HTTP: basicAuth
HTTP Authorization Scheme: basic
," +
Flow type: implicit
Required scopes: write:pets read:pets
Scopes:
  • write:pets -

    modify pets in your account

    +
  • read:pets -

    read your pets

    +
API Key: GitLab_PersonalAccessToken

GitLab Personal Access Token description

+
Header parameter name: PRIVATE-TOKEN
OpenID Connect: GitLab_OpenIdConnect

GitLab OpenIdConnect description

+
HTTP: basicAuth
HTTP Authorization Scheme: basic
," `; diff --git a/src/utils/__tests__/__snapshots__/loadAndBundleSpec.test.ts.snap b/src/utils/__tests__/__snapshots__/loadAndBundleSpec.test.ts.snap index c5b366c9..1efeffcb 100644 --- a/src/utils/__tests__/__snapshots__/loadAndBundleSpec.test.ts.snap +++ b/src/utils/__tests__/__snapshots__/loadAndBundleSpec.test.ts.snap @@ -33,6 +33,7 @@ Object { "schema": Object { "properties": Object { "name": Object { + "default": Array [], "description": "hooray", "type": "string", }, @@ -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", @@ -2796,6 +2798,7 @@ Object { "type": "string", }, "photoUrls": Object { + "default": Array [], "description": "The list of URL to a cute photos featuring pet", "else": Object { "maxItems": 20, @@ -4686,6 +4689,7 @@ Object { "type": "string", }, "photoUrls": Object { + "default": Array [], "description": "The list of URL to a cute photos featuring pet", "items": Object { "format": "url",