ljmotta commented on code in PR #3624:
URL:
https://github.com/apache/incubator-kie-tools/pull/3624#discussion_r3402274139
##########
packages/bpmn-editor/tests-e2e/__fixtures__/jsonModel.ts:
##########
@@ -18,52 +18,234 @@
*/
import { Page } from "@playwright/test";
+import { BpmnLatestModel } from "@kie-tools/bpmn-marshaller";
+import { Normalized } from
"@kie-tools/bpmn-editor/dist/normalization/normalize";
+import "@kie-tools/bpmn-marshaller/dist/drools-extension";
+import { BPMN20__tProcess } from
"@kie-tools/bpmn-marshaller/dist/schemas/bpmn-2_0/ts-gen/types";
+export type FlowElements = BPMN20__tProcess["flowElement"];
+export type ArtifactElements = BPMN20__tProcess["artifact"];
export class JsonModel {
constructor(
public page: Page,
public baseURL?: string
) {}
- public async getModel(): Promise<any> {
+ public async getModel(): Promise<Normalized<BpmnLatestModel>> {
const modelElement = this.page.getByTestId("storybook--bpmn-editor-model");
const modelText = await modelElement.textContent();
- return modelText ? JSON.parse(modelText) : undefined;
+ try {
+ if (modelText === null) {
+ throw new Error("BPMN Editor - jsonModel - couldn't get modelText");
+ }
+ return JSON.parse(modelText);
+ } catch (error: any) {
+ // Just throw the error
+ throw new Error(error);
+ }
}
- public async getDefinitions(): Promise<any> {
- const model = await this.getModel();
- return model?.definitions;
+ public async getDefinitions() {
+ return (await this.getModel()).definitions;
}
- public async getProcess(processIndex: number = 0): Promise<any> {
- const definitions = await this.getDefinitions();
- const processes = definitions?.rootElement || definitions?.process;
- return Array.isArray(processes) ? processes[processIndex] : processes;
+ public async getProcess() {
+ return (await this.getDefinitions()).rootElement?.find((e) =>
e.__$$element === "process");
}
- public async getFlowElement(args: { processIndex?: number; elementIndex:
number }): Promise<any> {
- const process = await this.getProcess(args.processIndex ?? 0);
- return process?.flowElement?.[args.elementIndex];
+ // Events
+ public async getEvents(flowElements?: FlowElements) {
+ const elements = flowElements ?? (await this.getProcess())?.flowElement;
+ return elements?.filter((e) => e.__$$element === "event") ?? [];
}
- public async getDiagram(diagramIndex: number = 0): Promise<any> {
- const definitions = await this.getDefinitions();
- return definitions?.["bpmndi:BPMNDiagram"]?.[diagramIndex];
+ public async getStartEvents(flowElements?: FlowElements) {
+ const elements = flowElements ?? (await this.getProcess())?.flowElement;
+ return elements?.filter((e) => e.__$$element === "startEvent") ?? [];
}
- public async getPlane(diagramIndex: number = 0): Promise<any> {
- const diagram = await this.getDiagram(diagramIndex);
- return diagram?.["bpmndi:BPMNPlane"];
+ public async getEndEvents(flowElements?: FlowElements) {
+ const elements = flowElements ?? (await this.getProcess())?.flowElement;
+ return elements?.filter((e) => e.__$$element === "endEvent") ?? [];
}
- public async getShape(args: { diagramIndex?: number; shapeIndex: number }):
Promise<any> {
- const plane = await this.getPlane(args.diagramIndex ?? 0);
- return plane?.["di:DiagramElement"]?.[args.shapeIndex];
+ public async getIntermediateThrowEvents(flowElements?: FlowElements) {
+ const elements = flowElements ?? (await this.getProcess())?.flowElement;
+ return elements?.filter((e) => e.__$$element === "intermediateThrowEvent")
?? [];
}
- public async getBounds(args: { diagramIndex?: number; shapeIndex: number }):
Promise<any> {
+ public async getIntermediateCatchEvents(flowElements?: FlowElements) {
+ const elements = flowElements ?? (await this.getProcess())?.flowElement;
+ return elements?.filter((e) => e.__$$element === "intermediateCatchEvent")
?? [];
+ }
+
+ public async getBoundaryEvents(flowElements?: FlowElements) {
+ const elements = flowElements ?? (await this.getProcess())?.flowElement;
+ return elements?.filter((e) => e.__$$element === "boundaryEvent") ?? [];
+ }
+
+ public async getImplicitThrowEvents(flowElements?: FlowElements) {
+ const elements = flowElements ?? (await this.getProcess())?.flowElement;
+ return elements?.filter((e) => e.__$$element === "implicitThrowEvent") ??
[];
+ }
+
+ // Gateways
+ public async getExclusiveGateways(flowElements?: FlowElements) {
+ const elements = flowElements ?? (await this.getProcess())?.flowElement;
+ return elements?.filter((e) => e.__$$element === "exclusiveGateway") ?? [];
+ }
+
+ public async getInclusiveGateways(flowElements?: FlowElements) {
+ const elements = flowElements ?? (await this.getProcess())?.flowElement;
+ return elements?.filter((e) => e.__$$element === "inclusiveGateway") ?? [];
+ }
+
+ public async getParallelGateways(flowElements?: FlowElements) {
+ const elements = flowElements ?? (await this.getProcess())?.flowElement;
+ return elements?.filter((e) => e.__$$element === "parallelGateway") ?? [];
+ }
+
+ public async getEventBasedGateways(flowElements?: FlowElements) {
+ const elements = flowElements ?? (await this.getProcess())?.flowElement;
+ return elements?.filter((e) => e.__$$element === "eventBasedGateway") ??
[];
+ }
+
+ public async getComplexGateways(flowElements?: FlowElements) {
+ const elements = flowElements ?? (await this.getProcess())?.flowElement;
+ return elements?.filter((e) => e.__$$element === "complexGateway") ?? [];
+ }
+
+ // Tasks
+ public async getTasks(flowElements?: FlowElements) {
+ const elements = flowElements ?? (await this.getProcess())?.flowElement;
+ return elements?.filter((e) => e.__$$element === "task") ?? [];
+ }
+
+ public async getScriptTasks(flowElements?: FlowElements) {
+ const elements = flowElements ?? (await this.getProcess())?.flowElement;
+ return elements?.filter((e) => e.__$$element === "scriptTask") ?? [];
+ }
+
+ public async getUserTasks(flowElements?: FlowElements) {
+ const elements = flowElements ?? (await this.getProcess())?.flowElement;
+ return elements?.filter((e) => e.__$$element === "userTask") ?? [];
+ }
+
+ public async getManualTasks(flowElements?: FlowElements) {
+ const elements = flowElements ?? (await this.getProcess())?.flowElement;
+ return elements?.filter((e) => e.__$$element === "manualTask") ?? [];
+ }
+
+ public async getServiceTasks(flowElements?: FlowElements) {
+ const elements = flowElements ?? (await this.getProcess())?.flowElement;
+ return elements?.filter((e) => e.__$$element === "serviceTask") ?? [];
+ }
+
+ public async getSendTasks(flowElements?: FlowElements) {
+ const elements = flowElements ?? (await this.getProcess())?.flowElement;
+ return elements?.filter((e) => e.__$$element === "sendTask") ?? [];
+ }
+
+ public async getReceiveTasks(flowElements?: FlowElements) {
+ const elements = flowElements ?? (await this.getProcess())?.flowElement;
+ return elements?.filter((e) => e.__$$element === "receiveTask") ?? [];
+ }
Review Comment:
I've added an exhaustive list based on the `flowElement` types available in
the `bpmn-marshaller`, even though we don't currently expose all of them in the
palette or implement them. This keeps us aligned with the BPMN model and allows
for future extensibility.
--
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]