From 61e8b6228115dff9abc89685bfdb37bbc550815e Mon Sep 17 00:00:00 2001 From: lauramekaj1 Date: Mon, 12 Aug 2024 21:45:31 +0200 Subject: [PATCH 1/4] validate elements and data of entries of submitted forms --- .../Entries/EntriesPageDataValidations.cy.js | 194 ++++++++++++++++++ .../e2e/Entries/doNotStoreEntries.cy.js | 57 ----- 2 files changed, 194 insertions(+), 57 deletions(-) create mode 100644 tests/cypress/e2e/Entries/EntriesPageDataValidations.cy.js delete mode 100644 tests/cypress/e2e/Entries/doNotStoreEntries.cy.js diff --git a/tests/cypress/e2e/Entries/EntriesPageDataValidations.cy.js b/tests/cypress/e2e/Entries/EntriesPageDataValidations.cy.js new file mode 100644 index 0000000000..fb0d8de29e --- /dev/null +++ b/tests/cypress/e2e/Entries/EntriesPageDataValidations.cy.js @@ -0,0 +1,194 @@ +describe("Entries submitted from a form", () => { + beforeEach(() => { + cy.login(); + cy.visit('/wp-admin/admin.php?page=formidable'); + cy.viewport(1280, 720); + }); + + it("should not be stored in the entry list", () => { + + cy.log("Create a blank form"); + cy.contains(".frm_nav_bar .button-primary", "Add New").click(); + cy.get(".frm-form-templates-grid-layout #frm-form-templates-create-form").should("contain", "Create a blank form").click(); + cy.get("#frm_submit_side_top", { timeout: 5000 }).should("contain", "Save").click(); + cy.get("#frm_new_form_name_input").type("Test Form"); + cy.get("#frm-save-form-name-button").should("contain", "Save").click(); + + cy.log(`Create a text field`); + cy.get(`li[id="text"] a[title="Text"]`).click({ force: true }); + + cy.log("Update form"); + cy.get('#frm_submit_side_top').should("contain", "Update").click(); + + cy.log("Go to Settings tab and enable the 'Do not store entries submitted from this form' option"); + cy.xpath("//ul[@class='frm_form_nav']//a[contains(text(),'Settings')]").should("contain", "Settings").click(); + cy.get(':nth-child(8) > .frm_inline_block').should("contain", "Do not store entries submitted from this form"); + cy.get('#no_save').check(); + cy.get('#frm_submit_side_top').should("contain", "Update").click(); + + cy.log("Submit form and verify entry is not stored"); + cy.get("#frm-previewDrop", { timeout: 5000 }).should("contain", "Preview").click(); + cy.get('.preview > .frm-dropdown-menu > :nth-child(1) > a').should("contain", "On Blank Page").invoke('removeAttr', 'target').click(); + cy.get('[id^="field_"]').filter('input, textarea').type("Entry is not stored"); + cy.get("button[type='submit']").should("contain", "Submit").click(); + cy.go(-2); + cy.get('.frm_form_nav > :nth-child(4) > a').should("contain", "Entries").click(); + cy.get('.wrap > h2').should("contain", "Form Entries"); + + cy.log("Check that the tip info text matches one of the expected messages"); + cy.get('.frm-tip-info').then(($el) => { + const text = $el.text().trim(); + + expect(text).to.be.oneOf([ + "Want to search submitted entries?", + "A site with dynamic, user-generated content is within reach.", + "Want to edit form submissions?", + "A site with dynamic, user-generated content is within reach.", + "Want to import entries into your forms?" + ]); + }) + + cy.log("Check that the upgrade text matches one of the expected messages"); + cy.get('.frm-tip-cta').then(($el) => { + const text = $el.text().trim(); + expect(text).to.be.oneOf([ + "Upgrade to Pro.", + "Add entry management.", + "A site with dynamic, user-generated content is within reach.", + "Display form data with Views." + ]); + }) + + cy.get('h3').should("contain", "This form is not set to save any entries."); + + cy.get('.frmcenter.frm_no_entries_form.frm_placeholder_block') + .should('exist') + .within(() => { + cy.get('h3').should('contain.text', 'This form is not set to save any entries.'); + + cy.get('p').should('contain.text', 'If you would like to save entries in this form, go to the'); + + cy.get('a') + .should('have.attr', 'href') + .and('match', /page=formidable&frm_action=settings&id=\d+/); + }); + + + cy.get('.frm_form_nav > :nth-child(1) > a').should("contain", "Build").click(); + cy.get("a[aria-label='Close']", { timeout: 5000 }).click({ force: true }); + cy.log("Verify that entries are not allowed from the forms list"); + cy.get('td[data-colname="Entries"] svg[data-original-title="Saving entries is disabled for this form"]').should("exist"); + + + }); + + it("should be stored and validated in the entry list", () => { + + cy.log("Create a blank form"); + cy.contains(".frm_nav_bar .button-primary", "Add New").click(); + cy.get(".frm-form-templates-grid-layout #frm-form-templates-create-form").should("contain", "Create a blank form").click(); + cy.get("#frm_submit_side_top", { timeout: 5000 }).should("contain", "Save").click(); + cy.get("#frm_new_form_name_input").type("Test Form"); + cy.get("#frm-save-form-name-button").should("contain", "Save").click(); + + cy.log(`Create a text field`); + cy.get(`li[id="text"] a[title="Text"]`).click({ force: true }); + + cy.log("Update form"); + cy.get('#frm_submit_side_top').should("contain", "Update").click(); + + cy.log("Submit form and verify entry is stored"); + cy.get("#frm-previewDrop", { timeout: 5000 }).should("contain", "Preview").click(); + cy.get('.preview > .frm-dropdown-menu > :nth-child(1) > a').should("contain", "On Blank Page").invoke('removeAttr', 'target').click(); + cy.get('[id^="field_"]').filter('input, textarea').type("Entry is stored"); + cy.get("button[type='submit']").should("contain", "Submit").click(); + cy.go(-2); + cy.get('.frm_form_nav > :nth-child(4) > a').should("contain", "Entries").click(); + cy.get('.wrap > h2').should("contain", "Form Entries"); + cy.get('.displaying-num').should("contain", "1 item"); + + cy.log("Verify column names in the entries forms page"); + cy.get('th[id$="_id"] > a').should("contain", "ID"); + cy.get('th[id$="_item_key"] > a').should("contain", "Entry Key"); + cy.get('th').contains('a', 'Text').should("contain", "Text"); + cy.get('th[id$="_is_draft"] > a').should("contain", "Entry Status"); + cy.get('th[id$="_created_at"] > a').should("contain", "Entry creation date"); + cy.get('th[id$="_updated_at"] > a').should("contain", "Entry update date"); + cy.get('th[id$="_ip"] > a').should("contain", "IP"); + + cy.get('a.row-title').should('exist'); + cy.get('td[data-colname="Entry Key"]').invoke('text').should('match', /^[a-zA-Z0-9]+$/); + cy.get("#the-list td[data-colname='Text']").should("contain", "Entry is stored"); + cy.get('.frm-meta-tag').should("contain", "Submitted"); + cy.get('td[data-colname="Entry creation date"] abbr') + .invoke('text') + .should('match', /^[A-Za-z]+ \d{1,2}, \d{4} at \d{1,2}:\d{2} (am|pm)$/); + + cy.get('td[data-colname="Entry update date"] abbr') + .invoke('text') + .should('match', /^[A-Za-z]+ \d{1,2}, \d{4} at \d{1,2}:\d{2} (am|pm)$/); + + cy.get('td[data-colname="Entry creation date"] abbr').invoke('text').then((creationDate) => { + cy.get('td[data-colname="Entry update date"] abbr').invoke('text').should('equal', creationDate); + }); + cy.get('td[data-colname="IP"]').should('contain', "127.0.0.1"); + + cy.log("Click on View"); + cy.get('tr').first().trigger('mouseover'); + cy.get('div.row-actions span.view a').should("contain", "View").click({ force: true }); + cy.url().should('include', 'frm_action=show&id='); + + cy.get('.hndle > :nth-child(1)').should("contain", "Entry"); + cy.get('.frm-odd > th').should("contain", "Text"); + cy.get('.frm-odd > td').should("contain", "Entry is stored"); + + cy.get('#frm-entry-show-empty-fields').should("contain", "Show empty fields").click(); + cy.get('.frm-empty-row > th').should("contain", "Submit"); + + cy.log("Check for entry actions elements"); + cy.get('.frm_no_print > h3').should("contain", "Entry Actions"); + cy.get('.frm_no_print > .inside > :nth-child(1)').should("contain", "Delete Entry"); + cy.get('.frm_no_print > .inside > :nth-child(2)').should("contain", "Print Entry"); + cy.get('.frm_no_print > .inside > :nth-child(3)').should("contain", "Resend Emails"); + cy.get('.frm_no_print > .inside > :nth-child(4)').should("contain", "Download as PDF"); + cy.get('.inside > :nth-child(5)').should("contain", "Edit Entry"); + + cy.log("Verify for entry details"); + cy.get(':nth-child(2) > h3').should("contain", "Entry Details"); + cy.get('#timestamp') + .invoke('text') + .should('match', /Submitted: [A-Za-z]{3} \d{1,2}, \d{4} @ \d{1,2}:\d{2}/); + cy.get(':nth-child(2) > .inside > :nth-child(2)').should("contain", "Entry ID:"); + cy.log('Extract and trim the value after "Entry Key:') + cy.get(':nth-child(2) > .inside > :nth-child(3)') + .invoke('text') + .then((text) => { + const keyValue = text.split(':')[1].trim(); + expect(keyValue).to.match(/^[a-zA-Z0-9]+$/); + }); + + cy.log("Verify for user information"); + cy.get(':nth-child(3) > h3').should("contain", "User Information"); + cy.get(':nth-child(3) > .inside > :nth-child(1)').should("contain", "Created by: admin"); + cy.get(':nth-child(3) > .inside > :nth-child(2)').should("contain", "IP Address:"); + cy.get(':nth-child(3) > .inside > :nth-child(3)').should("contain", "Browser/OS:"); + + cy.log("Delete entry"); + cy.get('a[href*="frm_action=destroy"] span.frm_link_label').should("contain", "Delete Entry").click(); + cy.get('.frm-confirm-msg').should("contain", "Delete this form entry?"); + cy.get('.frm-flex-box > .button-secondary').should("contain", "Cancel").click(); + cy.get('a[href*="frm_action=destroy"] span.frm_link_label').should("contain", "Delete Entry").click(); + cy.get('#frm-confirmed-click').should("contain", "Confirm").click(); + cy.log("Verify that entry has been deleted"); + cy.get('.frm_updated_message').should("contain", "Entry was successfully deleted"); + cy.get('.frm_no_entries_header').should("contain", "No Entries for form: Test Form"); + + cy.get('.frm_form_nav > :nth-child(1) > a').should("contain", "Build").click(); + cy.get("a[aria-label='Close']", { timeout: 5000 }).click({ force: true }); + }); + + afterEach(() => { + cy.log("Teardown - Delete form"); + cy.deleteForm(); + }); +}); diff --git a/tests/cypress/e2e/Entries/doNotStoreEntries.cy.js b/tests/cypress/e2e/Entries/doNotStoreEntries.cy.js deleted file mode 100644 index 3da425d9a2..0000000000 --- a/tests/cypress/e2e/Entries/doNotStoreEntries.cy.js +++ /dev/null @@ -1,57 +0,0 @@ -describe("Entries submitted from a form", () => { - beforeEach(() => { - cy.login(); - cy.visit('/wp-admin/admin.php?page=formidable'); - cy.viewport(1280, 720); - }); - - it("should not be stored in the entry list", () => { - - cy.log("Create a blank form"); - cy.contains(".frm_nav_bar .button-primary", "Add New").click(); - cy.get(".frm-form-templates-grid-layout #frm-form-templates-create-form").should("contain", "Create a blank form").click(); - cy.get("#frm_submit_side_top", { timeout: 5000 }).should("contain", "Save").click(); - cy.get("#frm_new_form_name_input").type("Test Form"); - cy.get("#frm-save-form-name-button").should("contain", "Save").click(); - - cy.log(`Create a text field`); - cy.get(`li[id="text"] a[title="Text"]`).click({ force: true }); - - cy.log("Update form"); - cy.get('#frm_submit_side_top').should("contain", "Update").click(); - - cy.log("Submit form and verify entry is stored"); - cy.get("#frm-previewDrop",{timeout:5000}).should("contain", "Preview").click(); - cy.get('.preview > .frm-dropdown-menu > :nth-child(1) > a').should("contain", "On Blank Page").invoke('removeAttr', 'target').click(); - cy.get('[id^="field_"]').filter('input, textarea').type("Entry is stored"); - cy.get("button[type='submit']").should("contain", "Submit").click(); - cy.go(-2); - cy.get('.frm_form_nav > :nth-child(4) > a').should("contain","Entries").click(); - cy.get('.wrap > h2').should("contain","Form Entries"); - cy.get("#the-list td[data-colname='Text']").should("contain","Entry is stored"); - cy.get('.frm-meta-tag',{timeout:5000}).should("contain","Submitted"); - - cy.log("Go to Settings tab and enable the 'Do not store entries submitted from this form' option"); - cy.xpath("//ul[@class='frm_form_nav']//a[contains(text(),'Settings')]").should("contain","Settings").click(); - cy.get(':nth-child(8) > .frm_inline_block').should("contain","Do not store entries submitted from this form"); - cy.get('#no_save').check(); - cy.get('#frm_submit_side_top').should("contain", "Update").click(); - - cy.log("Submit another form and verify entry is not stored"); - cy.get("#frm-previewDrop",{timeout:5000}).should("contain", "Preview").click(); - cy.get('.preview > .frm-dropdown-menu > :nth-child(1) > a').should("contain", "On Blank Page").invoke('removeAttr', 'target').click(); - cy.get('[id^="field_"]').filter('input, textarea').type("Entry is not stored"); - cy.get("button[type='submit']").should("contain", "Submit").click(); - cy.go(-2); - cy.get('.frm_form_nav > :nth-child(4) > a').should("contain","Entries").click(); - cy.get('.wrap > h2').should("contain","Form Entries"); - cy.get("#the-list td[data-colname='Text']").should("not.contain","Entry is not stored"); - cy.get('.displaying-num').should("contain", "1 item"); - - cy.log("Teardown - Close and delete form"); - cy.get('.frm_form_nav > :nth-child(1) > a').should("contain","Build").click(); - cy.get("a[aria-label='Close']", { timeout: 5000 }).click({ force: true }); - cy.deleteForm(); - }); - -}); From 0adda67d0178371c314b001dbc38d645ebb1e871 Mon Sep 17 00:00:00 2001 From: lauramekaj1 Date: Mon, 12 Aug 2024 22:44:13 +0200 Subject: [PATCH 2/4] update test --- tests/cypress/e2e/Entries/EntriesPageDataValidations.cy.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/cypress/e2e/Entries/EntriesPageDataValidations.cy.js b/tests/cypress/e2e/Entries/EntriesPageDataValidations.cy.js index fb0d8de29e..4e8eec875f 100644 --- a/tests/cypress/e2e/Entries/EntriesPageDataValidations.cy.js +++ b/tests/cypress/e2e/Entries/EntriesPageDataValidations.cy.js @@ -131,7 +131,7 @@ describe("Entries submitted from a form", () => { cy.get('td[data-colname="Entry creation date"] abbr').invoke('text').then((creationDate) => { cy.get('td[data-colname="Entry update date"] abbr').invoke('text').should('equal', creationDate); }); - cy.get('td[data-colname="IP"]').should('contain', "127.0.0.1"); + cy.get('td[data-colname="IP"]').should("exist"); cy.log("Click on View"); cy.get('tr').first().trigger('mouseover'); From fea9ad56c57fc907c93ac8e06fe1f7b8bda4bf3d Mon Sep 17 00:00:00 2001 From: lauramekaj1 Date: Mon, 12 Aug 2024 23:05:53 +0200 Subject: [PATCH 3/4] fix mousover on element --- .../e2e/Entries/EntriesPageDataValidations.cy.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tests/cypress/e2e/Entries/EntriesPageDataValidations.cy.js b/tests/cypress/e2e/Entries/EntriesPageDataValidations.cy.js index 4e8eec875f..dc57dcd000 100644 --- a/tests/cypress/e2e/Entries/EntriesPageDataValidations.cy.js +++ b/tests/cypress/e2e/Entries/EntriesPageDataValidations.cy.js @@ -134,8 +134,13 @@ describe("Entries submitted from a form", () => { cy.get('td[data-colname="IP"]').should("exist"); cy.log("Click on View"); - cy.get('tr').first().trigger('mouseover'); - cy.get('div.row-actions span.view a').should("contain", "View").click({ force: true }); + cy.get('tr').first().trigger('mouseover', { force: true }); + cy.wait(500); + cy.get('div.row-actions span.view a') + .should('be.visible') + .and('contain', 'View') + .click({ force: true }); + cy.url().should('include', 'frm_action=show&id='); cy.get('.hndle > :nth-child(1)').should("contain", "Entry"); @@ -143,7 +148,7 @@ describe("Entries submitted from a form", () => { cy.get('.frm-odd > td').should("contain", "Entry is stored"); cy.get('#frm-entry-show-empty-fields').should("contain", "Show empty fields").click(); - cy.get('.frm-empty-row > th').should("contain", "Submit"); + cy.get('.frm-empty-row > th',{timeout:5000}).should("contain", "Submit"); cy.log("Check for entry actions elements"); cy.get('.frm_no_print > h3').should("contain", "Entry Actions"); From 45c5934ede1b31534906406adcedbd3a2a3f3128 Mon Sep 17 00:00:00 2001 From: lauramekaj1 Date: Mon, 12 Aug 2024 23:28:20 +0200 Subject: [PATCH 4/4] remove arbitrary wait and fix test --- .../e2e/Entries/EntriesPageDataValidations.cy.js | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/tests/cypress/e2e/Entries/EntriesPageDataValidations.cy.js b/tests/cypress/e2e/Entries/EntriesPageDataValidations.cy.js index dc57dcd000..3c9acec379 100644 --- a/tests/cypress/e2e/Entries/EntriesPageDataValidations.cy.js +++ b/tests/cypress/e2e/Entries/EntriesPageDataValidations.cy.js @@ -134,21 +134,17 @@ describe("Entries submitted from a form", () => { cy.get('td[data-colname="IP"]').should("exist"); cy.log("Click on View"); - cy.get('tr').first().trigger('mouseover', { force: true }); - cy.wait(500); - cy.get('div.row-actions span.view a') - .should('be.visible') - .and('contain', 'View') - .click({ force: true }); - + cy.get('tr div.row-actions span.view a', { timeout: 5000 }) + .should("contain", "View") + .click({ force: true }); + cy.url().should('include', 'frm_action=show&id='); cy.get('.hndle > :nth-child(1)').should("contain", "Entry"); cy.get('.frm-odd > th').should("contain", "Text"); cy.get('.frm-odd > td').should("contain", "Entry is stored"); - cy.get('#frm-entry-show-empty-fields').should("contain", "Show empty fields").click(); - cy.get('.frm-empty-row > th',{timeout:5000}).should("contain", "Submit"); + cy.get('#frm-entry-show-empty-fields').should("contain", "Show empty fields"); cy.log("Check for entry actions elements"); cy.get('.frm_no_print > h3').should("contain", "Entry Actions");