From 21ff0cc3331a044a62360977924535a411ddc418 Mon Sep 17 00:00:00 2001 From: Chris Lanzo Date: Fri, 18 Aug 2023 13:56:37 -0400 Subject: [PATCH] refactor(adding data-test attributes): add data-test attributes (#233) --- .../__snapshots__/index.spec.tsx.snap | 282 +++++++++--------- src/__tests__/index.spec.tsx | 96 +++--- src/components/SchemaRow/SchemaRow.tsx | 8 +- src/components/shared/Description.tsx | 1 + src/components/shared/Format.tsx | 2 +- src/components/shared/Properties.tsx | 8 +- src/components/shared/Types.tsx | 4 +- src/components/shared/Validations.tsx | 4 +- .../shared/__tests__/Property.spec.tsx | 32 +- 9 files changed, 223 insertions(+), 214 deletions(-) diff --git a/src/__tests__/__snapshots__/index.spec.tsx.snap b/src/__tests__/__snapshots__/index.spec.tsx.snap index 234f99a0..ff93176c 100644 --- a/src/__tests__/__snapshots__/index.spec.tsx.snap +++ b/src/__tests__/__snapshots__/index.spec.tsx.snap @@ -6,24 +6,24 @@ exports[`Expanded depth nested object static given initial level set to 0, shoul
-
+
-
bar
- object +
bar
+ object
-
+
-
foo
- array[object] +
foo
+ array[object]
@@ -41,83 +41,83 @@ exports[`Expanded depth nested object static given initial level set to 1, shoul
-
+
-
bar
- object +
bar
+ object
-
+
-
barFoo
- object +
barFoo
+ object
-
+
-
barBar
- string +
barBar
+ string
-
+
-
barBaz
- boolean +
barBaz
+ boolean
-
+
-
foo
- array[object] +
foo
+ array[object]
-
+
-
fooBar
- string +
fooBar
+ string
-
+
-
fooFoo
- number +
fooFoo
+ number
@@ -136,96 +136,96 @@ exports[`Expanded depth nested object static given initial level set to 2, shoul
-
+
-
bar
- object +
bar
+ object
-
+
-
barFoo
- object +
barFoo
+ object
-
+
-
barFooBar
- object +
barFooBar
+ object
-
+
-
barBar
- string +
barBar
+ string
-
+
-
barBaz
- boolean +
barBaz
+ boolean
-
+
-
foo
- array[object] +
foo
+ array[object]
-
+
-
fooBar
- string +
fooBar
+ string
-
+
-
fooFoo
- number +
fooFoo
+ number
@@ -251,17 +251,17 @@ exports[`HTML Output given anyOf combiner placed next to allOf given allOf mergi
(any of)
-
+
-
type
- string +
type
+ string
- required + required
-
+
Allowed values:
admin @@ -270,43 +270,43 @@ exports[`HTML Output given anyOf combiner placed next to allOf given allOf mergi
-
+
-
enabled
- boolean +
enabled
+ boolean

Is this account enabled

-
+
-
root
- boolean +
root
+ boolean
-
+
-
group
- string +
group
+ string
-
+
-
expirationDate
- string +
expirationDate
+ string
@@ -330,10 +330,10 @@ exports[`HTML Output given array with oneOf containing items, should merge it co
(one of)
-
+
-
array[string]
+
array[string]
@@ -349,15 +349,15 @@ exports[`HTML Output given complex type that includes array and complex array su
-
+
-
items
+
items
- null + null or - array[string or number] + array[string or number]
@@ -381,27 +381,27 @@ exports[`HTML Output given multiple object and string type, should process prope
-
+
- string + string or - object + object
-
+
-
ids
- array[integer] +
ids
+ array[integer]
@@ -426,17 +426,17 @@ exports[`HTML Output given oneOf combiner placed next to allOf given allOf mergi
(one of)
-
+
-
type
- string +
type
+ string
- required + required
-
+
Allowed values:
admin @@ -445,43 +445,43 @@ exports[`HTML Output given oneOf combiner placed next to allOf given allOf mergi
-
+
-
enabled
- boolean +
enabled
+ boolean

Is this account enabled

-
+
-
root
- boolean +
root
+ boolean
-
+
-
group
- string +
group
+ string
-
+
-
expirationDate
- string +
expirationDate
+ string
@@ -498,27 +498,27 @@ exports[`HTML Output given read mode, should populate proper nodes 1`] = `
-
+
- string + string or - object + object
-
+
-
id
- string +
id
+ string
@@ -535,42 +535,42 @@ exports[`HTML Output given standalone mode, should populate proper nodes 1`] = `
-
+
- string + string or - object + object
-
+
-
id
- string +
id
+ string
- read-only + read-only
-
+
-
description
- string +
description
+ string
- write-only + write-only
@@ -587,37 +587,37 @@ exports[`HTML Output given visible $ref node, should try to inject the title imm
-
+
-
foo
- User +
foo
+ User
-
+
-
name
- string +
name
+ string
-
+
-
user
- User +
user
+ User
@@ -634,27 +634,27 @@ exports[`HTML Output given write mode, should populate proper nodes 1`] = `
-
+
- string + string or - object + object
-
+
-
description
- string +
description
+ string
@@ -672,22 +672,22 @@ exports[`HTML Output top level descriptions should not render top-level descript
-
+
-
foo
- string +
foo
+ string
-
+
-
baz
- string +
baz
+ string
@@ -706,22 +706,22 @@ exports[`HTML Output top level descriptions should render top-level description

This is a description that should be rendered

-
+
-
foo
- string +
foo
+ string
-
+
-
baz
- string +
baz
+ string
diff --git a/src/__tests__/index.spec.tsx b/src/__tests__/index.spec.tsx index ef686840..12e2383a 100644 --- a/src/__tests__/index.spec.tsx +++ b/src/__tests__/index.spec.tsx @@ -262,13 +262,13 @@ describe('Expanded depth', () => {
array of:
-
+
-
foo
- array[object] +
foo
+ array[object]
@@ -291,13 +291,13 @@ describe('Expanded depth', () => {
array of:
-
+
-
foo
- array[object] +
foo
+ array[object]
@@ -320,26 +320,26 @@ describe('Expanded depth', () => {
array of:
-
+
-
foo
- array[object] +
foo
+ array[object]
-
+
-
bar
- object +
bar
+ object
@@ -397,23 +397,23 @@ describe('Expanded depth', () => {
array of:
-
+
-
bar
- integer +
bar
+ integer
-
+
-
foo
- array[object] +
foo
+ array[object]
@@ -436,23 +436,23 @@ describe('Expanded depth', () => {
array of:
-
+
-
bar
- integer +
bar
+ integer
-
+
-
foo
- array[object] +
foo
+ array[object]
@@ -475,46 +475,46 @@ describe('Expanded depth', () => {
array of:
-
+
-
bar
- integer +
bar
+ integer
-
+
-
foo
- array[object] +
foo
+ array[object]
-
+
-
bar
- string +
bar
+ string
-
+
-
foo
- number +
foo
+ number
@@ -584,24 +584,24 @@ describe('Expanded depth', () => {
-
+
-
bar
- object +
bar
+ object
-
+
-
foo
- array[object] +
foo
+ array[object]
@@ -651,10 +651,10 @@ describe('$ref resolving', () => {
-
+
-
string
+
string
@@ -678,20 +678,20 @@ describe('$ref resolving', () => {
-
+
-
$ref(#/foo)[]
+
$ref(#/foo)[]
-
+
-
#/foo
+
#/foo
diff --git a/src/components/SchemaRow/SchemaRow.tsx b/src/components/SchemaRow/SchemaRow.tsx index bd89d998..39e1d7c3 100644 --- a/src/components/SchemaRow/SchemaRow.tsx +++ b/src/components/SchemaRow/SchemaRow.tsx @@ -92,6 +92,7 @@ export const SchemaRow: React.FunctionComponent = React.memo( pl={pl} py={2} data-id={originalNodeId} + data-test="schema-row" pos="relative" onMouseEnter={(e: any) => { e.stopPropagation(); @@ -115,7 +116,12 @@ export const SchemaRow: React.FunctionComponent = React.memo( {schemaNode.subpath.length > 0 && shouldShowPropertyName(schemaNode) && ( - + {last(schemaNode.subpath)} )} diff --git a/src/components/shared/Description.tsx b/src/components/shared/Description.tsx index b76f0c57..eec1cd36 100644 --- a/src/components/shared/Description.tsx +++ b/src/components/shared/Description.tsx @@ -26,6 +26,7 @@ export const Description: React.FunctionComponent<{ value: unknown }> = ({ value return ( = ({ format }) => { - return {`<${format}>`}; + return {`<${format}>`}; }; diff --git a/src/components/shared/Properties.tsx b/src/components/shared/Properties.tsx index e012e97a..8464653e 100644 --- a/src/components/shared/Properties.tsx +++ b/src/components/shared/Properties.tsx @@ -29,11 +29,11 @@ export const Properties: React.FunctionComponent = ({ const showVisibilityValidations = viewMode === 'standalone' && !!readOnly !== !!writeOnly; const visibility = showVisibilityValidations ? ( readOnly ? ( - + read-only ) : ( - + write-only ) @@ -42,13 +42,13 @@ export const Properties: React.FunctionComponent = ({ return ( <> {deprecated ? ( - + deprecated ) : null} {visibility} {required && ( - + required )} diff --git a/src/components/shared/Types.tsx b/src/components/shared/Types.tsx index 828935e7..3d04273c 100644 --- a/src/components/shared/Types.tsx +++ b/src/components/shared/Types.tsx @@ -61,7 +61,7 @@ function getFormats(schemaNode: RegularNode): Partial = ({ schemaNode }) => { if (isReferenceNode(schemaNode)) { return ( - + {schemaNode.value ?? '$ref'} ); @@ -80,7 +80,7 @@ export const Types: React.FunctionComponent<{ schemaNode: SchemaNode }> = ({ sch const rendered = types.map((type, i, { length }) => ( - + {shouldRenderName(type) ? printName(schemaNode) ?? type : type} diff --git a/src/components/shared/Validations.tsx b/src/components/shared/Validations.tsx index 65c7bbd6..4353175d 100644 --- a/src/components/shared/Validations.tsx +++ b/src/components/shared/Validations.tsx @@ -132,7 +132,7 @@ const NumberValidations = ({ return null; } return ( - + {entries .map(([key, value]) => numberValidationFormatters[key](value)) .map((value, i) => ( @@ -159,7 +159,7 @@ const KeyValueValidations = ({ validations }: { validations: Dictionary const KeyValueValidation = ({ name, values }: { name: string; values: string[] }) => { return ( - + {capitalize(name)}: diff --git a/src/components/shared/__tests__/Property.spec.tsx b/src/components/shared/__tests__/Property.spec.tsx index bc19a88a..70836550 100644 --- a/src/components/shared/__tests__/Property.spec.tsx +++ b/src/components/shared/__tests__/Property.spec.tsx @@ -46,7 +46,7 @@ describe('Property component', () => { const wrapper = render(schema); expect(wrapper.find(Types).first().html()).toMatchInlineSnapshot( - `"array[string]"`, + `"array[string]"`, ); }); @@ -58,7 +58,7 @@ describe('Property component', () => { const wrapper = render(schema); expect(wrapper.find(Types).first().html()).toMatchInlineSnapshot( - `"array"`, + `"array"`, ); }); @@ -68,7 +68,9 @@ describe('Property component', () => { }; const wrapper = render(schema); - expect(wrapper.find(Types).first().html()).toMatchInlineSnapshot(`"$ref"`); + expect(wrapper.find(Types).first().html()).toMatchInlineSnapshot( + `"$ref"`, + ); }); describe('properties names', () => { @@ -83,7 +85,7 @@ describe('Property component', () => { const wrapper = render(schema, ['properties', 'foo']); expect(wrapper.find(SchemaRow).html()).toMatchInlineSnapshot( - `"
foo
string
"`, + `"
foo
string
"`, ); }); @@ -102,7 +104,7 @@ describe('Property component', () => { const wrapper = render(schema, ['properties', 'foo']); expect(wrapper.find(SchemaRow).html()).toMatchInlineSnapshot( - `"
foo
array[integer]
"`, + `"
foo
array[integer]
"`, ); }); @@ -120,7 +122,7 @@ describe('Property component', () => { const wrapper = render(schema, ['items', 'properties', 'foo']); expect(wrapper.html()).toMatchInlineSnapshot( - `"
foo
string
"`, + `"
foo
string
"`, ); }); @@ -141,7 +143,7 @@ describe('Property component', () => { const wrapper = render(schema); expect(wrapper.html()).toMatchInlineSnapshot( - `"
"`, + `"
"`, ); }); @@ -164,7 +166,7 @@ describe('Property component', () => { const wrapper = render(schema); expect(wrapper.html()).toMatchInlineSnapshot( - `"
array[object]
foo
bar
baz
"`, + `"
array[object]
foo
bar
baz
"`, ); }); @@ -199,12 +201,12 @@ describe('Property component', () => { let wrapper = render(schema, ['properties', 'array-all-objects', 'items', 'properties', 'foo']); expect(wrapper.html()).toMatchInlineSnapshot( - `"
foo
string
"`, + `"
foo
string
"`, ); wrapper = render(schema, ['properties', 'array-all-objects', 'items', 'properties', 'bar']); expect(wrapper.html()).toMatchInlineSnapshot( - `"
bar
string
"`, + `"
bar
string
"`, ); }); @@ -224,7 +226,7 @@ describe('Property component', () => { const wrapper = mount(); expect(wrapper.html()).toMatchInlineSnapshot( - `"
foo
object
"`, + `"
foo
object
"`, ); wrapper.unmount(); }); @@ -244,7 +246,7 @@ describe('Property component', () => { const wrapper = render(schema); expect(wrapper.find(Types).first().html()).toMatchInlineSnapshot( - `"User"`, + `"User"`, ); }); @@ -264,7 +266,7 @@ describe('Property component', () => { const wrapper = render(schema); expect(wrapper.find(Types).first().html()).toMatchInlineSnapshot( - `"array[User]"`, + `"array[User]"`, ); }); @@ -276,7 +278,7 @@ describe('Property component', () => { const wrapper = render(schema); expect(wrapper.find(Types).first().html()).toMatchInlineSnapshot( - `"User"`, + `"User"`, ); }); @@ -297,7 +299,7 @@ describe('Property component', () => { const wrapper = render(schema); expect(wrapper.find(Types).first().html()).toMatchInlineSnapshot( - `"array"`, + `"array"`, ); }); });