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,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';