From efd4102c2eadc941b8531f992abe55572d06f8e8 Mon Sep 17 00:00:00 2001 From: Matt Blenkinsop Date: Thu, 5 Jun 2025 10:04:15 +0100 Subject: [PATCH] Bug 40067: Add a cypress test --- .../integration/Acquisitions/Vendors_spec.ts | 71 ++----------------- t/cypress/integration/Toolbar_spec.ts | 34 +++++++++ t/cypress/support/e2e.js | 61 ++++++++++++++++ 3 files changed, 100 insertions(+), 66 deletions(-) create mode 100644 t/cypress/integration/Toolbar_spec.ts diff --git a/t/cypress/integration/Acquisitions/Vendors_spec.ts b/t/cypress/integration/Acquisitions/Vendors_spec.ts index 7935d40d4f6..b82e30f071e 100644 --- a/t/cypress/integration/Acquisitions/Vendors_spec.ts +++ b/t/cypress/integration/Acquisitions/Vendors_spec.ts @@ -1,64 +1,3 @@ -const getVendor = () => { - return { - accountnumber: "69823", - active: true, - address1: "6897 Library Rd", - address2: "Springfield, MA 44224", - address3: null, - address4: null, - aliases: [{ alias: "Test alias" }], - baskets: [], - baskets_count: 0, - contacts: [ - { - name: "Test contact", - position: "Test", - email: "test@email.com", - phone: "0123456789", - notes: "Some interesting notes", - altphone: "9876543210", - fax: "Who uses fax these days?", - acqprimary: false, - orderacquisition: false, - claimacquisition: false, - serialsprimary: false, - claimissues: false, - }, - ], - deliverytime: 3, - discount: 10, - external_id: "test1234", - fax: "555-555-9999", - gst: false, - id: 1, - interfaces: [ - { - type: "interface", - name: "fancy website", - uri: "www.uri.com", - login: "login", - password: "password", - account_email: "email@email.com", - notes: "This is a website", - }, - ], - invoice_currency: "USD", - invoice_includes_gst: false, - invoices_count: 0, - list_currency: "USD", - list_includes_gst: false, - name: "My Vendor", - notes: "Sample vendor", - phone: "555-555-5555", - postal: "567 Main St. PO Box 25 Springfield, MA 44224", - subscriptions: [], - subscriptions_count: 0, - tax_rate: 0.1965, - type: "Print books", - url: "https://koha-community.org/", - }; -}; - describe("Vendor CRUD operations", () => { beforeEach(() => { cy.login(); @@ -72,7 +11,7 @@ describe("Vendor CRUD operations", () => { cy.visit("/cgi-bin/koha/acquisition/vendors"); cy.get("#vendors_list").contains("There are no vendors defined"); - const vendor = getVendor(); + const vendor = cy.getVendor(); cy.intercept("GET", "/api/v1/acquisitions/vendors\?*", { statusCode: 200, body: [vendor], @@ -86,7 +25,7 @@ describe("Vendor CRUD operations", () => { }); it("should add a vendor", () => { - const vendor = getVendor(); + const vendor = cy.getVendor(); cy.intercept("GET", "/api/v1/acquisitions/vendors\?*", { statusCode: 200, @@ -180,7 +119,7 @@ describe("Vendor CRUD operations", () => { }); it("should edit a vendor", () => { - const vendor = getVendor(); + const vendor = cy.getVendor(); cy.intercept("GET", "/api/v1/acquisitions/vendors\?*", { statusCode: 200, @@ -219,7 +158,7 @@ describe("Vendor CRUD operations", () => { }); it("should show a vendor", () => { - const vendor = getVendor(); + const vendor = cy.getVendor(); // Click the "name" link from the list cy.intercept("GET", "/api/v1/acquisitions/vendors\?*", { @@ -249,7 +188,7 @@ describe("Vendor CRUD operations", () => { }); it("should delete a vendor", () => { - const vendor = getVendor(); + const vendor = cy.getVendor(); // Delete from list // Click the 'Delete' button from the list diff --git a/t/cypress/integration/Toolbar_spec.ts b/t/cypress/integration/Toolbar_spec.ts new file mode 100644 index 00000000000..0a4f3de0525 --- /dev/null +++ b/t/cypress/integration/Toolbar_spec.ts @@ -0,0 +1,34 @@ +describe("Sticky toolbar", () => { + beforeEach(() => { + cy.login(); + cy.title().should("eq", "Koha staff interface"); + }); + + it("Should open non-Vue links correctly in the same tab", () => { + const vendor = cy.getVendor(); + vendor.baskets_count = 1; + // Click the "name" link from the list + cy.intercept("GET", "/api/v1/acquisitions/vendors\?*", { + statusCode: 200, + body: [vendor], + headers: { + "X-Base-Total-Count": "1", + "X-Total-Count": "1", + }, + }); + cy.visit("/cgi-bin/koha/acquisition/vendors"); + cy.intercept( + "GET", + new RegExp("/api/v1/acquisitions/vendors/(?!config$).+"), + vendor + ).as("get-vendor"); + + const name_link = cy.get( + "#vendors_list table tbody tr:first td:first a" + ); + name_link.click(); + cy.wait(500); // Cypress is too fast! Vue hasn't populated the form yet! + cy.get("#toolbar a").contains("Receive shipments").click(); + cy.get("h1").contains("Receive shipment from vendor " + vendor.name); + }); +}); diff --git a/t/cypress/support/e2e.js b/t/cypress/support/e2e.js index b94cc0637af..e420889c3b5 100644 --- a/t/cypress/support/e2e.js +++ b/t/cypress/support/e2e.js @@ -1813,6 +1813,67 @@ cy.getSushiService = () => { }; }; +cy.getVendor = () => { + return { + accountnumber: "69823", + active: true, + address1: "6897 Library Rd", + address2: "Springfield, MA 44224", + address3: null, + address4: null, + aliases: [{ alias: "Test alias" }], + baskets: [], + baskets_count: 0, + contacts: [ + { + name: "Test contact", + position: "Test", + email: "test@email.com", + phone: "0123456789", + notes: "Some interesting notes", + altphone: "9876543210", + fax: "Who uses fax these days?", + acqprimary: false, + orderacquisition: false, + claimacquisition: false, + serialsprimary: false, + claimissues: false, + }, + ], + deliverytime: 3, + discount: 10, + external_id: "test1234", + fax: "555-555-9999", + gst: false, + id: 1, + interfaces: [ + { + type: "interface", + name: "fancy website", + uri: "www.uri.com", + login: "login", + password: "password", + account_email: "email@email.com", + notes: "This is a website", + }, + ], + invoice_currency: "USD", + invoice_includes_gst: false, + invoices_count: 0, + list_currency: "USD", + list_includes_gst: false, + name: "My Vendor", + notes: "Sample vendor", + phone: "555-555-5555", + postal: "567 Main St. PO Box 25 Springfield, MA 44224", + subscriptions: [], + subscriptions_count: 0, + tax_rate: 0.1965, + type: "Print books", + url: "https://koha-community.org/", + }; +}; + const mysql = require("cypress-mysql"); mysql.addCommands(); -- 2.48.1