diff --git a/assets/js/admin.js b/assets/js/admin.js index 68fb4ee..2a967bd 100644 --- a/assets/js/admin.js +++ b/assets/js/admin.js @@ -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; } diff --git a/tests/cypress/e2e/admin.test.js b/tests/cypress/e2e/admin.test.js index 65d5f4a..4d797f5 100644 --- a/tests/cypress/e2e/admin.test.js +++ b/tests/cypress/e2e/admin.test.js @@ -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.'); + }); });