Bug 40430: Fix Toolbar_spec.ts

See comment 1 on the bug.

We are adding the capability to insert vendors and baskets.

Test plan:
Confirm that
  yarn cypress run t/cypress/integration/Toolbar_spec.ts
pass, even if you do not have any vendors in DB.

Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
(cherry picked from commit 250580016d)
Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de>
This commit is contained in:
Jonathan Druart 2025-07-17 14:48:34 +02:00 committed by Paul Derscheid
parent a63e3775ea
commit d13bdbe6d4
No known key found for this signature in database
GPG Key ID: C25F9FD44CED595B
2 changed files with 111 additions and 31 deletions

View File

@ -1,39 +1,9 @@
describe("Sticky toolbar", () => {
describe("Sticky toolbar - basic behavior", () => {
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",
},
}).as("get-vendors");
cy.intercept(
"GET",
new RegExp("/api/v1/acquisitions/vendors/(?!config$).+"),
vendor
).as("get-vendor");
cy.visit("/cgi-bin/koha/acquisition/vendors");
cy.wait("@get-vendors");
const name_link = cy.get(
"#vendors_list table tbody tr:first td:first a"
);
name_link.click();
cy.wait("@get-vendor");
cy.get("#toolbar a").contains("Receive shipments").click();
cy.get("h1").contains("Receive shipment from vendor " + vendor.name);
});
it("Should stick on scroll", () => {
cy.visit("/cgi-bin/koha/acqui/acqui-home.pl");
@ -46,3 +16,52 @@ describe("Sticky toolbar", () => {
cy.get("#toolbar").should("not.have.class", "floating");
});
});
describe("Sticky toolbar - vendors", () => {
beforeEach(() => {
cy.login();
cy.title().should("eq", "Koha staff interface");
cy.task("buildSampleObject", {
object: "vendor",
values: { active: 1 },
})
.then(generatedVendor => {
delete generatedVendor.list_currency;
delete generatedVendor.invoice_currency;
return cy.task("insertObject", {
type: "vendor",
object: generatedVendor,
});
})
.then(vendor => {
cy.wrap(vendor).as("vendor");
return cy.task("buildSampleObject", {
object: "basket",
values: { vendor_id: vendor.id },
});
})
.then(generatedBasket => {
return cy.task("insertObject", {
type: "basket",
object: generatedBasket,
});
})
.then(basket => {
cy.wrap(basket).as("basket");
});
});
afterEach(function () {
cy.task("deleteSampleObjects", [
{ vendor: this.vendor, basket: this.basket },
]);
});
it("Should open non-Vue links correctly in the same tab", function () {
cy.visit(`/cgi-bin/koha/acquisition/vendors/${this.vendor.id}`);
cy.get("#toolbar a").contains("Receive shipments").click();
cy.get("h1").contains(
`Receive shipment from vendor ${this.vendor.name}`
);
});
});

View File

@ -333,6 +333,8 @@ const deleteSampleObjects = async allObjects => {
hold: "holds",
checkout: "checkouts",
old_checkout: "old_checkouts",
basket: "baskets",
vendor: "vendors",
patron: "patrons",
item: "items",
biblio: "biblios",
@ -360,6 +362,8 @@ const deleteSampleObjects = async allObjects => {
"holds",
"checkouts",
"old_checkouts",
"baskets",
"vendors",
"patrons",
"items",
"biblios",
@ -431,6 +435,20 @@ const deleteSampleObjects = async allObjects => {
values: ids,
});
break;
case "baskets":
ids = objects.map(i => i.basket_id);
await query({
sql: `DELETE FROM aqbasket WHERE basketno IN (${ids.map(() => "?").join(",")})`,
values: ids,
});
break;
case "vendors":
ids = objects.map(i => i.id);
await query({
sql: `DELETE FROM aqbooksellers WHERE id IN (${ids.map(() => "?").join(",")})`,
values: ids,
});
break;
default:
throw Error(
`Not implemented yet: cannot deleted object '${type}'`
@ -544,6 +562,49 @@ const insertObject = async ({ type, object, baseUrl, authHeader }) => {
baseUrl,
authHeader,
});
} else if (type == "vendor") {
const {
id,
baskets_count,
invoices_count,
subscriptions_count,
external_id,
aliases,
baskets,
contacts,
contracts,
interfaces,
invoices,
...vendor
} = object;
let endpoint = "/api/v1/acquisitions/vendors";
return apiPost({
endpoint,
body: vendor,
baseUrl,
authHeader,
});
} else if (type == "basket") {
const keysToKeep = ["name", "vendor_id", "close_date"];
const basket = Object.fromEntries(
Object.entries(object).filter(([key]) => keysToKeep.includes(key))
);
return query({
sql: "INSERT INTO aqbasket(basketname, booksellerid, closedate) VALUES (?, ?, ?)",
values: [basket.name, basket.vendor_id, basket.close_date],
})
.then(result => {
const basket_id = result.insertId;
// FIXME We need /acquisitions/baskets/:basket_id
return apiGet({
endpoint: `/api/v1/acquisitions/baskets?q={"basket_id":"${basket_id}"}`,
baseUrl,
authHeader,
});
})
.then(baskets => baskets[0]);
} else {
throw Error(`Unsupported object type '${type}' to insert`);
}