From bc33af13f91bfd1bb5a1a5fa793084bd92c8ce19 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Tue, 29 Nov 2022 16:27:06 +0000 Subject: [PATCH] Fix types in table migration tests --- .../functions/tests/tableSettings.spec.ts | 94 +++++++++++-------- 1 file changed, 55 insertions(+), 39 deletions(-) diff --git a/packages/server/src/migrations/functions/tests/tableSettings.spec.ts b/packages/server/src/migrations/functions/tests/tableSettings.spec.ts index 70701443c5..8d28a43322 100644 --- a/packages/server/src/migrations/functions/tests/tableSettings.spec.ts +++ b/packages/server/src/migrations/functions/tests/tableSettings.spec.ts @@ -1,4 +1,4 @@ -import { App, Screen, ScreenProps, Component } from "@budibase/types" +import { App, Screen } from "@budibase/types" import { db as dbCore } from "@budibase/backend-core" import TestConfig from "../../../tests/utilities/TestConfiguration" @@ -7,7 +7,7 @@ import { run as runMigration } from "../tableSettings" describe("run", () => { const config = new TestConfig(false) let app: App - let screen: Component + let screen: Screen beforeAll(async () => { await config.init() @@ -19,14 +19,18 @@ describe("run", () => { it("migrates table block row on click settings", async () => { // Add legacy table block as first child - screen.props._children[0] = { - _component: "@budibase/standard-components/tableblock", - _id: "foo", - linkRows: true, - linkURL: "/rows/:id", - linkPeek: true, - linkColumn: "name", - } + screen.props._children = [ + { + _instanceName: "Table Block", + _styles: {}, + _component: "@budibase/standard-components/tableblock", + _id: "foo", + linkRows: true, + linkURL: "/rows/:id", + linkPeek: true, + linkColumn: "name", + }, + ] await config.createScreen(screen) // Run migration @@ -36,7 +40,7 @@ describe("run", () => { }) // Verify new "onClick" setting - const onClick = screen.props._children[0].onClick + const onClick = screen.props._children?.[0].onClick expect(onClick).toBeDefined() expect(onClick.length).toBe(1) expect(onClick[0]["##eventHandlerType"]).toBe("Navigate To") @@ -48,14 +52,18 @@ describe("run", () => { it("migrates table row on click settings", async () => { // Add legacy table block as first child - screen.props._children[0] = { - _component: "@budibase/standard-components/table", - _id: "foo", - linkRows: true, - linkURL: "/rows/:id", - linkPeek: true, - linkColumn: "name", - } + screen.props._children = [ + { + _instanceName: "Table", + _styles: {}, + _component: "@budibase/standard-components/table", + _id: "foo", + linkRows: true, + linkURL: "/rows/:id", + linkPeek: true, + linkColumn: "name", + }, + ] await config.createScreen(screen) // Run migration @@ -65,7 +73,7 @@ describe("run", () => { }) // Verify new "onClick" setting - const onClick = screen.props._children[0].onClick + const onClick = screen.props._children?.[0].onClick expect(onClick).toBeDefined() expect(onClick.length).toBe(1) expect(onClick[0]["##eventHandlerType"]).toBe("Navigate To") @@ -77,13 +85,17 @@ describe("run", () => { it("migrates table block title button settings", async () => { // Add legacy table block as first child - screen.props._children[0] = { - _component: "@budibase/standard-components/tableblock", - _id: "foo", - showTitleButton: true, - titleButtonURL: "/url", - titleButtonPeek: true, - } + screen.props._children = [ + { + _instanceName: "Table Block", + _styles: {}, + _component: "@budibase/standard-components/tableblock", + _id: "foo", + showTitleButton: true, + titleButtonURL: "/url", + titleButtonPeek: true, + }, + ] await config.createScreen(screen) // Run migration @@ -93,7 +105,7 @@ describe("run", () => { }) // Verify new "onClickTitleButton" setting - const onClick = screen.props._children[0].onClickTitleButton + const onClick = screen.props._children?.[0].onClickTitleButton expect(onClick).toBeDefined() expect(onClick.length).toBe(1) expect(onClick[0]["##eventHandlerType"]).toBe("Navigate To") @@ -103,16 +115,20 @@ describe("run", () => { it("ignores components that have already been migrated", async () => { // Add legacy table block as first child - screen.props._children[0] = { - _component: "@budibase/standard-components/tableblock", - _id: "foo", - linkRows: true, - linkURL: "/rows/:id", - linkPeek: true, - linkColumn: "name", - onClick: "foo", - } - const initialDefinition = JSON.stringify(screen.props._children[0]) + screen.props._children = [ + { + _instanceName: "Table Block", + _styles: {}, + _component: "@budibase/standard-components/tableblock", + _id: "foo", + linkRows: true, + linkURL: "/rows/:id", + linkPeek: true, + linkColumn: "name", + onClick: "foo", + }, + ] + const initialDefinition = JSON.stringify(screen.props._children?.[0]) await config.createScreen(screen) // Run migration @@ -122,7 +138,7 @@ describe("run", () => { }) // Verify new "onClick" setting - const newDefinition = JSON.stringify(screen.props._children[0]) + const newDefinition = JSON.stringify(screen.props._children?.[0]) expect(initialDefinition).toEqual(newDefinition) }) })