ljmotta commented on code in PR #2189: URL: https://github.com/apache/incubator-kie-tools/pull/2189#discussion_r1511180658
########## packages/dmn-editor/tests/e2e/__fixtures__/nodes.ts: ########## @@ -0,0 +1,237 @@ +/* + * 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 { Locator, Page } from "@playwright/test"; +import { Diagram } from "./diagram"; +import { EdgeType } from "./edges"; + +export enum NodeType { + INPUT_DATA, + DECISION, + KNOWLEDGE_SOURCE, + BKM, + DECISION_SERVICE, + GROUP, + TEXT_ANNOTATION, +} + +export enum DefaultNodeName { + INPUT_DATA = "New Input Data", + DECISION = "New Decision", + KNOWLEDGE_SOURCE = "New Knowledge Source", + BKM = "New BKM", + DECISION_SERVICE = "New Decision Service", + GROUP = "New group", + TEXT_ANNOTATION = "New text annotation", +} + +export enum NodePosition { + BOTTOM, + CENTER, + LEFT, + RIGHT, + TOP, + TOP_PADDING, +} + +export class Nodes { + constructor(public page: Page, public diagram: Diagram, public browserName: string) {} + + public get(args: { name: string }) { + return this.page.locator(`div[data-nodelabel="${args.name}"]`); + } + + public async getId(args: { name: string }): Promise<string> { + return (await this.get({ name: args.name }).getAttribute("data-nodehref")) ?? ""; + } + + public async delete(args: { name: string }) { + await this.select({ name: args.name, position: NodePosition.TOP_PADDING }); + await this.diagram.get().press("Delete"); + } + + public async deleteMultiple(args: { names: string[] }) { + await this.selectMultiple({ names: args.names, position: NodePosition.TOP_PADDING }); + await this.diagram.get().press("Delete"); + } + + public async rename(args: { current: string; new: string }) { + await this.get({ name: args.current }).getByRole("textbox").nth(0).fill(args.new); + await this.diagram.get().press("Enter"); + } + + public async dragNewConnectedNode(args: { + type: NodeType; + from: string; + targetPosition: { x: number; y: number }; + thenRenameTo?: string; + }) { + await this.hover({ name: args.from, position: NodePosition.TOP }); + const node = this.get({ name: args.from }); + + switch (args.type) { + case NodeType.INPUT_DATA: + await node + .getByTitle("Add Input Data node") + .dragTo(this.diagram.get(), { targetPosition: args.targetPosition }); + await this.waitForNodeToBeFocused({ name: DefaultNodeName.INPUT_DATA }); + if (args.thenRenameTo) { + await this.rename({ current: DefaultNodeName.INPUT_DATA, new: args.thenRenameTo }); + } + break; + case NodeType.DECISION: + await node.getByTitle("Add Decision node").dragTo(this.diagram.get(), { targetPosition: args.targetPosition }); + await this.waitForNodeToBeFocused({ name: DefaultNodeName.DECISION }); + if (args.thenRenameTo) { + await this.rename({ current: DefaultNodeName.DECISION, new: args.thenRenameTo }); + } + break; + case NodeType.KNOWLEDGE_SOURCE: + await node + .getByTitle("Add Knowledge Source node") + .dragTo(this.diagram.get(), { targetPosition: args.targetPosition }); + await this.waitForNodeToBeFocused({ name: DefaultNodeName.KNOWLEDGE_SOURCE }); + if (args.thenRenameTo) { + await this.rename({ current: DefaultNodeName.KNOWLEDGE_SOURCE, new: args.thenRenameTo }); + } + break; + case NodeType.BKM: + await node.getByTitle("Add BKM node").dragTo(this.diagram.get(), { targetPosition: args.targetPosition }); + await this.waitForNodeToBeFocused({ name: DefaultNodeName.BKM }); + if (args.thenRenameTo) { + await this.rename({ current: DefaultNodeName.BKM, new: args.thenRenameTo }); + } + break; + case NodeType.TEXT_ANNOTATION: + await node + .getByTitle("Add Text Annotation node") + .dragTo(this.diagram.get(), { targetPosition: args.targetPosition }); + await this.waitForNodeToBeFocused({ name: DefaultNodeName.TEXT_ANNOTATION }); + if (args.thenRenameTo) { + await this.rename({ current: DefaultNodeName.TEXT_ANNOTATION, new: args.thenRenameTo }); + } + } Review Comment: We can shorten this method, but I don't think this approach is the ideal one, as creating mutable variables isn't very friendly. We can create a private method where we return the `{ nodeTitle, nodeName }` on the `case` statement. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
