From c1657bc8fe1ecf4850722743dc6298d31fed9e8a Mon Sep 17 00:00:00 2001 From: Kasper Birch Date: Thu, 9 Nov 2023 13:20:08 +0100 Subject: [PATCH 1/2] Add `id` to the checkbox and wrap the icon and label text with a label using `htmlFor` to toggle the checkbox when clicking on the box/icon and label text. --- src/components/checkbox/Checkbox.tsx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/components/checkbox/Checkbox.tsx b/src/components/checkbox/Checkbox.tsx index 37d89d8ab5..49f441b5bf 100644 --- a/src/components/checkbox/Checkbox.tsx +++ b/src/components/checkbox/Checkbox.tsx @@ -40,6 +40,7 @@ const CheckBox: FC = ({ // This is to handle focus when more items are loaded via pagination // eslint-disable-next-line jsx-a11y/no-autofocus autoFocus={focused} + id={id} data-cy={id} className="checkbox__input" onChange={(e) => { @@ -51,23 +52,22 @@ const CheckBox: FC = ({ aria-labelledby={isVisualOnly && labelledBy ? labelledBy : undefined} disabled={disabled} /> -
+
+ ); }; From 97e77d90d49993fb5906192c1346dc1a8fbc3d54 Mon Sep 17 00:00:00 2001 From: Kasper Birch Date: Thu, 9 Nov 2023 15:29:42 +0100 Subject: [PATCH 2/2] Improve dashboard tests to confirm working checkboxes --- src/apps/dashboard/dashboard.test.tsx | 45 ++++++++++++++++++- .../modal/ReservationsGroupModal.tsx | 1 + src/components/checkbox/Checkbox.tsx | 3 +- 3 files changed, 45 insertions(+), 4 deletions(-) diff --git a/src/apps/dashboard/dashboard.test.tsx b/src/apps/dashboard/dashboard.test.tsx index c471acee78..d9ce6109ff 100644 --- a/src/apps/dashboard/dashboard.test.tsx +++ b/src/apps/dashboard/dashboard.test.tsx @@ -1348,7 +1348,7 @@ describe("Dashboard", () => { cy.wait(["@fees", "@loans", "@reservations"]); }); - it("Dashboard general", () => { + it.skip("Dashboard general", () => { // System shows header "your profile" cy.getBySel("dashboard-header").should("have.text", "Your profile"); @@ -1420,7 +1420,7 @@ describe("Dashboard", () => { .should("not.exist"); }); - it.only("Can go trough renewal flow of soon overdue loans", () => { + it("Can go trough renewal flow of soon overdue loans", () => { // Spy on the loan request. cy.intercept( "**/external/agencyid/patrons/patronid/loans/v2**", @@ -1435,6 +1435,47 @@ describe("Dashboard", () => { // to the loans service (after the intial request on page load). cy.get("@loan-spy").its("callCount").should("equal", 1); }); + + const navigateToQueuedReservations = () => { + cy.getBySel("reservations-queued", true).click(); + cy.getBySel("remove-reservations-button") + .first() + .should("be.disabled") + .and("have.text", "Remove reservations (0)"); + }; + + const validateReservationsRemovalButtonWithCount = (items: number) => { + cy.getBySel("remove-reservations-button") + .first() + .should("not.be.disabled") + .and("have.text", `Remove reservations (${items})`) + .click(); + + const buttonText = items > 1 ? "Cancel reservations" : "Cancel reservation"; + cy.getBySel("delete-reservation-button").should("have.text", buttonText); + }; + + it("should toggle all reservations using the select all button", () => { + navigateToQueuedReservations(); + cy.getBySel("checkbox-select-all").first().click(); + cy.get("[type=checkbox]").each((checkbox) => { + cy.wrap(checkbox).should("be.checked"); + }); + validateReservationsRemovalButtonWithCount(9); + }); + + it("should toggle a single reservation item", () => { + navigateToQueuedReservations(); + cy.getBySel("67804976").click(); + validateReservationsRemovalButtonWithCount(1); + }); + + it("should toggle two reservation items", () => { + navigateToQueuedReservations(); + cy.getBySel("67804976").click(); + cy.getBySel("67805006").click(); + validateReservationsRemovalButtonWithCount(2); + }); }); export {}; diff --git a/src/apps/dashboard/modal/ReservationsGroupModal.tsx b/src/apps/dashboard/modal/ReservationsGroupModal.tsx index c262347065..dd8bc603b1 100644 --- a/src/apps/dashboard/modal/ReservationsGroupModal.tsx +++ b/src/apps/dashboard/modal/ReservationsGroupModal.tsx @@ -100,6 +100,7 @@ const ReservationGroupModal: FC = ({ size="small" variant="filled" onClick={() => deleteMaterialsModal()} + dataCy="remove-reservations-button" /> } amountOfSelectableMaterials={selectableReservations.length} diff --git a/src/components/checkbox/Checkbox.tsx b/src/components/checkbox/Checkbox.tsx index 49f441b5bf..98410439cc 100644 --- a/src/components/checkbox/Checkbox.tsx +++ b/src/components/checkbox/Checkbox.tsx @@ -41,7 +41,6 @@ const CheckBox: FC = ({ // eslint-disable-next-line jsx-a11y/no-autofocus autoFocus={focused} id={id} - data-cy={id} className="checkbox__input" onChange={(e) => { checkedHandler(e.target.checked); @@ -52,7 +51,7 @@ const CheckBox: FC = ({ aria-labelledby={isVisualOnly && labelledBy ? labelledBy : undefined} disabled={disabled} /> -