From d5ef35ed03dbe997dad3ee7e9ffb60aaf242d3f4 Mon Sep 17 00:00:00 2001 From: Josh <37798644+joshuaellis@users.noreply.github.com> Date: Fri, 9 Dec 2022 16:29:37 +0000 Subject: [PATCH] chore: add tests --- ...cursivelyFindPathsBasedOnCondition.test.js | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/packages/core/admin/admin/src/content-manager/components/EditViewDataManagerProvider/utils/tests/recursivelyFindPathsBasedOnCondition.test.js b/packages/core/admin/admin/src/content-manager/components/EditViewDataManagerProvider/utils/tests/recursivelyFindPathsBasedOnCondition.test.js index 5d2bb7a886..bd3f4a1fea 100644 --- a/packages/core/admin/admin/src/content-manager/components/EditViewDataManagerProvider/utils/tests/recursivelyFindPathsBasedOnCondition.test.js +++ b/packages/core/admin/admin/src/content-manager/components/EditViewDataManagerProvider/utils/tests/recursivelyFindPathsBasedOnCondition.test.js @@ -611,4 +611,79 @@ describe('recursivelyFindPathsBasedOnCondition', () => { expect(actual).toEqual(['dynamic_relations', 'dynamic_relations.simple']); }); }); + + describe('components', () => { + test('given that a component exits, it should be returned', () => { + const components = { + 'basic.simple': { + attributes: { + id: { + type: 'integer', + }, + categories: { + type: 'relation', + relation: 'oneToMany', + target: 'api::category.category', + targetModel: 'api::category.category', + relationType: 'oneToMany', + }, + my_name: { + type: 'string', + }, + }, + }, + }; + + const attributes = { + relation: { + type: 'component', + component: 'basic.simple', + repeatable: false, + }, + }; + + const actual = recursivelyFindPathsBasedOnCondition( + components, + (value) => value.type === 'component' && !value.repeatable + )(attributes); + + expect(actual).toEqual(['relation']); + }); + + test('given that a component is in a dynamic zone it should not return the name of the dynamic zone', () => { + const components = { + 'basic.simple': { + attributes: { + id: { + type: 'integer', + }, + categories: { + type: 'relation', + relation: 'oneToMany', + target: 'api::category.category', + targetModel: 'api::category.category', + relationType: 'oneToMany', + }, + my_name: { + type: 'string', + }, + }, + }, + }; + + const attributes = { + dynamic_relations: { + type: 'dynamiczone', + components: ['basic.simple'], + }, + }; + + const actual = recursivelyFindPathsBasedOnCondition( + components, + (value) => value.type === 'component' && value.repeatable === false + )(attributes); + + expect(actual).toEqual([]); + }); + }); });