Skip to content

Commit 7932097

Browse files
author
Christian Burk
committed
VACMS-12217: Adds Cypress test changes
1 parent 9408419 commit 7932097

File tree

1 file changed

+20
-35
lines changed

1 file changed

+20
-35
lines changed

tests/cypress/support/commands.js

+20-35
Original file line numberDiff line numberDiff line change
@@ -134,54 +134,39 @@ Cypress.Commands.add("drupalWatchdogHasNewErrors", (username, count) => {
134134
});
135135

136136
Cypress.Commands.add("iframe", { prevSubject: "element" }, ($iframe) => {
137-
cy.get($iframe).scrollIntoView();
138-
cy.get($iframe)
139-
.its("0.contentDocument")
140-
.should("not.be.empty")
141-
.its("body")
142-
.as("body");
143-
cy.get("@body").should("be.visible").should("not.be.empty").then(cy.wrap);
137+
return cy
138+
.wrap($iframe)
139+
.should((iframe) => expect(iframe.contents().find("body")).to.exist)
140+
.then((iframe) => cy.wrap(iframe.contents().find("body")));
144141
});
145142

146-
Cypress.Commands.add("type_ckeditor", (element, content) => {
147-
cy.window().then((win) => {
143+
Cypress.Commands.add("get_ckeditor", (element) => {
144+
cy.wait(5000);
145+
return cy.window().then((win) => {
148146
const elements = Object.keys(win.CKEDITOR.instances);
149-
if (elements.indexOf(element) === -1) {
147+
const index = elements.indexOf(element);
148+
if (index === -1) {
150149
const matches = elements.filter((el) => el.includes(element));
151150
if (matches.length) {
152151
// eslint-disable-next-line prefer-destructuring
153152
element = matches[0];
153+
} else {
154+
throw new Error(`CKEditor instance not found: ${element}`);
154155
}
155156
}
156-
cy.wait(2000);
157-
cy.get(`#${element}`)
158-
.parent()
159-
.find("iframe")
160-
.iframe()
161-
.then(() => {
162-
win.CKEDITOR.instances[element].setData(content);
163-
});
157+
return cy.wrap(win.CKEDITOR.instances[element]);
158+
});
159+
});
160+
161+
Cypress.Commands.add("type_ckeditor", (element, content) => {
162+
return cy.get_ckeditor(element).then((editor) => {
163+
return cy.wrap(editor.setData(content));
164164
});
165165
});
166166

167167
Cypress.Commands.add("read_ckeditor", (element) => {
168-
return cy.window().then((win) => {
169-
const elements = Object.keys(win.CKEDITOR.instances);
170-
if (elements.indexOf(element) === -1) {
171-
const matches = elements.filter((el) => el.includes(element));
172-
if (matches.length) {
173-
[element] = matches;
174-
}
175-
}
176-
cy.wait(2000);
177-
return cy
178-
.get(`#${element}`)
179-
.parent()
180-
.find("iframe")
181-
.iframe()
182-
.then(() => {
183-
return cy.wrap(win.CKEDITOR.instances[element].getData());
184-
});
168+
return cy.get_ckeditor(element).then((editor) => {
169+
return cy.wrap(editor.getData());
185170
});
186171
});
187172

0 commit comments

Comments
 (0)