jomarko commented on code in PR #3624:
URL:
https://github.com/apache/incubator-kie-tools/pull/3624#discussion_r3400720121
##########
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:
could you please explain more `sendTask` and `receiveTask` I do not think we
have such tasks in palette
##########
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") ?? [];
+ }
+
+ public async getBusinessRuleTasks(flowElements?: FlowElements) {
+ const elements = flowElements ?? (await this.getProcess())?.flowElement;
+ return elements?.filter((e) => e.__$$element === "businessRuleTask") ?? [];
+ }
+
+ // Activities
+ public async getCallActivities(flowElements?: FlowElements) {
+ const elements = flowElements ?? (await this.getProcess())?.flowElement;
+ return elements?.filter((e) => e.__$$element === "callActivity") ?? [];
+ }
+
+ public async getSubProcesses(flowElements?: FlowElements) {
+ const elements = flowElements ?? (await this.getProcess())?.flowElement;
+ return elements?.filter((e) => e.__$$element === "subProcess") ?? [];
+ }
+
+ public async getAdHocSubProcesses(flowElements?: FlowElements) {
+ const elements = flowElements ?? (await this.getProcess())?.flowElement;
+ return elements?.filter((e) => e.__$$element === "adHocSubProcess") ?? [];
+ }
+
+ public async getTransactions(flowElements?: FlowElements) {
+ const elements = flowElements ?? (await this.getProcess())?.flowElement;
+ return elements?.filter((e) => e.__$$element === "transaction") ?? [];
+ }
+
+ // Data
+ public async getDataObjects(flowElements?: FlowElements) {
+ const elements = flowElements ?? (await this.getProcess())?.flowElement;
+ return elements?.filter((e) => e.__$$element === "dataObject") ?? [];
+ }
+
+ public async getDataObjectReferences(flowElements?: FlowElements) {
+ const elements = flowElements ?? (await this.getProcess())?.flowElement;
+ return elements?.filter((e) => e.__$$element === "dataObjectReference") ??
[];
+ }
+
+ public async getDataStoreReferences(flowElements?: FlowElements) {
+ const elements = flowElements ?? (await this.getProcess())?.flowElement;
+ return elements?.filter((e) => e.__$$element === "dataStoreReference") ??
[];
+ }
+
+ // Flows
+ public async getSequenceFlows(flowElements?: FlowElements) {
+ const elements = flowElements ?? (await this.getProcess())?.flowElement;
+ return elements?.filter((e) => e.__$$element === "sequenceFlow") ?? [];
+ }
+
+ // Choreography
+ public async getCallChoreographies(flowElements?: FlowElements) {
+ const elements = flowElements ?? (await this.getProcess())?.flowElement;
+ return elements?.filter((e) => e.__$$element === "callChoreography") ?? [];
+ }
+
+ public async getChoreographyTasks(flowElements?: FlowElements) {
+ const elements = flowElements ?? (await this.getProcess())?.flowElement;
+ return elements?.filter((e) => e.__$$element === "choreographyTask") ?? [];
+ }
+
+ public async getSubChoreographies(flowElements?: FlowElements) {
+ const elements = flowElements ?? (await this.getProcess())?.flowElement;
+ return elements?.filter((e) => e.__$$element === "subChoreography") ?? [];
+ }
Review Comment:
similar question as above
##########
packages/bpmn-editor/tests-e2e/flowElements/addSubProcess.spec.ts:
##########
@@ -253,9 +254,68 @@ test.describe("Add node - Sub-process", () => {
await expect(nodes.get({ name: "Order Processing" })).toBeAttached();
- const subProcess = await jsonModel.getFlowElement({ elementIndex: 0 });
+ const subProcess = (await jsonModel.getSubProcesses())[0];
+ expect(subProcess?.__$$element).toBe("subProcess");
+ expect(subProcess?.["@_name"]).toBe("Order Processing");
+ });
+ });
+
+ test.describe("Sub-process default properties", () => {
+ test(`should check sub-process default properties`, async ({ palette,
nodes, jsonModel }) => {
+ await palette.dragNewNode({ type: NodeType.SUB_PROCESS, targetPosition:
{ x: 100, y: 300 } });
+ await expect(nodes.get({ name: DefaultNodeName.SUB_PROCESS
})).toBeAttached();
+
+ const subProcess = (await jsonModel.getSubProcesses())[0];
+ expect(subProcess.__$$element).toBe("subProcess");
+ expect(subProcess["@_name"]).toBe(DefaultNodeName.SUB_PROCESS);
+ expect(subProcess["@_triggeredByEvent"]).toBe(false);
+
expect(subProcess.extensionElements?.["drools:metaData"]?.length).toBe(1);
+
expect(subProcess.extensionElements?.["drools:metaData"]?.[0]["@_name"]).toBe("customAsync");
+ });
+
+ test(`should check event sub-process default properties`, async ({
palette, nodes, jsonModel }) => {
+ await palette.dragNewNode({ type: NodeType.SUB_PROCESS, targetPosition:
{ x: 100, y: 300 } });
+ await nodes.morph({ node: nodes.get({ name: DefaultNodeName.SUB_PROCESS
}), to: SubProcessNodeType.EVENT });
+ await expect(nodes.get({ name: DefaultNodeName.SUB_PROCESS
})).toBeAttached();
+
+ const subProcess = (await jsonModel.getSubProcesses())[0];
expect(subProcess.__$$element).toBe("subProcess");
- expect(subProcess["@_name"]).toBe("Order Processing");
+ expect(subProcess["@_name"]).toBe(DefaultNodeName.SUB_PROCESS);
+ expect(subProcess["@_triggeredByEvent"]).toBe(true);
+
expect(subProcess.extensionElements?.["drools:metaData"]?.length).toBe(1);
+
expect(subProcess.extensionElements?.["drools:metaData"]?.[0]["@_name"]).toBe("customAsync");
Review Comment:
`addSubProcecess.spec.ts` adds multiple tests - that is perfect. My question
is if we want to be consistent as in test of user tasks? If yes, I think we
should do similar check as we have there:
```
expect(userTask.extensionElements?.["drools:metaData"]?.[0]?.["drools:metaValue"].__$$text).toBe("false");
```
so in this file we currently check only the presence of `customAsync`, but
we do not inspect actual value.
--
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]