apache / incubator-kie-issues

Apache License 2.0
12 stars 1 forks source link

Create E2E tests API and some test cases for the DMN Boxed Expression Editor #1369

Closed danielzhe closed 3 months ago

danielzhe commented 4 months ago

The problem: In DMN Boxed Expression Editor, we are using Playwright to write E2E tests, which can be a bit verbose and hard to write new tests with a lot of copy-paste of code.

For example, consider the code below to add a new entry in the Context Expression:

    await this.locator.getByRole("cell", { name: "ContextEntry-1 (<Undefined>)" }).nth(0).hover();
    await this.locator.getByRole("cell", { name: "ContextEntry-1 (<Undefined>)" }).nth(0).locator("svg").click();

Also, consider that in the example above we can change the name of the Context, so the example will not work without changing the ContextEntry-1 to the new name.

This can become very tricky and annoying in more complex scenarios.

The solution:

We need an API to encapsulate the Playwright details and make it easier and clearer to perform tests in BEE.

The API should follow the fluent pattern, with the current BEE editor being the entry point.

The entry point should be a Playwright's fixture.

Some API examples:

// Select the Decision Table in an empty Boxed Expression Editor
await bee.selectExpressionMenu.selectDecisionTable();

// Adds an output column at the start (the rightmost)
await bee.expression.asDecisionTable().addOutputAtStart();

// Adds a row in the decision table
await bee.expression.asDecisionTable().addRow();

// Fills the cell at row 2 column 1 with the text "this is my text"
await bee.expression.asDecisionTable().cellAt({ row: 2, column: 1 }).fill("this is my text"); 

On-screen Result: image

// Select the Context in an empty Boxed Expression Editor
await bee.selectExpressionMenu.selectContext();

// In the "Select Expression Menu" of the first entry, select Context to add a new nested context
await bee.expression.asContext().entry(0).selectExpressionMenu.selectContext();

// In the firs entry of the nested Context in the first entry of the top-level Context, select Literal
await bee.expression.asContext().entry(0).expression.asContext().entry(0).selectExpressionMenu.selectLiteral()

On-screen Result: image

Tests:

We must cover the common and basic functionalities for every expression in the BEE. Here is a list of the tests that should cover those features:

1. TO ALL EXPRESSIONS:

  1. Copy, Paste, Cut:
    • [x] a. Copy and Past top-level expression
    • [x] b. Cut and Past top-level expressions

2. SPECIFIC TESTS

1. Literal

2. Relation

3. Context

4. Decision Table

5. List

6. Invocation

7. Conditional

8. For

9. Every

10. Some

11. Filter

3. TO EXPRESSION WITH NESTED EXPRESSIONS Need some more complex tests to mix expressions that allow nested expressions (Filter, Some, Every, For, Conditional, List, Context and Invocation)

danielzhe commented 4 months ago

Draft PR: https://github.com/apache/incubator-kie-tools/pull/2456

This may be interest @jomarko too.

@tiagobento @ljmotta