From 48b39533f6855e8966ce8704985fbb01d99ced51 Mon Sep 17 00:00:00 2001 From: Pedro Amorim Date: Fri, 24 Feb 2023 16:06:31 +0000 Subject: [PATCH] Bug 32991: Fix cypress tests. Added new test for when deleting from show view. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jonathan Druart Signed-off-by: Pedro Amorim Signed-off-by: Agustín Moyano Signed-off-by: Tomas Cohen Arazi --- t/cypress/integration/Agreements_spec.ts | 53 +++++++++++++++++--- t/cypress/integration/Licenses_spec.ts | 50 +++++++++++++++--- t/cypress/integration/Packages_spec.ts | 52 +++++++++++++++++-- t/cypress/integration/Titles_spec.ts | 64 ++++++++++++++++++++++-- 4 files changed, 196 insertions(+), 23 deletions(-) diff --git a/t/cypress/integration/Agreements_spec.ts b/t/cypress/integration/Agreements_spec.ts index d6b7ffcb30..b983545954 100644 --- a/t/cypress/integration/Agreements_spec.ts +++ b/t/cypress/integration/Agreements_spec.ts @@ -491,6 +491,7 @@ describe("Agreement CRUD operations", () => { let agreement = get_agreement(); let agreements = [agreement]; + // Delete from list // Click the 'Delete' button from the list cy.intercept("GET", "/api/v1/erm/agreements*", { statusCode: 200, @@ -506,27 +507,65 @@ describe("Agreement CRUD operations", () => { cy.get("#agreements_list table tbody tr:first") .contains("Delete") .click(); - cy.get("#agreements_confirm_delete h2").contains("Delete agreement"); - cy.contains("Agreement name: " + agreement.name); + cy.get(".dialog.alert.confirmation h1").contains("remove this agreement"); + cy.contains(agreement.name); - // Submit the form, get 500 + // Accept the confirmation dialog, get 500 cy.intercept("DELETE", "/api/v1/erm/agreements/*", { statusCode: 500, error: "Something went wrong", }); - cy.contains("Yes, delete").click(); + cy.contains("Accept").click(); cy.get("main div[class='dialog alert']").contains( "Something went wrong: Error: Internal Server Error" ); - // Submit the form, success! + // Accept the confirmation dialog, success! cy.intercept("DELETE", "/api/v1/erm/agreements/*", { statusCode: 204, body: null, }); + cy.get("#agreements_list table tbody tr:first") + .contains("Delete") + .click(); + cy.get(".dialog.alert.confirmation h1").contains("remove this agreement"); cy.contains("Yes, delete").click(); - cy.get("main div[class='dialog message']").contains( - "Agreement deleted" + cy.get("main div[class='dialog message']").contains("Agreement").contains("deleted"); + + // Delete from show + // Click the "name" link from the list + cy.intercept("GET", "/api/v1/erm/agreements*", { + statusCode: 200, + body: agreements, + headers: { + "X-Base-Total-Count": "1", + "X-Total-Count": "1", + }, + }); + cy.intercept("GET", "/api/v1/erm/agreements/*", agreement).as( + "get-agreement" ); + cy.visit("/cgi-bin/koha/erm/agreements"); + let name_link = cy.get( + "#agreements_list table tbody tr:first td:first a" + ); + name_link.should( + "have.text", + agreement.name + " (#" + agreement.agreement_id + ")" + ); + name_link.click(); + cy.wait("@get-agreement"); + cy.wait(500); // Cypress is too fast! Vue hasn't populated the form yet! + cy.get("#agreements_show h2").contains( + "Agreement #" + agreement.agreement_id + ); + + cy.get('#agreements_show .action_links .fa-trash').click(); + cy.get(".dialog.alert.confirmation h1").contains("remove this agreement"); + cy.contains("Yes, delete").click(); + cy.get("main div[class='dialog message']").contains("Agreement").contains("deleted"); + + //Make sure we return to list after deleting from show + cy.get("#agreements_list table tbody tr:first") }); }); diff --git a/t/cypress/integration/Licenses_spec.ts b/t/cypress/integration/Licenses_spec.ts index f825808138..628417aa18 100644 --- a/t/cypress/integration/Licenses_spec.ts +++ b/t/cypress/integration/Licenses_spec.ts @@ -253,10 +253,10 @@ describe("License CRUD operations", () => { cy.get("#licenses_list table tbody tr:first") .contains("Delete") .click(); - cy.get("#licenses_confirm_delete h2").contains("Delete license"); - cy.contains("License name: " + license.name); + cy.get(".dialog.alert.confirmation h1").contains("remove this license"); + cy.contains(license.name); - // Submit the form, get 500 + // Accept the confirmation dialog, get 500 cy.intercept("DELETE", "/api/v1/erm/licenses/*", { statusCode: 500, error: "Something went wrong", @@ -266,14 +266,52 @@ describe("License CRUD operations", () => { "Something went wrong: Error: Internal Server Error" ); - // Submit the form, success! + // Accept the confirmation dialog, success! cy.intercept("DELETE", "/api/v1/erm/licenses/*", { statusCode: 204, body: null, }); + cy.get("#licenses_list table tbody tr:first") + .contains("Delete") + .click(); + cy.get(".dialog.alert.confirmation h1").contains("remove this license"); cy.contains("Yes, delete").click(); - cy.get("main div[class='dialog message']").contains( - "License deleted" + cy.get("main div[class='dialog message']").contains("License").contains("deleted"); + + // Delete from show + // Click the "name" link from the list + cy.intercept("GET", "/api/v1/erm/licenses*", { + statusCode: 200, + body: licenses, + headers: { + "X-Base-Total-Count": "1", + "X-Total-Count": "1", + }, + }); + cy.intercept("GET", "/api/v1/erm/licenses/*", license).as( + "get-license" ); + cy.visit("/cgi-bin/koha/erm/licenses"); + let name_link = cy.get( + "#licenses_list table tbody tr:first td:first a" + ); + name_link.should( + "have.text", + license.name + " (#" + license.license_id + ")" + ); + name_link.click(); + cy.wait("@get-license"); + cy.wait(500); // Cypress is too fast! Vue hasn't populated the form yet! + cy.get("#licenses_show h2").contains( + "License #" + license.license_id + ); + + cy.get('#licenses_show .action_links .fa-trash').click(); + cy.get(".dialog.alert.confirmation h1").contains("remove this license"); + cy.contains("Yes, delete").click(); + cy.get("main div[class='dialog message']").contains("License").contains("deleted"); + + //Make sure we return to list after deleting from show + cy.get("#licenses_list table tbody tr:first") }); }); diff --git a/t/cypress/integration/Packages_spec.ts b/t/cypress/integration/Packages_spec.ts index 48689e9a0e..2fd7da3511 100644 --- a/t/cypress/integration/Packages_spec.ts +++ b/t/cypress/integration/Packages_spec.ts @@ -295,10 +295,10 @@ describe("Package CRUD operations", () => { cy.get("#packages_list table tbody tr:first") .contains("Delete") .click(); - cy.get("#packages_confirm_delete h2").contains("Delete package"); - cy.contains("Package name: " + erm_package.name); + cy.get(".dialog.alert.confirmation h1").contains("remove this package"); + cy.contains(erm_package.name); - // Submit the form, get 500 + // Accept the confirmation dialog, get 500 cy.intercept("DELETE", "/api/v1/erm/eholdings/local/packages/*", { statusCode: 500, error: "Something went wrong", @@ -308,12 +308,54 @@ describe("Package CRUD operations", () => { "Something went wrong: Error: Internal Server Error" ); - // Submit the form, success! + // Accept the confirmation dialog, success! cy.intercept("DELETE", "/api/v1/erm/eholdings/local/packages/*", { statusCode: 204, body: null, }); + cy.get("#packages_list table tbody tr:first") + .contains("Delete") + .click(); + cy.get(".dialog.alert.confirmation h1").contains("remove this package"); + cy.contains("Yes, delete").click(); + cy.get("main div[class='dialog message']").contains("Local package").contains("deleted"); + + // Delete from show + // Click the "name" link from the list + cy.intercept("GET", "/api/v1/erm/eholdings/local/packages*", { + statusCode: 200, + body: packages, + headers: { + "X-Base-Total-Count": "1", + "X-Total-Count": "1", + }, + }); + cy.intercept( + "GET", + "/api/v1/erm/eholdings/local/packages/*", + erm_package + ).as("get-package"); + cy.visit("/cgi-bin/koha/erm/eholdings/local/packages"); + let name_link = cy.get( + "#packages_list table tbody tr:first td:first a" + ); + name_link.should( + "have.text", + erm_package.name + " (#" + erm_package.package_id + ")" + ); + name_link.click(); + cy.wait("@get-package"); + cy.wait(500); // Cypress is too fast! Vue hasn't populated the form yet! + cy.get("#packages_show h2").contains( + "Package #" + erm_package.package_id + ); + + cy.get('#packages_show .action_links .fa-trash').click(); + cy.get(".dialog.alert.confirmation h1").contains("remove this package"); cy.contains("Yes, delete").click(); - cy.get("main div[class='dialog message']").contains("Package deleted"); + cy.get("main div[class='dialog message']").contains("Local package").contains("deleted"); + + //Make sure we return to list after deleting from show + cy.get("#packages_list table tbody tr:first") }); }); diff --git a/t/cypress/integration/Titles_spec.ts b/t/cypress/integration/Titles_spec.ts index 11fd825b29..c2deebdd44 100644 --- a/t/cypress/integration/Titles_spec.ts +++ b/t/cypress/integration/Titles_spec.ts @@ -428,10 +428,10 @@ describe("Title CRUD operations", () => { cy.get("#titles_list table tbody tr:first") .contains("Delete") .click(); - cy.get("#eholdings_confirm_delete h2").contains("Delete title"); - cy.contains("Title: " + erm_title.publication_title); + cy.get(".dialog.alert.confirmation h1").contains("remove this title"); + cy.contains(erm_title.publication_title); - // Submit the form, get 500 + // Accept the confirmation dialog, get 500 cy.intercept("DELETE", "/api/v1/erm/eholdings/local/titles/*", { statusCode: 500, error: "Something went wrong", @@ -441,12 +441,66 @@ describe("Title CRUD operations", () => { "Something went wrong: Error: Internal Server Error" ); - // Submit the form, success! + // Accept the confirmation dialog, success! cy.intercept("DELETE", "/api/v1/erm/eholdings/local/titles/*", { statusCode: 204, body: null, }); + cy.get("#titles_list table tbody tr:first") + .contains("Delete") + .click(); + cy.get(".dialog.alert.confirmation h1").contains("remove this title"); + cy.contains("Yes, delete").click(); + cy.get("main div[class='dialog message']").contains("Local title").contains("deleted"); + + // Delete from show + // Click the "name" link from the list + cy.intercept("GET", "/api/v1/erm/eholdings/local/titles*", { + statusCode: 200, + body: titles, + headers: { + "X-Base-Total-Count": "1", + "X-Total-Count": "1", + }, + }); + // Title with empty resources. + cy.intercept( + { + method: "GET", + url: "/api/v1/erm/eholdings/local/titles/*", + times: 1 + }, + { + body: { + publication_title: "publication title", + resources: [], + title_id: 1, + } + } + ).as("get-title"); + cy.visit("/cgi-bin/koha/erm/eholdings/local/titles"); + let title_link = cy.get( + "#titles_list table tbody tr:first td:first a" + ); + title_link.should( + "have.text", + erm_title.publication_title + " (#" + erm_title.title_id + ")" + ); + cy.get( + "#titles_list table tbody tr:first td:first a" + ).click(); + cy.wait("@get-title"); + cy.wait(500); // Cypress is too fast! Vue hasn't populated the form yet! + cy.get("#eholdings_title_show h2").contains( + "Title #" + erm_title.title_id + ); + + cy.get('#eholdings_title_show .action_links .fa-trash').click(); + cy.get(".dialog.alert.confirmation h1").contains("remove this title"); cy.contains("Yes, delete").click(); - cy.get("main div[class='dialog message']").contains("Title deleted"); + cy.get("main div[class='dialog message']").contains("Local title").contains("deleted"); + + //Make sure we return to list after deleting from show + cy.get("#titles_list table tbody tr:first") }); }); -- 2.39.5