From 39ad9e6f0e8bea6380a5ec79c9889037e6ccf0cc Mon Sep 17 00:00:00 2001 From: Mateusz Podlasin Date: Fri, 3 Sep 2021 17:11:58 +0200 Subject: [PATCH] fix: long validations (#166) * fix: long validations * fix: linter errors * fix: snapshot tests --- src/__fixtures__/default-schema.json | 2 +- .../__snapshots__/index.spec.tsx.snap | 3 ++ src/components/SchemaRow/SchemaRow.tsx | 6 ++-- src/components/shared/Validations.tsx | 29 ++++++++++++++----- .../shared/__tests__/Property.spec.tsx | 16 +++++----- 5 files changed, 36 insertions(+), 20 deletions(-) diff --git a/src/__fixtures__/default-schema.json b/src/__fixtures__/default-schema.json index 7f61a2b2..4167fd7a 100644 --- a/src/__fixtures__/default-schema.json +++ b/src/__fixtures__/default-schema.json @@ -5,7 +5,7 @@ "name": { "type": "string", "const": "Constant name", - "examples": ["Example name", "Different name"], + "examples": ["Example name", "Different name", "Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa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aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"], "description": "The user's full name. This description can be long and should truncate once it reaches the end of the row. If it's not truncating then theres and issue that needs to be fixed. Help!" }, "age": { diff --git a/src/__tests__/__snapshots__/index.spec.tsx.snap b/src/__tests__/__snapshots__/index.spec.tsx.snap index 5f1ef5d3..af4f9e83 100644 --- a/src/__tests__/__snapshots__/index.spec.tsx.snap +++ b/src/__tests__/__snapshots__/index.spec.tsx.snap @@ -2693,6 +2693,9 @@ exports[`HTML Output should match default-schema.json 1`] = ` Example values: Example name Different name + + Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa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emaRow/SchemaRow.tsx b/src/components/SchemaRow/SchemaRow.tsx index e2e46a2d..587372d2 100644 --- a/src/components/SchemaRow/SchemaRow.tsx +++ b/src/components/SchemaRow/SchemaRow.tsx @@ -57,13 +57,13 @@ export const SchemaRow: React.FunctionComponent = ({ schemaNode, const childNodes = React.useMemo(() => calculateChildrenToShow(typeToShow), [typeToShow]); return (
-
-
+
+
0 ? () => setExpanded(!isExpanded) : undefined} className={cn({ 'sl-cursor-pointer': childNodes.length > 0 })} > -
+
{childNodes.length > 0 ? : null}
diff --git a/src/components/shared/Validations.tsx b/src/components/shared/Validations.tsx index 3eeffbc4..775c7224 100644 --- a/src/components/shared/Validations.tsx +++ b/src/components/shared/Validations.tsx @@ -138,11 +138,11 @@ const NumberValidations = ({ return null; } return ( - + {entries .map(([key, value]) => numberValidationFormatters[key](value)) .map((value, i) => ( - + ))} ); @@ -165,10 +165,12 @@ const KeyValueValidations = ({ validations }: { validations: Dictionary const KeyValueValidation = ({ name, values }: { name: string; values: string[] }) => { return ( - - {capitalize(name)}: + + + {capitalize(name)}: + {uniq(values).map(value => ( - + ))} ); @@ -177,11 +179,11 @@ const KeyValueValidation = ({ name, values }: { name: string; values: string[] } const NameValidations = ({ validations }: { validations: Dictionary }) => ( <> {keys(validations).length ? ( - + {keys(validations) .filter(key => validations[key]) .map(key => ( - + ))} ) : null} @@ -189,7 +191,18 @@ const NameValidations = ({ validations }: { validations: Dictionary }) ); const Value = ({ name, className }: { name: string; className?: string }) => ( - + {name} ); diff --git a/src/components/shared/__tests__/Property.spec.tsx b/src/components/shared/__tests__/Property.spec.tsx index 9672a530..917a0c7f 100644 --- a/src/components/shared/__tests__/Property.spec.tsx +++ b/src/components/shared/__tests__/Property.spec.tsx @@ -83,7 +83,7 @@ describe('Property component', () => { const wrapper = render(schema, ['properties', 'foo']); expect(wrapper.find(SchemaRow).html()).toMatchInlineSnapshot( - `"
foo
string
"`, + `"
foo
string
"`, ); }); @@ -102,7 +102,7 @@ describe('Property component', () => { const wrapper = render(schema, ['properties', 'foo']); expect(wrapper.find(SchemaRow).html()).toMatchInlineSnapshot( - `"
foo
array[integer]
"`, + `"
foo
array[integer]
"`, ); }); @@ -120,7 +120,7 @@ describe('Property component', () => { const wrapper = render(schema, ['items', 'properties', 'foo']); expect(wrapper.html()).toMatchInlineSnapshot( - `"
foo
string
"`, + `"
foo
string
"`, ); }); @@ -141,7 +141,7 @@ describe('Property component', () => { const wrapper = render(schema); expect(wrapper.html()).toMatchInlineSnapshot( - `"
"`, + `"
"`, ); }); @@ -164,7 +164,7 @@ describe('Property component', () => { const wrapper = render(schema); expect(wrapper.html()).toMatchInlineSnapshot( - `"
array[object]
foo
bar
baz
"`, + `"
array[object]
foo
bar
baz
"`, ); }); @@ -199,12 +199,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 +224,7 @@ describe('Property component', () => { const wrapper = mount(); expect(wrapper.html()).toMatchInlineSnapshot( - `"
foo
object
"`, + `"
foo
object
"`, ); wrapper.unmount(); });