first commit

This commit is contained in:
2024-07-15 11:28:08 +02:00
commit f52d538ea5
21891 changed files with 6161164 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
{
"name": "Using fixtures to represent data",
"email": "hello@cypress.io",
"body": "Fixtures are a great way to mock data for responses to routes"
}

View File

@@ -0,0 +1,9 @@
/// <reference types="Cypress" />
describe( 'Test If The Editor Load', () => {
it( 'Should Load', () => {
cy.visit( '/wp-admin/' );
cy.addElementorPage();
} );
} );

View File

@@ -0,0 +1,48 @@
/// <reference types="Cypress" />
const canvasTemplate = 'Canvas-Template' + Date.now();
describe( 'Tests if Canvas Template works', () => {
it( 'should show elementor-template-canvas without editing in elementor', () => {
cy.visit( '/wp-admin/post-new.php' );
cy.wait( 200 );
cy.get( '.components-popover__content > .components-icon-button' ).click();
cy.get( '#post-title-0' ).click().type( canvasTemplate );
cy.get( ':nth-child(7) > .components-panel__body-title > .components-button' )
.should( 'be.visible' ).click();
cy.get( 'select' ).contains( 'Elementor Canvas' ).parent( 'select' ).select( 'Elementor Canvas' );
cy.get( '.editor-default-block-appender__content' ).click();
cy.get( '[aria-label="Empty block; start writing or type forward slash to choose a block"]' ).click()
.type( 'Text' );
cy.get( '.editor-post-publish-panel__toggle' ).click();
cy.get( '.editor-post-publish-panel__header-publish-button > .components-button' ).click();
cy.get( '.editor-post-publish-panel__header-published' ).should( 'exist' );
cy.get( '.post-publish-panel__postpublish-buttons > a.components-button' ).click();
cy.get( '.elementor-template-canvas' ).should( 'exist' );
} );
it( 'should show elementor-template-canvas with editing in elementor', () => {
cy.visit( '/wp-admin/edit.php' );
cy.get( 'a[class="row-title"]' ).contains( canvasTemplate ).click();
cy.get( '#elementor-switch-mode-button' ).click();
cy.addWidget( 'basic', 'heading' );
cy.get( '#elementor-panel-saver-button-save-options' ).click();
cy.get( '#elementor-panel-saver-menu-save-draft > .elementor-title' ).click();
cy.disableElementorPopup();
cy.visit( '/wp-admin/edit.php' );
cy.get( 'a[class="row-title"]' ).contains( canvasTemplate ).click();
cy.wait( 200 );
cy.get( '#elementor-switch-mode-button' ).click();
cy.get( '.editor-block-list__block' ).click();
cy.get( '#mce_0' ).type( 'some-test' );
cy.get( '.editor-post-publish-button' ).should( 'have.attr', 'aria-disabled', 'true' );
cy.get( '.editor-post-publish-button' ).should( 'have.attr', 'aria-disabled', 'false' );
cy.get( '.editor-post-preview' ).invoke( 'attr', 'href' ).then( ( url ) => {
cy.visit( url );
} );
cy.get( '.elementor-template-canvas' ).should( 'exist' );
} );
} );

View File

@@ -0,0 +1,22 @@
/// <reference types="Cypress" />
describe( 'Test If The Frontend handlers works', () => {
it( 'Should open the `Toggle` content', () => {
cy.addElementorPage().then( ( pageId ) => {
cy.addWidget( 'general', 'toggle' );
cy.wait( 100 );
cy.get( '#elementor-panel-saver-button-publish' ).click();
cy.wait( 100 );
cy.get( '#elementor-toast' ).should( 'be.visible' );
cy.visit( '/?p=' + pageId ).then( () => {
cy.get( '.elementor-tab-title:first' ).click();
cy.get( '.elementor-tab-content:first' ).should( 'be.visible' );
} );
} );
} );
} );

View File

