-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathcommands.js
More file actions
97 lines (89 loc) · 2.83 KB
/
commands.js
File metadata and controls
97 lines (89 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add("login", (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This is will overwrite an existing command --
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })
import { defaultViewportDimensions } from './constants';
import { waitToRenderAllShapes } from './utils';
Cypress.Commands.add('loadModeler', () => {
const url = Cypress.env('inProcessmaker')
? '/modeler/1'
: '/';
cy.viewport(defaultViewportDimensions.width, defaultViewportDimensions.height);
cy.intercept('/js/chunk-vendors.js').as('chunkVendorsJs');
cy.intercept('/js/app.js').as('appJs');
cy.visit(url);
cy.wait('@chunkVendorsJs', { timeout: 30000 });
cy.wait('@appJs', { timeout: 30000 }).then((interception) => {
if (!interception.response) {
// if there is no response, wait 5 additional seconds
return cy.wait(5000);
}
});
waitToRenderAllShapes();
});
Cypress.Commands.add('moveTo', {
prevSubject: 'element',
}, (element, x, y) => {
cy.window()
.its('store.state.paper')
.then(paper => {
const paperOrigin = paper.localToPagePoint(0, 0);
cy.wrap(element)
.trigger('mousedown')
.trigger('mousemove', {
clientX: paperOrigin.x + x,
clientY: paperOrigin.y + y,
})
.trigger('mouseup');
});
});
Cypress.Commands.add('getPosition', {
prevSubject: 'element',
}, element => {
cy.window()
.its('store.state.paper')
.then(paper => {
const paperOrigin = paper.localToPagePoint(0, 0);
const { left, top } = element.position();
const { x, y } = element[0].getBBox();
return {
x: left - paperOrigin.x - x,
y: top - paperOrigin.y - y,
};
});
});
Cypress.Commands.add('getType', {
prevSubject: 'element',
}, element => {
cy.window()
.its('store.state.paper')
.invoke('getModelById', element.attr('model-id'))
.then(shape => shape.component.node.type);
});
Cypress.Commands.add('selectOption', { prevSubject: true }, (subject, option) => {
cy.get(subject).click();
cy.get(subject).find('input').clear().type(option);
cy.get(subject).find(`span:not(.multiselect__option--disabled) span:contains("${option}"):first`).click();
cy.wait(300);
});