From 9d3586d8293db8a07dd4489498ef94d12c3e6b49 Mon Sep 17 00:00:00 2001 From: syl-p <50445384+syl-p@users.noreply.github.com> Date: Thu, 17 Jun 2021 18:03:34 +0200 Subject: [PATCH] Update cypress tests (#548) * fix: update workflows and command.js * fix: remove useless comments validation.spec.js * fix: add retries for cypress test * fix: merge 2 test * fix: add wait * fix: change retrie test * fix: use .then * fix: fix.then * fix: add focus_out * feat: add some condition to validation dpo * fix: remove condition and add class to selector * fix: replace input.DPOname by input[type=text] * feat: full rewrite validation test code * feat: change react time and selector * feat: change selector * feat: add more wait, and change order execute validation * feat: add separation for validation and refuse pia Co-authored-by: Timothee-Picard Co-authored-by: Sylvain Pastor --- .github/workflows/integration-tests.yml | 7 +- .../pia-angular/dpo_and_pia_refuse.spec.js | 37 ++++++ .../dpo_and_pia_validation.spec.js | 39 ++++++ .../pia-angular/validation.spec.js | 56 --------- cypress/support/commands.js | 118 ++++++++---------- 5 files changed, 132 insertions(+), 125 deletions(-) create mode 100644 cypress/integration/pia-angular/dpo_and_pia_refuse.spec.js create mode 100644 cypress/integration/pia-angular/dpo_and_pia_validation.spec.js delete mode 100644 cypress/integration/pia-angular/validation.spec.js diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml index 855a30e87..8274ac3f2 100644 --- a/.github/workflows/integration-tests.yml +++ b/.github/workflows/integration-tests.yml @@ -2,15 +2,16 @@ name: integration-tests on: [push] jobs: cypress-run: - runs-on: ubuntu-18.04 + runs-on: ubuntu-latest + container: cypress/browsers:node12.18.3-chrome87-ff82 steps: - name: Checkout - uses: actions/checkout@v1 + uses: actions/checkout@v2 - name: Cypress uses: cypress-io/github-action@v2 with: - start: npm start + start: yarn start browser: chrome headless: true wait-on: http://localhost:4200 diff --git a/cypress/integration/pia-angular/dpo_and_pia_refuse.spec.js b/cypress/integration/pia-angular/dpo_and_pia_refuse.spec.js new file mode 100644 index 000000000..a17ec8bf5 --- /dev/null +++ b/cypress/integration/pia-angular/dpo_and_pia_refuse.spec.js @@ -0,0 +1,37 @@ +describe("Validation", () => { + before(() => { + cy.init(); + }); + + beforeEach(() => { + // Skip tutorial + cy.disable_onboarding(); + }); + + context("Prepare data with import", () => { + // TODO: Import pia with .json + it("File Upload using cypress-file-upload package", () => { + cy.import_pia(); + }); + }); + + context("Refuse or ask pia signature", () => { + it( + "should refuse pia", + { + retries: { + runMode: 2, + openMode: 2 + } + }, + () => { + cy.get_current_pia_id(id => { + cy.go_edited_pia(id, 4, 3).then(() => { + cy.validateDPO(); + }); + cy.refusePia(); + }); + } + ); + }); +}); diff --git a/cypress/integration/pia-angular/dpo_and_pia_validation.spec.js b/cypress/integration/pia-angular/dpo_and_pia_validation.spec.js new file mode 100644 index 000000000..d984b6ddc --- /dev/null +++ b/cypress/integration/pia-angular/dpo_and_pia_validation.spec.js @@ -0,0 +1,39 @@ +describe("Validation", () => { + before(() => { + cy.init(); + }); + + beforeEach(() => { + // Skip tutorial + cy.disable_onboarding(); + }); + + context("Prepare data with import", () => { + // TODO: Import pia with .json + it("File Upload using cypress-file-upload package", () => { + cy.import_pia(); + }); + }); + + context("Avis du DPD et des personnes concernées", () => { + it("should complete DPD", () => { + cy.get_current_pia_id(id => { + cy.go_edited_pia(id, 4, 3).then(() => { + cy.validateDPO(); + }); + }); + }); + it("should valid pia", () => { + cy.validatePia(); + // cy.closeValidationEvaluationModal(); + }); + it("should show report", () => { + cy.closeValidationEvaluationModal(); + cy.get('.pia-previewBlock[href="#/preview/2"]').click(); + + cy.url().should("include", "/preview/2"); + + cy.get(".pia-fullPreviewBlock-data").should("exist"); + }); + }); +}); diff --git a/cypress/integration/pia-angular/validation.spec.js b/cypress/integration/pia-angular/validation.spec.js deleted file mode 100644 index f3ed05f73..000000000 --- a/cypress/integration/pia-angular/validation.spec.js +++ /dev/null @@ -1,56 +0,0 @@ -describe("Validation", () => { - before(() => { - cy.init(); - }); - - beforeEach(() => { - // Skip tutorial - cy.disable_onboarding(); - }); - - context("Prepare data with import", () => { - // TODO: Import pia with .json - it("File Upload using cypress-file-upload package", () => { - cy.import_pia(); - }); - }); - - context("Avis du DPD et des personnes concernées", () => { - it("should complete DPD", () => { - cy.get_current_pia_id(id => { - cy.go_edited_pia(id, 4, 3).then(() => { - // cy.validateDPO(); - }); - }); - }); - it("should valid pia", () => { - // cy.validatePia(); - // cy.closeValidationEvaluationModal(); - }); - // it("should show report", () => { - // cy.closeValidationEvaluationModal(); - // cy.get('.pia-previewBlock[href="#/preview/2"]').click(); - - // cy.url().should("include", "/preview/2"); - - // cy.get(".pia-fullPreviewBlock-data").should("exist"); - // }); - }); - - context("Refuse or ask pia signature", () => { - it("Upload file", () => { - cy.init(); - cy.disable_onboarding(); - cy.import_pia(); - }); - - // it("should refuse pia", () => { - // cy.get_current_pia_id(id => { - // cy.go_edited_pia(id, 4, 3).then(() => { - // cy.validateDPO(); - // }); - // cy.refusePia(); - // }); - // }); - }); -}); diff --git a/cypress/support/commands.js b/cypress/support/commands.js index a452ff448..9a9e69e76 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -70,7 +70,7 @@ Cypress.Commands.add("import_pia", () => { // Import cy.get('input[type="file"]#import_file').attachFile(filepath); - cy.wait(5000); + cy.wait(10000); // there is a new pia ? cy.get(".pia-cardsBlock.pia").should("have.length", 1); @@ -261,19 +261,19 @@ Cypress.Commands.add("acceptMultipleEval", () => { cy.get(".pia-evaluationBlock") .find(".btn-green") .each(($el, $index, $list) => { - cy.wait(2000); + cy.wait(500); cy.wrap($el) .click() .wait(250); }); - cy.wait(2000) + cy.wait(500) .get(".pia-entryContentBlock-footer") .find(".btn-green") .should("have.class", "btn-active") .click(); }); Cypress.Commands.add("closeCompletedValidationEvaluationModal", () => { - cy.wait(2000) + cy.wait(500) .get("#completed-evaluation") .invoke("show") .find("button") @@ -282,16 +282,16 @@ Cypress.Commands.add("closeCompletedValidationEvaluationModal", () => { .wait(500); }); Cypress.Commands.add("closeValidationEvaluationModal", () => { - cy.wait(2000) + cy.wait(1000) .get("#validate-evaluation") .invoke("show") .find(".pia-modalBlock-close") .first() .click() - .wait(2000); + .wait(1000); }); Cypress.Commands.add("validateModal", () => { - cy.wait(2000) + cy.wait(500) .get(".pia-modalBlock-content .btn.btn-green") .click() .wait(500); @@ -300,66 +300,48 @@ Cypress.Commands.add("redirectMeasureOnAcceptation", () => { cy.visit("/#/entry/2/section/3/item/3"); }); Cypress.Commands.add("validateDPO", () => { - cy.get(".pia-entryContentBlock-content-DPO").each(($el, $index, $list) => { - if (cy.wrap($el).find('input[type="text"]').length > 0) { - cy.wrap($el) - .find('input[type="text"]') - .first() - .type("DPO Pia", { force: true }); - } - if (cy.wrap($el).find('input[type="radio"]').length > 0) { - cy.wrap($el) - .find('input[type="radio"]') - .first() - .check({ force: true }); - } - cy.wrap($el) - .find("textarea") - .type( - "Nam tincidunt sem vel pretium scelerisque. Aliquam tincidunt commodo magna, vitae rutrum massa. Praesent lobortis porttitor gravida. Fusce nulla libero, feugiat eu sodales at, semper ac diam. Morbi sit amet luctus libero, eu sagittis neque", - { force: true } - ); - }); - cy.get(".pia-entryContentBlock-content-people").each(($el, $index, $list) => { - cy.wrap($el) - .find("form") - .first() - .find("label") - .first() - .click({ force: true }); - cy.wrap($el) - .find("form") - .last() - .find("input") - .first() - .type("DPO Pia", { force: true }); - cy.wrap($el) - .find("form") - .last() - .find("label") - .first() - .click({ force: true }); - cy.wrap($el) - .find("form") - .last() - .find("textarea") - .type( - "Nam tincidunt sem vel pretium scelerisque. Aliquam tincidunt commodo magna, vitae rutrum massa. Praesent lobortis porttitor gravida. Fusce nulla libero, feugiat eu sodales at, semper ac diam. Morbi sit amet luctus libero, eu sagittis neque", - { force: true } - ); - cy.wrap($el) + + // 1 block + const baseContentDPO = ".pia-entryContentBlock-content-DPO " + const reactTime = 1000 + cy.wait(reactTime) + cy.get(baseContentDPO + "input[type=text]").first().type("DPO Pia", { force: true }); + cy.get(baseContentDPO + ".pia-entryContentBlock-content-DPO-treatment label").first().click({ force: true }); + cy.get(baseContentDPO).find("textarea").type( + "Nam tincidunt sem vel pretium scelerisque. Aliquam tincidunt commodo magna, vitae rutrum massa. Praesent lobortis porttitor gravida. Fusce nulla libero, feugiat eu sodales at, semper ac diam. Morbi sit amet luctus libero, eu sagittis neque", + { force: true } + ); + cy.wait(reactTime) + + // 2 block + const baseContentPeople = ".pia-entryContentBlock-content-people " + cy.get(baseContentPeople + "label[for=concerned-people-choice-searched]").first().click({ force: true }); + + cy.wait(reactTime) + cy.wait(reactTime) + cy.get(baseContentPeople + "input.DPOName").first().type("DPO Pia", { force: true }); + + cy.wait(reactTime) + cy.get(baseContentPeople + "label[for=dpoAvis-1]").first().click({ force: true }); + + cy.wait(reactTime) + + cy.get(baseContentPeople + "textarea").type( + "Nam tincidunt sem vel pretium scelerisque. Aliquam tincidunt commodo magna, vitae rutrum massa. Praesent lobortis porttitor gravida. Fusce nulla libero, feugiat eu sodales at, semper ac diam. Morbi sit amet luctus libero, eu sagittis neque", + { force: true } + ); + cy.get(baseContentPeople) .find("form") .parent() .click({ force: true }); - }); }); Cypress.Commands.add("validatePia", () => { cy.get(".pia-validatePIABlock") .find(".btn-green") .should("have.class", "btn-active") .click(); - cy.wait(2000); - cy.get(".pia-entryContentBlock-content-list-confirm") + cy.wait(1000) + .get(".pia-entryContentBlock-content-list-confirm") .each(($el, $index, $list) => { cy.wrap($el) .find("label") @@ -380,7 +362,7 @@ Cypress.Commands.add("refusePia", () => { .find(".btn-green") .should("have.class", "btn-active") .click({ force: true }); - cy.wait(500) + cy.wait(1000) .get(".pia-entryContentBlock-content-list-confirm") .each(($el, $index, $list) => { cy.wrap($el) @@ -391,17 +373,21 @@ Cypress.Commands.add("refusePia", () => { cy.get(".btn-red") .first() .click(); - cy.wait(3000); + cy.wait(6000); cy.get(".pia-entryContentBlock-content-subject-textarea") .find("textarea", { force: true }) - .type( - "Nam tincidunt sem vel pretium scelerisque. Aliquam tincidunt commodo magna, vitae rutrum massa. Praesent lobortis porttitor gravida. Fusce nulla libero, feugiat eu sodales at, semper ac diam. Morbi sit amet luctus libero, eu sagittis neque", - { force: true } - ); + .then(() => { + cy.get(".pia-entryContentBlock-content-subject-textarea") + .find("textarea", { force: true }) + .type( + "Nam tincidunt sem vel pretium scelerisque. Aliquam tincidunt commodo magna, vitae rutrum massa. Praesent lobortis porttitor gravida. Fusce nulla libero, feugiat eu sodales at, semper ac diam. Morbi sit amet luctus libero, eu sagittis neque", + { force: true } + ); + }); cy.get(".pia-entryContentBlock-content-subject") - .wait(500) + .wait(1000) .click("bottom"); - cy.wait(500) + cy.wait(1000) .get(".pia-entryContentBlock-footer") .find("button") .last()