From e8137a2c945bdea6064aeacf68750ac1f8a0eea4 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 24 Aug 2026 09:39:05 +0200 Subject: [PATCH] Bug 42322: Add Cypress tests Signed-off-by: Pedro Amorim --- t/cypress/integration/Sidebar_spec.ts | 77 +++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 t/cypress/integration/Sidebar_spec.ts diff --git a/t/cypress/integration/Sidebar_spec.ts b/t/cypress/integration/Sidebar_spec.ts new file mode 100644 index 0000000000..7e9441729e --- /dev/null +++ b/t/cypress/integration/Sidebar_spec.ts @@ -0,0 +1,77 @@ +describe("Sidebar toggle", () => { + beforeEach(() => { + cy.login(); + cy.title().should("eq", "Koha staff interface"); + cy.task("insertSamplePatron").then(objects_patron => { + cy.wrap(objects_patron).as("objects_patron"); + }); + }); + + afterEach(function () { + cy.task("deleteSampleObjects", this.objects_patron); + }); + + it("Should display toggle button on patron detail page", function () { + const patron = this.objects_patron.patron; + cy.visit( + `/cgi-bin/koha/members/moremember.pl?borrowernumber=${patron.patron_id}` + ); + cy.get("#toggle-sidebar").should("be.visible"); + }); + + it("Should toggle sidebar collapsed state when button is clicked", function () { + const patron = this.objects_patron.patron; + cy.visit( + `/cgi-bin/koha/members/moremember.pl?borrowernumber=${patron.patron_id}` + ); + + // Sidebar should not be collapsed initially + cy.get("#sidebar-container").should("not.have.class", "collapsed"); + cy.get("#toggle-sidebar").should("have.attr", "aria-expanded", "true"); + + // Click the toggle button + cy.get("#toggle-sidebar").click(); + + // Sidebar should now be collapsed + cy.get("#sidebar-container").should("have.class", "collapsed"); + cy.get("#toggle-sidebar").should("have.attr", "aria-expanded", "false"); + + // Click again to expand + cy.get("#toggle-sidebar").click(); + + // Sidebar should be expanded again + cy.get("#sidebar-container").should("not.have.class", "collapsed"); + cy.get("#toggle-sidebar").should("have.attr", "aria-expanded", "true"); + }); + + it("Should update chevron icon when sidebar is toggled", function () { + const patron = this.objects_patron.patron; + cy.visit( + `/cgi-bin/koha/members/moremember.pl?borrowernumber=${patron.patron_id}` + ); + + // Initially should have chevron-left (expanded state) + cy.get("#toggle-sidebar i").should("have.class", "fa-chevron-left"); + cy.get("#toggle-sidebar i").should( + "not.have.class", + "fa-chevron-right" + ); + + // Click to collapse + cy.get("#toggle-sidebar").click(); + + // Should now have chevron-right (collapsed state) + cy.get("#toggle-sidebar i").should("have.class", "fa-chevron-right"); + cy.get("#toggle-sidebar i").should("not.have.class", "fa-chevron-left"); + + // Click again to expand + cy.get("#toggle-sidebar").click(); + + // Should have chevron-left again + cy.get("#toggle-sidebar i").should("have.class", "fa-chevron-left"); + cy.get("#toggle-sidebar i").should( + "not.have.class", + "fa-chevron-right" + ); + }); +});