diff --git a/packages/builder/src/userInterface/pagesParsing/searchComponents.js b/packages/builder/src/userInterface/pagesParsing/searchComponents.js index a55cbff9ca..e61be6122b 100644 --- a/packages/builder/src/userInterface/pagesParsing/searchComponents.js +++ b/packages/builder/src/userInterface/pagesParsing/searchComponents.js @@ -19,9 +19,10 @@ const isRootComponent = c => isUndefined(c.inherits); export const searchAllComponents = (derivedComponents, rootComponents, phrase) => { - const hasPhrase = (...vals) => pipe(vals, [ - some(v => includes(phrase)(v)) - ]); + const hasPhrase = (...vals) => + pipe(vals, [ + some(v => includes(normalString(phrase))(normalString(v))) + ]); const rootComponentMatches = c => hasPhrase(c.name, ...(c.tags || [])); diff --git a/packages/builder/tests/searchComponentsProps.spec.js b/packages/builder/tests/searchComponentsProps.spec.js index 92b9a4072d..794e9c3f8e 100644 --- a/packages/builder/tests/searchComponentsProps.spec.js +++ b/packages/builder/tests/searchComponentsProps.spec.js @@ -12,22 +12,100 @@ describe("searchAllComponents", () => { const results = searchAllComponents( derivedComponents(), rootComponents(), - "smalltextbox" + "password" ); expect(results.length).toBe(1); - expect(results[0].name).toBe("common/SmallTextbox"); + expect(results[0].name).toBe("common/PasswordBox"); - }) + }); + + it("should match derived component by tag", () => { + + const results = searchAllComponents( + derivedComponents(), + rootComponents(), + "mask" + ); + + expect(results.length).toBe(1); + expect(results[0].name).toBe("common/PasswordBox"); + + }); + + it("should match component if ancestor matches", () => { + + const results = searchAllComponents( + derivedComponents(), + rootComponents(), + "smalltext" + ); + + expect(results.length).toBe(2); + + }); }); describe("getExactComponent", () => { + it("should get component by name", () => { + const result = getExactComponent( + derivedComponents(), + rootComponents(), + "common/SmallTextbox" + ) + + expect(result).toBeDefined(); + expect(result.name).toBe("common/SmallTextbox"); + }); + + it("should return nothing when no result (should not fail)", () => { + const result = getExactComponent( + derivedComponents(), + rootComponents(), + "bla/bla/bla" + ) + + expect(result).not.toBeDefined(); + }); }); describe("getAncestorProps", () => { + it("should return props of root component", () => { + + const result = getAncestorProps( + derivedComponents(), + rootComponents(), + "budibase-components/TextBox" + ); + + expect(result).toEqual([ + rootComponents()[0].props + ]); + + }); + + it("should return props of all ancestors and current component, in order", () => { + + const derived = derivedComponents(); + const root = rootComponents(); + + const result = getAncestorProps( + derived, + root, + "common/PasswordBox" + ); + + expect(result).toEqual([ + root[0].props, + {_component: "budibase-components/TextBox", ...derived[0].props}, + {_component: "common/SmallTextbox", ...derived[1].props} + ]); + + }); + }) const derivedComponents = () => ([