|
|
|
@ -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 = () => ([ |
|
|
|
|