-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Ensure commands work in the new iframed Block Editor
- Loading branch information
Showing
10 changed files
with
227 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/** | ||
* Get the Block Editor | ||
* | ||
* @returns Block Editor element. | ||
* | ||
* @example | ||
* Find the title input and type in it | ||
* ``` | ||
* cy.getBlockEditor().find('.editor-post-title__input').type('Test Post'); | ||
* ``` | ||
*/ | ||
export declare const getBlockEditor: () => Cypress.Chainable<unknown>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getBlockEditor = void 0; | ||
const get_iframe_1 = require("../functions/get-iframe"); | ||
/** | ||
* Get the Block Editor | ||
* | ||
* @returns Block Editor element. | ||
* | ||
* @example | ||
* Find the title input and type in it | ||
* ``` | ||
* cy.getBlockEditor().find('.editor-post-title__input').type('Test Post'); | ||
* ``` | ||
*/ | ||
const getBlockEditor = () => { | ||
// Ensure the editor is loaded. | ||
cy.get('.edit-post-visual-editor').should('exist'); | ||
return cy | ||
.get('body') | ||
.then($body => { | ||
if ($body.find('iframe[name="editor-canvas"]').length) { | ||
return (0, get_iframe_1.getIframe)('iframe[name="editor-canvas"]'); | ||
} | ||
return $body; | ||
}) | ||
.then(cy.wrap); // eslint-disable-line @typescript-eslint/unbound-method | ||
}; | ||
exports.getBlockEditor = getBlockEditor; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/** | ||
* Code taken from the Cypress iframe package. | ||
* | ||
* https://gitlab.com/kgroat/cypress-iframe | ||
*/ | ||
export declare const getIframe: Cypress.Chainable['iframe']; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
"use strict"; | ||
/** | ||
* Code taken from the Cypress iframe package. | ||
* | ||
* https://gitlab.com/kgroat/cypress-iframe | ||
*/ | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getIframe = void 0; | ||
const DEFAULT_OPTS = { | ||
log: true, | ||
timeout: 30000, | ||
}; | ||
const DEFAULT_IFRAME_SELECTOR = 'iframe'; | ||
function sleep(timeout) { | ||
return new Promise(resolve => setTimeout(resolve, timeout)); | ||
} | ||
const frameLoaded = (selector, opts) => { | ||
if (selector === undefined) { | ||
selector = DEFAULT_IFRAME_SELECTOR; | ||
} | ||
else if (typeof selector === 'object') { | ||
opts = selector; | ||
selector = DEFAULT_IFRAME_SELECTOR; | ||
} | ||
const fullOpts = Object.assign(Object.assign({}, DEFAULT_OPTS), opts); | ||
const log = fullOpts.log | ||
? Cypress.log({ | ||
name: 'frame loaded', | ||
displayName: 'frame loaded', | ||
message: [selector], | ||
}).snapshot() | ||
: null; | ||
return cy | ||
.get(selector, { log: false }) | ||
.then({ timeout: fullOpts.timeout }, ($frame) => __awaiter(void 0, void 0, void 0, function* () { | ||
log === null || log === void 0 ? void 0 : log.set('$el', $frame); | ||
if ($frame.length !== 1) { | ||
throw new Error(`cypress-iframe commands can only be applied to exactly one iframe at a time. Instead found ${$frame.length}`); | ||
} | ||
const contentWindow = $frame.prop('contentWindow'); | ||
const hasNavigated = fullOpts.url | ||
? () => { | ||
var _a; | ||
return typeof fullOpts.url === 'string' | ||
? contentWindow.location.toString().includes(fullOpts.url) | ||
: (_a = fullOpts.url) === null || _a === void 0 ? void 0 : _a.test(contentWindow.location.toString()); | ||
} | ||
: () => contentWindow.location.toString() !== 'about:blank'; | ||
while (!hasNavigated()) { | ||
yield sleep(100); | ||
} | ||
if (contentWindow.document.readyState === 'complete') { | ||
return $frame; | ||
} | ||
const loadLog = Cypress.log({ | ||
name: 'Frame Load', | ||
message: [contentWindow.location.toString()], | ||
event: true, | ||
}).snapshot(); | ||
yield new Promise(resolve => { | ||
Cypress.$(contentWindow).on('load', resolve); | ||
}); | ||
loadLog.end(); | ||
log === null || log === void 0 ? void 0 : log.finish(); | ||
return $frame; | ||
})); | ||
}; | ||
const getIframe = (selector, opts) => { | ||
if (selector === undefined) { | ||
selector = DEFAULT_IFRAME_SELECTOR; | ||
} | ||
else if (typeof selector === 'object') { | ||
opts = selector; | ||
selector = DEFAULT_IFRAME_SELECTOR; | ||
} | ||
const fullOpts = Object.assign(Object.assign({}, DEFAULT_OPTS), opts); | ||
const log = fullOpts.log | ||
? Cypress.log({ | ||
name: 'iframe', | ||
displayName: 'iframe', | ||
message: [selector], | ||
}).snapshot() | ||
: null; | ||
return frameLoaded(selector, Object.assign(Object.assign({}, fullOpts), { log: false })).then($frame => { | ||
log === null || log === void 0 ? void 0 : log.set('$el', $frame).end(); | ||
const contentWindow = $frame.prop('contentWindow'); | ||
return Cypress.$(contentWindow.document.body); | ||
}); | ||
}; | ||
exports.getIframe = getIframe; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters