Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement/update critical flows with e2e test coverage #87

Open
wants to merge 92 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
92 commits
Select commit Hold shift + click to select a range
af402a1
Dismiss cookie modal if exists
Dec 21, 2024
7506a93
Add notes regarding 2FA and special password chars
Dec 21, 2024
8b3bc7f
Add info on running settings.test.js successfully
MaxwellGarceau Dec 21, 2024
50b39f6
Add assertion to connect test match testing doc expectations
MaxwellGarceau Dec 21, 2024
86cee0f
Add base style verification to custom CSS test
MaxwellGarceau Dec 21, 2024
e57474d
Add Mailchimp login command
MaxwellGarceau Dec 21, 2024
9f2e052
Update E2E test requirement documentation
MaxwellGarceau Dec 21, 2024
2ce5125
Update merge fields test to test all optional fields
MaxwellGarceau Dec 21, 2024
cbfc5d0
Add expectations to ensure custom CSS does not cover submit
MaxwellGarceau Dec 23, 2024
97d30f3
Start validation test
MaxwellGarceau Dec 23, 2024
2af1bf9
Add blocked tests to validation.test.js
MaxwellGarceau Dec 23, 2024
9ec57a7
Modularize conditional mailchimp login
MaxwellGarceau Dec 23, 2024
6512804
Scaffold unsubscribe.test.js
MaxwellGarceau Dec 23, 2024
101d0b8
Ensure user is logged out of mailchimp accounts for admin tests
MaxwellGarceau Dec 23, 2024
d107a76
Stub out future tests
MaxwellGarceau Dec 23, 2024
a506004
Add check for env variables
MaxwellGarceau Dec 24, 2024
0bc4fa9
Add test to unsubscribe valid emails
MaxwellGarceau Dec 24, 2024
87050ef
Add test to prevent invalid email from unsubscribing
MaxwellGarceau Dec 24, 2024
303c221
Add note for future test
MaxwellGarceau Dec 24, 2024
1a84ca8
Add username and password arguments to log in to Mailchimp account
MaxwellGarceau Dec 24, 2024
b6d1da1
Add test to ensure settings persist in Mailchimp account
MaxwellGarceau Dec 24, 2024
7cb8ffd
If a user has not saved a list they can not see the form
MaxwellGarceau Dec 24, 2024
7bf0871
Enhancement/add mailchimp api client (#99)
MaxwellGarceau Dec 31, 2024
7bdc1b9
Add second user with no history to test list option persistence
MaxwellGarceau Dec 31, 2024
6a36ff9
Separate list from settings tests
MaxwellGarceau Dec 31, 2024
bd6c903
Move subscribe tests to subscribe page
MaxwellGarceau Jan 1, 2025
510effb
Add subscribe test placeholders
MaxwellGarceau Jan 1, 2025
7080ffe
Add double opt-in test cases
MaxwellGarceau Jan 1, 2025
725c604
Add command to select list
MaxwellGarceau Jan 1, 2025
d1a911f
Add command for updating merge fields in Mailchimp account
MaxwellGarceau Jan 1, 2025
e8140c6
Simplify querying Mailchimp list
MaxwellGarceau Jan 1, 2025
31029eb
Add test to validate required fields
MaxwellGarceau Jan 1, 2025
b9c5054
Rename validation test
MaxwellGarceau Jan 1, 2025
2ebf4ca
Reorganize tests
MaxwellGarceau Jan 1, 2025
f1963c7
Clean up validate test
MaxwellGarceau Jan 1, 2025
c50530a
Encapsulate submission flow in cypress command
MaxwellGarceau Jan 1, 2025
db55cec
Add address validation test
MaxwellGarceau Jan 2, 2025
ec03e91
Add phone validation
MaxwellGarceau Jan 2, 2025
b68c711
Add better grouping to address test
MaxwellGarceau Jan 2, 2025
1e95e26
Add set javascript command. Tweak updateMergeFieldByTag
MaxwellGarceau Jan 2, 2025
202792e
Add US phone validation test
MaxwellGarceau Jan 2, 2025
ffde068
Convert to indent with tab
MaxwellGarceau Jan 2, 2025
2c40857
Add email validation
MaxwellGarceau Jan 2, 2025
1407964
Revamp email validation. Add unrequired fields validation.
MaxwellGarceau Jan 2, 2025
8c49bc2
Remove comments
MaxwellGarceau Jan 2, 2025
75f6439
Rename validate unrequired fields test
MaxwellGarceau Jan 2, 2025
528c0fa
Fix bug with get all lists test
MaxwellGarceau Jan 10, 2025
13ae078
Add ability to run all specs together in cypress GUI
MaxwellGarceau Jan 10, 2025
9158bb4
Update tests to avoid false failures
MaxwellGarceau Jan 10, 2025
61c0117
Fix failing tests by loosening assertions
MaxwellGarceau Jan 10, 2025
b8b3cfb
Add function to subscribe and archive contacts
MaxwellGarceau Jan 10, 2025
491cdb4
Finish subscribe test
MaxwellGarceau Jan 10, 2025
7c141d0
Fix error in after causing test to fail
MaxwellGarceau Jan 10, 2025
8dbc4be
Remove toggle to include merge fields when they are all set to required
MaxwellGarceau Jan 10, 2025
504d887
Add pagination consideration for getMergeFields
MaxwellGarceau Jan 10, 2025
b65dcf3
Update validate required fields test
MaxwellGarceau Jan 10, 2025
7bf9d20
Add login to prevent test from failing
MaxwellGarceau Jan 10, 2025
a1be126
Add login and list selection to ensure tests can be run in isolation
MaxwellGarceau Jan 10, 2025
370afb7
Wrap deleteContact with 10up list ID
MaxwellGarceau Jan 10, 2025
dbf5b18
Add docblocks
MaxwellGarceau Jan 10, 2025
eaa1c56
Remove JS email testing and move js submission into correct directory
MaxwellGarceau Jan 10, 2025
a570644
Add bug note in mailchimp.js
MaxwellGarceau Jan 10, 2025
967d46c
Rename mailchimp.js to js-subission.js
MaxwellGarceau Jan 10, 2025
8caaf89
Add mergeFields as fixture
MaxwellGarceau Jan 10, 2025
f3c64bf
Start JS submission test
MaxwellGarceau Jan 10, 2025
7e36de0
Add generateRandomEmail utility function and update tests
MaxwellGarceau Jan 10, 2025
ef81e72
Fix bug with deleteContactFrom10UpList
MaxwellGarceau Jan 10, 2025
7177f13
Add generateRandomEmail as function and imported in test cases
MaxwellGarceau Jan 10, 2025
d8bfe80
Finish js-submission tests
MaxwellGarceau Jan 10, 2025
beb097e
Clean up todo comments and add to global before
MaxwellGarceau Jan 10, 2025
9ac4021
Remove testing JS support on validation tests
MaxwellGarceau Jan 10, 2025
a023439
Remove shortcode testing from validation tests
MaxwellGarceau Jan 10, 2025
bb4166d
Reorganize and add tests for subscription options
MaxwellGarceau Jan 10, 2025
d50b510
Fix file extension
MaxwellGarceau Jan 10, 2025
7da61eb
Finish subscribe tests to verify contacts in mailchimp account
MaxwellGarceau Jan 10, 2025
8f44eac
Refactor to use new support functions
MaxwellGarceau Jan 10, 2025
ded9cf9
Add data persistence test
MaxwellGarceau Jan 10, 2025
07e1ec6
Rename verify mailchimp contact to better reflect function
MaxwellGarceau Jan 10, 2025
1673755
Finish unsubscribe tests
MaxwellGarceau Jan 10, 2025
b8a27a2
Add getContact functionality
MaxwellGarceau Jan 10, 2025
f4e8034
Add test for not updating subscribers without option
MaxwellGarceau Jan 10, 2025
3bafb35
Update gitignore for vscode
MaxwellGarceau Jan 10, 2025
ad5209b
Specify error message
MaxwellGarceau Jan 10, 2025
e7ccd64
Write test for duplicate emails
MaxwellGarceau Jan 10, 2025
02ead24
Fix bug failing admin.test.js
MaxwellGarceau Jan 11, 2025
00d265e
Small tweaks
MaxwellGarceau Jan 11, 2025
1c2b833
Skip data persistence for now
MaxwellGarceau Jan 11, 2025
ad9334d
Add select 10up list globally
MaxwellGarceau Jan 11, 2025
7b1277d
Remove test to verify form is not visible on fe if no list is saved
MaxwellGarceau Jan 11, 2025
8747d6f
Finish data persistence test
MaxwellGarceau Jan 11, 2025
8b95dec
Removed logout from data persistence test
MaxwellGarceau Jan 11, 2025
0183f37
Skip resubscribe actions due to only stubs
MaxwellGarceau Jan 11, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .env.test.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
##
## Users
##

# Main user for testing
CYPRESS_MAILCHIMP_USERNAME="your mailchimp username"
CYPRESS_MAILCHIMP_PASSWORD="your mailchimp password"

# Generate API Key: https://mailchimp.com/help/about-api-keys/
CYPRESS_MAILCHIMP_API_KEY="generate an API key from your mailchimp account and paste here" # e.g. "1234567890abcdef1234567890abcdef-us19"
CYPRESS_MAILCHIMP_API_SERVER_PREFIX="" # e.g "us19" - your server prefix may be different
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ dist/*
docs-built
.phpunit.result.cache
/.wp-env.override.json
.env.test

tests/cypress/videos
tests/cypress/screenshots
tests/cypress/reports
tests/cypress/downloads

mailchimp.zip

# IDE
/.vscode
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,13 @@ The `tests` directory contains end-to-end tests for the project, utilizing Cypre
1. Run `npm install`.
2. Run `npm run build`.
3. Run `npm run env:start`.
4. Set Mailchimp credentials as environment variables:
- run `export CYPRESS_MAILCHIMP_USERNAME="your mailchimp username"`
- run `export CYPRESS_MAILCHIMP_PASSWORD="your mailchimp password"`
5. Run `npm run cypress:run`. You can also run `npm run cypress:open` to run tests in UI mode.
4. Duplicate the `.env.test.sample` file and rename `.env.test`. Populate this file with your own Mailchimp account credentials.
- **NOTE:** Use a test account that does not require 2FA. 2FA will fail some of the tests.
5. Set your Mailchimp account up
- Name the audience in your Mailchimp test account "10up". Required for `settings.test.js`.
- Enable all merge fields. From your Mailchimp account home page -> `/audience/settings/` -> Edit merge fields/tags -> Set all merge fields to "visible". Required for `settings.test.js`.

6. Run `npm run cypress:run`. You can also run `npm run cypress:open` to run tests in UI mode.

## Support Level

Expand Down
2 changes: 2 additions & 0 deletions assets/js/mailchimp.js → assets/js/js-submission.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
// See if we're successful, if so, wipe the fields
const reg = /class="|'mc_success_msg"|'/i;

// TODO: Bug: The form data is always cleared regardless of JS or no JS support
if (reg.test(data)) {
$('#mc_signup_form').each(function () {
this.reset();
});
$('#mc_submit_type').val('js');
}

window.scrollTo({
top: document.getElementById('mc_signup').offsetTop - 28,
behavior: 'smooth',
Expand Down
2 changes: 1 addition & 1 deletion mailchimp.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ function mailchimp_sf_load_resources() {
// JS
if ( get_option( 'mc_use_javascript' ) === 'on' ) {
if ( ! is_admin() ) {
wp_enqueue_script( 'mailchimp_sf_main_js', MCSF_URL . 'assets/js/mailchimp.js', array( 'jquery', 'jquery-form' ), MCSF_VER, true );
wp_enqueue_script( 'mailchimp_sf_main_js', MCSF_URL . 'assets/js/js-submission.js', array( 'jquery', 'jquery-form' ), MCSF_VER, true );
// some javascript to get ajax version submitting to the proper location
global $wp_scripts;
$wp_scripts->localize(
Expand Down
162 changes: 162 additions & 0 deletions package-lock.json

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

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@
},
"devDependencies": {
"@10up/cypress-wp-utils": "^0.4.0",
"@mailchimp/mailchimp_marketing": "^3.0.80",
"@wordpress/env": "^10.2.0",
"10up-toolkit": "^6.2.0",
"cypress": "^13.13.2",
"cypress-dotenv": "^3.0.1",
"cypress-mochawesome-reporter": "^3.8.2",
"mochawesome-json-to-md": "^1.3.5"
},
Expand Down
3 changes: 3 additions & 0 deletions tests/cypress/config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const { defineConfig } = require( 'cypress' );
const { loadConfig } = require( '@wordpress/env/lib/config' );
const getCacheDirectory = require( '@wordpress/env/lib/config/get-cache-directory' );
const dotenvPlugin = require('cypress-dotenv');

module.exports = defineConfig( {
chromeWebSecurity: false,
Expand All @@ -19,11 +20,13 @@ module.exports = defineConfig( {
},
e2e: {
setupNodeEvents( on, config ) {
config = dotenvPlugin(config, { path: '../../.env.test' }); // Load .env variables into Cypress
return setBaseUrl( on, config );
},
specPattern: 'tests/cypress/e2e/**/*.test.{js,jsx,ts,tsx}',
supportFile: 'tests/cypress/support/index.js',
defaultCommandTimeout: 20000,
experimentalRunAllSpecs: true,
},
retries: {
runMode: 2,
Expand Down
31 changes: 9 additions & 22 deletions tests/cypress/e2e/connect.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,17 @@ describe('Admin can connect to "Mailchimp" Account', () => {
}
});

// Check Mailchimp menu.
cy.get('#mailchimp_sf_oauth_connect').should('exist');

// Enable popup capture.
cy.capturePopup();

cy.get('#mailchimp_sf_oauth_connect').click();
cy.wait(6000);

cy.popup()
.find('input#username')
.clear()
.type(Cypress.env('MAILCHIMP_USERNAME'), { force: true });
cy.popup()
.find('input#password')
.clear()
.type(Cypress.env('MAILCHIMP_PASSWORD'), { force: true });
cy.popup().find('button[type="submit"]').click({ force: true });
cy.wait(10000); // Not a best practice, but did not find a better way to handle this.

cy.popup().find('input#submitButton').click({ force: true });
cy.wait(10000); // Not a best practice, but did not find a better way to handle this.
// Mailchimp connection login as a command in order to be reusable
cy.mailchimpLogin();

// Logout exists
cy.get('.mc-user h3').contains('Logged in as: ');
cy.get('input[value="Logout"]').should('exist');

// Mailchimp lists exists and has at least one audience
cy.get('#mc_list_id').should('exist');
cy.get('#mc_list_id')
.children()
.should('have.length.greaterThan', 1); // The " — Select A List — " default option will always be present
});
});
Loading
Loading