|
| 1 | +/* eslint-disable no-undef */ |
| 2 | +describe('Form Templates Tests', () => { |
| 3 | + before(() => { |
| 4 | + cy.login(); |
| 5 | + cy.mailchimpLoginIfNotAlreadyLoggedIn(); |
| 6 | + cy.toggleMergeFields('check'); |
| 7 | + |
| 8 | + // Hide all interest groups |
| 9 | + cy.visit('/wp-admin/admin.php?page=mailchimp_sf_options'); |
| 10 | + cy.get('input[id^="mc_show_interest_groups_"]').uncheck(); |
| 11 | + cy.get('input[value="Update Subscribe Form Settings"]').first().click(); |
| 12 | + }); |
| 13 | + |
| 14 | + it('Admin should see the form templates in the block', () => { |
| 15 | + const postTitle = 'Mailchimp signup form - Form Templates'; |
| 16 | + const beforeSave = () => { |
| 17 | + cy.insertBlock('mailchimp/mailchimp', 'Mailchimp List Subscribe Form').then( |
| 18 | + (blockId) => { |
| 19 | + cy.getBlockEditor() |
| 20 | + .find(`#${blockId} ul.block-editor-block-variation-picker__variations li`) |
| 21 | + .should('have.length', 4); |
| 22 | + cy.getBlockEditor() |
| 23 | + .find( |
| 24 | + `#${blockId} ul li:nth-child(1) span.block-editor-block-variation-picker__variation-label`, |
| 25 | + ) |
| 26 | + .should('have.text', 'Quick Signup (Email Only)'); |
| 27 | + cy.getBlockEditor() |
| 28 | + .find( |
| 29 | + `#${blockId} ul li:nth-child(2) span.block-editor-block-variation-picker__variation-label`, |
| 30 | + ) |
| 31 | + .should('have.text', 'Personal Signup (Name and Email)'); |
| 32 | + cy.getBlockEditor() |
| 33 | + .find( |
| 34 | + `#${blockId} ul li:nth-child(3) span.block-editor-block-variation-picker__variation-label`, |
| 35 | + ) |
| 36 | + .should('have.text', 'Contact Form (Contact Details)'); |
| 37 | + cy.getBlockEditor() |
| 38 | + .find( |
| 39 | + `#${blockId} ul li:nth-child(4) span.block-editor-block-variation-picker__variation-label`, |
| 40 | + ) |
| 41 | + .should('have.text', 'Default Form (All Fields)'); |
| 42 | + }, |
| 43 | + ); |
| 44 | + cy.wait(500); |
| 45 | + }; |
| 46 | + cy.createPost({ title: postTitle, content: '', beforeSave }); |
| 47 | + }); |
| 48 | + |
| 49 | + const beforeSave = (variation) => { |
| 50 | + cy.insertBlock('mailchimp/mailchimp', 'Mailchimp List Subscribe Form').then((blockId) => { |
| 51 | + cy.getBlockEditor() |
| 52 | + .find( |
| 53 | + `#${blockId} ul.block-editor-block-variation-picker__variations li:nth-child(${variation})`, |
| 54 | + ) |
| 55 | + .click(); |
| 56 | + cy.getBlockEditor() |
| 57 | + .find('h2[aria-label="Enter a header (optional)"]') |
| 58 | + .should('be.visible'); |
| 59 | + }); |
| 60 | + cy.wait(500); |
| 61 | + }; |
| 62 | + |
| 63 | + it('Admin can select a form template (Quick Signup)', () => { |
| 64 | + const postTitle = 'Mailchimp signup form - Form Template 1'; |
| 65 | + |
| 66 | + cy.createPost({ title: postTitle, content: '', beforeSave: () => beforeSave(1) }).then( |
| 67 | + (postBlock) => { |
| 68 | + if (postBlock) { |
| 69 | + cy.visit(`/?p=${postBlock.id}`); |
| 70 | + cy.get('#mc_mv_EMAIL').should('exist'); |
| 71 | + cy.get('#mc_signup_submit').should('exist'); |
| 72 | + cy.get('#mc_mv_FNAME').should('not.exist'); |
| 73 | + cy.get('#mc_mv_LNAME').should('not.exist'); |
| 74 | + cy.get('#mc_mv_PHONE').should('not.exist'); |
| 75 | + } |
| 76 | + }, |
| 77 | + ); |
| 78 | + }); |
| 79 | + |
| 80 | + it('Admin can select a form template (Personal Signup)', () => { |
| 81 | + const postTitle = 'Mailchimp signup form - Form Template 2'; |
| 82 | + cy.createPost({ title: postTitle, content: '', beforeSave: () => beforeSave(2) }).then( |
| 83 | + (postBlock2) => { |
| 84 | + if (postBlock2) { |
| 85 | + cy.visit(`/?p=${postBlock2.id}`); |
| 86 | + cy.get('#mc_mv_EMAIL').should('exist'); |
| 87 | + cy.get('#mc_signup_submit').should('exist'); |
| 88 | + cy.get('#mc_mv_FNAME').should('exist'); |
| 89 | + cy.get('#mc_mv_LNAME').should('exist'); |
| 90 | + cy.get('input[id^="mc_mv_PHONE"]').should('not.exist'); |
| 91 | + } |
| 92 | + }, |
| 93 | + ); |
| 94 | + }); |
| 95 | + |
| 96 | + it('Admin can select a form template (Contact Form)', () => { |
| 97 | + const postTitle = 'Mailchimp signup form - Form Template 3'; |
| 98 | + cy.createPost({ title: postTitle, content: '', beforeSave: () => beforeSave(3) }).then( |
| 99 | + (postBlock3) => { |
| 100 | + if (postBlock3) { |
| 101 | + cy.visit(`/?p=${postBlock3.id}`); |
| 102 | + cy.get('#mc_mv_EMAIL').should('exist'); |
| 103 | + cy.get('#mc_signup_submit').should('exist'); |
| 104 | + cy.get('#mc_mv_FNAME').should('exist'); |
| 105 | + cy.get('#mc_mv_LNAME').should('exist'); |
| 106 | + cy.get('input[id^="mc_mv_PHONE"]').should('exist'); |
| 107 | + cy.get('#mc_mv_ADDRESS-addr1').should('exist'); |
| 108 | + cy.get('#mc_mv_ADDRESS-addr2').should('exist'); |
| 109 | + cy.get('#mc_mv_ADDRESS-city').should('exist'); |
| 110 | + } |
| 111 | + }, |
| 112 | + ); |
| 113 | + }); |
| 114 | + |
| 115 | + it('Admin can select a form template (Default Form)', () => { |
| 116 | + const postTitle = 'Mailchimp signup form - Form Template 4'; |
| 117 | + cy.createPost({ title: postTitle, content: '', beforeSave: () => beforeSave(4) }).then( |
| 118 | + (postBlock4) => { |
| 119 | + if (postBlock4) { |
| 120 | + cy.visit(`/?p=${postBlock4.id}`); |
| 121 | + cy.get('#mc_mv_EMAIL').should('exist'); |
| 122 | + cy.get('#mc_signup_submit').should('exist'); |
| 123 | + cy.get('#mc_mv_FNAME').should('exist'); |
| 124 | + cy.get('#mc_mv_LNAME').should('exist'); |
| 125 | + cy.get('input[id^="mc_mv_PHONE"]').should('exist'); |
| 126 | + cy.get('#mc_mv_COMPANY').should('exist'); |
| 127 | + cy.get('#mc_mv_ADDRESS-addr1').should('exist'); |
| 128 | + cy.get('#mc_mv_ADDRESS-addr2').should('exist'); |
| 129 | + } |
| 130 | + }, |
| 131 | + ); |
| 132 | + }); |
| 133 | +}); |
0 commit comments