@@ -0,0 +1,44 @@
/// <reference types="Cypress" />
const templateName = 'presetPage' + Date.now();
describe( 'Tests if maintenance mode works properly', () => {
before( () => {
cy.login( 'admin' );
cy.addTemplate( {
templateType: 'page',
presetSearch: 'COMING SOON 5',
name: templateName,
} ).then( ( templateId ) => {
Cypress.env( 'maintenanceModeTemplateId', templateId );
} );
} );
it( 'should show maintenance mode in the main page', () => {
cy.visit( 'wp-admin/admin.php?page=elementor-tools#tab-maintenance_mode' );
cy.get( 'select[name="elementor_maintenance_mode_mode"]' ).select( 'Coming Soon' );
cy.get( 'select[name="elementor_maintenance_mode_template_id"]' ).select( templateName );
cy.get( '#submit' ).click();
cy.clearCookies();
cy.setCookie( 'wordpress_test_cookie', 'WP+Cookie+check' );
cy.visit( '/' );
cy.get( '.elementor-' + Cypress.env( 'maintenanceModeTemplateId' ) );
cy.request( { url: '/' } ).then( ( res ) => {
expect( res.status ).to.eq( 200 );
} );
} );
it( 'should return 503', () => {
cy.visit( 'wp-admin/admin.php?page=elementor-tools#tab-maintenance_mode' );
cy.get( 'select[name="elementor_maintenance_mode_mode"]' ).select( 'Maintenance' );
cy.get( 'select[name="elementor_maintenance_mode_template_id"]' ).select( templateName );
cy.get( '#submit' ).click();
cy.clearCookies();
cy.setCookie( 'wordpress_test_cookie', 'WP+Cookie+check' );
cy.visit( '/', { failOnStatusCode: false } );
cy.get( '.elementor-' + Cypress.env( 'maintenanceModeTemplateId' ) );
cy.request( { url: '/', failOnStatusCode: false } ).then( ( res ) => {
expect( res.status ).to.eq( 503 );
} );
} );
} );

View File

@@ -0,0 +1,25 @@
/// <reference types="Cypress" />
describe( 'Test the hide functionality of the navigator', () => {
it( 'Should hide the elementor in when hide in mobile is activated', () => {
cy.addElementorPage();
cy.addWidget( 'basic', 'heading' );
cy.get( '#elementor-preview-iframe' ).then( ( $iframe ) => {
cy.wrap( $iframe.contents().find( '.elementor-widget-heading' ) )
.click( { force: true } )
.trigger( 'contextmenu' );
} );
cy.get( '.elementor-context-menu-list__item-navigator' ).click();
cy.get( '.elementor-tab-control-advanced' ).click();
cy.get( '.elementor-control-_section_responsive' ).scrollIntoView().click();
cy.get( '.elementor-control-hide_mobile .elementor-switch-label' ).click();
cy.get( '.elementor-navigator__item.elementor-editing > .elementor-navigator__element__toggle' )
.click( { force: true } );
cy.get( '#elementor-preview-iframe' ).then( ( $iframe ) => {
cy.wrap( $iframe.contents().find( '.elementor-widget-heading' ), { timeout: 5000 } )
.should( 'not.be.visible' );
} );
} );
} );

View File

@@ -0,0 +1,31 @@
/// <reference types="Cypress" />
describe( 'Test If Try Safe Mode is shown', () => {
it( 'Should show the Safe Mode notice', () => {
cy.addElementorPage().then( ( pageId ) => {
// With `ELEMENTOR_TESTS=1` elementor should not run.
cy.visit( '/wp-admin/post.php?post=' + pageId + '&action=elementor&ELEMENTOR_TESTS=1' );
// On loading the Try Safe Mode should be hidden.
cy.get( '#elementor-try-safe-mode' ).should( 'not.be.visible' );
cy.wait( 10001 );
// After 10 sec that the editor is not loaded the Try Safe Mode should appear.
cy.get( '#elementor-try-safe-mode' ).should( 'be.visible' );
// Click on Try Safe Mode.
cy.get( '.elementor-safe-mode-button' ).click();
// After reload the Safe Mode message should appear But the Try Safe Mode should be removed..
cy.get( '#elementor-safe-mode-message' ).should( 'be.visible' );
cy.get( '#elementor-try-safe-mode' ).should( 'not.exist' );
// Exit Safe Mode.
cy.get( '.elementor-disable-safe-mode' ).click();
// The Safe Mode message should not exist.
cy.get( '#elementor-safe-mode-message' ).should( 'not.exist' );
} );
} );
} );

