Skip to content
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

add tests for the node resize feature and properties panel #27

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
f2bc309
draft decisionPropertiesPanel.spec.ts
jomarko Mar 20, 2024
be3b5de
add assertions of properties panel
jomarko Mar 21, 2024
05d9db1
cover all properties
jomarko Mar 22, 2024
73a04ad
split fixtures into more files
jomarko Mar 26, 2024
8237c6b
draft resize tests
jomarko Mar 27, 2024
a444b95
test resize for all nodes
jomarko Mar 28, 2024
67293da
fix resize group tests
jomarko Mar 28, 2024
3ab3220
decisionServiceProperties -> containerNodeProperties
jomarko Mar 28, 2024
44c98b4
Add missing Group And text Annotation properties tests
jomarko Mar 28, 2024
672c372
incorporate review feedback
jomarko Apr 2, 2024
25cf3b0
remove not needed comment
jomarko Apr 2, 2024
de4c9f8
test diagram properties
jomarko Apr 3, 2024
671f90a
multiple nodes tests
jomarko Apr 3, 2024
5e4a2a7
do not select ndoe as part of panel fixture
jomarko Apr 3, 2024
e7e3354
throw error for unsupported
jomarko Apr 4, 2024
a89f90c
more resize tests
jomarko Apr 5, 2024
c571611
Update packages/dmn-editor/src/propertiesPanel/FontOptions.tsx
jomarko Apr 8, 2024
c6faf3d
fix for the new locator
jomarko Apr 8, 2024
7a85909
Update packages/dmn-editor/src/propertiesPanel/ShapeOptions.tsx
jomarko Apr 8, 2024
98603f1
fix locators
jomarko Apr 8, 2024
18bd5ba
Update packages/dmn-editor/src/propertiesPanel/ShapeOptions.tsx
jomarko Apr 8, 2024
c94c619
fix locators
jomarko Apr 8, 2024
bbb528a
move spec one level up
jomarko Apr 8, 2024
eb927b7
move spec one level up
jomarko Apr 8, 2024
9783f4d
add regenerate id namespace tests
jomarko Apr 8, 2024
a4f1168
add more resize tests - snapping
jomarko Apr 8, 2024
a523e35
color picker tests (#9)
ljmotta Apr 9, 2024
975e6a5
add fill and stroke color tests
jomarko Apr 9, 2024
8625980
resize on top of node tests
jomarko Apr 9, 2024
aaa9bbc
resize in properties panel
jomarko Apr 10, 2024
c7ed0af
cover font options
jomarko Apr 10, 2024
dadb960
last properties panel tests
jomarko Apr 10, 2024
37668ac
move diagram.resetFocus()
jomarko Apr 11, 2024
f664020
refactor to composition
jomarko Apr 11, 2024
2be3da4
use diagram for screenshots
jomarko Apr 12, 2024
8c6860b
use ... notation
jomarko Apr 12, 2024
a30a105
use ... notation 2
jomarko Apr 12, 2024
af9a679
fix ./packages/dmn-editor/tests/e2e/__screenshots__/chromium/drdArtif…
jomarko Apr 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/dmn-editor/src/diagram/nodes/Nodes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ export const InputDataNode = React.memo(
nodeType={type as typeof NODE_TYPES.inputData}
snapGrid={snapGrid}
nodeId={id}
nodeName={inputData["@_label"] ?? inputData["@_name"]}
nodeShapeIndex={shape.index}
isAlternativeInputDataShape={isAlternativeInputDataShape}
/>
Expand Down Expand Up @@ -466,6 +467,7 @@ export const DecisionNode = React.memo(
nodeType={type as typeof NODE_TYPES.decision}
snapGrid={snapGrid}
nodeId={id}
nodeName={decision["@_label"] ?? decision["@_name"] ?? ""}
nodeShapeIndex={shape.index}
/>
)}
Expand Down Expand Up @@ -604,6 +606,7 @@ export const BkmNode = React.memo(
nodeType={type as typeof NODE_TYPES.bkm}
snapGrid={snapGrid}
nodeId={id}
nodeName={bkm["@_label"] ?? bkm["@_name"] ?? ""}
nodeShapeIndex={shape.index}
/>
)}
Expand Down Expand Up @@ -730,6 +733,7 @@ export const KnowledgeSourceNode = React.memo(
nodeType={type as typeof NODE_TYPES.knowledgeSource}
snapGrid={snapGrid}
nodeId={id}
nodeName={knowledgeSource["@_label"] ?? knowledgeSource["@_name"] ?? ""}
nodeShapeIndex={shape.index}
/>
)}
Expand Down Expand Up @@ -846,6 +850,7 @@ export const TextAnnotationNode = React.memo(
nodeType={type as typeof NODE_TYPES.textAnnotation}
snapGrid={snapGrid}
nodeId={id}
nodeName={textAnnotation["@_label"] ?? textAnnotation.text?.__$$text ?? ""}
nodeShapeIndex={shape.index}
/>
)}
Expand Down Expand Up @@ -1042,6 +1047,7 @@ export const DecisionServiceNode = React.memo(
nodeType={type as typeof NODE_TYPES.decisionService}
snapGrid={snapGrid}
nodeId={id}
nodeName={decisionService["@_label"] ?? decisionService["@_name"] ?? ""}
nodeShapeIndex={shape.index}
/>
)}
Expand Down Expand Up @@ -1187,6 +1193,7 @@ export const GroupNode = React.memo(
nodeType={type as typeof NODE_TYPES.group}
snapGrid={snapGrid}
nodeId={id}
nodeName={group["@_label"] ?? group["@_name"] ?? ""}
nodeShapeIndex={shape.index}
/>
)}
Expand Down Expand Up @@ -1263,6 +1270,7 @@ export const UnknownNode = React.memo(
nodeType={type as typeof NODE_TYPES.unknown}
snapGrid={snapGrid}
nodeId={id}
nodeName={"unknown"}
nodeShapeIndex={shape.index}
/>
)}
Expand Down Expand Up @@ -1293,6 +1301,7 @@ const resizerControlStyle = {
type NodeResizeHandleProps = {
snapGrid: SnapGrid;
nodeId: string;
nodeName: string;
nodeShapeIndex: number;
} & (
| { nodeType: Extract<NodeType, typeof NODE_TYPES.inputData>; isAlternativeInputDataShape: boolean }
Expand All @@ -1312,6 +1321,7 @@ export function NodeResizerHandle(props: NodeResizeHandleProps) {
return (
<RF.NodeResizeControl style={resizerControlStyle} minWidth={minSize["@_width"]} minHeight={minSize["@_height"]}>
<div
data-testid={`${props.nodeName}-resize-handle`}
style={{
position: "absolute",
top: "-10px",
Expand Down
2 changes: 2 additions & 0 deletions packages/dmn-editor/src/overlaysPanel/OverlaysPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export function OverlaysPanel() {
</FormGroup>
<FormGroup label="Horizontal">
<Slider
data-testid={"horizontal-snapping-control"}
className={"kie-dmn-editor--snap-slider"}
isDisabled={!diagram.snapGrid.isEnabled}
value={diagram.snapGrid.x}
Expand All @@ -69,6 +70,7 @@ export function OverlaysPanel() {
</FormGroup>
<FormGroup label="Vertical">
<Slider
data-testid={"vertical-snapping-control"}
className={"kie-dmn-editor--snap-slider"}
isDisabled={!diagram.snapGrid.isEnabled}
value={diagram.snapGrid.y}
Expand Down
5 changes: 4 additions & 1 deletion packages/dmn-editor/src/propertiesPanel/ColorPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export function ColorPicker(props: {
colorPickerRef?: React.MutableRefObject<HTMLInputElement>;
icon?: React.ReactNode;
colorDisplay?: React.ReactNode;
name: string;
}) {
const inputRef = useRef<HTMLInputElement>(null);

Expand Down Expand Up @@ -56,7 +57,9 @@ export function ColorPicker(props: {
}
}
}}
aria-label={"Font color"}
name={props.name}
data-testid={`color-picker-${props.name}`}
aria-label={"Color picker"}
type={"color"}
disabled={false}
value={props.color}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export function DiagramPropertiesPanel() {

return (
<DrawerPanelContent
data-testid="properties-panel-container"
isResizable={true}
minSize={"300px"}
defaultSize={"500px"}
Expand Down
38 changes: 20 additions & 18 deletions packages/dmn-editor/src/propertiesPanel/FontOptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import { FormSection } from "@patternfly/react-core/dist/js/components/Form";
import { NumberInput } from "@patternfly/react-core/dist/js/components/NumberInput";
import { Select, SelectOption, SelectVariant } from "@patternfly/react-core/dist/js/components/Select";
import { ToggleGroup, ToggleGroupItem } from "@patternfly/react-core/dist/js/components/ToggleGroup";
import { Tooltip } from "@patternfly/react-core/dist/js/components/Tooltip";
import { PencilAltIcon } from "@patternfly/react-icons/dist/js/icons/pencil-alt-icon";
import { UndoAltIcon } from "@patternfly/react-icons/dist/js/icons/undo-alt-icon";
import * as React from "react";
Expand Down Expand Up @@ -359,11 +358,12 @@ export function FontOptions({ startExpanded, nodeIds }: { startExpanded: boolean
<ToggleGroupItem
key={FontStyleToggleOptions.FONT_COLOR}
className={"kie-dmn-editor--font-options-toggle-group-item-color-picker"}
aria-label={"Toggle font strike through"}
aria-label={"Font color"}
buttonId={FontStyleToggleOptions.FONT_COLOR}
onClick={() => colorPickerRef.current?.click()}
text={
<ColorPicker
name={"font"}
icon={<p>A</p>}
colorPickerRef={colorPickerRef}
color={fontColor}
Expand All @@ -374,22 +374,24 @@ export function FontOptions({ startExpanded, nodeIds }: { startExpanded: boolean
</ToggleGroup>
</div>
<br />
<Select
toggleRef={toggleRef}
variant={SelectVariant.single}
aria-label={"Select font style"}
isOpen={isFontFamilySelectOpen}
onSelect={onSelectFont}
onToggle={() => setFontFamilySelectOpen((prev) => !prev)}
selections={fontFamily ?? ""}
isDisabled={false}
maxHeight={inViewTimezoneSelect.maxHeight}
direction={inViewTimezoneSelect.direction}
>
{WEBSAFE_FONTS_LIST.map((fontName, index) => (
<SelectOption key={index} value={fontName} style={{ fontFamily: fontName }} />
))}
</Select>
<div data-testid="properties-panel-node-font-style">
<Select
toggleRef={toggleRef}
variant={SelectVariant.single}
aria-label={"Select font style"}
isOpen={isFontFamilySelectOpen}
onSelect={onSelectFont}
onToggle={() => setFontFamilySelectOpen((prev) => !prev)}
selections={fontFamily ?? ""}
isDisabled={false}
maxHeight={inViewTimezoneSelect.maxHeight}
direction={inViewTimezoneSelect.direction}
>
{WEBSAFE_FONTS_LIST.map((fontName, index) => (
<SelectOption key={index} value={fontName} style={{ fontFamily: fontName }} />
))}
</Select>
</div>
</div>
</FormSection>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ export function GlobalDiagramProperties() {
<FormSection style={{ paddingLeft: "20px", marginTop: 0 }}>
<FormGroup label="ID">
<ClipboardCopy
placeholder="Enter a diagram ID..."
isReadOnly={false}
hoverTip="Copy"
clickTip="Copied"
Expand All @@ -166,6 +167,7 @@ export function GlobalDiagramProperties() {

<FormGroup label="Namespace">
<ClipboardCopy
placeholder="Enter a diagram Namespace..."
isReadOnly={false}
hoverTip="Copy"
clickTip="Copied"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export function PropertiesPanelHeader(props: {
{props.expands && (
<div className={"kie-dmn-editor--properties-panel-header-toogle-expanded"}>
<Button
title={"Expand / collapse documentation link"}
title={`Expand / collapse ${props.title}`}
variant={ButtonVariant.plain}
className={"kie-dmn-editor--documentation-link--row-expand-toogle"}
onClick={() => props.toogleSectionExpanded?.()}
Expand Down
11 changes: 8 additions & 3 deletions packages/dmn-editor/src/propertiesPanel/ShapeOptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ export function ShapeOptions({
className={"kie-dmn-editor--shape-options-toggle-button"}
text={
<ColorPicker
name="shape-fill"
icon={
<div
style={{
Expand Down Expand Up @@ -305,6 +306,7 @@ export function ShapeOptions({
className={"kie-dmn-editor--shape-options-toggle-button"}
text={
<ColorPicker
name="shape-stroke"
colorDisplay={
<div
style={{
Expand Down Expand Up @@ -344,6 +346,7 @@ export function ShapeOptions({
>
<TextInput
aria-label={"Width"}
data-testid={"properties-panel-node-shape-width-input"}
type={"number"}
isDisabled={isDimensioningEnabled ? false : true}
value={isDimensioningEnabled ? boundWidth : undefined}
Expand All @@ -369,6 +372,7 @@ export function ShapeOptions({
>
<TextInput
aria-label={"Height"}
data-testid={"properties-panel-node-shape-height-input"}
type={"number"}
isDisabled={isDimensioningEnabled ? false : true}
value={isDimensioningEnabled ? boundHeight : undefined}
Expand All @@ -385,8 +389,9 @@ export function ShapeOptions({
buttonId={"shape-style-toggle-group-bound-height"}
/>
</Tooltip>
<Tooltip content={"Reset"}>
<Tooltip content={"Reset shape"}>
<ToggleGroupItem
title={"Reset shape"}
onClick={onReset}
className={"kie-dmn-editor--shape-options-toggle-button"}
text={<UndoAltIcon />}
Expand Down Expand Up @@ -417,7 +422,7 @@ export function ShapeOptions({
isDisabled={false}
value={boundPositionX}
onChange={onChangePositionX}
placeholder={"Enter a value..."}
placeholder={"Enter X value..."}
/>
</div>
<div style={{ gridArea: "position-x-label" }}>
Expand All @@ -431,7 +436,7 @@ export function ShapeOptions({
isDisabled={false}
value={boundPositionY}
onChange={onChangePositionY}
placeholder={"Enter a value..."}
placeholder={"Enter Y value..."}
/>
</div>
<div style={{ gridArea: "position-y-label" }}>
Expand Down
50 changes: 50 additions & 0 deletions packages/dmn-editor/tests/e2e/__fixtures__/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ import { Nodes } from "./nodes";
import { Editor } from "./editor";
import { Edges } from "./edges";
import { JsonModel } from "./jsonModel";
import { DecisionServicePropertiesPanel } from "./propertiesPanel/decisionServicePropertiesPanel";
import { DecisionPropertiesPanel } from "./propertiesPanel/decisionPropertiesPanel";
import { KnowledgeSourcePropertiesPanel } from "./propertiesPanel/knowledgeSourcePropertiesPanel";
import { TextAnnotationProperties as TextAnnotationPropertiesPanel } from "./propertiesPanel/textAnnotationPropertiesPanel";
import { BkmPropertiesPanel } from "./propertiesPanel/bkmPropertiesPanel";
import { InputDataPropertiesPanel } from "./propertiesPanel/inputDataPropertiesPanel";
import { GroupPropertiesPanel } from "./propertiesPanel/groupPropertiesPanel";
import { DiagramPropertiesPanel } from "./propertiesPanel/diagramPropertiesPanel";
import { MultipleNodesPropertiesPanel } from "./propertiesPanel/multipleNodesPropertiesPanel";
import { Overlays } from "./overlays";

type DmnEditorFixtures = {
diagram: Diagram;
Expand All @@ -32,6 +42,16 @@ type DmnEditorFixtures = {
jsonModel: JsonModel;
nodes: Nodes;
palette: Palette;
overlays: Overlays;
bkmPropertiesPanel: BkmPropertiesPanel;
decisionPropertiesPanel: DecisionPropertiesPanel;
decisionServicePropertiesPanel: DecisionServicePropertiesPanel;
diagramPropertiesPanel: DiagramPropertiesPanel;
groupPropertiesPanel: GroupPropertiesPanel;
inputDataPropertiesPanel: InputDataPropertiesPanel;
knowledgeSourcePropertiesPanel: KnowledgeSourcePropertiesPanel;
multipleNodesPropertiesPanel: MultipleNodesPropertiesPanel;
textAnnotationPropertiesPanel: TextAnnotationPropertiesPanel;
};

export const test = base.extend<DmnEditorFixtures>({
Expand All @@ -53,6 +73,36 @@ export const test = base.extend<DmnEditorFixtures>({
palette: async ({ page, diagram, nodes }, use) => {
await use(new Palette(page, diagram, nodes));
},
overlays: async ({ page }, use) => {
await use(new Overlays(page));
},
bkmPropertiesPanel: async ({ diagram, page }, use) => {
await use(new BkmPropertiesPanel(diagram, page));
},
decisionPropertiesPanel: async ({ diagram, page }, use) => {
await use(new DecisionPropertiesPanel(diagram, page));
},
decisionServicePropertiesPanel: async ({ diagram, page }, use) => {
await use(new DecisionServicePropertiesPanel(diagram, page));
},
diagramPropertiesPanel: async ({ diagram, page }, use) => {
await use(new DiagramPropertiesPanel(diagram, page));
},
groupPropertiesPanel: async ({ diagram, page }, use) => {
await use(new GroupPropertiesPanel(diagram, page));
},
knowledgeSourcePropertiesPanel: async ({ diagram, page }, use) => {
await use(new KnowledgeSourcePropertiesPanel(diagram, page));
},
inputDataPropertiesPanel: async ({ diagram, page }, use) => {
await use(new InputDataPropertiesPanel(diagram, page));
},
multipleNodesPropertiesPanel: async ({ diagram, page }, use) => {
await use(new MultipleNodesPropertiesPanel(diagram, page));
},
textAnnotationPropertiesPanel: async ({ diagram, page }, use) => {
await use(new TextAnnotationPropertiesPanel(diagram, page));
},
jomarko marked this conversation as resolved.
Show resolved Hide resolved
});

export { expect } from "@playwright/test";
13 changes: 12 additions & 1 deletion packages/dmn-editor/tests/e2e/__fixtures__/nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export class Nodes {
targetPosition: { x: number; y: number };
thenRenameTo?: string;
}) {
await this.hover({ name: args.from, position: NodePosition.TOP });
await this.select({ name: args.from, position: NodePosition.TOP });
const node = this.get({ name: args.from });
const { addNodeTitle, nodeName } = this.getNewConnectedNodeProperties(args.type);

Expand Down Expand Up @@ -124,6 +124,17 @@ export class Nodes {
await this.diagram.get().press("Enter");
}

public async resize(args: { nodeName: string; position?: NodePosition; xOffset: number; yOffset: number }) {
await this.select({ name: args.nodeName, position: args.position ?? NodePosition.CENTER });

const resizeHandle = this.get({ name: args.nodeName }).getByTestId(`${args.nodeName}-resize-handle`);
const { x, y, width, height } = (await resizeHandle.boundingBox()) ?? { x: 0, y: 0, width: 0, height: 0 };
await this.page.mouse.move(x + width / 2, y + height / 2);
await this.page.mouse.down();
await this.page.mouse.move(x + args.xOffset + width / 2, y + args.yOffset + height / 2);
await this.page.mouse.up();
}
Comment on lines +127 to +136
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I am interested in general opinion regarding fixtures. How much we should group/wrap the logic into particular methods.

Here we have resize method with parameters:

  • nodeName
  • position
  • xOffset
  • yOffset

Where I admit position is kind of surprising in context of resizing node. It is there because every resize call needs to precessed with select where the postion is used.

So it is question, should we refactor eah test, that uses resize to be changed:

//...
nodes.select();
nodes.resize();
//...

it is hard for me to decide as both select and resize are from the same fixture nodes.

for example in the properties panel fixtures we do not include select into properties panel fixture implementation. So every time test developer needs to interact with properties panel, the test code looks like:

nodes.select(); // select proper node to have proper content in prop. panel
propertiesPanel.doSomethingThere()


public async select(args: { name: string; position?: NodePosition }) {
const node = this.get({ name: args.name });

Expand Down
Loading
Loading