Bugzilla – Attachment 182637 Details for
Bug 39916
The 'Place booking' modal should have cypress tests
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 39916: WIP Cypress tests for the bookings modal
Bug-39916-WIP-Cypress-tests-for-the-bookings-modal.patch (text/plain), 30.44 KB, created by
Martin Renvoize (ashimema)
on 2025-05-19 18:06:31 UTC
(
hide
)
Description:
Bug 39916: WIP Cypress tests for the bookings modal
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2025-05-19 18:06:31 UTC
Size:
30.44 KB
patch
obsolete
>From cbeb17cb38bafa1324eee8f6aa1e6337818d71d1 Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@openfifth.co.uk> >Date: Fri, 16 May 2025 11:36:47 +0100 >Subject: [PATCH] Bug 39916: WIP Cypress tests for the bookings modal > >Lots of passing tests :) >--- > .../prog/js/modals/place_booking.js | 84 ++-- > .../fixtures/bookings/bookable_items.json | 29 ++ > t/cypress/fixtures/bookings/bookings.json | 32 ++ > t/cypress/fixtures/bookings/checkouts.json | 9 + > .../fixtures/bookings/circulation_rules.json | 9 + > t/cypress/fixtures/bookings/patron.json | 12 + > .../fixtures/bookings/pickup_locations.json | 20 + > .../integration/Biblio/bookingsModal_spec.ts | 469 ++++++++++++++++++ > 8 files changed, 622 insertions(+), 42 deletions(-) > create mode 100644 t/cypress/fixtures/bookings/bookable_items.json > create mode 100644 t/cypress/fixtures/bookings/bookings.json > create mode 100644 t/cypress/fixtures/bookings/checkouts.json > create mode 100644 t/cypress/fixtures/bookings/circulation_rules.json > create mode 100644 t/cypress/fixtures/bookings/patron.json > create mode 100644 t/cypress/fixtures/bookings/pickup_locations.json > create mode 100644 t/cypress/integration/Biblio/bookingsModal_spec.ts > >diff --git a/koha-tmpl/intranet-tmpl/prog/js/modals/place_booking.js b/koha-tmpl/intranet-tmpl/prog/js/modals/place_booking.js >index 634cce0c36e..8c579b7a4fe 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/modals/place_booking.js >+++ b/koha-tmpl/intranet-tmpl/prog/js/modals/place_booking.js >@@ -93,29 +93,29 @@ $("#placeBookingModal").on("show.bs.modal", function (e) { > let $patron = $("<span></span>") > .append( > "" + >- (patron.surname >- ? escape_str(patron.surname) + ", " >- : "") + >- (patron.firstname >- ? escape_str(patron.firstname) + " " >- : "") + >- (patron.cardnumber >- ? " (" + escape_str(patron.cardnumber) + ")" >- : "") + >- "<small>" + >- (patron.date_of_birth >- ? ' <span class="age_years">' + >- $get_age(patron.date_of_birth) + >- " " + >- __("years") + >- "</span>" >- : "") + >- (patron.library >- ? ' <span class="ac-library">' + >- escape_str(patron.library.name) + >- "</span>" >- : "") + >- "</small>" >+ (patron.surname >+ ? escape_str(patron.surname) + ", " >+ : "") + >+ (patron.firstname >+ ? escape_str(patron.firstname) + " " >+ : "") + >+ (patron.cardnumber >+ ? " (" + escape_str(patron.cardnumber) + ")" >+ : "") + >+ "<small>" + >+ (patron.date_of_birth >+ ? ' <span class="age_years">' + >+ $get_age(patron.date_of_birth) + >+ " " + >+ __("years") + >+ "</span>" >+ : "") + >+ (patron.library >+ ? ' <span class="ac-library">' + >+ escape_str(patron.library.name) + >+ "</span>" >+ : "") + >+ "</small>" > ) > .addClass(loggedInClass); > return $patron; >@@ -211,10 +211,10 @@ $("#placeBookingModal").on("show.bs.modal", function (e) { > ) { > let option = $( > '<option value="' + >- pickup_location.library_id + >- '">' + >- pickup_location.name + >- "</option>" >+ pickup_location.library_id + >+ '">' + >+ pickup_location.name + >+ "</option>" > ); > > option.attr( >@@ -413,8 +413,8 @@ $("#placeBookingModal").on("show.bs.modal", function (e) { > if ( > !$("#booking_itemtype").find( > "option[value='" + >- item.item_type.item_type_id + >- "']" >+ item.item_type.item_type_id + >+ "']" > ).length > ) { > // Create a DOM Option and de-select by default >@@ -752,7 +752,7 @@ $("#placeBookingModal").on("show.bs.modal", function (e) { > for (let i = 0; i < renewalsAllowed; i++) { > nextDate.setDate( > nextDate.getDate() + >- parseInt(renewalLength) >+ parseInt(renewalLength) > ); > boldDates.push(new Date(nextDate)); > } >@@ -932,8 +932,8 @@ $("#placeBookingModal").on("show.bs.modal", function (e) { > ); > const startDate = periodPicker.selectedDates[0] > ? dayjs(periodPicker.selectedDates[0]).startOf( >- "day" >- ) >+ "day" >+ ) > : null; > > const leadStart = startDate >@@ -959,7 +959,7 @@ $("#placeBookingModal").on("show.bs.modal", function (e) { > dayElem.classList.toggle( > "leadRange", > elemDate.isSameOrAfter(leadStart) && >- elemDate.isBefore(leadEnd) >+ elemDate.isBefore(leadEnd) > ); > dayElem.classList.toggle( > "leadRangeEnd", >@@ -972,7 +972,7 @@ $("#placeBookingModal").on("show.bs.modal", function (e) { > dayElem.classList.toggle( > "trailRange", > elemDate.isAfter(trailStart) && >- elemDate.isSameOrBefore(trailEnd) >+ elemDate.isSameOrBefore(trailEnd) > ); > dayElem.classList.toggle( > "trailRangeEnd", >@@ -1195,8 +1195,8 @@ $("#placeBookingForm").on("submit", function (e) { > // Set feedback > $("#transient_result").replaceWith( > '<div id="transient_result" class="alert alert-info">' + >- __("Booking successfully placed") + >- "</div>" >+ __("Booking successfully placed") + >+ "</div>" > ); > > // Close modal >@@ -1206,8 +1206,8 @@ $("#placeBookingForm").on("submit", function (e) { > posting.fail(function (data) { > $("#booking_result").replaceWith( > '<div id="booking_result" class="alert alert-danger">' + >- __("Failure") + >- "</div>" >+ __("Failure") + >+ "</div>" > ); > }); > } else { >@@ -1264,8 +1264,8 @@ $("#placeBookingForm").on("submit", function (e) { > // Set feedback > $("#transient_result").replaceWith( > '<div id="transient_result" class="alert alert-info">' + >- __("Booking successfully updated") + >- "</div>" >+ __("Booking successfully updated") + >+ "</div>" > ); > > // Close modal >@@ -1275,8 +1275,8 @@ $("#placeBookingForm").on("submit", function (e) { > putting.fail(function (data) { > $("#booking_result").replaceWith( > '<div id="booking_result" class="alert alert-danger">' + >- __("Failure") + >- "</div>" >+ __("Failure") + >+ "</div>" > ); > }); > } >diff --git a/t/cypress/fixtures/bookings/bookable_items.json b/t/cypress/fixtures/bookings/bookable_items.json >new file mode 100644 >index 00000000000..bdb61b29732 >--- /dev/null >+++ b/t/cypress/fixtures/bookings/bookable_items.json >@@ -0,0 +1,29 @@ >+[ >+ { >+ "item_id": "789", >+ "external_id": "BARCODE789", >+ "effective_item_type_id": "BK", >+ "item_type": { >+ "item_type_id": "BK", >+ "description": "Book" >+ } >+ }, >+ { >+ "item_id": "790", >+ "external_id": "BARCODE790", >+ "effective_item_type_id": "BK", >+ "item_type": { >+ "item_type_id": "BK", >+ "description": "Book" >+ } >+ }, >+ { >+ "item_id": "791", >+ "external_id": "BARCODE791", >+ "effective_item_type_id": "DVD", >+ "item_type": { >+ "item_type_id": "DVD", >+ "description": "DVD" >+ } >+ } >+] >diff --git a/t/cypress/fixtures/bookings/bookings.json b/t/cypress/fixtures/bookings/bookings.json >new file mode 100644 >index 00000000000..9a9d69c4cad >--- /dev/null >+++ b/t/cypress/fixtures/bookings/bookings.json >@@ -0,0 +1,32 @@ >+[ >+ { >+ "booking_id": "1001", >+ "biblio_id": "123", >+ "patron_id": "456", >+ "item_id": "789", >+ "pickup_library_id": "1", >+ "start_date": "2025-05-01T00:00:00.000Z", >+ "end_date": "2025-05-05T23:59:59.999Z", >+ "status": "pending" >+ }, >+ { >+ "booking_id": "1002", >+ "biblio_id": "123", >+ "patron_id": "457", >+ "item_id": "790", >+ "pickup_library_id": "1", >+ "start_date": "2025-05-06T00:00:00.000Z", >+ "end_date": "2025-05-10T23:59:59.999Z", >+ "status": "pending" >+ }, >+ { >+ "booking_id": "1003", >+ "biblio_id": "123", >+ "patron_id": "458", >+ "item_id": null, >+ "pickup_library_id": "1", >+ "start_date": "2025-05-20T00:00:00.000Z", >+ "end_date": "2025-05-25T23:59:59.999Z", >+ "status": "pending" >+ } >+] >diff --git a/t/cypress/fixtures/bookings/checkouts.json b/t/cypress/fixtures/bookings/checkouts.json >new file mode 100644 >index 00000000000..66da27df25f >--- /dev/null >+++ b/t/cypress/fixtures/bookings/checkouts.json >@@ -0,0 +1,9 @@ >+[ >+ { >+ "checkout_id": "5001", >+ "biblio_id": "123", >+ "item_id": "791", >+ "patron_id": "459", >+ "due_date": "2025-05-30T23:59:59.999Z" >+ } >+] >diff --git a/t/cypress/fixtures/bookings/circulation_rules.json b/t/cypress/fixtures/bookings/circulation_rules.json >new file mode 100644 >index 00000000000..e1c0963f3ab >--- /dev/null >+++ b/t/cypress/fixtures/bookings/circulation_rules.json >@@ -0,0 +1,9 @@ >+[ >+ { >+ "bookings_lead_period": 3, >+ "bookings_trail_period": 2, >+ "issuelength": 14, >+ "renewalsallowed": 2, >+ "renewalperiod": 7 >+ } >+] >diff --git a/t/cypress/fixtures/bookings/patron.json b/t/cypress/fixtures/bookings/patron.json >new file mode 100644 >index 00000000000..bcdb2de24bb >--- /dev/null >+++ b/t/cypress/fixtures/bookings/patron.json >@@ -0,0 +1,12 @@ >+{ >+ "patron_id": "456", >+ "surname": "Doe", >+ "firstname": "John", >+ "cardnumber": "12345", >+ "library_id": "1", >+ "library": { >+ "name": "Main Library" >+ }, >+ "category_id": "1", >+ "date_of_birth": "1990-01-01" >+} >diff --git a/t/cypress/fixtures/bookings/pickup_locations.json b/t/cypress/fixtures/bookings/pickup_locations.json >new file mode 100644 >index 00000000000..a1c660499bc >--- /dev/null >+++ b/t/cypress/fixtures/bookings/pickup_locations.json >@@ -0,0 +1,20 @@ >+[ >+ { >+ "library_id": "1", >+ "name": "Main Library", >+ "needs_override": false, >+ "pickup_items": [ >+ 789, >+ 790 >+ ] >+ }, >+ { >+ "library_id": "2", >+ "name": "Branch Library", >+ "needs_override": false, >+ "pickup_items": [ >+ 789, >+ 791 >+ ] >+ } >+] >diff --git a/t/cypress/integration/Biblio/bookingsModal_spec.ts b/t/cypress/integration/Biblio/bookingsModal_spec.ts >new file mode 100644 >index 00000000000..3f1a5d20d37 >--- /dev/null >+++ b/t/cypress/integration/Biblio/bookingsModal_spec.ts >@@ -0,0 +1,469 @@ >+describe("Booking Modal Tests", () => { >+ // Test data setup >+ const testData = { >+ biblionumber: "134", >+ patronId: "19", >+ pickupLibraryId: "CPL", >+ itemNumber: "287", >+ itemTypeId: "BK", >+ startDate: new Date(new Date().setDate(new Date().getDate() + 1)), // 1 day from now >+ endDate: new Date(new Date().setDate(new Date().getDate() + 5)), // 5 days from now >+ }; >+ >+ beforeEach(() => { >+ cy.login(); >+ cy.title().should("eq", "Koha staff interface"); >+ >+ // Visit the page with the booking modal >+ cy.visit( >+ "/cgi-bin/koha/catalogue/detail.pl?biblionumber=" + >+ testData.biblionumber >+ ); >+ >+ // Intercept API calls and provide mock responses >+ cy.intercept("GET", "/api/v1/biblios/*/items?bookable=1&_per_page=-1", { >+ fixture: "bookings/bookable_items.json", >+ }).as("getBookableItems"); >+ >+ cy.fixture("bookings/bookings.json").then(bookings => { >+ // Get today's date >+ const today = new Date(); >+ >+ // Update the dates in the fixture data relative to today >+ bookings[0].start_date = new Date( >+ today.getTime() + 8 * 24 * 60 * 60 * 1000 >+ ).toISOString(); // Today + 8 day >+ bookings[0].end_date = new Date( >+ today.getTime() + 13 * 24 * 60 * 60 * 1000 >+ ).toISOString(); // Today + 13 days >+ >+ bookings[1].start_date = new Date( >+ today.getTime() + 14 * 24 * 60 * 60 * 1000 >+ ).toISOString(); // Today + 14 days >+ bookings[1].end_date = new Date( >+ today.getTime() + 18 * 24 * 60 * 60 * 1000 >+ ).toISOString(); // Today + 18 days >+ >+ bookings[2].start_date = new Date( >+ today.getTime() + 28 * 24 * 60 * 60 * 1000 >+ ).toISOString(); // Today + 28 days >+ bookings[2].end_date = new Date( >+ today.getTime() + 33 * 24 * 60 * 60 * 1000 >+ ).toISOString(); // Today + 33 days >+ >+ // Use the modified fixture data in your intercept >+ cy.intercept("GET", "/api/v1/bookings?biblio_id=*&_per_page=-1*", { >+ body: bookings, >+ }).as("getBookings"); >+ }); >+ >+ cy.intercept("GET", "/api/v1/biblios/*/checkouts?_per_page=-1", { >+ fixture: "bookings/checkouts.json", >+ }).as("getCheckouts"); >+ >+ cy.intercept("GET", "/api/v1/patrons/*", { >+ fixture: "bookings/patron.json", >+ }).as("getPatron"); >+ >+ cy.intercept("GET", "/api/v1/biblios/*/pickup_locations*", { >+ fixture: "bookings/pickup_locations.json", >+ }).as("getPickupLocations"); >+ >+ cy.intercept("GET", "/api/v1/circulation_rules*", { >+ fixture: "bookings/circulation_rules.json", >+ }).as("getCirculationRules"); >+ >+ cy.intercept("POST", "/api/v1/bookings", { >+ statusCode: 201, >+ body: { >+ booking_id: "1001", >+ start_date: testData.startDate.toISOString(), >+ end_date: testData.endDate.toISOString(), >+ pickup_library_id: testData.pickupLibraryId, >+ biblio_id: testData.biblionumber, >+ item_id: testData.itemNumber, >+ patron_id: testData.patronId, >+ }, >+ }).as("createBooking"); >+ >+ cy.intercept("PUT", "/api/v1/bookings/*", { >+ statusCode: 200, >+ body: { >+ booking_id: "1001", >+ start_date: testData.startDate.toISOString(), >+ end_date: testData.endDate.toISOString(), >+ pickup_library_id: testData.pickupLibraryId, >+ biblio_id: testData.biblionumber, >+ item_id: testData.itemNumber, >+ patron_id: testData.patronId, >+ }, >+ }).as("updateBooking"); >+ >+ // Populate the select2 search results for patron search >+ cy.intercept("GET", "/api/v1/patrons*", { >+ body: [ >+ { >+ patron_id: testData.patronId, >+ surname: "Doe", >+ firstname: "John", >+ cardnumber: "12345", >+ library_id: "1", >+ library: { >+ name: "Main Library", >+ }, >+ category_id: "1", >+ date_of_birth: "1990-01-01", >+ }, >+ ], >+ pagination: { more: false }, >+ }).as("searchPatrons"); >+ >+ // Add clickable button >+ cy.document().then(doc => { >+ const button = doc.createElement("button"); >+ button.setAttribute("data-bs-toggle", "modal"); >+ button.setAttribute("data-bs-target", "#placeBookingModal"); >+ button.setAttribute("data-biblionumber", testData.biblionumber); >+ button.setAttribute("id", "placebooking"); >+ doc.body.appendChild(button); >+ }); >+ >+ // Open the booking modal >+ cy.get("#placebooking").click(); >+ }); >+ >+ it("should load the booking modal correctly", () => { >+ // Check modal title >+ cy.get("#placeBookingLabel").should("contain", "Place booking"); >+ >+ // Check form elements are present >+ cy.get("#booking_patron_id").should("exist"); >+ cy.get("#pickup_library_id").should("exist"); >+ cy.get("#booking_itemtype").should("exist"); >+ cy.get("#booking_item_id").should("exist"); >+ cy.get("#period").should("exist"); >+ >+ // Check hidden fields >+ cy.get("#booking_biblio_id").should( >+ "have.value", >+ testData.biblionumber >+ ); >+ cy.get("#booking_start_date").should("have.value", ""); >+ cy.get("#booking_end_date").should("have.value", ""); >+ }); >+ >+ it("should enable fields in proper sequence", () => { >+ // Initially only patron field should be enabled >+ cy.get("#booking_patron_id").should("not.be.disabled"); >+ cy.get("#pickup_library_id").should("be.disabled"); >+ cy.get("#booking_itemtype").should("be.disabled"); >+ cy.get("#booking_item_id").should("be.disabled"); >+ cy.get("#period").should("be.disabled"); >+ >+ // Select patron >+ cy.selectFromSelect2ByIndex("#booking_patron_id", 0, "John"); >+ //cy.getSelect2("#booking_patron_id") >+ // .select2({ search: "John" }) >+ // .select2({ selectIndex: 0 }); >+ cy.wait("@getPickupLocations"); >+ >+ // After patron selection, pickup location, item type and item should be enabled >+ cy.get("#pickup_library_id").should("not.be.disabled"); >+ cy.get("#booking_itemtype").should("not.be.disabled"); >+ cy.get("#booking_item_id").should("not.be.disabled"); >+ cy.get("#period").should("be.disabled"); >+ >+ // Select pickup location >+ cy.selectFromSelect2ByIndex("#pickup_library_id", 0); >+ >+ // Select item type, trigger circulation rules >+ cy.selectFromSelect2ByIndex("#booking_itemtype", 0); >+ cy.wait("@getCirculationRules"); >+ >+ // After patron, pickup location and itemtype/item selection, date picker should be enabled >+ cy.get("#period").should("not.be.disabled"); >+ >+ // Clear item type and confirm period is disabled >+ cy.clearSelect2("#booking_itemtype"); >+ cy.get("#period").should("be.disabled"); >+ >+ // Select item, re-enable period >+ cy.selectFromSelect2ByIndex("#booking_item_id", 1); >+ cy.get("#period").should("not.be.disabled"); >+ }); >+ >+ it("should handle item type and item dependencies correctly", () => { >+ // Select patron and pickup location first >+ cy.selectFromSelect2ByIndex("#booking_patron_id", 0, "John"); >+ cy.wait("@getPickupLocations"); >+ cy.selectFromSelect2ByIndex("#pickup_library_id", 0); >+ >+ // Select an item first >+ cy.selectFromSelect2ByIndex("#booking_item_id", 1); >+ cy.wait("@getCirculationRules"); >+ >+ // Verify that item type gets selected automatically >+ cy.get("#booking_itemtype").should("have.value", testData.itemTypeId); >+ >+ // Verify that item type gets disabled >+ cy.get("#booking_itemtype").should("be.disabled"); >+ >+ // Reset the modal >+ cy.get('#placeBookingModal button[data-bs-dismiss="modal"]') >+ .first() >+ .click(); >+ cy.get("#placebooking").click(); >+ >+ // Now select patron, pickup and item type first >+ cy.selectFromSelect2ByIndex("#booking_patron_id", 0, "John"); >+ cy.wait("@getPickupLocations"); >+ cy.selectFromSelect2ByIndex("#pickup_library_id", 0); >+ cy.selectFromSelect2ByIndex("#booking_itemtype", 0); >+ cy.wait("@getCirculationRules"); >+ cy.wait(300); >+ >+ // Verify that only 'Any item' option and items of selected type are enabled >+ cy.get("#booking_item_id > option").then($options => { >+ const enabledOptions = $options.filter(":not(:disabled)"); >+ enabledOptions.each(function () { >+ const $option = cy.wrap(this); >+ >+ // Get both the value and the data-itemtype attribute to make decisions >+ $option.invoke("val").then(value => { >+ if (value === "0") { >+ // We need to re-wrap the element since invoke('val') changed the subject >+ cy.wrap(this).should("contain.text", "Any item"); >+ } else { >+ // Re-wrap the element again for this assertion >+ cy.wrap(this).should( >+ "have.attr", >+ "data-itemtype", >+ testData.itemTypeId >+ ); >+ } >+ }); >+ }); >+ }); >+ }); >+ >+ it("should handle date selection and availability", () => { >+ // Select patron, pickup location and item >+ cy.selectFromSelect2ByIndex("#booking_patron_id", 0, "John"); >+ cy.wait("@getPickupLocations"); >+ cy.selectFromSelect2ByIndex("#pickup_library_id", 0); >+ cy.selectFromSelect2ByIndex("#booking_item_id", 1); >+ cy.wait("@getCirculationRules"); >+ >+ // Open flatpickr >+ cy.openFlatpickr("#period"); >+ >+ // Get today's date >+ const today = new Date(); >+ const todayDay = today.getDate(); >+ >+ // Get target date (5 days from now) >+ const targetDate = new Date(today); >+ targetDate.setDate(today.getDate() + 5); >+ const targetDay = targetDate.getDate(); >+ >+ // Check if the dates are in the same month >+ if ( >+ today.getMonth() === targetDate.getMonth() && >+ today.getFullYear() === targetDate.getFullYear() >+ ) { >+ // Same month - select start date >+ cy.selectDay(todayDay); >+ cy.wait(300); >+ >+ // Select end date >+ cy.selectDay(targetDay, "#period"); >+ } else { >+ // Different months - select start date >+ cy.selectDay(todayDay); >+ cy.wait(300); >+ >+ // Navigate to the target month >+ cy.navigateToMonth(targetDate); >+ cy.wait(300); >+ >+ // Select end date >+ cy.selectDay(targetDay, "#period"); >+ cy.wait(300); >+ } >+ >+ // QUESTION: Why does my flatpickr appear to be re-triggered here >+ // so it's open and all the below assertions fail? >+ >+ /* >+ // Use should with retry capability instead of a simple assertion >+ cy.get("#period").should("have.value", /\w+/); // First check that there's any value >+ >+ // Verify the flatpickr visible input also has value >+ cy.getFlatpickr("#period").should("have.value", /\w+/); >+ >+ // Now check the hidden fields >+ cy.get("#booking_start_date").should("have.value", /\w+/); >+ cy.get("#booking_end_date").should("have.value", /\w+/); >+ >+ // Verify the range was selected properly >+ cy.get("#period").should("not.have.value", ""); >+ >+ // Now check the hidden fields >+ cy.get("#booking_start_date").should("not.have.value", ""); >+ cy.get("#booking_end_date").should("not.have.value", ""); >+ >+ // Check for disabled dates due to other bookings >+ cy.get(".flatpickr-day.flatpickr-disabled").should("exist"); >+ >+ // Check for event dots indicating existing bookings >+ cy.get(".flatpickr-day .event-dots").should("exist"); >+ */ >+ }); >+ >+ it("should handle date selection and availability - programatically", () => { >+ // Select patron, pickup location and item >+ cy.selectFromSelect2ByIndex("#booking_patron_id", 0, "John"); >+ cy.wait("@getPickupLocations"); >+ cy.selectFromSelect2ByIndex("#pickup_library_id", 0); >+ cy.selectFromSelect2ByIndex("#booking_item_id", 1); >+ cy.wait("@getCirculationRules"); >+ >+ const picker = win.document.getElementById("period")._flatpickr; >+ >+ // Available dates >+ let startDate = new Date(testData.startDate); >+ let endDate = new Date(testData.endDate); >+ picker.setDate([startDate, endDate], true); >+ >+ // Verify the range was selected properly >+ cy.get("#period").should("not.have.value", ""); >+ >+ // Now check the hidden fields >+ cy.get("#booking_start_date").should("not.have.value", ""); >+ cy.get("#booking_end_date").should("not.have.value", ""); >+ >+ // Unavailable dates - Should throw error >+ startDate = new Date(testData.startDate); >+ endDate = new Date(testData.endDate); >+ picker.setDate([startDate, endDate], true); >+ }); >+ >+ it("should submit a new booking successfully", () => { >+ // Select patron, pickup location and item >+ cy.selectFromSelect2ByIndex("#booking_patron_id", 0, "John"); >+ cy.wait("@getPickupLocations"); >+ cy.selectFromSelect2ByIndex("#pickup_library_id", 0); >+ cy.selectFromSelect2ByIndex("#booking_item_id", 1); >+ cy.wait("@getCirculationRules"); >+ >+ // Set dates with flatpickr >+ cy.window().then(win => { >+ const picker = win.document.getElementById("period")._flatpickr; >+ const startDate = new Date(testData.startDate); >+ const endDate = new Date(testData.endDate); >+ picker.setDate([startDate, endDate], true); >+ }); >+ >+ // Submit the form >+ cy.get("#placeBookingForm").submit(); >+ cy.wait("@createBooking"); >+ >+ // Check success message >+ cy.get("#transient_result").should( >+ "contain", >+ "Booking successfully placed" >+ ); >+ >+ // Check modal closes >+ cy.get("#placeBookingModal").should("not.be.visible"); >+ }); >+ >+ it("should edit an existing booking successfully", () => { >+ // Open edit booking modal >+ cy.get("#placebooking").invoke("attr", "data-booking", "1001").click(); >+ >+ // Check modal title for edit >+ cy.get("#placeBookingLabel").should("contain", "Edit booking"); >+ >+ // Verify booking ID is set >+ cy.get("#booking_id").should("have.value", "1001"); >+ >+ // Change pickup location >+ cy.get("#pickup_library_id").select("2"); >+ >+ // Submit the form >+ cy.get("#placeBookingForm").submit(); >+ cy.wait("@updateBooking"); >+ >+ // Check success message >+ cy.get("#transient_result").should( >+ "contain", >+ "Booking successfully updated" >+ ); >+ >+ // Check modal closes >+ cy.get("#placeBookingModal").should("not.be.visible"); >+ }); >+ >+ it("should handle booking failure gracefully", () => { >+ // Override the create booking intercept to return an error >+ cy.intercept("POST", "/api/v1/bookings", { >+ statusCode: 400, >+ body: { >+ error: "Booking failed", >+ }, >+ }).as("failedBooking"); >+ >+ // Fill out the booking form >+ cy.selectFromSelect2ByIndex("#booking_patron_id", 0, "John"); >+ cy.wait("@getPickupLocations"); >+ cy.selectFromSelect2ByIndex("#pickup_library_id", 0); >+ cy.selectFromSelect2ByIndex("#booking_item_id", 1); >+ cy.wait("@getCirculationRules"); >+ >+ // Set dates with flatpickr >+ cy.window().then(win => { >+ const picker = win.document.getElementById("period")._flatpickr; >+ const startDate = new Date(testData.startDate); >+ const endDate = new Date(testData.endDate); >+ picker.setDate([startDate, endDate], true); >+ }); >+ >+ // Submit the form >+ cy.get("#placeBookingForm").submit(); >+ cy.wait("@failedBooking"); >+ >+ // Check error message >+ cy.get("#booking_result").should("contain", "Failure"); >+ >+ // Modal should remain open >+ cy.get("#placeBookingModal").should("be.visible"); >+ }); >+ >+ it("should reset form when modal is closed", () => { >+ // Fill out some form fields >+ cy.selectFromSelect2ByIndex("#booking_patron_id", 0, "John"); >+ cy.wait("@getPickupLocations"); >+ cy.selectFromSelect2ByIndex("#pickup_library_id", 0); >+ cy.selectFromSelect2ByIndex("#booking_item_id", 1); >+ cy.wait("@getCirculationRules"); >+ >+ // Close the modal >+ cy.get('#placeBookingModal button[data-bs-dismiss="modal"]') >+ .first() >+ .click(); >+ >+ // Re-open the modal >+ cy.get("#placebooking").click(); >+ >+ // Check fields are reset >+ cy.get("#booking_patron_id").should("have.value", null); >+ cy.get("#pickup_library_id").should("be.disabled"); >+ cy.get("#booking_itemtype").should("be.disabled"); >+ cy.get("#booking_item_id").should("be.disabled"); >+ cy.get("#period").should("be.disabled"); >+ cy.get("#booking_start_date").should("have.value", ""); >+ cy.get("#booking_end_date").should("have.value", ""); >+ cy.get("#booking_id").should("have.value", ""); >+ }); >+}); >-- >2.49.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 39916
:
182515
|
182516
|
182545
|
182546
|
182635
|
182636
|
182637
|
182771
|
182772
|
182773
|
183206
|
183207
|
183208
|
183209
|
183210