From f3b6dfab04ccc8fb836c73079e92f42fd7b6125b Mon Sep 17 00:00:00 2001 From: Kevin Date: Wed, 16 Mar 2022 19:58:42 +0300 Subject: [PATCH] Updated tests --- .../components/specs/EntitySection.spec.tsx | 88 +++++++------------ .../components/specs/fixture/state.ts | 15 ++++ 2 files changed, 46 insertions(+), 57 deletions(-) diff --git a/app/react/Markdown/components/specs/EntitySection.spec.tsx b/app/react/Markdown/components/specs/EntitySection.spec.tsx index 2a0b74cf0f..f513ab0ed1 100644 --- a/app/react/Markdown/components/specs/EntitySection.spec.tsx +++ b/app/react/Markdown/components/specs/EntitySection.spec.tsx @@ -24,76 +24,50 @@ describe('EntitySection Markdown', () => { component = renderConnectedMount(() => innerComponent, state); }; + const testShowIf = (showIf: string, expected: string) => { + render( + +
test
+
+ ); + expect(component.html()).toBe(expected); + }; + describe('root properties Values', () => { it('should show if title and root dates of entity exists', () => { - render( - - Exists - - ); - expect(component.html()).toBe('Exists'); - - render( - - Exists - - ); - expect(component.html()).toBe('Exists'); + testShowIf('{ "title": { "$exists": true }}', '
test
'); + testShowIf('{ "creationDate": { "$exists": true }}', '
test
'); }); it('should not show if a root property does not exist', () => { - render( - - Exists - - ); - expect(component.html()).toBe(''); + testShowIf('{ "titledoesntexist": { "$exists": true }}', ''); }); }); describe('metadata property Values', () => { it('should show if unwrapped metadata properties exist', () => { - render( - - Exists - - ); - expect(component.html()).toBe('Exists'); - - render( - - Exists - - ); - expect(component.html()).toBe('Exists'); - - render( - - Exists - - ); - expect(component.html()).toBe('Exists'); + testShowIf('{ "metadata.description": { "$exists": true }}', '
test
'); + testShowIf('{ "metadata.date": { "$exists": true }}', '
test
'); + testShowIf('{ "metadata.main_image": { "$exists": true }}', '
test
'); }); it('should show if a metadata property matches a value', () => { - render( - - Exists - - ); - expect(component.html()).toBe('Exists'); - render( - - Exists - - ); - expect(component.html()).toBe('Exists'); + testShowIf('{ "metadata.description": { "$eq": "A long description" }}', '
test
'); + testShowIf('{ "metadata.description": "A long description" }', '
test
'); }); it('should not show if a metadata property does not exist', () => { - render( - - Exists - - ); - expect(component.html()).toBe(''); + testShowIf('{ "metadata.nonexistent": { "$exists": true }}', ''); + }); + }); + describe('inherited Values', () => { + it('should show if inherited text exists', () => { + testShowIf('{ "metadata.inherited_text": { "$exists": true }}', '
test
'); + }); + it('should show if inherited text has a value', () => { + testShowIf('{ "metadata.inherited_text": { "$in": ["something"] }}', '
test
'); + testShowIf('{ "metadata.inherited_text": { "$nin": ["something"] }}', ''); + }); + it('should not show if inherited text has no specified value', () => { + testShowIf('{ "metadata.inherited_text": { "$nin": ["here"] }}', '
test
'); + testShowIf('{ "metadata.inherited_text": { "$in": ["here"] }}', ''); }); }); }); diff --git a/app/react/Markdown/components/specs/fixture/state.ts b/app/react/Markdown/components/specs/fixture/state.ts index 04b08fd096..ad60a33d94 100644 --- a/app/react/Markdown/components/specs/fixture/state.ts +++ b/app/react/Markdown/components/specs/fixture/state.ts @@ -10,6 +10,20 @@ const state = { description: [{ value: 'A long description' }], date: [{ value: 237600000 }], main_image: [{ value: 'https://www.google.com' }], + inherited_text: [ + { + value: '7ycel666l65vobt9', + label: 'Corte Interamericana de Derechos Humanos', + icon: null, + type: 'relationship', + inheritedValue: [ + { + value: 'something', + }, + ], + inheritedType: 'text', + }, + ], }, }), }, @@ -21,6 +35,7 @@ const state = { { name: 'description', type: 'text' }, { name: 'date', type: 'date' }, { name: 'main_image', label: 'Main Image', type: 'image' }, + { name: 'inherited_text', label: 'Inherited Text', type: 'relationship' }, ], }, ]),