Skip to content

Commit

Permalink
Separate list from settings tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxwellGarceau committed Dec 31, 2024
1 parent 7bdc1b9 commit 6a36ff9
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 44 deletions.
82 changes: 82 additions & 0 deletions tests/cypress/e2e/list.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/* eslint-disable no-undef */
describe('Mailchimp lists ', () => {
let shortcodePostURL;
let blockPostPostURL;

before(() => {
// TODO: Initialize tests from a blank state
// TODO: Wipe WP data related to a users options
// TODO: Delete all contacts in a users Mailchimp account
// TODO: Ensure the default audience list is "10up"
// TODO: Include all merge fields as "Visible" in the users Mailchimp account

// Load the post URLs from the JSON file
cy.fixture('postUrls.json').then((urls) => {
shortcodePostURL = urls.shortcodePostURL;
blockPostPostURL = urls.blockPostPostURL;
});

cy.login(); // WP
cy.mailchimpLoginIfNotAlreadyLoggedIn();

// Call mailchimpLists once and store the result in the alias 'mailchimpLists'
cy.getMailchimpLists().then((mailchimpLists) => {
Cypress.env('mailchimpLists', mailchimpLists); // Save globally
});
});

it('All lists from user\'s account populate the WP admin dropdown list', () => {
cy.visit('/wp-admin/admin.php?page=mailchimp_sf_options');
const $wpLists = cy.get('#mc_list_id'); // Lists from the WP admin dropdown
const mailchimpLists = Cypress.env('mailchimpLists');

// Verify that the same number of lists exist in the dropdown as in the Mailchimp account
$wpLists.should('have.length', mailchimpLists.length);

mailchimpLists.forEach((list) => {
// Verify that all Mailchimp account lists exist in dropdown
cy.get('#mc_list_id').should('contain', list.name);
});
});

it('Admin can see list and save it', () => {
cy.visit('/wp-admin/admin.php?page=mailchimp_sf_options');

// Verify that list can be saved
cy.get('.mc-h2').contains('Your Lists');
cy.get('#mc_list_id').select('10up');
cy.get('input[value="Update List"]').click();
cy.get('#mc-message .success_msg b').contains('Success!');

// Verify that the settings are visible if a list is saved
cy.get('input[value="Update Subscribe Form Settings"]').should('exist');
});

it('Admin that has never saved a list can not see the form on the front end', () => {
// Step 1: Log the user out of the current account (if logged in)
cy.visit('/wp-admin/admin.php?page=mailchimp_sf_options');
cy.mailchimpLogout();

// Verify the user is logged out
cy.get('#mailchimp_sf_oauth_connect').should('exist');

// Step 2: Log in with a test user account that has never saved a list
cy.mailchimpLogin(Cypress.env('MAILCHIMP_USERNAME_NO_LIST'), Cypress.env('MAILCHIMP_PASSWORD_NO_LIST'));
cy.visit('/wp-admin/admin.php?page=mailchimp_sf_options');

// Step 3: Verify no list is saved for the test user
cy.get('#mc_list_id').should('have.value', ''); // Assuming empty value indicates no list is saved

// Step 4: Verify there is no settings form if no list is saved
// If there are no Update Subscribe Form Settings buttons then we can assume no settings form is visible
cy.get('input[value="Update Subscribe Form Settings"]').should('not.exist');

// Step 5: Verify the signup form is not displayed on the frontend
cy.visit('/'); // Navigate to the frontend homepage
cy.get('#mc_signup').should('not.exist'); // Ensure the form does not exist

// Clean up
cy.mailchimpLogout();
cy.mailchimpLogin();
});
});
44 changes: 0 additions & 44 deletions tests/cypress/e2e/settings.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,50 +25,6 @@ describe('Admin can update plugin settings', () => {
});
});

it('All lists from user\'s account populate the WP admin dropdown list', () => {
cy.visit('/wp-admin/admin.php?page=mailchimp_sf_options');
const $wpLists = cy.get('#mc_list_id'); // Lists from the WP admin dropdown
const mailchimpLists = Cypress.env('mailchimpLists');

// Verify that the same number of lists exist in the dropdown as in the Mailchimp account
$wpLists.should('have.length', mailchimpLists.length);

mailchimpLists.forEach((list) => {
// Verify that all Mailchimp account lists exist in dropdown
cy.get('#mc_list_id').should('contain', list.name);
});
});

it('Admin can see list and save it', () => {
cy.visit('/wp-admin/admin.php?page=mailchimp_sf_options');

// Verify that list can be saved
cy.get('.mc-h2').contains('Your Lists');
cy.get('#mc_list_id').select('10up');
cy.get('input[value="Update List"]').click();
cy.get('#mc-message .success_msg b').contains('Success!');
});

it('Admin that has never saved a list can not see the form on the front end', () => {
// Step 1: Log the user out of the current account (if logged in)
cy.visit('/wp-admin/admin.php?page=mailchimp_sf_options');
cy.mailchimpLogout();

// Verify the user is logged out
cy.get('#mailchimp_sf_oauth_connect').should('exist');

// Step 2: Log in with a test user account that has never saved a list
cy.mailchimpLogin(Cypress.env('MAILCHIMP_USERNAME_NO_LIST'), Cypress.env('MAILCHIMP_PASSWORD_NO_LIST'));
cy.visit('/wp-admin/admin.php?page=mailchimp_sf_options');

// Verify no list is saved for the test user
cy.get('#mc_list_id').should('have.value', ''); // Assuming empty value indicates no list is saved

// Step 3: Verify the signup form is not displayed on the frontend
cy.visit('/'); // Navigate to the frontend homepage
cy.get('#mc_signup').should('not.exist'); // Ensure the form does not exist
});

// TODO: Default settings are populated as expected
it.skip('The default settings populate as expected', () => {
// Test here...
Expand Down

0 comments on commit 6a36ff9

Please sign in to comment.