Skip to content

Commit

Permalink
chore(deps): update Cypress (#1709)
Browse files Browse the repository at this point in the history
* chore(deps): update Cypress

* style: reformat

Co-authored-by: Vis Bot <[email protected]>
  • Loading branch information
Thomaash and vis-bot authored Mar 11, 2022
1 parent aa38a61 commit 73fea1f
Show file tree
Hide file tree
Showing 23 changed files with 6,900 additions and 6,867 deletions.
71 changes: 42 additions & 29 deletions cypress/integration/functional/directed-hierarchical-layout.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,17 +166,23 @@ describe("Directed hierarchical layout", (): void => {
const configs = [
{ nodes: [], swallowsEdges: 0 },
...(clusterConfigs || []),
].map(({ nodes }, i, arr): {
expectedVisibleEdges: number;
nodesToCluster: Set<IdType>;
} => ({
expectedVisibleEdges:
data.edges.length -
].map(
(
{ nodes },
i,
arr
.slice(0, i + 1)
.reduce((acc, { swallowsEdges }): number => acc + swallowsEdges, 0),
nodesToCluster: new Set(nodes),
}));
): {
expectedVisibleEdges: number;
nodesToCluster: Set<IdType>;
} => ({
expectedVisibleEdges:
data.edges.length -
arr
.slice(0, i + 1)
.reduce((acc, { swallowsEdges }): number => acc + swallowsEdges, 0),
nodesToCluster: new Set(nodes),
})
);

describe(name, (): void => {
it("Preparation", (): void => {
Expand Down Expand Up @@ -244,32 +250,39 @@ describe("Directed hierarchical layout", (): void => {
* assertions are indeed necessary.
*/
const visibleEdges = Object.values(
((network as unknown) as {
body: {
edges: {
fromId: string;
toId: string;
}[];
};
}).body.edges
(
network as unknown as {
body: {
edges: {
fromId: string;
toId: string;
}[];
};
}
).body.edges
).filter(
(edge): boolean =>
visibleNodeIds.has(edge.fromId) &&
visibleNodeIds.has(edge.toId)
);

const invalidEdges = visibleEdges
.map(({ fromId, toId }): {
fromId: IdType;
fromPosition: Point;
toId: IdType;
toPosition: Point;
} => ({
fromId,
fromPosition: network.getPositions([fromId])[fromId],
toId,
toPosition: network.getPositions([toId])[toId],
}))
.map(
({
fromId,
toId,
}): {
fromId: IdType;
fromPosition: Point;
toId: IdType;
toPosition: Point;
} => ({
fromId,
fromPosition: network.getPositions([fromId])[fromId],
toId,
toPosition: network.getPositions([toId])[toId],
})
)
.filter(({ fromPosition, toPosition }): boolean => {
return !(fromPosition.y < toPosition.y);
});
Expand Down
8 changes: 5 additions & 3 deletions cypress/integration/functional/drags.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ function drag(
): { name: string; event: VisEvent }[] {
const events: { name: string; event: VisEvent }[] = [];

const eventListener = (name: string) => (event: VisEvent): void => {
events.push({ name, event });
};
const eventListener =
(name: string) =>
(event: VisEvent): void => {
events.push({ name, event });
};

cy.visRunWithWindow(({ network }): void => {
network.on("dragStart", eventListener("dragStart"));
Expand Down
18 changes: 8 additions & 10 deletions cypress/integration/helpers/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,14 @@ export function createGridPoints(
const offset = (size * ((perRowOrCol - 1) / perRowOrCol)) / 2;

return Object.freeze<Point[]>(
new Array(amount).fill(null).map(
(_, i): Point => {
const col = Math.floor(i / perRowOrCol);
const row = i - col * perRowOrCol;
new Array(amount).fill(null).map((_, i): Point => {
const col = Math.floor(i / perRowOrCol);
const row = i - col * perRowOrCol;

return Object.freeze<Point>({
x: (row / perRowOrCol) * size - offset,
y: (col / perRowOrCol) * size - offset,
});
}
)
return Object.freeze<Point>({
x: (row / perRowOrCol) * size - offset,
y: (col / perRowOrCol) * size - offset,
});
})
);
}
86 changes: 45 additions & 41 deletions cypress/pages/standard-cytest-script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,15 @@ type VisUtil = typeof visUtil;
updateSelectionJSON();

// Selection events:
([
"deselectEdge",
"deselectNode",
"select",
"selectEdge",
"selectNode",
] as const).forEach((eventName): void => {
(
[
"deselectEdge",
"deselectNode",
"select",
"selectEdge",
"selectNode",
] as const
).forEach((eventName): void => {
network.on(eventName, updateSelectionJSON);

network.on(eventName, (): void => {
Expand Down Expand Up @@ -239,40 +241,42 @@ type VisUtil = typeof visUtil;

// Event queue:
const eventQueue: VisWindow["visEventQueue"] = {} as any;
([
"afterDrawing",
"animationFinished",
"beforeDrawing",
"blurEdge",
"blurNode",
"click",
"configChange",
"controlNodeDragEnd",
"controlNodeDragging",
"deselectEdge",
"deselectNode",
"doubleClick",
"dragEnd",
"dragStart",
"dragging",
"hidePopup",
"hold",
"hoverEdge",
"hoverNode",
"initRedraw",
"oncontext",
"release",
"resize",
"select",
"selectEdge",
"selectNode",
"showPopup",
"stabilizationIterationsDone",
"stabilizationProgress",
"stabilized",
"startStabilizing",
"zoom",
] as const).forEach((eventName): void => {
(
[
"afterDrawing",
"animationFinished",
"beforeDrawing",
"blurEdge",
"blurNode",
"click",
"configChange",
"controlNodeDragEnd",
"controlNodeDragging",
"deselectEdge",
"deselectNode",
"doubleClick",
"dragEnd",
"dragStart",
"dragging",
"hidePopup",
"hold",
"hoverEdge",
"hoverNode",
"initRedraw",
"oncontext",
"release",
"resize",
"select",
"selectEdge",
"selectNode",
"showPopup",
"stabilizationIterationsDone",
"stabilizationProgress",
"stabilized",
"startStabilizing",
"zoom",
] as const
).forEach((eventName): void => {
eventQueue[eventName] = [];
network.on(eventName, (params: any): void => {
eventQueue[eventName].push({ params });
Expand Down
36 changes: 15 additions & 21 deletions cypress/support/commands/vis-assert-event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,10 @@ declare global {
}

export function visShiftAndAssertEventFired(name: NetworkEvents): void {
cy.visRun(
async ({ eventQueue }): Promise<void> => {
expect(eventQueue[name], `${name} event queue`).to.not.be.empty;
eventQueue[name].shift();
}
);
cy.visRun(async ({ eventQueue }): Promise<void> => {
expect(eventQueue[name], `${name} event queue`).to.not.be.empty;
eventQueue[name].shift();
});
}
Cypress.Commands.add(
"visShiftAndAssertEventFired",
Expand All @@ -48,15 +46,13 @@ export function visShiftAndAssertEventFiredWithParams(
name: NetworkEvents,
params: any
): void {
cy.visRun(
async ({ eventQueue }): Promise<void> => {
expect(eventQueue[name], `${name} event queue`).to.not.be.empty;
const event = eventQueue[name].shift();
expect(event, `${name} event`)
.to.have.ownProperty("params")
.that.deep.equals(params);
}
);
cy.visRun(async ({ eventQueue }): Promise<void> => {
expect(eventQueue[name], `${name} event queue`).to.not.be.empty;
const event = eventQueue[name].shift();
expect(event, `${name} event`)
.to.have.ownProperty("params")
.that.deep.equals(params);
});
}
Cypress.Commands.add(
"visShiftAndAssertEventFiredWithParams",
Expand All @@ -66,12 +62,10 @@ Cypress.Commands.add(
export function visShiftAndAssertEventNone(
...names: readonly NetworkEvents[]
): void {
cy.visRun(
async ({ eventQueue }): Promise<void> => {
for (const name of names) {
expect(eventQueue[name], `${name} event queue`).to.be.empty;
}
cy.visRun(async ({ eventQueue }): Promise<void> => {
for (const name of names) {
expect(eventQueue[name], `${name} event queue`).to.be.empty;
}
);
});
}
Cypress.Commands.add("visShiftAndAssertEventNone", visShiftAndAssertEventNone);
5 changes: 1 addition & 4 deletions cypress/support/commands/vis-assert-selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ declare global {
}
}

function sortSelection(selection: {
nodes: IdType[];
edges: IdType[];
}): {
function sortSelection(selection: { nodes: IdType[]; edges: IdType[] }): {
nodes: IdType[];
edges: IdType[];
} {
Expand Down
29 changes: 13 additions & 16 deletions cypress/support/commands/vis-run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,20 @@ export function visRun(
callback: (props: VisGlobals) => void | Promise<void>,
{ timeout = VIS_DEFAULT_RUN_TIMEOUT }: VisRunOptions = {}
): void {
cy.window().then(
{ timeout },
async (win: any): Promise<void> => {
const {
visEdges: edges,
visEventQueue: eventQueue,
visLastEvents: lastEvents,
visNetwork: network,
visNodes: nodes,
}: VisWindow = win;
cy.window().then({ timeout }, async (win: any): Promise<void> => {
const {
visEdges: edges,
visEventQueue: eventQueue,
visLastEvents: lastEvents,
visNetwork: network,
visNodes: nodes,
}: VisWindow = win;

if (edges && lastEvents && network && nodes) {
await callback({ edges, eventQueue, lastEvents, network, nodes });
} else {
throw new Error("No page globals were found.");
}
if (edges && lastEvents && network && nodes) {
await callback({ edges, eventQueue, lastEvents, network, nodes });
} else {
throw new Error("No page globals were found.");
}
);
});
}
Cypress.Commands.add("visRun", visRun);
3 changes: 1 addition & 2 deletions examples/network/edgeStyles/imageArrowHeads.html
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,7 @@ <h3>Image Arrow Heads</h3>
type: "image",
imageWidth: 24,
imageHeight: 24,
src:
"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' style='width:24px;height:24px' viewBox='0 0 24 24'%3E%3Cpath fill='%23000000' d='M19,3A2,2 0 0,1 21,5V19A2,2 0 0,1 19,21H5A2,2 0 0,1 3,19V5A2,2 0 0,1 5,3H9.18C9.6,1.84 10.7,1 12,1C13.3,1 14.4,1.84 14.82,3H19M12,8L7,13H10V17H14V13H17L12,8M12,3A1,1 0 0,0 11,4A1,1 0 0,0 12,5A1,1 0 0,0 13,4A1,1 0 0,0 12,3Z' /%3E%3C/svg%3E",
src: "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' style='width:24px;height:24px' viewBox='0 0 24 24'%3E%3Cpath fill='%23000000' d='M19,3A2,2 0 0,1 21,5V19A2,2 0 0,1 19,21H5A2,2 0 0,1 3,19V5A2,2 0 0,1 5,3H9.18C9.6,1.84 10.7,1 12,1C13.3,1 14.4,1.84 14.82,3H19M12,8L7,13H10V17H14V13H17L12,8M12,3A1,1 0 0,0 11,4A1,1 0 0,0 12,5A1,1 0 0,0 13,4A1,1 0 0,0 12,3Z' /%3E%3C/svg%3E",
},
},
},
Expand Down
5 changes: 2 additions & 3 deletions examples/network/other/changingClusteredEdgesNodes.html
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,8 @@ <h2 id="eventSpanHeading"></h2>
);
document.getElementById("eventSpanHeading").innerText =
"selectEdge event:";
document.getElementById(
"eventSpanContent"
).innerText = JSON.stringify(obj, null, 4);
document.getElementById("eventSpanContent").innerText =
JSON.stringify(obj, null, 4);
}
});
</script>
Expand Down
5 changes: 2 additions & 3 deletions examples/network/other/manipulation.html
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,8 @@
data,
callback
);
document.getElementById(
"cancelButton"
).onclick = clearPopUp.bind();
document.getElementById("cancelButton").onclick =
clearPopUp.bind();
document.getElementById("network-popUp").style.display = "block";
},
editNode: function (data, callback) {
Expand Down
10 changes: 4 additions & 6 deletions examples/network/other/manipulationEditEdgeNoDrag.html
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,8 @@
data,
callback
);
document.getElementById(
"node-cancelButton"
).onclick = cancelAction.bind(this, callback);
document.getElementById("node-cancelButton").onclick =
cancelAction.bind(this, callback);
document.getElementById("node-popUp").style.display = "block";
}

Expand Down Expand Up @@ -192,9 +191,8 @@
data,
callback
);
document.getElementById(
"edge-cancelButton"
).onclick = cancelEdgeEdit.bind(this, callback);
document.getElementById("edge-cancelButton").onclick =
cancelEdgeEdit.bind(this, callback);
document.getElementById("edge-popUp").style.display = "block";
}

Expand Down
Loading

0 comments on commit 73fea1f

Please sign in to comment.