Bug 40127: Add a Cypress test

Signed-off-by: David Nind <david@davidnind.com>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
(cherry picked from commit 90c2a53b99)
Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de>
This commit is contained in:
Jonathan Druart 2025-06-12 09:54:37 +02:00 committed by Paul Derscheid
parent ce72073ff5
commit 27292c9ea2
No known key found for this signature in database
GPG Key ID: C25F9FD44CED595B
1 changed files with 114 additions and 1 deletions

View File

@ -1,7 +1,7 @@
const RESTdefaultPageSize = "20"; // FIXME Mock this
const baseTotalCount = "42";
describe("catalogue/detail/holdings_table", () => {
describe("catalogue/detail/holdings_table with items", () => {
const table_id = "holdings_table";
beforeEach(() => {
cy.login();
@ -409,3 +409,116 @@ describe("catalogue/detail/holdings_table", () => {
});
});
});
describe("catalogue/detail/holdings_table without items", () => {
const table_id = "holdings_table";
beforeEach(() => {
cy.login();
cy.title().should("eq", "Koha staff interface");
cy.window().then(win => {
win.localStorage.clear();
});
// FIXME All the following code should not be reused as it
// It must be moved to a Cypress command or task "buildSampleBiblio" or even "insertSampleBiblio"
let generated_objects = {};
const objects = [{ object: "library" }, { object: "item_type" }];
cy.wrap(Promise.resolve())
.then(() => {
return objects.reduce((chain, { object }) => {
return chain.then(() => {
return cy
.task("buildSampleObject", { object })
.then(attributes => {
generated_objects[object] = attributes;
});
});
}, Promise.resolve());
})
.then(() => {
const item_type = generated_objects["item_type"];
const queries = [
{
query: "INSERT INTO itemtypes(itemtype, description) VALUES (?, ?)",
values: [item_type.item_type_id, item_type.description],
},
];
cy.wrap(Promise.resolve())
.then(() => {
return queries.reduce((chain, { query, values }) => {
return chain.then(() => cy.query(query, values));
}, Promise.resolve());
})
.then(() => {
let biblio = {
leader: " nam a22 7a 4500",
fields: [
{ "005": "20250120101920.0" },
{
"245": {
ind1: "",
ind2: "",
subfields: [{ a: "Some boring read" }],
},
},
{
"100": {
ind1: "",
ind2: "",
subfields: [
{ c: "Some boring author" },
],
},
},
{
"942": {
ind1: "",
ind2: "",
subfields: [
{ c: item_type.item_type_id },
],
},
},
],
};
cy.request({
method: "POST",
url: "/api/v1/biblios",
headers: {
"Content-Type": "application/marc-in-json",
"x-confirm-not-duplicate": 1,
},
body: biblio,
}).then(response => {
const biblio_id = response.body.id;
cy.wrap(biblio_id).as("biblio_id");
});
});
});
cy.query(
"SELECT value FROM systempreferences WHERE variable='AlwaysShowHoldingsTableFilters'"
).then(value => {
cy.wrap(value).as("syspref_AlwaysShowHoldingsTableFilters");
});
});
afterEach(
() =>
function () {
cleanup();
cy.set_syspref(
"AlwaysShowHoldingsTableFilters",
this.syspref_AlwaysShowHoldingsTableFilters
);
}
);
it("Do not display the table", function () {
// Do not use `() => {` or this.biblio_id won't be retrieved
const biblio_id = this.biblio_id;
cy.visit("/cgi-bin/koha/catalogue/detail.pl?biblionumber=" + biblio_id);
cy.get(`#${table_id}_wrapper`).should("not.exist");
});
});