Skip to content

Commit

Permalink
Bug 38632: Add tests
Browse files Browse the repository at this point in the history
You need bug 38461 to run successfully this test.

Signed-off-by: Brendan Lawlor <blawlor@clamsnet.org>
Signed-off-by: Matt Blenkinsop <matt.blenkinsop@ptfs-europe.com>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
  • Loading branch information
joubu authored and kfischer committed Jan 16, 2025
1 parent 0fefe2b commit 1264622
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@
embed.push('analytics_count');
[% END %]

let items_table_settings = {
var items_table_settings = {
holdings: [% TablesSettings.GetTableSettings('catalogue', 'detail','holdings_table','json') | $raw %],
otherholdings: [% TablesSettings.GetTableSettings('catalogue', 'detail','otherholdings_table','json') | $raw %],
};
Expand Down
95 changes: 89 additions & 6 deletions t/cypress/integration/KohaTable_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,34 +22,42 @@ function build_libraries() {
});
}

function mock_table_settings(settings) {
function mock_table_settings(settings, table_settings_var) {
cy.window().then(win => {
win.table_settings.columns = win.table_settings.columns.map(c => ({
let table_settings =
typeof table_settings_var === "undefined"
? win.table_settings
: table_settings_var
.split(".")
.reduce((acc, key) => acc[key], win);

table_settings.columns = table_settings.columns.map(c => ({
...c,
is_hidden: 0,
cannot_be_toggled: 0,
}));
if (settings && settings.hasOwnProperty("default_save_state")) {
win.table_settings.default_save_state = settings.default_save_state;
table_settings.default_save_state = settings.default_save_state;
}
if (settings && settings.hasOwnProperty("default_save_state_search")) {
win.table_settings.default_save_state_search =
table_settings.default_save_state_search =
settings.default_save_state_search;
}

if (settings && settings.columns) {
Object.entries(settings.columns).forEach(([name, values]) => {
let column = win.table_settings.columns.find(
let column = table_settings.columns.find(
cc => cc.columnname == name
);
Object.entries(values).forEach(([prop, value]) => {
column[prop] = value;
});
});
}
cy.wrap(win.table_settings.columns).as("columns");
cy.wrap(table_settings.columns).as("columns");
});
}

describe("kohaTable (using REST API)", () => {
beforeEach(() => {
cy.login();
Expand Down Expand Up @@ -528,5 +536,80 @@ describe("Hit all tables", () => {
);
});
});

it("Show filters", () => {
const biblio_id = 1;
cy.task("buildSampleObjects", {
object: "item",
count: RESTdefaultPageSize,
values: {
biblio_id,
checkout: null,
transfer: null,
lost_status: 0,
withdrawn: 0,
damaged_status: 0,
not_for_loan_status: 0,
course_item: null,
},
}).then(items => {
cy.intercept("get", `/api/v1/biblios/${biblio_id}/items*`, {
statuscode: 200,
body: items,
headers: {
"X-Base-Total-Count": baseTotalCount,
"X-Total-Count": baseTotalCount,
},
});

cy.visit(
"/cgi-bin/koha/catalogue/detail.pl?biblionumber=" +
biblio_id
);

// Hide the 'URL' column
mock_table_settings(
{
columns: { uri: { is_hidden: 1 } },
},
"items_table_settings.holdings"
);

cy.window().then(win => {
win.libraries_map = items.reduce((map, i) => {
map[i.library_id] = i.library_id;
return map;
}, {});
});

cy.get("@columns").then(columns => {
cy.get(`#${table_id}_wrapper tbody tr`).should(
"have.length",
RESTdefaultPageSize
);

cy.get(`#${table_id} th`).contains("Status");
cy.get(`#${table_id} th`)
.contains("URL")
.should("not.exist");
cy.get(`#${table_id} th`)
.contains("Course reserves")
.should("not.exist");

cy.get(".show_filters").click();
cy.get(`#${table_id}_wrapper .dt-info`).contains(
`Showing 1 to ${RESTdefaultPageSize} of ${baseTotalCount} entries`
);

cy.get(`#${table_id} th`).contains("Status");
cy.get(`#${table_id} th`)
.contains("URL")
.should("not.exist");
cy.get(`#${table_id} th`)
.contains("Course reserves")
.should("not.exist");
});
});
});
});
});

0 comments on commit 1264622

Please sign in to comment.