-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
introduce invalid[Edge].spec.ts #24
introduce invalid[Edge].spec.ts #24
Conversation
packages/dmn-editor/tests/e2e/drgRequirements/invalidAuthorityRequirement.spec.ts
Outdated
Show resolved
Hide resolved
test("shouldn't add an Information Requirement edge from Input Data node to BKM node", async ({ | ||
palette, | ||
edges, | ||
nodes, | ||
}) => { | ||
await palette.dragNewNode({ | ||
type: NodeType.BKM, | ||
targetPosition: { x: 300, y: 100 }, | ||
}); | ||
|
||
await nodes.dragNewConnectedEdge({ | ||
type: EdgeType.INFORMATION_REQUIREMENT, | ||
from: "Source Node", | ||
to: DefaultNodeName.BKM, | ||
}); | ||
|
||
expect(await edges.get({ from: "Source Node", to: DefaultNodeName.BKM })).not.toBeAttached(); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I put the comment here, but it is general for all tests. Currently, each test checks only the DOM structural changes.
However, we could also check the visual effect. Once the user starts to drag edge, non-valid node targets are dimmed. We can say disabled. however, in code, the change is represented only by the change in the css class. If I am correct, we want to avoid using similar internal changes, non-visible for users for writing tests. So I am not sure if we should test also this visual effect or not, please share your opinion.
Please, notice the div class
in the highlighted html source code row.
Non dimmed nodes
Dimmed nodes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, here is some update after my investigation, similar visual dim effect test would be possible, it would look like
test.only("should dim the target Input Data node", async ({
page,
palette,
nodes,
}) => {
await palette.dragNewNode({
type: NodeType.BKM,
targetPosition: { x: 300, y: 100 },
});
// lines below could be refactored to single fixture method, e.g. `nodes.startDraggingEdge(from, edgeType)`
await nodes.select({ name: "Source Node", position: NodePosition.TOP });
await nodes.get({ name: "Source Node" }).getByTitle("Add Information Requirement edge").hover();
await page.mouse.down();
await expect(nodes.get({ name: DefaultNodeName.BKM })).toHaveClass(/.*dimmed/);
});
however, was not able to get this working without actual class
check, below I put my attempts, that didn't work:
await expect(nodes.get({ name: DefaultNodeName.BKM })).toBeDisabled()
await expect(nodes.get({ name: DefaultNodeName.BKM })).not.toBeEditable()
one more problem is the dim
implementation, for some nodes we add dimmed
class to existing div
:
however for other nodes we add new nested div
with dimmed
class
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, I think we could select the node with the this.get()
before using the locator(".dimmed")
. And I'm not sure if the toBeAttached()
is the best option here., we have a toHaveClass
assertion, making it unnecessary to add a new assertion method.
34b45f8
to
e75b167
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see my comments inline
@@ -53,6 +53,10 @@ export enum NodePosition { | |||
export class Nodes { | |||
constructor(public page: Page, public diagram: Diagram, public browserName: string) {} | |||
|
|||
public async asserrtIsDimmed(args: { name: string }) { | |||
await expect(this.page.locator(".dimmed").locator("span:has-text('" + args.name + "')")).toBeAttached(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this locator was done by me after reading the documentation https://playwright.dev/docs/other-locators#css-matching-by-text
we need to match:
- elements with
dimmed
class, however, we do not know exactly what level of the node structure contain this class - firstlocator
- however we know, inside
dimmed
there is a text containing node name - secondlocator
public async asserrtIsDimmed(args: { name: string }) { | ||
await expect(this.page.locator(".dimmed").locator("span:has-text('" + args.name + "')")).toBeAttached(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The correct way to add custom expect is to extend the expect
object. You can read more about it here: https://playwright.dev/docs/test-assertions#add-custom-matchers-using-expectextend
Also we have a typo on the method name.
@@ -219,4 +220,17 @@ export class Nodes { | |||
return { x: toBoundingBox.width / 2, y: 10 }; | |||
} | |||
} | |||
|
|||
private getAddTitle(edgeType: EdgeType) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we read only the method name we can't say for sure what is getting. Maybe getAddEdgeTitle
will give us a better understand of what is happening? WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, totally agree, getAddEdgeTitle
brings better clarity of the code, pushing now!
}); | ||
|
||
test.describe("Invalid edge - Authority Requirement", () => { | ||
test.describe("Knowledge Source", () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Forgot to change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, thank you for spotting
test("shouldn't add an Information Requirement edge from Input Data node to BKM node", async ({ | ||
palette, | ||
edges, | ||
nodes, | ||
}) => { | ||
await palette.dragNewNode({ | ||
type: NodeType.BKM, | ||
targetPosition: { x: 300, y: 100 }, | ||
}); | ||
|
||
await nodes.dragNewConnectedEdge({ | ||
type: EdgeType.INFORMATION_REQUIREMENT, | ||
from: "Source Node", | ||
to: DefaultNodeName.BKM, | ||
}); | ||
|
||
expect(await edges.get({ from: "Source Node", to: DefaultNodeName.BKM })).not.toBeAttached(); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, I think we could select the node with the this.get()
before using the locator(".dimmed")
. And I'm not sure if the toBeAttached()
is the best option here., we have a toHaveClass
assertion, making it unnecessary to add a new assertion method.
@@ -239,7 +239,7 @@ export const InputDataNode = React.memo( | |||
onDoubleClick={triggerEditing} | |||
onKeyDown={triggerEditingIfEnter} | |||
style={alternativeSvgStyle} | |||
className={`kie-dmn-editor--input-data-node ${selectedAlternativeClass}`} | |||
className={`kie-dmn-editor--input-data-node ${additionalClasses} ${selectedAlternativeClass}`} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With this change we have code:
<div
onDoubleClick={triggerEditing}
onKeyDown={triggerEditingIfEnter}
style={alternativeSvgStyle}
className={`kie-dmn-editor--input-data-node ${additionalClasses} ${selectedAlternativeClass}`}
ref={ref}
tabIndex={-1}
data-nodehref={id}
data-nodelabel={inputData["@_name"]}
>
{/* {`render count: ${renderCount.current}`}
<br /> */}
<div className={`kie-dmn-editor--node ${additionalClasses}`}>
<InfoNodePanel isVisible={!isTargeted && shouldActLikeHovered} />
....
I know we have currently twice ${additionalClasses}
used, I thought it could be enough to keep ${additionalClasses}
only in the top level div
, however in such scenario, node is disabled, user can not add connection to it, however the text is not 'dimmed', see the screenshot below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is the correct approach, we're adding the additionalClasses
just to select the desired div without any real change on the editor. To make this change, we need to remove the other. Taking a look into the DmnEditor.css
file I could see why removing the class broke the opacity. The css class was declared as .kie-dmn-editor--node.dimmed
. What we could do, is to create a new .kie-dmn-editor--input-data-node.dimmed
with the same properties.
It's important to test those changes with the alternative visualization too. To change to the alternative, click on the DRD name, and select the "Alternative" option.
@@ -239,7 +239,7 @@ export const InputDataNode = React.memo( | |||
onDoubleClick={triggerEditing} | |||
onKeyDown={triggerEditingIfEnter} | |||
style={alternativeSvgStyle} | |||
className={`kie-dmn-editor--input-data-node ${selectedAlternativeClass}`} | |||
className={`kie-dmn-editor--input-data-node ${additionalClasses} ${selectedAlternativeClass}`} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is the correct approach, we're adding the additionalClasses
just to select the desired div without any real change on the editor. To make this change, we need to remove the other. Taking a look into the DmnEditor.css
file I could see why removing the class broke the opacity. The css class was declared as .kie-dmn-editor--node.dimmed
. What we could do, is to create a new .kie-dmn-editor--input-data-node.dimmed
with the same properties.
It's important to test those changes with the alternative visualization too. To change to the alternative, click on the DRD name, and select the "Alternative" option.
|
||
await nodes.startDraggingEdge({ from: "Source Node", edgeType: EdgeType.AUTHORITY_REQUIREMENT }); | ||
|
||
await expect(nodes.get({ name: DefaultNodeName.INPUT_DATA })).toHaveClass(/.*dimmed/); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any particular reason to use RegExp over a string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, toHaveClass
compares for equality, so we would need to have toHaveClass("kie-dmn-editor--input-data-node dimmed")
ff23ad6
into
ljmotta:kie-issues-946-part-3-main
No description provided.