From 7e1dcd41b4639e49d2e0294ae95c7ea645073738 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 20 Jan 2025 16:01:29 +0100 Subject: [PATCH] Bug 36025: Add cypress tests Signed-off-by: Magnus Enger Tests pass, with the followup patch. --- t/cypress/integration/PatronSearch_spec.ts | 116 +++++++++++++++++++++ t/cypress/support/e2e.js | 7 ++ 2 files changed, 123 insertions(+) create mode 100644 t/cypress/integration/PatronSearch_spec.ts diff --git a/t/cypress/integration/PatronSearch_spec.ts b/t/cypress/integration/PatronSearch_spec.ts new file mode 100644 index 0000000000..b706f1eb80 --- /dev/null +++ b/t/cypress/integration/PatronSearch_spec.ts @@ -0,0 +1,116 @@ +import { mount } from "@cypress/vue"; + +const RESTdefaultPageSize = "20"; // FIXME Mock this +const baseTotalCount = "42"; + +const ExtendedPatronAttributes = 42; + +const patron_attr_type = "attribute_type4TEST"; + +function cleanup() { + const sql = "DELETE FROM borrower_attribute_types WHERE code=?"; + cy.query(sql, patron_attr_type); +} +describe("ExtendedPatronAttributes", () => { + beforeEach(() => { + cleanup(); + cy.login(); + cy.title().should("eq", "Koha staff interface"); + cy.window().then(win => { + win.localStorage.clear(); + }); + cy.query( + "SELECT value FROM systempreferences WHERE variable='ExtendedPatronAttributes'" + ).then(value => { + cy.wrap(value).as("syspref_ExtendedPatronAttributes"); + }); + }); + + afterEach( + () => + function () { + cleanup(); + cy.set_syspref( + "ExtendedPatronAttributes", + this.syspref_ExtendedPatronAttributes + ); + } + ); + + const table_id = "memberresultst"; + + it("ExtendedPatronAttributes=0", () => { + cy.intercept("GET", "/api/v1/patrons*").as("searchPatrons"); + + cy.set_syspref("ExtendedPatronAttributes", 0).then(() => { + cy.visit("/cgi-bin/koha/members/members-home.pl"); + + cy.get("#search_patron_filter").type("something"); + cy.get("form.patron_search_form input[type='submit']").click(); + + cy.query( + "select count(*) as nb_searchable from borrower_attribute_types where staff_searchable=1" + ).then(result => { + const has_searchable = result[0].nb_searchable; + cy.wait("@searchPatrons").then(interception => { + const q = interception.request.query.q; + expect(q).to.not.match(/extended_attributes/); + }); + }); + + cy.query( + "INSERT INTO borrower_attribute_types(code, description, staff_searchable, searched_by_default) VALUES (?, 'only for tests', 1, 1)", + patron_attr_type + ).then(() => { + cy.visit("/cgi-bin/koha/members/members-home.pl"); + + cy.get("#search_patron_filter").type("something"); + cy.get("form.patron_search_form input[type='submit']").click(); + + cy.wait("@searchPatrons").then(interception => { + const q = interception.request.query.q; + expect(q).to.not.match(/extended_attributes/); + }); + }); + }); + }); + it("ExtendedPatronAttributes=1", () => { + cy.intercept("GET", "/api/v1/patrons*").as("searchPatrons"); + + cy.set_syspref("ExtendedPatronAttributes", 1).then(() => { + cy.visit("/cgi-bin/koha/members/members-home.pl"); + + cy.get("#search_patron_filter").type("something"); + cy.get("form.patron_search_form input[type='submit']").click(); + + cy.query( + "select count(*) as nb_searchable from borrower_attribute_types where staff_searchable=1 AND searched_by_default=1" + ).then(result => { + const has_searchable = result[0].nb_searchable; + cy.wait("@searchPatrons").then(interception => { + const q = interception.request.query.q; + if (has_searchable) { + expect(q).to.match(/extended_attributes/); + } else { + expect(q).to.not.match(/extended_attributes/); + } + }); + }); + + cy.query( + "INSERT INTO borrower_attribute_types(code, description, staff_searchable, searched_by_default) VALUES (?, 'only for tests', 1, 1)", + patron_attr_type + ).then(() => { + cy.visit("/cgi-bin/koha/members/members-home.pl"); + + cy.get("#search_patron_filter").type("something"); + cy.get("form.patron_search_form input[type='submit']").click(); + + cy.wait("@searchPatrons").then(interception => { + const q = interception.request.query.q; + expect(q).to.match(/extended_attributes/); + }); + }); + }); + }); +}); diff --git a/t/cypress/support/e2e.js b/t/cypress/support/e2e.js index 01e5c19bd7..ae5c10d019 100644 --- a/t/cypress/support/e2e.js +++ b/t/cypress/support/e2e.js @@ -1815,3 +1815,10 @@ cy.getSushiService = () => { const mysql = require("cypress-mysql"); mysql.addCommands(); + +Cypress.Commands.add('set_syspref', (variable, value) => { + cy.window().then(win => { + const client = win.APIClient.syspref; + return client.sysprefs.update(variable, value); + }); +}); -- 2.34.1