Skip to content

Commit

Permalink
Merge pull request #145 from 10up/feature/add-cypress-tests
Browse files Browse the repository at this point in the history
Add cypress tests
  • Loading branch information
iamdharmesh authored Apr 11, 2022
2 parents f745125 + e64ae36 commit 4df6a36
Show file tree
Hide file tree
Showing 29 changed files with 2,574 additions and 351 deletions.
1 change: 0 additions & 1 deletion .distignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,3 @@ phpunit.xml
README.md
webpack.config.js
webpack.gutenberg.config.js
wpacceptance.json
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ assets
dist
node_modules
vendor
tests
54 changes: 54 additions & 0 deletions .github/workflows/cypress.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: E2E Tests

on:
push:
branches:
- develop
- trunk
pull_request:
branches:
- develop

jobs:
cypress:
runs-on: ubuntu-latest

strategy:
matrix:
core:
- { name: 'WP latest', version: 'latest' }
- { name: 'WP trunk', version: 'WordPress/WordPress#master' }
- { name: 'WP minimum', version: 'WordPress/WordPress#5.2' }

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

- name: Install dependencies
run: npm i && npm i -g [email protected]

- name: Build asset
run: npm run build

- name: Add dependencies
run: composer install -o --no-dev --ignore-platform-reqs

- name: Set the core version
run: ./tests/bin/set-core-version.js ${{ matrix.core.version }}

- name: Set up WP environment
run: npm run env:start

- name: Test
run: cypress run --config-file tests/cypress/config.json --env TWITTER_API_KEY=${{ secrets.TWITTER_API_KEY }},TWITTER_API_SECRET=${{ secrets.TWITTER_API_SECRET }},TWITTER_ACCESS_TOKEN=${{ secrets.TWITTER_ACCESS_TOKEN }},TWITTER_ACCESS_SECRET=${{ secrets.TWITTER_ACCESS_SECRET }}

- name: Upload artifacts
uses: actions/upload-artifact@v2
if: failure()
with:
name: cypress-artifact-autoshare-for-twitter
retention-days: 2
path: |
${{ github.workspace }}/tests/cypress/screenshots/
${{ github.workspace }}/tests/cypress/videos/
${{ github.workspace }}/tests/cypress/logs/
2 changes: 1 addition & 1 deletion .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ jobs:
extensions: mysql, imagick

- name: Run PHPUnit
run: ./bin/test.sh
run: ./bin/test.sh
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ node_modules
screenshots
tests/coverage
vendor

tests/cypress/downloads
tests/cypress/screenshots
tests/cypress/videos
13 changes: 13 additions & 0 deletions .wp-env.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"plugins": [
"https://downloads.wordpress.org/plugin/classic-editor.1.6.1.zip",
"."
],
"env": {
"tests": {
"mappings": {
"wp-cli.yml": "./tests/bin/wp-cli.yml"
}
}
}
}
34 changes: 19 additions & 15 deletions assets/js/admin-autoshare-for-twitter-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,27 @@
postTypesWrap = document.querySelector( '.post-types' ),
postTypesCheckboxes = document.getElementsByName( 'autoshare-for-twitter[enable_for]' );

openCredSettingsBtn.addEventListener( 'click', function() {
credSetup.classList.remove( 'connected' );
} );

closeCredSettingsBtn.addEventListener( 'click', function() {
credSetup.classList.add( 'connected' );
} );

postTypesCheckboxes.forEach( function( item ) {
item.addEventListener( 'change', function( event) {
if ( event.target.value === 'all' )
return postTypesWrap.classList.add( 'hidden' );
return postTypesWrap.classList.remove( 'hidden' );
if ( openCredSettingsBtn ) {
openCredSettingsBtn.addEventListener( 'click', function() {
credSetup.classList.remove( 'connected' );
} );
} );

}

if ( closeCredSettingsBtn ) {
closeCredSettingsBtn.addEventListener( 'click', function() {
credSetup.classList.add( 'connected' );
} );
}

if ( postTypesCheckboxes ) {
postTypesCheckboxes.forEach( function( item ) {
item.addEventListener( 'change', function( event) {
if ( event.target.value === 'all' )
return postTypesWrap.classList.add( 'hidden' );
return postTypesWrap.classList.remove( 'hidden' );
} );
} );
}
} );

jQuery( document ).ready(function() {
Expand Down
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
"scripts": {
"test": "phpunit",
"setup-local-tests": "bash bin/install-wp-tests.sh wordpress_test root root 127.0.0.1 latest",
"test:acceptance": "wpacceptance run",
"phpcs": "vendor/bin/phpcs autoshare-for-twitter.php includes/ --extensions=php -s",
"phpcs:compat": "vendor/bin/phpcs autoshare-for-twitter.php includes/ --standard=PHPCompatibilityWP --extensions=php --runtime-set testVersion 7.0-",
"lint-fix": "./vendor/bin/phpcbf --extensions=php ."
Expand Down
25 changes: 18 additions & 7 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion includes/admin/post-meta.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,11 @@ function save_autoshare_for_twitter_meta_data( $post_id, $data ) {
foreach ( $data as $key => $value ) {
switch ( $key ) {
case ENABLE_AUTOSHARE_FOR_TWITTER_KEY:
update_autoshare_for_twitter_meta( $post_id, ENABLE_AUTOSHARE_FOR_TWITTER_KEY, $value );
if ( ! empty( $value ) ) {
update_autoshare_for_twitter_meta( $post_id, ENABLE_AUTOSHARE_FOR_TWITTER_KEY, $value );
} else {
delete_autoshare_for_twitter_meta( $post_id, ENABLE_AUTOSHARE_FOR_TWITTER_KEY );
}
break;

case TWEET_BODY_KEY:
Expand Down
Loading

0 comments on commit 4df6a36

Please sign in to comment.