View File

@@ -0,0 +1,44 @@
/// <reference types="Cypress" />
describe( 'Test is section work as properly', () => {
it( 'Should add section', () => {
cy.addElementorPage().then( () => {
cy.get( '#elementor-preview-iframe' ).then( ( $iframe ) => {
cy.wrap( $iframe.contents().find( '.elementor-add-section-button' ) ).click();
cy.wrap( $iframe.contents().find( 'li[data-structure="20"]' ) ).click();
//cy.wrap( $iframe.contents().find( 'div.elementor-column' ) ).should( 'have.length', 2 );
} );
cy.get( '#elementor-preview-iframe' ).then( ( $iframe ) => {
cy.wrap( $iframe.contents().find( '.elementor-section' ).last().find( '.elementor-column' ) ).should( 'have.length', 2 );
} );
cy.testHistory( { addedLength: 1, title: 'Section', action: 'Added' } );
cy.get( '#elementor-preview-iframe' ).then( ( $iframe ) => {
cy.wrap( $iframe.contents().find( '.elementor-section' ).last().find( '.elementor-editor-element-setting.elementor-editor-element-edit.ui-sortable-handle' ).first() )
.click( { force: true } )
.trigger( 'contextmenu' );
} );
cy.get( '.elementor-context-menu-list__group-addNew' ).click();
cy.get( '#elementor-preview-iframe' ).then( ( $iframe ) => {
cy.wrap( $iframe.contents().find( '.elementor-section' ).last().find( '.elementor-column' ) ).should( 'have.length', 3 );
} );
cy.testHistory( { addedLength: 1, title: 'Column', action: 'Added' } );
cy.get( '#elementor-preview-iframe' ).then( ( $iframe ) => {
cy.wrap( $iframe.contents().find( '.elementor-section' ).last().find( '.elementor-editor-element-setting.elementor-editor-element-edit.ui-sortable-handle' ).first() )
.click( { force: true } )
.trigger( 'contextmenu' );
} );
cy.get( '.elementor-context-menu-list__item-duplicate' ).click();
cy.get( '#elementor-preview-iframe' ).then( ( $iframe ) => {
cy.wrap( $iframe.contents().find( '.elementor-section' ).last().find( '.elementor-column' ) ).should( 'have.length', 4 );
} );
cy.testHistory( { addedLength: 1, title: 'Column', action: 'Added' } );
} );
} );
} );

View File

