Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/npm_and_yarn/semver-5.7.2
Browse files Browse the repository at this point in the history
  • Loading branch information
AnthonyLedesma authored Aug 8, 2023
2 parents 23e8e2b + f074b69 commit ea82f3c
Show file tree
Hide file tree
Showing 12 changed files with 248 additions and 130 deletions.
95 changes: 24 additions & 71 deletions .dev/tests/cypress/helpers.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,8 @@
/**
* Close layout selector.
*/
export function closeLayoutSelector() {
cy.get( '.coblocks-layout-selector-modal' ).its( 'length' ).then( ( layoutSelectorModal ) => {
if ( layoutSelectorModal > 0 ) {
cy.get( '.coblocks-layout-selector-modal' )
.find( '.components-button[aria-label*="Close"]' ).first()
.click();
}
} );

cy.get( '.coblocks-layout-selector-modal' ).should( 'not.exist' );
}

/**
* Returns true if styles tab exists false otherwise.
*/
export function selectStylesTabIfExists() {
if ( isWP62AtLeast() ) {
cy.get( '.edit-post-sidebar' ).find( 'button[aria-label="Styles"]' ).click();
}
cy.get( '.edit-post-sidebar' ).find( 'button[aria-label="Styles"]' ).click();
}

/**
Expand All @@ -30,7 +13,7 @@ export function selectStylesTabIfExists() {
export function addFormChild( name ) {
cy.get( '[data-type="coblocks/form"] [data-type^="coblocks/field"]' ).first().click( { force: true } );
cy.get( '.block-editor-block-settings-menu' ).click();
cy.get( '.components-popover__content button' ).contains( /insert after/i ).click( { force: true } );
cy.get( '.components-popover__content button' ).contains( /insert after|add after/i ).click( { force: true } );
cy.get( '[data-type="coblocks/form"] [data-type="core/paragraph"]' ).click( { force: true } );

cy.get( '.edit-post-header-toolbar' ).find( '.edit-post-header-toolbar__inserter-toggle' ).click( { force: true } );
Expand Down Expand Up @@ -157,13 +140,9 @@ export function addNewGroupToPost() {
cy.get( '.edit-post-header [aria-label="Add block"], .edit-site-header [aria-label="Add block"], .edit-post-header-toolbar__inserter-toggle' ).click();
cy.get( '.block-editor-inserter__search-input,input.block-editor-inserter__search, .components-search-control__input' ).click().type( 'group' );

if ( isWP62AtLeast() ) {
cy.wait( 1000 );
cy.wait( 1000 );

cy.get( '.block-editor-block-types-list__list-item' ).contains( 'Group' ).click();
} else {
cy.get( '.block-editor-block-types-list__item' ).first().click();
}
cy.get( '.block-editor-block-types-list__list-item' ).contains( 'Group' ).click();

// Make sure the block was added to our page
cy.get( `[class*="-visual-editor"] [data-type='core/group']` ).should( 'exist' ).then( () => {
Expand Down Expand Up @@ -256,28 +235,6 @@ export function getBlockSlug() {
return ( specFile.split( '/' ).pop().replace( '.cypress.js', '' ) );
}

/**
* Open the block navigator.
*/
export function openBlockNavigator( ) {
cy.get( '.block-editor-block-navigation,.edit-post-header-toolbar__list-view-toggle,.edit-post-header-toolbar__document-overview-toggle' ).then( ( element ) => {
if ( ! element.hasClass( 'is-pressed' ) ) {
element.click();
}
} );
}

/**
* Close the block navigator.
*/
export function closeBlockNavigator() {
const inserterButton = Cypress.$( '.edit-post-header__toolbar button.edit-post-header-toolbar__list-view-toggle.is-pressed' );
if ( inserterButton.length > 0 ) {
cy.get( '.edit-post-header__toolbar button.edit-post-header-toolbar__list-view-toggle.is-pressed' )
.click();
}
}

