add cypress scaffolding

This commit is contained in:
dwelle 2020-01-03 17:01:58 +01:00 committed by Giovanni Giordano
parent 3fb6f0413e
commit 9bffa6e52c
9 changed files with 100 additions and 1 deletions

View file

@ -0,0 +1,39 @@
function normalizeCoords(coords) {
// Note: Cypress seems to check against falsiness (thus 0 values are
// considered as not supplied, and position defualts to "center").
// Until fixed, default to `1`
// See https://github.com/cypress-io/cypress/issues/2338
return {
x: coords.x || 1,
y: coords.y || 1
};
}
Cypress.Commands.add("pickTool", { prevSubject: false }, tool =>
cy.contains("label", tool).click()
);
Cypress.Commands.add(
"canvasClick",
{ prevSubject: true },
($canvas, coords) => {
coords = normalizeCoords(coords);
cy.wrap($canvas)
.trigger("mousedown", coords.x, coords.y)
.trigger("mouseup", coords.x, coords.y);
}
);
Cypress.Commands.add(
"canvasDrag",
{ prevSubject: true },
($canvas, startCoods, endCoords) => {
startCoods = normalizeCoords(startCoods);
endCoords = normalizeCoords(endCoords);
cy.wrap($canvas)
.trigger("mousedown", startCoods.x, startCoods.y)
.trigger("mousemove", endCoords.x, endCoords.y)
.trigger("mouseup", endCoords.x, endCoords.y);
}
);

View file

@ -0,0 +1,9 @@
export default {
tools: {
rectangle: /rectangle/i,
ellipse: /ellipse/i,
arrow: /arrow/i,
text: /text/i,
selection: /selection/i
}
};

20
cypress/support/index.js Normal file
View file

@ -0,0 +1,20 @@
// ***********************************************************
// This example support/index.js is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************
// Import commands.js using ES2015 syntax:
import "./commands";
// Alternatively you can use CommonJS syntax:
// require('./commands')