From a6ae43a136ac465770144b031a9fb024c3aee858 Mon Sep 17 00:00:00 2001 From: Roman Hotsiy Date: Tue, 30 Jan 2018 16:45:52 +0200 Subject: [PATCH] tests: filter out options object from snapshorts --- package.json | 2 + .../__tests__/DiscriminatorDropdown.test.tsx | 6 +- .../DiscriminatorDropdown.test.tsx.snap | 272 +----------------- src/utils/test-utils.ts | 29 ++ yarn.lock | 6 +- 5 files changed, 44 insertions(+), 271 deletions(-) create mode 100644 src/utils/test-utils.ts diff --git a/package.json b/package.json index 052dea04..36f83283 100644 --- a/package.json +++ b/package.json @@ -32,6 +32,7 @@ "@types/enzyme-to-json": "^1.5.0", "@types/jest": "^22.1.0", "@types/json-pointer": "^1.0.30", + "@types/lodash": "^4.14.98", "@types/prismjs": "^1.6.4", "@types/prop-types": "^15.5.2", "@types/react": "^16.0.30", @@ -52,6 +53,7 @@ "enzyme-to-json": "^3.2.2", "html-webpack-plugin": "^2.30.1", "jest": "^22.1.4", + "lodash": "^4.17.4", "mobx-react-devtools": "^4.2.15", "prettier": "^1.5.3", "prettier-eslint": "^8.8.1", diff --git a/src/components/Schema/__tests__/DiscriminatorDropdown.test.tsx b/src/components/Schema/__tests__/DiscriminatorDropdown.test.tsx index 40757339..e9847b1d 100644 --- a/src/components/Schema/__tests__/DiscriminatorDropdown.test.tsx +++ b/src/components/Schema/__tests__/DiscriminatorDropdown.test.tsx @@ -1,8 +1,10 @@ -import { RedocNormalizedOptions } from '../../../services/RedocNormalizedOptions'; import * as React from 'react'; import { shallow } from 'enzyme'; import toJson from 'enzyme-to-json'; +import { filterPropsDeep } from '../../../utils/test-utils'; + +import { RedocNormalizedOptions } from '../../../services/RedocNormalizedOptions'; import { OpenAPIParser, SchemaModel } from '../../../services'; import { Schema } from '../Schema'; import { ObjectSchema } from '../ObjectSchema'; @@ -43,7 +45,7 @@ describe('Components', () => { }} />, ); - expect(toJson(schemaView)).toMatchSnapshot(); + expect(filterPropsDeep(toJson(schemaView), ['field.schema.options'])).toMatchSnapshot(); }); }); }); diff --git a/src/components/Schema/__tests__/__snapshots__/DiscriminatorDropdown.test.tsx.snap b/src/components/Schema/__tests__/__snapshots__/DiscriminatorDropdown.test.tsx.snap index be0d9853..2368b277 100644 --- a/src/components/Schema/__tests__/__snapshots__/DiscriminatorDropdown.test.tsx.snap +++ b/src/components/Schema/__tests__/__snapshots__/DiscriminatorDropdown.test.tsx.snap @@ -832,73 +832,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView "isCircular": undefined, "isPrimitive": true, "nullable": false, - "options": RedocNormalizedOptions { - "expandResponses": Object {}, - "hideHostname": false, - "nativeScrollbars": false, - "noAutoAuth": false, - "pathInMiddlePanel": false, - "requiredPropsFirst": false, - "scrollYOffset": [Function], - "theme": Object { - "baseFont": Object { - "family": "Roboto, sans-serif", - "lineHeight": "1.5", - "optimizeSpeed": true, - "size": "14px", - "smoothing": "antialiased", - "weight": "300", - }, - "code": Object { - "fontFamily": "Courier, monospace", - "fontSize": "13px", - }, - "colors": Object { - "error": "#e53935", - "http": Object { - "basic": "#999", - "delete": "#e27a7a", - "get": "#6bbd5b", - "link": "#31bbb6", - "options": "#d3ca12", - "patch": "#e09d43", - "post": "#248fb2", - "put": "#9b708b", - }, - "info": "skyblue", - "main": "#32329f", - "redirect": "orange", - "success": "#00aa13", - "text": "#263238", - "warning": "#f1c400", - }, - "headingsFont": Object { - "family": "Montserrat, sans-serif", - }, - "links": Object { - "color": undefined, - "hover": undefined, - "visited": undefined, - }, - "logo": Object { - "maxHeight": "120px", - }, - "menu": Object { - "backgroundColor": "#fafafa", - "width": "260px", - }, - "rightPanel": Object { - "backgroundColor": "#263238", - "width": 40, - }, - "schemaView": Object { - "defaultDetailsWidth": "75%", - "linesColor": "#7f99cf", - }, - "spacingUnit": 20, - }, - "untrustedSpec": false, - }, + "options": "<<>>", "pattern": undefined, "rawSchema": Object { "default": undefined, @@ -937,73 +871,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView "isCircular": undefined, "isPrimitive": true, "nullable": false, - "options": RedocNormalizedOptions { - "expandResponses": Object {}, - "hideHostname": false, - "nativeScrollbars": false, - "noAutoAuth": false, - "pathInMiddlePanel": false, - "requiredPropsFirst": false, - "scrollYOffset": [Function], - "theme": Object { - "baseFont": Object { - "family": "Roboto, sans-serif", - "lineHeight": "1.5", - "optimizeSpeed": true, - "size": "14px", - "smoothing": "antialiased", - "weight": "300", - }, - "code": Object { - "fontFamily": "Courier, monospace", - "fontSize": "13px", - }, - "colors": Object { - "error": "#e53935", - "http": Object { - "basic": "#999", - "delete": "#e27a7a", - "get": "#6bbd5b", - "link": "#31bbb6", - "options": "#d3ca12", - "patch": "#e09d43", - "post": "#248fb2", - "put": "#9b708b", - }, - "info": "skyblue", - "main": "#32329f", - "redirect": "orange", - "success": "#00aa13", - "text": "#263238", - "warning": "#f1c400", - }, - "headingsFont": Object { - "family": "Montserrat, sans-serif", - }, - "links": Object { - "color": undefined, - "hover": undefined, - "visited": undefined, - }, - "logo": Object { - "maxHeight": "120px", - }, - "menu": Object { - "backgroundColor": "#fafafa", - "width": "260px", - }, - "rightPanel": Object { - "backgroundColor": "#263238", - "width": 40, - }, - "schemaView": Object { - "defaultDetailsWidth": "75%", - "linesColor": "#7f99cf", - }, - "spacingUnit": 20, - }, - "untrustedSpec": false, - }, + "options": "<<>>", "pattern": undefined, "rawSchema": Object { "default": undefined, @@ -1165,73 +1033,7 @@ exports[`Components SchemaView discriminator should correctly render discriminat "isCircular": undefined, "isPrimitive": true, "nullable": false, - "options": RedocNormalizedOptions { - "expandResponses": Object {}, - "hideHostname": false, - "nativeScrollbars": false, - "noAutoAuth": false, - "pathInMiddlePanel": false, - "requiredPropsFirst": false, - "scrollYOffset": [Function], - "theme": Object { - "baseFont": Object { - "family": "Roboto, sans-serif", - "lineHeight": "1.5", - "optimizeSpeed": true, - "size": "14px", - "smoothing": "antialiased", - "weight": "300", - }, - "code": Object { - "fontFamily": "Courier, monospace", - "fontSize": "13px", - }, - "colors": Object { - "error": "#e53935", - "http": Object { - "basic": "#999", - "delete": "#e27a7a", - "get": "#6bbd5b", - "link": "#31bbb6", - "options": "#d3ca12", - "patch": "#e09d43", - "post": "#248fb2", - "put": "#9b708b", - }, - "info": "skyblue", - "main": "#32329f", - "redirect": "orange", - "success": "#00aa13", - "text": "#263238", - "warning": "#f1c400", - }, - "headingsFont": Object { - "family": "Montserrat, sans-serif", - }, - "links": Object { - "color": undefined, - "hover": undefined, - "visited": undefined, - }, - "logo": Object { - "maxHeight": "120px", - }, - "menu": Object { - "backgroundColor": "#fafafa", - "width": "260px", - }, - "rightPanel": Object { - "backgroundColor": "#263238", - "width": 40, - }, - "schemaView": Object { - "defaultDetailsWidth": "75%", - "linesColor": "#7f99cf", - }, - "spacingUnit": 20, - }, - "untrustedSpec": false, - }, + "options": "<<>>", "pattern": undefined, "rawSchema": Object { "default": undefined, @@ -1277,73 +1079,7 @@ exports[`Components SchemaView discriminator should correctly render discriminat "isCircular": undefined, "isPrimitive": true, "nullable": false, - "options": RedocNormalizedOptions { - "expandResponses": Object {}, - "hideHostname": false, - "nativeScrollbars": false, - "noAutoAuth": false, - "pathInMiddlePanel": false, - "requiredPropsFirst": false, - "scrollYOffset": [Function], - "theme": Object { - "baseFont": Object { - "family": "Roboto, sans-serif", - "lineHeight": "1.5", - "optimizeSpeed": true, - "size": "14px", - "smoothing": "antialiased", - "weight": "300", - }, - "code": Object { - "fontFamily": "Courier, monospace", - "fontSize": "13px", - }, - "colors": Object { - "error": "#e53935", - "http": Object { - "basic": "#999", - "delete": "#e27a7a", - "get": "#6bbd5b", - "link": "#31bbb6", - "options": "#d3ca12", - "patch": "#e09d43", - "post": "#248fb2", - "put": "#9b708b", - }, - "info": "skyblue", - "main": "#32329f", - "redirect": "orange", - "success": "#00aa13", - "text": "#263238", - "warning": "#f1c400", - }, - "headingsFont": Object { - "family": "Montserrat, sans-serif", - }, - "links": Object { - "color": undefined, - "hover": undefined, - "visited": undefined, - }, - "logo": Object { - "maxHeight": "120px", - }, - "menu": Object { - "backgroundColor": "#fafafa", - "width": "260px", - }, - "rightPanel": Object { - "backgroundColor": "#263238", - "width": 40, - }, - "schemaView": Object { - "defaultDetailsWidth": "75%", - "linesColor": "#7f99cf", - }, - "spacingUnit": 20, - }, - "untrustedSpec": false, - }, + "options": "<<>>", "pattern": undefined, "rawSchema": Object { "default": undefined, diff --git a/src/utils/test-utils.ts b/src/utils/test-utils.ts new file mode 100644 index 00000000..b21f6931 --- /dev/null +++ b/src/utils/test-utils.ts @@ -0,0 +1,29 @@ +import { instanceOf } from 'prop-types'; +import { RedocNormalizedOptions } from '../services/RedocNormalizedOptions'; +import { set, has } from 'lodash'; + +function traverseComponent(root, fn) { + if (!root) return; + + fn(root); + + if (root.children) { + for (let child of root.children) { + traverseComponent(child, fn); + } + } +} + +export function filterPropsDeep(component: T, paths: string[]): T { + traverseComponent(component, comp => { + if (comp.props) { + for (const path of paths) { + if (has(comp.props, path)) { + set(comp.props, path, '<<>>'); + } + } + } + }); + + return component; +} diff --git a/yarn.lock b/yarn.lock index ea47de94..d1f27040 100644 --- a/yarn.lock +++ b/yarn.lock @@ -40,7 +40,7 @@ "@types/chai" "*" "@types/jquery" "*" -"@types/chai@4.0.8", "@types/chai@*": +"@types/chai@*", "@types/chai@4.0.8": version "4.0.8" resolved "https://registry.yarnpkg.com/@types/chai/-/chai-4.0.8.tgz#d27600e9ba2f371e08695d90a0fe0408d89c7be7" @@ -91,6 +91,10 @@ version "4.14.87" resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.87.tgz#55f92183b048c2c64402afe472f8333f4e319a6b" +"@types/lodash@^4.14.98": + version "4.14.98" + resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.98.tgz#aaf012ae443e657e7885e605a4c1b340db160609" + "@types/minimatch@3.0.1": version "3.0.1" resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-3.0.1.tgz#b683eb60be358304ef146f5775db4c0e3696a550"