/**
* Click on a style button within the style panel
*
Expand Down Expand Up @@ -321,7 +278,7 @@ export function selectBlock( name ) {
cy.wait( 1000 );

// `data-type` includes lower case name and `data-title` includes upper case name.
// Allows for case insensitive search.
// Allows for case-insensitive search.
cy.get( `[data-type*="${ name }"], [data-title*="${ name }"]` )
.invoke( 'attr', 'data-block' )
.then( ( clientId ) => {
Expand Down Expand Up @@ -364,7 +321,7 @@ export const upload = {
/**
* Upload image to input element and trigger replace image flow.
*
* @param {string} blockName The name of the block that is replace target
* @param {string} blockName The name of the block that is replacing target
* imageReplaceFlow works with CoBlocks Galleries: Carousel, Collage, Masonry, Offset, Stacked.
*/
imageReplaceFlow: ( blockName ) => {
Expand Down Expand Up @@ -442,7 +399,12 @@ export function setColorSettingsFoldableSetting( settingName, hexColor ) {
const formattedHex = hexColor.split( '#' )[ 1 ];

cy.get( '.block-editor-panel-color-gradient-settings__dropdown' ).contains( settingName, { matchCase: false } ).click();
cy.get( '.components-color-palette__custom-color' ).click();

if ( isWP63AtLeast() ) {
cy.get( '.components-color-palette__custom-color-button' ).click();
} else {
cy.get( '.components-color-palette__custom-color' ).click();
}

cy.get( '.components-color-picker' ).find( '.components-input-control__input' ).click().clear().type( formattedHex );

Expand All @@ -455,7 +417,12 @@ export function setColorPanelSetting( settingName, hexColor ) {
const formattedHex = hexColor.split( '#' )[ 1 ];

cy.get( '.block-editor-panel-color-gradient-settings__dropdown' ).contains( settingName, { matchCase: false } ).click();
cy.get( '.components-color-palette__custom-color' ).click();

if ( isWP63AtLeast() ) {
cy.get( '.components-color-palette__custom-color-button' ).click();
} else {
cy.get( '.components-color-palette__custom-color' ).click();
}

cy.get( '.components-color-picker' ).find( '.components-input-control__input' ).click().clear().type( formattedHex );

Expand Down Expand Up @@ -506,7 +473,7 @@ export function openHeadingToolbarAndSelect( headingLevel ) {
}

/**
* Toggle an checkbox in the settings panel of the block editor
* Toggle a checkbox in the settings panel of the block editor
*
* @param {string} checkboxLabelText The checkbox label text. eg: Drop Cap
*/
Expand All @@ -521,7 +488,7 @@ export function toggleSettingCheckbox( checkboxLabelText ) {
/**
* Add custom classes to a block
*
* @param {string} classes Custom classe(s) to add to the block
* @param {string} classes Custom class(es) to add to the block
* @param {string} blockID The name of the block e.g. (accordion, alert, map)
*/
export function addCustomBlockClass( classes, blockID = '' ) {
Expand Down Expand Up @@ -553,20 +520,6 @@ export function addCustomBlockClass( classes, blockID = '' ) {
} );
}

/**
* Open the Editor Settings panel.
*/
export function openEditorSettingsModal() {
// Open "more" menu.
cy.get( '.edit-post-more-menu button' ).click();
cy.get( '.components-menu-group' ).contains( 'Editor settings' ).click();

cy.get( '.components-modal__frame' ).contains( 'Editor settings' ).should( 'exist' );

// Ensure settings have loaded.
cy.get( '.coblocks-settings-modal input[type="checkbox"]' ).should( 'have.length', 6 );
}

/**
* Open the CoBlocks Labs modal.
*/
Expand Down Expand Up @@ -608,10 +561,10 @@ export function isNotWPLocalEnv() {
return Cypress.env( 'testURL' ) !== 'http://localhost:8889';
}

// A condition to determine if we are testing on WordPress 6.2+
// This function should be removed in the process of the work for WP 6.3 compatibility
export function isWP62AtLeast() {
return Cypress.$( "[class*='branch-6-2']" ).length > 0 || Cypress.$( "[class*='branch-6-3']" ).length > 0;
// A condition to determine if we are testing on WordPress 6.3+
// This function should be removed in the process of the work for WP 6.4 compatibility
export function isWP63AtLeast() {
return Cypress.$( "[class*='branch-6-3']" ).length > 0 || Cypress.$( "[class*='branch-6-4']" ).length > 0;
}

function getIframeDocument( containerClass ) {
Expand Down
173 changes: 173 additions & 0 deletions .github/workflows/test-e2e-cypress-6.3rc2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
name: Test / E2E Cypress Job RC2

on:
workflow_call:
inputs:
browser:
required: false
type: string
default: chrome
theme:
required: false
type: string
wpVersion:
required: false
type: string
default: ""
phpVersion:
required: false
type: string
default: "8.2"
secrets:
record-key:
description: 'Record key for Cypress Dashboard'
required: false

jobs:
test_cypress_e2e:
name: E2E Test
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
spec:
- accordion.cypress.js
- alert.cypress.js
- author.cypress.js
- click-to-tweet.cypress.js
- counter.cypress.js
- dynamic-separator.cypress.js
- event-item.cypress.js
- events.cypress.js
- faq.cypress.js
- feature.cypress.js
- features.cypress.js
- food-item.cypress.js
- food-and-drinks.cypress.js
- form.cypress.js
- gallery-carousel.cypress.js
- gallery-collage.cypress.js
- gallery-masonry.cypress.js
- gallery-offset.cypress.js
- gallery-stacked.cypress.js
- gif.cypress.js
- gist.cypress.js
- hero.cypress.js
- highlight.cypress.js
- icon.cypress.js
- logos.cypress.js
- map.cypress.js
- media-card.cypress.js
- opentable.cypress.js
- post-carousel.cypress.js
- posts.cypress.js
- pricing-table-item.cypress.js
- pricing-table.cypress.js
- column.cypress.js
- row.cypress.js
- service.cypress.js
- services.cypress.js
- shape-divider.cypress.js
- social-profiles.cypress.js
- modal.cypress.js
- media-filter-control.cypress.js
- coblocks-labs.cypress.js
- layout-selector.cypress.js
- lightbox-controls-gallery.cypress.js
- lightbox-controls-image.cypress.js
- media-text-styles.cypress.js
- padding-controls.cypress.js
- settings-modal-control.cypress.js


steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup wp-env
uses: godaddy-wordpress/setup-wp-env@v1
with:
core: ${{ inputs.wpVersion }}
phpVersion: ${{ inputs.phpVersion }}
plugins: '["."]'
themes: '["https://downloads.wordpress.org/theme/go.zip"]'

- name: Setup Node
uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: 'yarn'

- name: Install dependencies
run: |
composer install --prefer-dist --optimize-autoloader &
yarn install --immutable
- name: Build plugin
run: |
npx grunt build
# moving the built directory to this location means no dev files in tests-container.
mv ./build/coblocks $(wp-env install-path)/tests-wordpress-6.3-RC2/wp-content/plugins/
- name: Prepare Theme
run: |
if [ "${{ inputs.theme }}" = "https://downloads.wordpress.org/theme/go.zip" ]; then
cd $(wp-env install-path)/go
else
cd $(wp-env install-path)/tests-wordpress-6.3-RC2/wp-content/themes/twentytwentythree
fi
mkdir -p coblocks/icons
echo '<svg height="20" viewBox="0 0 20 20" width="20" xmlns="http://www.w3.org/2000/svg"><circle class="inner-circle" cx="20" cy="20" r="8" stroke-width="8" stroke-dasharray="50.2655 50.2655" stroke-dashoffset="0"></circle></svg>' >> coblocks/icons/custom.svg
- name: Prepare tests
run: |
WP_CORE_VERSION=$(wp-env run cli wp core version)
echo "WP_CORE_VERSION=${WP_CORE_VERSION}" >> $GITHUB_ENV
wp-env run tests-cli wp post generate --count=5
wp-env run cli wp post generate --count=5
wp-env run cli wp option update permalink_structure '/%postname%'
if [ "${{ inputs.theme }}" = "https://downloads.wordpress.org/theme/go.zip" ]; then
wp-env run tests-cli wp theme activate go
fi
# Only create a new post if running the migrated specs
- name: Create post and get ID
if: matrix.spec == 'alert.cypress.js' || matrix.spec == 'author.cypress.js'
run: |
# Generate application-password to use with WP REST API.
app_password=$(wp-env run tests-cli wp user application-password create admin gha-password --porcelain)
# Retrieve post content from fixture.
post_content=$(cat .dev/tests/cypress/fixtures/${{matrix.spec}}.html)
echo $post_content
# Create a post using the REST API and parse the postId from the response.
postId=$(curl -s -X POST 'http://localhost:8889/?rest_route=/wp/v2/posts' --data-urlencode "title=${{matrix.spec}}" --data-raw "content=$post_content" --data-urlencode "status=publish" --user "admin:$app_password"| jq '.id')
# Save the postId to the output.
echo "postId=$postId" >> $GITHUB_OUTPUT
id: create-post

# Only retrieve the post ID if running the first spec
- name: Save post ID to file
if: matrix.spec == 'alert.cypress.js' || matrix.spec == 'author.cypress.js'
run: |
path="$GITHUB_WORKSPACE/.dev/tests/cypress/fixtures/${{matrix.spec}}.json"
touch "$path"
echo "{\"${{matrix.spec}}\": \"$(echo "${{ steps.create-post.outputs.postId }}")\"}" > "$path"
- name: Run tests
run: |
CYPRESS_SPEC=$(find ./src/* -name ${{ matrix.spec }} -type f)
echo '{"wpUsername":"admin","wpPassword":"password","testURL":"http://localhost:8889"}' | jq . > cypress.env.json
./node_modules/.bin/cypress verify
./node_modules/.bin/cypress run --browser ${{ inputs.browser }} --spec $CYPRESS_SPEC
- name: Upload failure video
if: ${{ failure() }}
uses: actions/upload-artifact@v3
with:
name: ${{ matrix.spec }}-fail.mp4
path: ./.dev/tests/cypress/videos/${{ matrix.spec }}.mp4
retention-days: 1

9 changes: 9 additions & 0 deletions .github/workflows/test-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,12 @@ jobs:
concurrency:
group: chrome-php74
cancel-in-progress: true

chrome_e2e_wp_63_rc2:
name: Chrome on WordPress 6.3 RC2
uses: ./.github/workflows/test-e2e-cypress-6.3rc2.yml
with:
wpVersion: "https://wordpress.org/wordpress-6.3-RC2.zip"
concurrency:
group: chrome-wp_63_rc2
cancel-in-progress: true
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,12 @@
"lint:php": "wp-env run tests-cli --env-cwd=/var/www/html 'composer run lint -d /var/www/html/wp-content/plugins/coblocks/'; #we use phpunit container because composer container only use php 8;",
"lint:php:fix": "wp-env run tests-cli --env-cwd=/var/www/html 'composer run lint:fix -d /var/www/html/wp-content/plugins/coblocks/'; #we use phpunit container because composer container only use php 8;",
"makepot": "./vendor/bin/wp i18n make-pot . --skip-audit --exclude=\".dev,.github,.wordpress-org,build,docs,dist,node_modules,vendor,wordpress\" --headers='{\"Last-Translator\":\"[email protected]\",\"Report-Msgid-Bugs-To\":\"https://github.com/godaddy-wordpress/coblocks/issues\"}' --file-comment=\"Copyright (c) $(date +'%Y') GoDaddy Operating Company, LLC. All Rights Reserved.\" languages/coblocks.pot && yarn run pot2json",
"php:composer:install": "wp-env run wordpress 'composer install -d /var/www/html/wp-content/plugins/coblocks/'",
"po2jed": "cd languages && find . -name '*.po' -execdir /bin/bash -c 'FROM=\"$0\" && TO=\"`basename $0 .po`-coblocks-editor.json\" && echo \"$FROM > $TO\" && po2json $FROM $TO -f jed' '{}' \\;",
"po2mo": "cd languages && find . -name '*.po' -execdir /bin/bash -c 'FROM=\"$0\" && TO=\"`basename $0 .po`.mo\" && echo \"$FROM > $TO\" && msgfmt $FROM -o $TO' '{}' \\;",
"postinstall": "yarn update:icon",
"pot2json": "./vendor/bin/pot2json languages/coblocks.pot languages/coblocks.json",
"prepare": "husky install .dev/husky",
"setup": "yarn install && yarn run build && wp-env start && yarn php:composer:install",
"setup": "yarn install && yarn run build && wp-env start",
"start:debug": "DEBUG_MODE=on wp-scripts start --progress",
"start": "wp-scripts start --progress",
"test:a11y": "node .dev/tests/a11y/pa11y.js",
Expand Down
Loading

0 comments on commit ea82f3c

Please sign in to comment.