budibase/packages/builder/tests/searchComponentsProps.spec.js

95 lines
2.3 KiB
JavaScript
Raw Normal View History

2019-07-28 09:03:11 +02:00
import {
searchAllComponents,
getExactComponent,
getAncestorProps
} from "../src/userInterface/pagesParsing/searchComponents";
import { componentsAndScreens } from "./testData";
2019-07-28 09:03:11 +02:00
describe("searchAllComponents", () => {
it("should match component by name", () => {
2019-07-28 09:03:11 +02:00
const results = searchAllComponents(
componentsAndScreens().components,
"Textbox"
2019-07-28 09:03:11 +02:00
);
expect(results.length).toBe(1);
expect(results[0].name).toBe("budibase-components/TextBox");
2019-07-28 09:03:11 +02:00
2019-07-28 13:45:00 +02:00
});
it("should match component by tag", () => {
2019-07-28 13:45:00 +02:00
const results = searchAllComponents(
componentsAndScreens().components,
"record"
2019-07-28 13:45:00 +02:00
);
expect(results.length).toBe(1);
expect(results[0].name).toBe("budibase-components/RecordView");
2019-07-28 13:45:00 +02:00
});
2019-07-28 09:03:11 +02:00
});
describe("getExactComponent", () => {
2019-07-28 13:45:00 +02:00
it("should get component by name", () => {
const {components, screens} = componentsAndScreens();
2019-07-28 13:45:00 +02:00
const result = getExactComponent(
[...components, ...screens],
2019-07-28 13:45:00 +02:00
"common/SmallTextbox"
)
expect(result).toBeDefined();
expect(result.name).toBe("common/SmallTextbox");
});
it("should return nothing when no result (should not fail)", () => {
const {components, screens} = componentsAndScreens();
2019-07-28 13:45:00 +02:00
const result = getExactComponent(
[...components, ...screens],
2019-07-28 13:45:00 +02:00
"bla/bla/bla"
)
expect(result).not.toBeDefined();
});
2019-07-28 09:03:11 +02:00
});
describe("getAncestorProps", () => {
2019-07-28 13:45:00 +02:00
it("should return props of root component", () => {
const result = getAncestorProps(
componentsAndScreens().components,
2019-07-28 13:45:00 +02:00
"budibase-components/TextBox"
);
expect(result).toEqual([
componentsAndScreens().components[0].props
2019-07-28 13:45:00 +02:00
]);
});
it("should return props of inherited and current component, in order", () => {
2019-07-28 13:45:00 +02:00
const {components, screens} = componentsAndScreens();
const allComponentsAndScreens = [...components, ...screens];
2019-07-28 13:45:00 +02:00
const result = getAncestorProps(
allComponentsAndScreens,
2019-07-28 13:45:00 +02:00
"common/PasswordBox"
);
expect(result).toEqual([
allComponentsAndScreens[0].props,
{...allComponentsAndScreens[5].props}
2019-07-28 13:45:00 +02:00
]);
});
2019-07-28 09:03:11 +02:00
})
2019-08-14 23:11:59 +02:00