Hi,
I'm using an automated tool to perform testing of our diagrams and am coding some Javascript within the tool.
I want to simulate the user clicking on a node which should cause the selectionChangeHandler event to fire.
I was hoping that diagram.addSelection(node1); would do the job, but it does not seem to work.
Here's my complete code:
var ports = [
{ name: "in", offset: { x: 0, y: 0.5 }, shape: "square", fillColor: "green" },
{ name: "out", offset: { x: 1, y: 0.5 }, shape: "square", fillColor: "green" }
];
var connectors = [{
name: "flow1",
sourceNode: "node1",
targetNode: "node2",
sourcePort: "out",
targetPort: "in"
}];
var addInfo = { NodeType: "Task", TaskType: "Task" };
var node1 = {
name: "node1", width: 120, height: 60,
offsetX: 100, offsetY: 100,
fillColor: "white", borderWidth: 1,
labels: [{ text: "Submit RFC" }],
addInfo: addInfo, ports: ports
};
var node2 = {
name: "node2", width: 120, height: 60,
offsetX: 325, offsetY: 100,
fillColor: "white", borderWidth: 1,
labels: [{ text: "Approve RFC" }],
addInfo: addInfo, ports: ports
};
var nodes = [node1, node2];
// Add nodes and connectors to the Diagram
diagram.add(nodes);
diagram.add(connectors);
diagram.clearSelection();
diagram.addSelection(node1);
diagram.nudge("down", 300);
console.log('diagram.model.selectedItems.children.length = ' + diagram.model.selectedItems.children.length);
The nodes and the connector are drawn correctly, but the nudge does not work and the selectedItems.children.length shows as zero!
Any suggestions for what I need to do to simulate a user selection in code?
Thanks
Jim