From 23744e7ef1851bb1379438db51994e4aa5501233 Mon Sep 17 00:00:00 2001 From: Pedro Amorim Date: Wed, 6 Sep 2023 15:34:07 +0000 Subject: [PATCH] Bug 33480: (QA follow-up) Add cypress tests: Add tests for vendor aliases Test plan: perl /kohadevbox/misc4dev/run_tests.pl --run-cypress-tests-only Signed-off-by: Tomas Cohen Arazi --- t/cypress/integration/ERM/Agreements_spec.ts | 24 ++++++++++++++++---- t/cypress/integration/ERM/Licenses_spec.ts | 23 +++++++++++++++---- t/cypress/support/e2e.js | 4 +++- 3 files changed, 42 insertions(+), 9 deletions(-) diff --git a/t/cypress/integration/ERM/Agreements_spec.ts b/t/cypress/integration/ERM/Agreements_spec.ts index f743d8b193..650768affc 100644 --- a/t/cypress/integration/ERM/Agreements_spec.ts +++ b/t/cypress/integration/ERM/Agreements_spec.ts @@ -242,6 +242,8 @@ describe("Agreement CRUD operations", () => { }); it("Add agreement", () => { + let agreement = get_agreement(); + let vendors = cy.get_vendors_to_relate(); // No agreement, no license yet cy.intercept("GET", "/api/v1/erm/agreements*", { statusCode: 200, @@ -251,6 +253,11 @@ describe("Agreement CRUD operations", () => { statusCode: 200, body: [], }); + //Intercept vendors request + cy.intercept("GET", "/api/v1/acquisitions/vendors*", { + statusCode: 200, + body: vendors, + }); // Click the button in the toolbar cy.visit("/cgi-bin/koha/erm/agreements"); @@ -259,9 +266,6 @@ describe("Agreement CRUD operations", () => { cy.left_menu_active_item_is("Agreements"); // Fill in the form for normal attributes - let agreement = get_agreement(); - let vendors = cy.get_vendors_to_relate(); - cy.get("#agreements_add").contains("Submit").click(); cy.get("input:invalid,textarea:invalid,select:invalid").should( "have.length", @@ -288,6 +292,11 @@ describe("Agreement CRUD operations", () => { ); cy.get("#agreement_vendor_id .vs__selected").contains(vendors[0].name); + // vendor aliases + cy.get("#agreement_vendor_id .vs__search").click(); + cy.get("#agreement_vendor_id #vs1__option-1").contains(vendors[1].name); + cy.get("#agreement_vendor_id #vs1__option-1 cite").contains(vendors[1].aliases[0].alias); + cy.contains("Add new period").click(); cy.get("#agreements_add").contains("Submit").click(); cy.get("input:invalid,textarea:invalid,select:invalid").should( @@ -460,7 +469,7 @@ describe("Agreement CRUD operations", () => { let vendors = cy.get_vendors_to_relate(); // Intercept vendors request - cy.intercept("GET", "/api/v1/acquisitions/vendors?_per_page=-1", { + cy.intercept("GET", "/api/v1/acquisitions/vendors*", { statusCode: 200, body: vendors, }).as("get-vendor-options"); @@ -520,6 +529,8 @@ describe("Agreement CRUD operations", () => { agreements[0].description ); cy.get("#agreement_status .vs__selected").contains("Active"); + + //vendors cy.get("#agreement_vendor_id .vs__selected").contains( agreement.vendor[0].name ); @@ -529,6 +540,11 @@ describe("Agreement CRUD operations", () => { { force: true } ); + //vendor aliases + cy.get("#agreement_vendor_id .vs__search").click(); + cy.get("#agreement_vendor_id #vs1__option-1").contains(vendors[1].name); + cy.get("#agreement_vendor_id #vs1__option-1 cite").contains(vendors[1].aliases[0].alias); + cy.get("#agreement_is_perpetual_no").should("be.checked"); cy.get("#started_on_0").invoke("val").should("eq", dates["today_iso"]); cy.get("#ended_on_0").invoke("val").should("eq", dates["tomorrow_iso"]); diff --git a/t/cypress/integration/ERM/Licenses_spec.ts b/t/cypress/integration/ERM/Licenses_spec.ts index 8b53c13ae4..95de03c469 100644 --- a/t/cypress/integration/ERM/Licenses_spec.ts +++ b/t/cypress/integration/ERM/Licenses_spec.ts @@ -80,6 +80,13 @@ describe("License CRUD operations", () => { }); it("Add license", () => { + let license = get_license(); + let vendors = cy.get_vendors_to_relate(); + //Intercept vendors request + cy.intercept("GET", "/api/v1/acquisitions/vendors*", { + statusCode: 200, + body: vendors, + }); // Click the button in the toolbar cy.visit("/cgi-bin/koha/erm/licenses"); cy.contains("New license").click(); @@ -87,9 +94,6 @@ describe("License CRUD operations", () => { cy.left_menu_active_item_is("Licenses"); // Fill in the form for normal attributes - let license = get_license(); - let vendors = cy.get_vendors_to_relate(); - cy.get("#licenses_add").contains("Submit").click(); cy.get("input:invalid,textarea:invalid,select:invalid").should( "have.length", @@ -108,6 +112,11 @@ describe("License CRUD operations", () => { // vendors cy.get("#license_vendor_id .vs__selected").should("not.exist"); //no vendor pre-selected for new license + // vendor aliases + cy.get("#license_vendor_id .vs__search").click(); + cy.get("#license_vendor_id #vs1__option-1").contains(vendors[1].name); + cy.get("#license_vendor_id #vs1__option-1 cite").contains(vendors[1].aliases[0].alias); + cy.get("#license_vendor_id .vs__search").type( vendors[0].name + "{enter}", { force: true } @@ -168,7 +177,7 @@ describe("License CRUD operations", () => { let vendors = cy.get_vendors_to_relate(); // Intercept vendors request - cy.intercept("GET", "/api/v1/acquisitions/vendors?_per_page=-1", { + cy.intercept("GET", "/api/v1/acquisitions/vendors*", { statusCode: 200, body: vendors, }).as("get-vendor-options"); @@ -195,6 +204,7 @@ describe("License CRUD operations", () => { // Form has been correctly filled in cy.get("#license_name").should("have.value", license.name); + //vendors cy.get("#license_vendor_id .vs__selected").contains( license.vendor[0].name ); @@ -204,6 +214,11 @@ describe("License CRUD operations", () => { { force: true } ); + //vendor aliases + cy.get("#license_vendor_id .vs__search").click(); + cy.get("#license_vendor_id #vs1__option-1").contains(vendors[1].name); + cy.get("#license_vendor_id #vs1__option-1 cite").contains(vendors[1].aliases[0].alias); + cy.get("#license_description").should( "have.value", license.description diff --git a/t/cypress/support/e2e.js b/t/cypress/support/e2e.js index a936f91537..0dbffe9ac8 100644 --- a/t/cypress/support/e2e.js +++ b/t/cypress/support/e2e.js @@ -123,7 +123,9 @@ cy.get_vendors_to_relate = () => { { "id": 2, "name": "My Vendor 2", - "aliases": [], + "aliases": [ + {"alias": "alias", alias_id: 1, vendor_id: 2} + ], } ] } -- 2.39.5