This is an automated email from the ASF dual-hosted git repository. kbowers pushed a commit to branch kie-issues#1374 in repository https://gitbox.apache.org/repos/asf/incubator-kie-tools.git
commit 905c18fba748ec05c9981c388f438abf726faafc Author: kbowers-ibm <[email protected]> AuthorDate: Wed Jul 17 11:47:31 2024 +0200 Adding playwright tests --- .../stories/boxedExpressionStoriesWrapper.tsx | 62 ++++++++++-------- .../DecisionTable/DecisionTable.stories.tsx | 54 +++++++++++++++ .../tests-e2e/__fixtures__/base.ts | 5 ++ .../tests-e2e/__fixtures__/jsonModel.ts | 56 ++++++++++++++++ .../tests-e2e/__fixtures__/stories.ts | 2 +- .../tests-e2e/features/resizing/resizing.spec.ts | 76 ++++++++++++++++++++++ 6 files changed, 227 insertions(+), 28 deletions(-) diff --git a/packages/boxed-expression-component/stories/boxedExpressionStoriesWrapper.tsx b/packages/boxed-expression-component/stories/boxedExpressionStoriesWrapper.tsx index 1d0980c6b1b..b4c7a281cff 100644 --- a/packages/boxed-expression-component/stories/boxedExpressionStoriesWrapper.tsx +++ b/packages/boxed-expression-component/stories/boxedExpressionStoriesWrapper.tsx @@ -154,33 +154,41 @@ export function BoxedExpressionEditorStory(props?: Partial<BoxedExpressionEditor }, [updateArgs, expressionState]); return ( - <div - ref={emptyRef} - onKeyDown={(e) => { - // Prevent keys from propagating to Storybook - console.log("wrapper stopped"); - // return e.stopPropagation(); - }} - > - <BoxedExpressionEditor - expressionHolderId={props?.expressionHolderId ?? args?.expressionHolderId ?? generateUuid()} - expressionHolderName={ - props?.expressionHolderName ?? args?.expressionHolderName ?? DEFAULT_EXPRESSION_VARIABLE_NAME - } - expressionHolderTypeRef={props?.expressionHolderTypeRef ?? args?.expressionHolderTypeRef} - expression={expressionState} - onExpressionChange={setExpressionState} - onWidthsChange={onWidthsChange} - dataTypes={props?.dataTypes ?? args?.dataTypes ?? dataTypes} - scrollableParentRef={props?.scrollableParentRef ?? args?.scrollableParentRef ?? emptyRef} - beeGwtService={props?.beeGwtService ?? args?.beeGwtService ?? beeGwtService} - pmmlDocuments={props?.pmmlDocuments ?? args?.pmmlDocuments ?? pmmlDocuments} - isResetSupportedOnRootExpression={ - props?.isResetSupportedOnRootExpression ?? args?.isResetSupportedOnRootExpression ?? false - } - widthsById={widthsByIdMap} - /> - </div> + <> + {args && ( + <div data-testid={"storybook--boxed-expression-component"} style={{ display: "none" }}> + {JSON.stringify(args)} + </div> + )} + + <div + ref={emptyRef} + onKeyDown={(e) => { + // Prevent keys from propagating to Storybook + console.log("wrapper stopped"); + // return e.stopPropagation(); + }} + > + <BoxedExpressionEditor + expressionHolderId={props?.expressionHolderId ?? args?.expressionHolderId ?? generateUuid()} + expressionHolderName={ + props?.expressionHolderName ?? args?.expressionHolderName ?? DEFAULT_EXPRESSION_VARIABLE_NAME + } + expressionHolderTypeRef={props?.expressionHolderTypeRef ?? args?.expressionHolderTypeRef} + expression={expressionState} + onExpressionChange={setExpressionState} + onWidthsChange={onWidthsChange} + dataTypes={props?.dataTypes ?? args?.dataTypes ?? dataTypes} + scrollableParentRef={props?.scrollableParentRef ?? args?.scrollableParentRef ?? emptyRef} + beeGwtService={props?.beeGwtService ?? args?.beeGwtService ?? beeGwtService} + pmmlDocuments={props?.pmmlDocuments ?? args?.pmmlDocuments ?? pmmlDocuments} + isResetSupportedOnRootExpression={ + props?.isResetSupportedOnRootExpression ?? args?.isResetSupportedOnRootExpression ?? false + } + widthsById={widthsByIdMap} + /> + </div> + </> ); } diff --git a/packages/boxed-expression-component/stories/boxedExpressions/DecisionTable/DecisionTable.stories.tsx b/packages/boxed-expression-component/stories/boxedExpressions/DecisionTable/DecisionTable.stories.tsx index 53dcfbe93b3..ee899e0bc8d 100644 --- a/packages/boxed-expression-component/stories/boxedExpressions/DecisionTable/DecisionTable.stories.tsx +++ b/packages/boxed-expression-component/stories/boxedExpressions/DecisionTable/DecisionTable.stories.tsx @@ -251,3 +251,57 @@ export const Nested: Story = { isResetSupportedOnRootExpression: false, }, }; + +export const UndefinedWidths: Story = { + render: (args) => BoxedExpressionEditorStory(), + parameters: { exclude: ["dataTypes", "beeGwtService", "pmmlDocuments"] }, + args: { + ...EmptyExpression.args, + expression: { + __$$element: "decisionTable", + "@_id": "_92929AE6-3BB5-4217-B66E-07614680971D", + "@_label": "Expression Name", + "@_hitPolicy": "UNIQUE", + input: [ + { + "@_id": generateUuid(), + inputExpression: { + "@_id": generateUuid(), + text: { __$$text: "input-1" }, + "@_typeRef": undefined, + }, + }, + ], + output: [ + { + "@_id": generateUuid(), + "@_label": "output-1", + "@_typeRef": undefined, + }, + ], + annotation: [ + { + "@_name": "Annotations", + }, + ], + rule: [ + { + "@_id": generateUuid(), + inputEntry: [{ "@_id": generateUuid(), text: { __$$text: DECISION_TABLE_INPUT_DEFAULT_VALUE } }], + outputEntry: [ + { + "@_id": generateUuid(), + text: { __$$text: DECISION_TABLE_OUTPUT_DEFAULT_VALUE }, + }, + ], + annotationEntry: [{ text: { __$$text: "// Your annotations here" } }], + }, + ], + }, + widthsById: { + "_92929AE6-3BB5-4217-B66E-07614680971D": [], + }, + + isResetSupportedOnRootExpression: true, + }, +}; diff --git a/packages/boxed-expression-component/tests-e2e/__fixtures__/base.ts b/packages/boxed-expression-component/tests-e2e/__fixtures__/base.ts index bcefbf44bcc..173ba8a7b6b 100644 --- a/packages/boxed-expression-component/tests-e2e/__fixtures__/base.ts +++ b/packages/boxed-expression-component/tests-e2e/__fixtures__/base.ts @@ -25,6 +25,7 @@ import { Resizing } from "./resizing"; import { UseCases } from "./useCases"; import { Monaco } from "./monaco"; import { ProjectName } from "@kie-tools/playwright-base/projectNames"; +import { JsonModel } from "./jsonModel"; type BoxedExpressionFixtures = { boxedExpressionEditor: BoxedExpressionEditor; @@ -33,6 +34,7 @@ type BoxedExpressionFixtures = { resizing: Resizing; useCases: UseCases; monaco: Monaco; + jsonModel: JsonModel; }; export const test = base.extend<BoxedExpressionFixtures>({ @@ -56,6 +58,9 @@ export const test = base.extend<BoxedExpressionFixtures>({ useCases: async ({ page, baseURL }, use) => { await use(new UseCases(page, baseURL)); }, + jsonModel: async ({ page, baseURL }, use) => { + await use(new JsonModel(page)); + }, }); export { expect } from "@playwright/test"; diff --git a/packages/boxed-expression-component/tests-e2e/__fixtures__/jsonModel.ts b/packages/boxed-expression-component/tests-e2e/__fixtures__/jsonModel.ts new file mode 100644 index 00000000000..e141eca67fb --- /dev/null +++ b/packages/boxed-expression-component/tests-e2e/__fixtures__/jsonModel.ts @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { Page } from "@playwright/test"; + +interface BoxedExpressionComponent { + expression: string; + widthsById: Record<string, number[]>; +} +export class JsonModel { + constructor(public page: Page) {} + + public async getDecisionTableId(): Promise<string | undefined> { + const jsonObject = await this.getBoxedExpressionContent(); + if (jsonObject === undefined) { + throw new Error("Couldn't find Boxed Expression Content"); + } + const expression = jsonObject.expression || {}; + return expression["@_id"]; + } + + public async getWidthsById(): Promise<number[]> { + const jsonObject = await this.getBoxedExpressionContent(); + const decisionTableId = await this.getDecisionTableId(); + if (jsonObject === undefined || decisionTableId === undefined) { + throw new Error("Couldn't find Boxed Expression Content"); + } + const widthsById = jsonObject.widthsById || {}; + return widthsById[decisionTableId] || []; + } + + private async getBoxedExpressionContent(): Promise<BoxedExpressionComponent | undefined> { + const textContent = await this.page.getByTestId("storybook--boxed-expression-component").textContent(); + + if (textContent === null || textContent === undefined) { + return; + } + return JSON.parse(textContent); + } +} diff --git a/packages/boxed-expression-component/tests-e2e/__fixtures__/stories.ts b/packages/boxed-expression-component/tests-e2e/__fixtures__/stories.ts index 99b61571683..979eb3c046a 100644 --- a/packages/boxed-expression-component/tests-e2e/__fixtures__/stories.ts +++ b/packages/boxed-expression-component/tests-e2e/__fixtures__/stories.ts @@ -38,7 +38,7 @@ export class Stories { await this.page.goto(`${this.baseURL}/${this.getIframeURL(`boxed-expressions-context--${type}`)}` ?? ""); } - public async openDecisionTable(type: BoxedExpressionTypes | "discount" = "base") { + public async openDecisionTable(type: BoxedExpressionTypes | "discount" | "undefined-widths" = "base") { await this.page.goto(`${this.baseURL}/${this.getIframeURL(`boxed-expressions-decision-table--${type}`)}` ?? ""); } diff --git a/packages/boxed-expression-component/tests-e2e/features/resizing/resizing.spec.ts b/packages/boxed-expression-component/tests-e2e/features/resizing/resizing.spec.ts index 1b7c617236a..ee1fa059657 100644 --- a/packages/boxed-expression-component/tests-e2e/features/resizing/resizing.spec.ts +++ b/packages/boxed-expression-component/tests-e2e/features/resizing/resizing.spec.ts @@ -19,6 +19,14 @@ import { test, expect } from "../../__fixtures__/base"; import { TestAnnotations } from "@kie-tools/playwright-base/annotations"; +import { + CONTEXT_ENTRY_VARIABLE_MIN_WIDTH, + DECISION_TABLE_ANNOTATION_MIN_WIDTH, + DECISION_TABLE_INPUT_MIN_WIDTH, + DECISION_TABLE_OUTPUT_MIN_WIDTH, + INVOCATION_PARAMETER_MIN_WIDTH, + RELATION_EXPRESSION_COLUMN_MIN_WIDTH, +} from "../../../src/resizing/WidthConstants.ts"; test.describe("Resizing", () => { test.describe("Literal expression", () => { @@ -238,6 +246,21 @@ test.describe("Resizing", () => { expect(await nestedEntry.boundingBox()).toHaveProperty("width", 120); expect(await nestedLiteralExpresison.boundingBox()).toHaveProperty("width", 212); }); + + test("should assign width values to all columns when no width defined", async ({ + stories, + page, + resizing, + jsonModel, + }) => { + test.skip(true, "https://github.com/apache/incubator-kie-issues/issues/1374"); + await stories.openBoxedContext("installment-calculation"); + const firstEntry = page.getByRole("cell", { name: "Fee (number)" }); + await resizing.resizeCell(firstEntry, { x: 0, y: 0 }, { x: 50, y: 0 }); + + const widths = await jsonModel.getWidthsById(); + expect(await widths[0]).toEqual(CONTEXT_ENTRY_VARIABLE_MIN_WIDTH + 50); + }); }); test.describe("Decision Table expression", () => { @@ -453,6 +476,24 @@ test.describe("Resizing", () => { expect(await annotationsHeader.boundingBox()).toHaveProperty("width", 158); } }); + + test("should assign width values to all columns when no width defined", async ({ + stories, + page, + resizing, + jsonModel, + }) => { + test.skip(true, "https://github.com/apache/incubator-kie-issues/issues/1374"); + await stories.openDecisionTable("undefined-widths"); + const annotationsHeader = page.getByRole("columnheader", { name: "Annotations", exact: true }); + await resizing.resizeCell(annotationsHeader, { x: 0, y: 0 }, { x: 50, y: 0 }); + + const widths = await jsonModel.getWidthsById(); + expect(await widths[0]).toEqual(DECISION_TABLE_INPUT_MIN_WIDTH); + expect(await widths[1]).toEqual(DECISION_TABLE_INPUT_MIN_WIDTH); + expect(await widths[2]).toEqual(DECISION_TABLE_OUTPUT_MIN_WIDTH); + expect(await widths[3]).toEqual(DECISION_TABLE_ANNOTATION_MIN_WIDTH + 50); + }); }); test.describe("Relation expression", () => { @@ -535,6 +576,25 @@ test.describe("Resizing", () => { } expect(await column2.boundingBox()).toHaveProperty("width", 100); }); + + test("should assign width values to all columns when no width defined", async ({ + stories, + page, + resizing, + jsonModel, + }) => { + test.skip(true, "https://github.com/apache/incubator-kie-issues/issues/1374"); + await stories.openRelation("bigger"); + const columnsHeader = page.getByRole("columnheader", { name: "column-3 (<Undefined>)" }); + await resizing.resizeCell(columnsHeader, { x: 0, y: 0 }, { x: 200, y: 0 }); + + const widths = await jsonModel.getWidthsById(); + expect(await widths[0]).toEqual(RELATION_EXPRESSION_COLUMN_MIN_WIDTH); + expect(await widths[1]).toEqual(RELATION_EXPRESSION_COLUMN_MIN_WIDTH); + expect(await widths[2]).toEqual(RELATION_EXPRESSION_COLUMN_MIN_WIDTH); + expect(await widths[3]).toEqual(RELATION_EXPRESSION_COLUMN_MIN_WIDTH + 200); + expect(await widths[4]).toBeUndefined(); + }); }); test.describe("Function expression", () => { @@ -805,6 +865,22 @@ test.describe("Resizing", () => { expect(await params.boundingBox()).toHaveProperty("width", 153); expect(await literal.boundingBox()).toHaveProperty("width", 212); }); + + test("should assign width values to all columns when no width defined", async ({ + stories, + page, + resizing, + jsonModel, + }) => { + test.skip(true, "https://github.com/apache/incubator-kie-issues/issues/1374"); + await stories.openBoxedInvocation("monthly-installment"); + const termCell = page.getByRole("cell", { name: "Term (number)" }); + await resizing.resizeCell(termCell, { x: 0, y: 0 }, { x: 70, y: 0 }); + + const widths = await jsonModel.getWidthsById(); + expect(await widths[0]).toEqual(INVOCATION_PARAMETER_MIN_WIDTH + 70); + expect(await widths[1]).toBeUndefined(); + }); }); test.describe("List expression", () => { --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