@@ -0,0 +1,69 @@
/// <reference types="Cypress" />
describe( 'Test if Widgets work as exprected', () => {
before( 'Test if Widgets work as exprected', () => {
cy.login( 'admin' );
cy.addElementorPage();
cy.getCookies().then( ( cookies ) => {
Cypress.env( 'cookies', cookies );
} );
} );
[
{ category: 'basic', widget: 'heading' },
{ category: 'basic', widget: 'image' },
{ category: 'basic', widget: 'video', delay: 3000 },
{ category: 'basic', widget: 'button' },
{ category: 'basic', widget: 'divider' },
{ category: 'basic', widget: 'spacer' },
{ category: 'basic', widget: 'google_maps', delay: 3000 },
{ category: 'basic', widget: 'icon' },
{ category: 'general', widget: 'image-box' },
{ category: 'general', widget: 'icon-box' },
{ category: 'general', widget: 'image-gallery', delay: 3000 },
{ category: 'general', widget: 'image-carousel', delay: 3000 },
{ category: 'general', widget: 'icon-list' },
{ category: 'general', widget: 'counter' },
{ category: 'general', widget: 'progress' },
{ category: 'general', widget: 'testimonial' },
{ category: 'general', widget: 'social-icons' },
{ category: 'general', widget: 'alert' },
{ category: 'general', widget: 'audio', delay: 3000 },
{ category: 'general', widget: 'shortcode', delay: 3000 },
{ category: 'general', widget: 'html' },
{ category: 'general', widget: 'menu-anchor' },
{ category: 'general', widget: 'sidebar', delay: 3000 },
].forEach( ( widget ) => {
it( 'Should show ' + widget.widget, () => {
Cypress.env( 'cookies' ).forEach( ( cookie ) => {
cy.setCookie( cookie.name, cookie.value );
} );
cy.get( '#elementor-panel-header-add-button' ).click();
cy.addWidget( widget.category, widget.widget ).then( ( colomeView ) => {
assert.equal( colomeView.model.get( 'elements' ).first().get( 'widgetType' ), widget.widget );
cy.testHistory( {
addedLength: 1,
title: 'audio' === widget.widget ? 'soundcloud' : widget.widget,
action: 'added',
caseSensitive: false,
} );
if ( widget.delay ) {
cy.wait( widget.delay );
}
cy.removeWidget( '[data-id="' + colomeView.model.get( 'elements' ).first().get( 'id' ) + '"]' );
cy.testHistory( {
addedLength: 1,
title: 'audio' === widget.widget ? 'soundcloud' : widget.widget,
action: 'removed',
caseSensitive: false,
} );
} );
} );
} );
} );

View File

@@ -0,0 +1,23 @@
/// <reference types="Cypress" />
describe( 'Tests the funcnaliti of the widget image', () => {
it( 'Should not dispaly empty image', () => {
cy.addElementorPage().then( ( pageId ) => {
cy.addWidget( 'basic', 'image' ).then( ( colomeView ) => {
const columnId = colomeView.model.get( 'id' ),
widgetId = colomeView.model.get( 'elements' ).first().get( 'id' );
cy.get( '.elementor-control-media__replace' ).click( { force: true } );
cy.get( '#elementor-panel-saver-button-publish' ).click();
cy.wait( 100 );
cy.get( '#elementor-panel-saver-button-publish' ).click();
cy.get( '.elementor-button.elementor-button-success.elementor-disabled' ).should( 'exist' );
cy.visit( '/?p=' + pageId );
cy.get( '[data-id=' + widgetId + ']' ).should( 'not.exist' );
cy.get( '[data-id=' + columnId + ']' ).should( 'exist' );
} );
} );
} );
} );

View File

@@ -0,0 +1,39 @@
// ***********************************************************
// This example plugins/index.js can be used to load plugins
//
// You can change the location of this file or turn off loading
// the plugins file with the 'pluginsFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/plugins-guide
// ***********************************************************
// This function is called when a project is opened or re-opened (e.g. due to
// the project's config changing)
const http = require( 'http' );
module.exports = async ( on, config ) => {
config.env.WP_VERSION = config.env.WP_VERSION || await getWordPressVersion( config.baseUrl );
return config;
};
function getWordPressVersion( baseUrl ) {
return new Promise( ( resolve ) => {
http.get( baseUrl, ( resp ) => {
let data = '';
// A chunk of data has been received.
resp.on( 'data', ( chunk ) => {
data += chunk;
} );
// The whole response has been received. Print out the result.
resp.on( 'end', () => {
resolve( data.match( /content="WordPress ([^"]+)"/ )[ 1 ] );
return data.match( /content="WordPress ([^"]+)"/ )[ 1 ];
} );
} ).on( 'error', ( err ) => {
throw new Error( err );
} );
} );
}

View File

