Skip to content

Commit

Permalink
Add basic E2E tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
iamdharmesh committed Aug 21, 2024
1 parent 316b214 commit f57605f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion assets/js/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@

if (input.name === 'email') {
if (!input.value.includes('@') || !input.value.includes('.'))
return params.invalid_email;
return params.invalid_email_error;
if (input.value !== $('#mailchimp-sf-profile-details input#confirm_email').val())
return params.confirm_email_match;
}
Expand Down
38 changes: 38 additions & 0 deletions tests/cypress/e2e/admin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,42 @@ describe('Admin can login and make sure plugin is activated', () => {
cy.get('#adminmenu li#toplevel_page_mailchimp_sf_options').click();
cy.get('#wpbody .mailchimp-header h1').contains('Mailchimp List Subscribe Form');
});

it('Admin can see "Create account" button and Can visit "Create account" settings page.', () => {
cy.visit('/wp-admin/admin.php?page=mailchimp_sf_options');

// Check Create account button.
cy.get('#mailchimp_sf_create_account_button').should('be.visible');
cy.get('#mailchimp_sf_create_account_button').contains('Create account');

cy.get('#mailchimp_sf_create_account_button').click();
cy.get('#mailchimp-sf-create-account .title').contains('Confirm your information');
cy.get('#mailchimp-sf-create-activate-account').should('be.visible');
});

it("Admin shouldn't able to submit create account form with invalid data", () => {
cy.visit('/wp-admin/admin.php?page=mailchimp_sf_create_account');

// Submit form without filling any data.
cy.get('#mailchimp-sf-create-activate-account').click();

// Check error messages.
cy.get('#mailchimp-sf-first_name-error').contains("First name can't be blank.");
cy.get('#mailchimp-sf-last_name-error').contains("Last name can't be blank.");
cy.get('#mailchimp-sf-email-error').contains(
'Email confirmation must match confirmation email.',
);
cy.get('#mailchimp-sf-confirm_email-error').contains(
'Email confirmation must match the field above.',
);
cy.get('#mailchimp-sf-address-error').contains("Address line 1 can't be blank.");
cy.get('#mailchimp-sf-city-error').contains("City can't be blank.");
cy.get('#mailchimp-sf-state-error').contains("State can't be blank.");
cy.get('#mailchimp-sf-zip-error').contains("Zip can't be blank.");

cy.get('#email').clear().type('test');
cy.get('#confirm_email').clear().type('test');
cy.get('#mailchimp-sf-create-activate-account').click();
cy.get('#mailchimp-sf-email-error').contains('Insert correct email.');
});
});

0 comments on commit f57605f

Please sign in to comment.