From 6b3c382b7cfdac3211752ff3ce8edab2df8ef792 Mon Sep 17 00:00:00 2001 From: Claudia Ifrim Date: Thu, 22 Dec 2022 12:04:23 +0200 Subject: [PATCH] update tests --- cypress/e2e/01-block-basics.cy.js | 9 +- cypress/support/commands.js | 239 ++---------------------------- cypress/support/e2e.js | 3 - 3 files changed, 15 insertions(+), 236 deletions(-) diff --git a/cypress/e2e/01-block-basics.cy.js b/cypress/e2e/01-block-basics.cy.js index 089c7b3..1e726ef 100644 --- a/cypress/e2e/01-block-basics.cy.js +++ b/cypress/e2e/01-block-basics.cy.js @@ -1,17 +1,20 @@ import { slateBeforeEach, slateAfterEach } from '../support/e2e'; +import 'cypress-fail-fast'; + describe('Blocks Tests', () => { beforeEach(slateBeforeEach); afterEach(slateAfterEach); it('Add Block: Empty', () => { // Change page title - cy.clearSlateTitle(); - cy.getSlateTitle().type('My Add-on Page'); + cy.get('[contenteditable=true]').first().clear(); + + cy.get('[contenteditable=true]').first().type('My Add-on Page'); cy.get('.documentFirstHeading').contains('My Add-on Page'); - cy.getSlate().click(); + cy.get('[contenteditable=true]').first().type('{enter}'); // Add block cy.get('.ui.basic.icon.button.block-add-button').first().click(); diff --git a/cypress/support/commands.js b/cypress/support/commands.js index f269a7f..ac48461 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -1,8 +1,5 @@ /* eslint no-console: ["error", { allow: ["log"] }] */ -const SLATE_SELECTOR = '.content-area .slate-editor [contenteditable=true]'; -const SLATE_TITLE_SELECTOR = '.block.inner.title [contenteditable="true"]'; - // --- AUTOLOGIN ------------------------------------------------------------- Cypress.Commands.add('autologin', () => { let api_url, user, password; @@ -71,7 +68,8 @@ Cypress.Commands.add( id: contentId, title: contentTitle, image: { - data: 'iVBORw0KGgoAAAANSUhEUgAAANcAAAA4CAMAAABZsZ3QAAAAM1BMVEX29fK42OU+oMvn7u9drtIPisHI4OhstdWZyt4fkcXX5+sAg74umMhNp86p0eJ7vNiKw9v/UV4wAAAAAXRS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aw6cpovGANwRiSdOAWJ5AGy4gLL64dl0QhUEAuEUNws+XxV+OKGPdw/hESGYF9XEGaFC7sNLMSXWJjHsnanYi87VK428N2uxpOjOFANcagLM5l+7mSycM8KknZpKLcGi6jmzWGr/vLurZ/0g4u9AZuAoeb5r1ceQhyiTPY1E4wUR6u/F3H2ojSpXMMriBPT9cezTto8Cx+MsglHL4fv1Rxrb1LVw9yvyQpJ3AhFnLZfuRLH2QsOG3FGGD20X/th/u5bFAt16Bt308KjF+MNOXgl/SquIEySX3GhaZvc67KZbDxcCDORz2N8yCWPaY5lyQZO7lQ29fnZbt3Xu6qoge4+DjXl/MocySPOp9rlvdyznahRyHEYd77v3LhugOXDv4J65QXfl803BDAdaWBEDhfVx7nKofjoVCgxnUAqw/UAUDPn788BDvQuG4TDtdtUPvzjSlXAB8DvaDOhhrmhwbywylXAm8CvaouikJTL93gs3y7Yy4VYbIxOHrcMizPqWOjqO9l3Uz52kibQy4xxOgqhJvD+w5rvokOcAlGvNCfeqCv1ste1stzLm0f71Iq3ZfTrPfuE5nhPtF+LvQE2lffQC7pYtQy3tdzdrKvd5TLVVzDetScS3nEKmmwDyt1Cev1kX3YfbvzNK4fzrlw+cB6vm+uiUgf2zdXI62241LawCb7Pi5FXFPF8KpzDoF/Sw2lg+GrHNbno1mhPu+VCF/vfMnw06PnUl6j48dVHD3jHNHPua+fc3o/5yp/zsGi0vYtzi3Pz5mHd4T6BWMIlewacd63AAAAAElFTkSuQmCC', encoding: 'base64', filename: 'image.png', 'content-type': 'image/png', @@ -94,7 +92,7 @@ Cypress.Commands.add( title: contentTitle, blocks: { 'd3f1c443-583f-4e8e-a682-3bf25752a300': { '@type': 'title' }, - '7624cf59-05d0-4055-8f55-5fd6597d84b0': { '@type': 'slate' }, + '7624cf59-05d0-4055-8f55-5fd6597d84b0': { '@type': 'text' }, }, blocks_layout: { items: [ @@ -124,103 +122,9 @@ Cypress.Commands.add( }) .then(() => console.log(`${contentType} created`)); } - } + }, ); -// --- Add DX Content-Type ---------------------------------------------------------- -Cypress.Commands.add('addContentType', (name) => { - let api_url, auth; - api_url = Cypress.env('API_PATH') || 'http://localhost:8080/Plone'; - auth = { - user: 'admin', - pass: 'admin', - }; - return cy - .request({ - method: 'POST', - url: `${api_url}/@controlpanels/dexterity-types/${name}`, - headers: { - Accept: 'application/json', - }, - auth: auth, - body: { - title: name, - }, - }) - .then(() => console.log(`${name} content-type added.`)); -}); - -// --- Remove DX behavior ---------------------------------------------------------- -Cypress.Commands.add('removeContentType', (name) => { - let api_url, auth; - api_url = Cypress.env('API_PATH') || 'http://localhost:8080/Plone'; - auth = { - user: 'admin', - pass: 'admin', - }; - return cy - .request({ - method: 'DELETE', - url: `${api_url}/@controlpanels/dexterity-types/${name}`, - headers: { - Accept: 'application/json', - }, - auth: auth, - body: {}, - }) - .then(() => console.log(`${name} content-type removed.`)); -}); - -// --- Add DX field ---------------------------------------------------------- -Cypress.Commands.add('addSlateJSONField', (type, name) => { - let api_url, auth; - api_url = Cypress.env('API_PATH') || 'http://localhost:8080/Plone'; - auth = { - user: 'admin', - pass: 'admin', - }; - return cy - .request({ - method: 'POST', - url: `${api_url}/@types/${type}`, - headers: { - Accept: 'application/json', - }, - auth: auth, - body: { - id: name, - title: name, - description: 'Slate JSON Field', - factory: 'SlateJSONField', - required: false, - }, - }) - .then(() => console.log(`${name} SlateJSONField field added to ${type}`)); -}); - -// --- Remove DX field ---------------------------------------------------------- -Cypress.Commands.add('removeSlateJSONField', (type, name) => { - let api_url, auth; - api_url = Cypress.env('API_PATH') || 'http://localhost:8080/Plone'; - auth = { - user: 'admin', - pass: 'admin', - }; - return cy - .request({ - method: 'DELETE', - url: `${api_url}/@types/${type}/${name}`, - headers: { - Accept: 'application/json', - }, - auth: auth, - body: {}, - }) - .then(() => - console.log(`${name} SlateJSONField field removed from ${type}`) - ); -}); - // --- REMOVE CONTENT -------------------------------------------------------- Cypress.Commands.add('removeContent', (path) => { let api_url, auth; @@ -242,41 +146,6 @@ Cypress.Commands.add('removeContent', (path) => { .then(() => console.log(`${path} removed`)); }); -Cypress.Commands.add('typeInSlate', { prevSubject: true }, (subject, text) => { - return ( - cy - .wrap(subject) - .then((subject) => { - subject[0].dispatchEvent( - new InputEvent('beforeinput', { - inputType: 'insertText', - data: text, - }) - ); - return subject; - }) - // TODO: do this only for Electron-based browser which does not understand instantaneously - // that the user inserted some text in the block - .wait(1000) - ); -}); - -Cypress.Commands.add('lineBreakInSlate', { prevSubject: true }, (subject) => { - return ( - cy - .wrap(subject) - .then((subject) => { - subject[0].dispatchEvent( - new InputEvent('beforeinput', { inputType: 'insertLineBreak' }) - ); - return subject; - }) - // TODO: do this only for Electron-based browser which does not understand instantaneously - // that the block was split - .wait(1000) - ); -}); - // --- SET WORKFLOW ---------------------------------------------------------- Cypress.Commands.add( 'setWorkflow', @@ -315,7 +184,7 @@ Cypress.Commands.add( include_children: include_children, }, }); - } + }, ); // --- waitForResourceToLoad ---------------------------------------------------------- @@ -375,86 +244,9 @@ Cypress.Commands.add( setBaseAndExtent(anchorNode, anchorOffset, focusNode, focusOffset); } }); - } + }, ); -Cypress.Commands.add('getSlate', ({ createNewSlate = true } = {}) => { - let slate; - cy.getIfExists( - SLATE_SELECTOR, - () => { - slate = cy.get(SLATE_SELECTOR).last(); - }, - () => { - if (createNewSlate) { - cy.get('.block.inner').last().type('{moveToEnd}{enter}'); - } - slate = cy.get(SLATE_SELECTOR, { timeout: 10000 }).last(); - } - ); - return slate; -}); - -Cypress.Commands.add('clearSlate', (selector) => { - return cy - .get(selector) - .focus() - .click() - .wait(1000) - .type('{selectAll}') - .wait(1000) - .type('{backspace}'); -}); - -Cypress.Commands.add('getSlateTitle', () => { - return cy.get(SLATE_TITLE_SELECTOR, { - timeout: 10000, - }); -}); - -Cypress.Commands.add('clearSlateTitle', () => { - return cy.clearSlate(SLATE_TITLE_SELECTOR); -}); - -Cypress.Commands.add('setSlateSelection', (subject, query, endQuery) => { - cy.get('.slate-editor.selected [contenteditable=true]') - .focus() - .click() - .setSelection(subject, query, endQuery) - .wait(1000); // this wait is needed for the selection change to be detected after -}); - -Cypress.Commands.add('getSlateEditorAndType', (type) => { - cy.getSlate().focus().click().type(type); -}); - -Cypress.Commands.add('setSlateCursor', (subject, query, endQuery) => { - cy.get('.slate-editor.selected [contenteditable=true]') - .focus() - .click() - .setCursor(subject, query, endQuery) - .wait(1000); -}); - -Cypress.Commands.add('clickSlateButton', (button) => { - cy.get(`.slate-inline-toolbar .button-wrapper a[title="${button}"]`, { - timeout: 10000, - }).click({ force: true }); //force click is needed to ensure the button in visible in view. -}); - -Cypress.Commands.add('toolbarSave', () => { - cy.wait(1000); - - // Save - cy.get('#toolbar-save').click(); - cy.waitForResourceToLoad('@navigation'); - cy.waitForResourceToLoad('@breadcrumbs'); - cy.waitForResourceToLoad('@actions'); - cy.waitForResourceToLoad('@types'); - cy.waitForResourceToLoad('my-page'); - cy.url().should('eq', Cypress.config().baseUrl + '/cypress/my-page'); -}); - // Low level command reused by `setCursorBefore` and `setCursorAfter`, equal to `setCursorAfter` Cypress.Commands.add( 'setCursor', @@ -470,7 +262,7 @@ Cypress.Commands.add( }); // Depending on what you're testing, you may need to chain a `.click()` here to ensure // further commands are picked up by whatever you're testing (this was required for Slate, for example). - } + }, ); Cypress.Commands.add( @@ -478,7 +270,7 @@ Cypress.Commands.add( { prevSubject: true }, (subject, query) => { cy.wrap(subject).setCursor(query, true); - } + }, ); Cypress.Commands.add( @@ -486,7 +278,7 @@ Cypress.Commands.add( { prevSubject: true }, (subject, query) => { cy.wrap(subject).setCursor(query); - } + }, ); // Helper functions @@ -521,16 +313,3 @@ Cypress.Commands.add('store', () => { Cypress.Commands.add('settings', (key, value) => { return cy.window().its('settings'); }); - -Cypress.Commands.add( - 'getIfExists', - (selector, successAction = () => {}, failAction = () => {}) => { - cy.get('body').then((body) => { - if (body.find(selector).length > 0 && successAction) { - successAction(); - } else if (failAction) { - failAction(); - } - }); - } -); diff --git a/cypress/support/e2e.js b/cypress/support/e2e.js index b7c02f2..f696418 100644 --- a/cypress/support/e2e.js +++ b/cypress/support/e2e.js @@ -21,9 +21,6 @@ import './commands'; //Generate code-coverage import '@cypress/code-coverage/support'; -// Fail Fast -import "cypress-fail-fast"; - export const slateBeforeEach = (contentType = 'Document') => { cy.autologin(); cy.createContent({