@@ -0,0 +1,17 @@
/// <reference types="Cypress" />
function addElementorPage() {
cy.visit( '/wp-admin/post-new.php?post_type=page' );
cy.get( '[id=elementor-switch-mode-button]' ).click();
cy.get( '[id=elementor-loading]' ).should( 'be.hidden' );
cy.get( '#elementor-preview-iframe' ).then( ( $iframe ) => {
cy.wrap( $iframe.contents().find( '.elementor-add-section-button' ) ).click();
cy.wrap( $iframe.contents().find( '[data-structure="10"]' ) ).click();
} );
Cypress.env( 'history', 2 );
cy.get( '#elementor-preview-iframe' ).then( ( $iframe ) => {
return $iframe.attr( 'src' ).split( /\?(p.*?)\&/ )[ 1 ].split( /.*=/ )[ 1 ];
} );
}
Cypress.Commands.add( 'addElementorPage', addElementorPage );

View File

@@ -0,0 +1,42 @@
/// <reference types="Cypress" />
/**
* add a new elementor tempalte
*
* @param {Object} options
* @param {string} options.templateType the post type ( Page | Section )
* @param {string} [options.presetSearch] what to search in Elementor template library
* @param {number} [options.PreDesignNumber] the place of the template in the library
* @param {string} [options.name] the place of the template in the library
*/
function addTemplate( options ) {
cy.visit( '/wp-admin/edit.php?post_type=elementor_library' );
cy.get( '.page-title-action' ).eq( 0 ).click();
cy.get( '#elementor-new-template__form__template-type' ).select( options.templateType );
if ( options.name ) {
cy.get( '#elementor-new-template__form__post-title' ).type( options.name );
}
cy.get( '#elementor-new-template__form__submit' ).click();
if ( options.PreDesignNumber || options.presetSearch ) {
cy.get( '#elementor-preview-iframe' ).then( ( $iframe ) => {
cy.wrap( $iframe.contents().find( '.elementor-add-template-button' ) ).click();
} );
if ( options.presetSearch ) {
cy.get( '#elementor-template-library-filter-text' ).type( options.presetSearch );
}
if ( ! options.PreDesignNumber ) {
options.PreDesignNumber = 1;
}
cy.get( `:nth-child(${ options.PreDesignNumber }) > .elementor-template-library-template-body > .elementor-template-library-template-preview`, { timeout: 30000 } )
.click();
cy.get( '.elementor-template-library-template-action' ).click();
}
cy.get( '.dialog-lightbox-widget-content', { timeout: 30000 } ).should( 'not.be.visible' );
cy.get( '#elementor-panel-saver-button-publish' ).click();
cy.get( '.elementor-disabled' ).should( 'exist' );
cy.get( '#elementor-preview-iframe' ).then( ( $iframe ) => {
return $iframe.attr( 'src' ).split( /&/ ).find( ( item ) => item.includes( 'p=' ) ).split( /.*=/ )[ 1 ];
} );
}
Cypress.Commands.add( 'addTemplate', addTemplate );

View File

@@ -0,0 +1,26 @@
/// <reference types="Cypress" />
const setPanelSelectedElement = ( elementor, category, widgetName ) => {
const elementsPanel = elementor.getPanelView().getCurrentPageView().elements.currentView,
basicElements = elementsPanel.collection.findWhere( { name: category } ),
view = elementsPanel.children.findByModel( basicElements ),
widget = view.children.findByModel( view.collection.findWhere( { widgetType: widgetName } ) );
elementor.channels.panelElements.reply( 'element:selected', widget );
};
function addWidget( category, widgetName ) {
cy.get( '#elementor-panel-header-add-button' ).click();
cy.window().then( ( win ) => {
const previewView = win.elementor.getPreviewView(),
firstSectionModel = previewView.collection.first(),
firstSectionView = previewView.children.findByModel( firstSectionModel ),
firstColumnModel = firstSectionModel.get( 'elements' ).first(),
firstColumnView = firstSectionView.children.findByModel( firstColumnModel );
setPanelSelectedElement( win.elementor, category, widgetName );
firstColumnView.addElementFromPanel( { at: 0 } );
return firstColumnView;
} );
}
Cypress.Commands.add( 'addWidget', addWidget );

