From fb7da9b3499df0a05f961e644d671809f3307271 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 21 Nov 2024 14:00:18 +0100 Subject: [PATCH] Bug 38461: Use buildSampleObjects --- t/cypress/integration/KohaTable_spec.ts | 165 +++++++++++++++--------- 1 file changed, 101 insertions(+), 64 deletions(-) diff --git a/t/cypress/integration/KohaTable_spec.ts b/t/cypress/integration/KohaTable_spec.ts index 9d655650e94..1cd60e07ed6 100644 --- a/t/cypress/integration/KohaTable_spec.ts +++ b/t/cypress/integration/KohaTable_spec.ts @@ -8,94 +8,131 @@ describe("kohaTable (using REST API)", () => { afterEach(() => {}); - const RESTdefaultPageSize = 20; // FIXME Mock this + const RESTdefaultPageSize = "20"; // FIXME Mock this + const baseTotalCount = "42"; - it("Simple tables", () => { + describe("Simple tables", () => { const table_id = "libraries"; it("Input search bar and clear filter ", () => { - cy.visit("/cgi-bin/koha/admin/branches.pl"); + cy.task("buildSampleObjects", { + object: "library", + count: RESTdefaultPageSize, + values: { library_hours: [] }, + }).then(libraries => { + cy.intercept("GET", "/api/v1/libraries*", { + statusCode: 200, + body: libraries, + headers: { + "X-Base-Total-Count": baseTotalCount, + "X-Total-Count": baseTotalCount, + }, + }); + + cy.visit("/cgi-bin/koha/admin/branches.pl"); - cy.query("SELECT COUNT(*) as count FROM branches").then(result => { - let count = result[0].count; - let display = Math.min(RESTdefaultPageSize, count); cy.get(`#${table_id}_wrapper .dt-info`).contains( - `Showing 1 to ${display} of ${count} entries` + `Showing 1 to ${RESTdefaultPageSize} of ${baseTotalCount} entries` ); - }); - // Should be disabled by default - empty search bar - cy.get(`#${table_id}_wrapper .dt_button_clear_filter`).should( - "have.class", - "disabled" - ); + // Should be disabled by default - empty search bar + cy.get(`#${table_id}_wrapper .dt_button_clear_filter`).should( + "have.class", + "disabled" + ); - // Type something in the input search bar - cy.get(`#${table_id}_wrapper input.dt-input`).type("centerville"); - cy.get(`#${table_id}_wrapper input.dt-input`).should( - "have.value", - "centerville" - ); + // Type something in the input search bar + cy.get(`#${table_id}_wrapper input.dt-input`).type( + "centerville" + ); + cy.get(`#${table_id}_wrapper input.dt-input`).should( + "have.value", + "centerville" + ); - // Should no longer be disabled - cy.get(`#${table_id}_wrapper .dt_button_clear_filter`).should( - "not.have.class", - "disabled" - ); + // Should no longer be disabled + cy.get(`#${table_id}_wrapper .dt_button_clear_filter`).should( + "not.have.class", + "disabled" + ); - // Click the clear_filter button - cy.get(`#${table_id}_wrapper .dt_button_clear_filter`).click(); - cy.get(`#${table_id}_wrapper input.dt-input`).should( - "have.value", - "" - ); + // Click the clear_filter button + cy.get(`#${table_id}_wrapper .dt_button_clear_filter`).click(); + cy.get(`#${table_id}_wrapper input.dt-input`).should( + "have.value", + "" + ); + }); }); }); - it("Patrons search", () => { + describe("Patrons search", () => { const table_id = "memberresultst"; it("Input search bar and clear filter ", () => { - cy.visit("/cgi-bin/koha/members/members-home.pl"); - - cy.get("form.patron_search_form input[type='submit']").click(); + cy.task("buildSampleObjects", { + object: "patron", + count: RESTdefaultPageSize, + values: {}, + }).then(patrons => { + // Needs more properties to not explode + // account_balace: balance_str.escapeHtml(...).format_price is not a function + patrons = patrons.map(p => ({ ...p, account_balance: 0 })); + + cy.intercept("GET", "/api/v1/patrons*", { + statusCode: 200, + body: patrons, + headers: { + "X-Base-Total-Count": baseTotalCount, + "X-Total-Count": baseTotalCount, + }, + }); + + cy.visit("/cgi-bin/koha/members/members-home.pl"); + + cy.window().then(win => { + win.categories_map = patrons.reduce((map, p) => { + map[p.category_id] = p.category_id; + return map; + }, {}); + }); + cy.get("form.patron_search_form input[type='submit']").click(); - cy.query("SELECT COUNT(*) as count FROM borrowers").then(result => { - let count = result[0].count; - let display = Math.min(RESTdefaultPageSize, count); cy.get(`#${table_id}_wrapper .dt-info`).contains( - `Showing 1 to ${display} of ${count} entries` + `Showing 1 to ${RESTdefaultPageSize} of ${baseTotalCount} entries` ); - }); - // Should be disabled by default - empty search bar - cy.get(`#${table_id}_wrapper .dt_button_clear_filter`).should( - "have.class", - "disabled" - ); + // Should be disabled by default - empty search bar + cy.get(`#${table_id}_wrapper .dt_button_clear_filter`).should( + "have.class", + "disabled" + ); - // Type something in the input search bar - cy.get(`#${table_id}_wrapper input.dt-input`).type( - "edna", - { force: true } // Needs to force because of sticky header? It's not clear what's happening, Cypress bug? - ); - cy.get(`#${table_id}_wrapper input.dt-input`).should( - "have.value", - "edna" - ); + // Type something in the input search bar + cy.get(`#${table_id}_wrapper input.dt-input`).type( + "edna", + { force: true } // Needs to force because of sticky header? It's not clear what's happening, Cypress bug? + ); + cy.get(`#${table_id}_wrapper input.dt-input`).should( + "have.value", + "edna" + ); - // Should no longer be disabled - cy.get(`#${table_id}_wrapper .dt_button_clear_filter`).should( - "not.have.class", - "disabled" - ); + // Should no longer be disabled + cy.get(`#${table_id}_wrapper .dt_button_clear_filter`).should( + "not.have.class", + "disabled" + ); - // Click the clear_filter button - cy.get(`#${table_id}_wrapper .dt_button_clear_filter`).click(); - cy.get(`#${table_id}_wrapper input.dt-input`).should( - "have.value", - "" - ); + // Click the clear_filter button + cy.get(`#${table_id}_wrapper .dt_button_clear_filter`).click({ + force: true, + }); // #searchheader is on top of it + cy.get(`#${table_id}_wrapper input.dt-input`).should( + "have.value", + "" + ); + }); }); }); }); -- 2.34.1