From 58f17d81d3d5e5b7864a79b2e36dbd329f6ff1d0 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 12 Jun 2025 09:54:37 +0200 Subject: [PATCH] Bug 40127: Add a Cypress test Signed-off-by: David Nind --- .../integration/KohaTable/Holdings_spec.ts | 115 +++++++++++++++++- 1 file changed, 114 insertions(+), 1 deletion(-) diff --git a/t/cypress/integration/KohaTable/Holdings_spec.ts b/t/cypress/integration/KohaTable/Holdings_spec.ts index 25928874b1..5565366602 100644 --- a/t/cypress/integration/KohaTable/Holdings_spec.ts +++ b/t/cypress/integration/KohaTable/Holdings_spec.ts @@ -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.only("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"); + }); +}); -- 2.39.5