2019-07-28 09:03:11 +02:00
|
|
|
import {
|
2020-02-03 10:24:25 +01:00
|
|
|
searchAllComponents,
|
|
|
|
getExactComponent,
|
|
|
|
getAncestorProps,
|
2020-04-01 12:38:07 +02:00
|
|
|
} from "../src/components/userInterface/pagesParsing/searchComponents"
|
2020-02-03 10:24:25 +01:00
|
|
|
import { componentsAndScreens } from "./testData"
|
2019-07-28 09:03:11 +02:00
|
|
|
|
|
|
|
describe("searchAllComponents", () => {
|
2020-02-03 10:24:25 +01:00
|
|
|
it("should match component by name", () => {
|
|
|
|
const results = searchAllComponents(
|
|
|
|
componentsAndScreens().components,
|
|
|
|
"Textbox"
|
|
|
|
)
|
|
|
|
|
|
|
|
expect(results.length).toBe(1)
|
|
|
|
expect(results[0].name).toBe("budibase-components/TextBox")
|
|
|
|
})
|
|
|
|
|
|
|
|
it("should match component by tag", () => {
|
|
|
|
const results = searchAllComponents(
|
|
|
|
componentsAndScreens().components,
|
|
|
|
"record"
|
|
|
|
)
|
|
|
|
|
|
|
|
expect(results.length).toBe(1)
|
|
|
|
expect(results[0].name).toBe("budibase-components/RecordView")
|
|
|
|
})
|
|
|
|
})
|
2019-07-28 09:03:11 +02:00
|
|
|
|
|
|
|
describe("getExactComponent", () => {
|
2020-02-03 10:24:25 +01:00
|
|
|
it("should get component by name", () => {
|
|
|
|
const { components, screens } = componentsAndScreens()
|
|
|
|
const result = getExactComponent(
|
|
|
|
[...components, ...screens],
|
|
|
|
"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()
|
|
|
|
const result = getExactComponent([...components, ...screens], "bla/bla/bla")
|
|
|
|
|
|
|
|
expect(result).not.toBeDefined()
|
|
|
|
})
|
|
|
|
})
|
2019-07-28 09:03:11 +02:00
|
|
|
|
|
|
|
describe("getAncestorProps", () => {
|
2020-02-03 10:24:25 +01:00
|
|
|
it("should return props of root component", () => {
|
|
|
|
const result = getAncestorProps(
|
|
|
|
componentsAndScreens().components,
|
|
|
|
"budibase-components/TextBox"
|
|
|
|
)
|
|
|
|
|
|
|
|
expect(result).toEqual([componentsAndScreens().components[0].props])
|
|
|
|
})
|
|
|
|
|
|
|
|
it("should return props of inherited and current component, in order", () => {
|
|
|
|
const { components, screens } = componentsAndScreens()
|
|
|
|
const allComponentsAndScreens = [...components, ...screens]
|
|
|
|
|
|
|
|
const result = getAncestorProps(
|
|
|
|
allComponentsAndScreens,
|
|
|
|
"common/PasswordBox"
|
|
|
|
)
|
|
|
|
|
|
|
|
expect(result).toEqual([
|
|
|
|
allComponentsAndScreens[0].props,
|
|
|
|
{ ...allComponentsAndScreens[5].props },
|
|
|
|
])
|
|
|
|
})
|
2019-07-28 09:03:11 +02:00
|
|
|
})
|