From ab7fea077e6aba79a522f3977ae2787ef049fe7f Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 21 Nov 2024 16:33:11 +0100 Subject: [PATCH] Bug 38461: Columns - All, is_hidden by default, then shown by user Signed-off-by: Victor Grousset/tuxayo --- t/cypress/integration/KohaTable_spec.ts | 132 ++++++++++++++++++++++++ 1 file changed, 132 insertions(+) diff --git a/t/cypress/integration/KohaTable_spec.ts b/t/cypress/integration/KohaTable_spec.ts index 1cd60e07ed..a1bb6b9499 100644 --- a/t/cypress/integration/KohaTable_spec.ts +++ b/t/cypress/integration/KohaTable_spec.ts @@ -4,6 +4,9 @@ describe("kohaTable (using REST API)", () => { beforeEach(() => { cy.login(); cy.title().should("eq", "Koha staff interface"); + cy.window().then(win => { + win.localStorage.clear(); + }); }); afterEach(() => {}); @@ -64,6 +67,135 @@ describe("kohaTable (using REST API)", () => { ); }); }); + + it("All columns displayed", () => { + 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.window().then(win => { + win.table_settings.columns = win.table_settings.columns.map( + c => ({ ...c, is_hidden: 0, cannot_be_toggled: 0 }) + ); + cy.get(`#${table_id} th`).should( + "have.length", + win.table_settings.columns.length + ); + }); + }); + }); + + it("One column hidden by default", () => { + 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.window().then(win => { + win.table_settings.columns = win.table_settings.columns.map( + c => ({ ...c, is_hidden: 0, cannot_be_toggled: 0 }) + ); + win.table_settings.columns.find( + c => c.columnname == "library_code" + ).is_hidden = 1; + cy.get(`#${table_id} th`).should( + "have.length", + win.table_settings.columns.length - 1 + ); + cy.get(`#${table_id} th`).contains("Name"); + cy.get(`#${table_id} th`) + .contains("Code") + .should("not.exist"); + }); + }); + }); + + /* TODO Missing mock, we assume that 'Save state' is ON */ + it("One column hidden by default then shown by user", () => { + 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.window().then(win => { + win.table_settings.columns = win.table_settings.columns.map( + c => ({ ...c, is_hidden: 0, cannot_be_toggled: 0 }) + ); + win.table_settings.columns.find( + c => c.columnname == "library_code" + ).is_hidden = 1; + cy.get(`#${table_id} th`).should( + "have.length", + win.table_settings.columns.length - 1 + ); + cy.get(`#${table_id} th`).contains("Name"); + cy.get(`#${table_id} th`) + .contains("Code") + .should("not.exist"); + cy.get(`#${table_id}_wrapper .buttons-colvis`).click(); + cy.get(`#${table_id}_wrapper .dt-button-collection`) + .contains("Code") + .click(); + cy.get(`#${table_id} th`).should( + "have.length", + win.table_settings.columns.length + ); + cy.get(`#${table_id} th`).contains("Name"); + cy.get(`#${table_id} th`).contains("Code"); + }); + + cy.visit("/cgi-bin/koha/admin/branches.pl"); + + cy.window().then(win => { + win.table_settings.columns = win.table_settings.columns.map( + c => ({ ...c, is_hidden: 0, cannot_be_toggled: 0 }) + ); + win.table_settings.columns.find( + c => c.columnname == "library_code" + ).is_hidden = 1; + cy.get(`#${table_id} th`).should( + "have.length", + win.table_settings.columns.length + ); + cy.get(`#${table_id} th`).contains("Name"); + cy.get(`#${table_id} th`).contains("Code"); + }); + }); + }); }); describe("Patrons search", () => { -- 2.47.1