View File

@@ -0,0 +1,10 @@
/// <reference types="Cypress" />
function disableElementorPopup() {
cy.window()
.then( ( win ) => {
win.elementor.channels.editor.reply( 'status', false );
} );
}
Cypress.Commands.add( 'disableElementorPopup', disableElementorPopup );

View File

@@ -0,0 +1,5 @@
import './add-elementor-page';
import './add-widget';
import './remove-widget';
import './disable-popup';
import './add-template';

View File

@@ -0,0 +1,12 @@
/// <reference types="Cypress" />
function removeWidget( selector ) {
cy.get( '#elementor-preview-iframe' ).then( ( $iframe ) => {
cy.wrap( $iframe.contents().find( selector ), { timeout: 5000 } )
.click( { force: true } )
.trigger( 'contextmenu' );
} );
cy.get( '.elementor-context-menu-list__group-delete' ).click();
}
Cypress.Commands.add( 'removeWidget', removeWidget );

View File

@@ -0,0 +1,19 @@
/// <reference types="Cypress" />
beforeEach( function() {
cy.login( 'admin' );
} );
afterEach( function() {
/*
* This exist because electron dose not show Prompt, alers and confirms.
* Cypress runs on electron and elementor alert the "user" from switching pages.
* This make cypress stack and unable to continue.
* So because of this, this event disable the confirm.
*/
cy.window()
.then( ( win ) => {
if ( win.elementor ) {
win.elementor.channels.editor.reply( 'status', false );
}
} );
} );

View File

@@ -0,0 +1,23 @@
// ***********************************************************
// 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 './hooks';
import './request';
import './commands/index';
import './tests/index';
// Alternatively you can use CommonJS syntax:
// require('./commands')

View File

@@ -0,0 +1,19 @@
/// <reference types="Cypress" />
Cypress.Commands.add( 'login', ( user ) => {
cy.request( {
url: '/wp-login.php', // assuming you've exposed a seeds route
method: 'POST',
form: true,
headers: {
wordpress_test_cookie: 'WP+Cookie+check',
},
body: {
log: user,
pwd: 'password',
'wp-submit': 'LogIn',
redirect_to: '/wp-admin/',
testcookie: 1,
},
} );
} );

View File

@@ -0,0 +1,42 @@
/// <reference types="Cypress" />
function assertTest( given, expected, caseSensitive ) {
if ( ! caseSensitive ) {
expected = expected.replace( /[-_]/g, ' ' );
given = given.replace( /[-_]/g, ' ' );
expected = expected.toLocaleLowerCase();
given = given.toLocaleLowerCase();
}
expect( given ).to.contain( expected );
}
/**
*
* @param {object} options
* @param {number} options.addedLength the added length to history.
* @param {string} options.title current item title.
* @param {string} options.action current item action.
* @param {string} [options.caseSensitive=true] if the test should consider case checks or "-" and "_"
*/
function testHistory( options ) {
if ( ! options.hasOwnProperty( 'caseSensitive' ) ) {
options.caseSensitive = true;
}
cy.get( '#elementor-panel-footer-history' ).click();
cy.get( '.elementor-history-item' ).should( 'have.length', Cypress.env( 'history' ) + options.addedLength );
cy.get( '.elementor-history-item' ).its( 'length' ).then( ( length ) => {
Cypress.env( 'history', length );
} );
cy.get( '.elementor-history-item-current > .elementor-history-item > .elementor-history-item__details > .elementor-history-item__title' )
.invoke( 'text' )
.then( ( text ) => {
assertTest( text, options.title, options.caseSensitive );
} );
cy.get( '.elementor-history-item-current > .elementor-history-item > .elementor-history-item__details > .elementor-history-item__action' )
.invoke( 'text' )
.then( ( text ) => {
assertTest( text, options.action, options.caseSensitive );
} );
}
Cypress.Commands.add( 'testHistory', testHistory );

View File

@@ -0,0 +1 @@
import './history';