Lines 22-63
function build_libraries() {
Link Here
|
22 |
}); |
22 |
}); |
23 |
} |
23 |
} |
24 |
|
24 |
|
25 |
function mock_table_settings(settings, table_settings_var) { |
|
|
26 |
cy.window().then(win => { |
27 |
let table_settings = |
28 |
typeof table_settings_var === "undefined" |
29 |
? win.table_settings |
30 |
: table_settings_var |
31 |
.split(".") |
32 |
.reduce((acc, key) => acc[key], win); |
33 |
|
34 |
table_settings.columns = table_settings.columns.map(c => ({ |
35 |
...c, |
36 |
is_hidden: 0, |
37 |
cannot_be_toggled: 0, |
38 |
})); |
39 |
if (settings && settings.hasOwnProperty("default_save_state")) { |
40 |
table_settings.default_save_state = settings.default_save_state; |
41 |
} |
42 |
if (settings && settings.hasOwnProperty("default_save_state_search")) { |
43 |
table_settings.default_save_state_search = |
44 |
settings.default_save_state_search; |
45 |
} |
46 |
|
47 |
if (settings && settings.columns) { |
48 |
Object.entries(settings.columns).forEach(([name, values]) => { |
49 |
let column = table_settings.columns.find( |
50 |
cc => cc.columnname == name |
51 |
); |
52 |
Object.entries(values).forEach(([prop, value]) => { |
53 |
column[prop] = value; |
54 |
}); |
55 |
}); |
56 |
} |
57 |
cy.wrap(table_settings.columns).as("columns"); |
58 |
}); |
59 |
} |
60 |
|
61 |
describe("kohaTable (using REST API)", () => { |
25 |
describe("kohaTable (using REST API)", () => { |
62 |
beforeEach(() => { |
26 |
beforeEach(() => { |
63 |
cy.login(); |
27 |
cy.login(); |
Lines 114-120
describe("kohaTable (using REST API)", () => {
Link Here
|
114 |
build_libraries().then(() => { |
78 |
build_libraries().then(() => { |
115 |
cy.visit("/cgi-bin/koha/admin/branches.pl"); |
79 |
cy.visit("/cgi-bin/koha/admin/branches.pl"); |
116 |
|
80 |
|
117 |
mock_table_settings(); |
81 |
cy.mock_table_settings(); |
118 |
cy.get("@columns").then(columns => { |
82 |
cy.get("@columns").then(columns => { |
119 |
cy.get(`#${table_id} th`).should( |
83 |
cy.get(`#${table_id} th`).should( |
120 |
"have.length", |
84 |
"have.length", |
Lines 128-134
describe("kohaTable (using REST API)", () => {
Link Here
|
128 |
build_libraries().then(() => { |
92 |
build_libraries().then(() => { |
129 |
cy.visit("/cgi-bin/koha/admin/branches.pl"); |
93 |
cy.visit("/cgi-bin/koha/admin/branches.pl"); |
130 |
|
94 |
|
131 |
mock_table_settings({ |
95 |
cy.mock_table_settings({ |
132 |
columns: { library_code: { is_hidden: 1 } }, |
96 |
columns: { library_code: { is_hidden: 1 } }, |
133 |
}); |
97 |
}); |
134 |
|
98 |
|
Lines 148-154
describe("kohaTable (using REST API)", () => {
Link Here
|
148 |
build_libraries().then(() => { |
112 |
build_libraries().then(() => { |
149 |
cy.visit("/cgi-bin/koha/admin/branches.pl"); |
113 |
cy.visit("/cgi-bin/koha/admin/branches.pl"); |
150 |
|
114 |
|
151 |
mock_table_settings({ |
115 |
cy.mock_table_settings({ |
152 |
default_save_state: 0, |
116 |
default_save_state: 0, |
153 |
columns: { library_code: { is_hidden: 1 } }, |
117 |
columns: { library_code: { is_hidden: 1 } }, |
154 |
}); |
118 |
}); |
Lines 176-182
describe("kohaTable (using REST API)", () => {
Link Here
|
176 |
|
140 |
|
177 |
cy.visit("/cgi-bin/koha/admin/branches.pl"); |
141 |
cy.visit("/cgi-bin/koha/admin/branches.pl"); |
178 |
|
142 |
|
179 |
mock_table_settings({ |
143 |
cy.mock_table_settings({ |
180 |
default_save_state: 0, |
144 |
default_save_state: 0, |
181 |
columns: { library_code: { is_hidden: 1 } }, |
145 |
columns: { library_code: { is_hidden: 1 } }, |
182 |
}); |
146 |
}); |
Lines 198-204
describe("kohaTable (using REST API)", () => {
Link Here
|
198 |
build_libraries().then(() => { |
162 |
build_libraries().then(() => { |
199 |
cy.visit("/cgi-bin/koha/admin/branches.pl"); |
163 |
cy.visit("/cgi-bin/koha/admin/branches.pl"); |
200 |
|
164 |
|
201 |
mock_table_settings({ |
165 |
cy.mock_table_settings({ |
202 |
default_save_state: 1, |
166 |
default_save_state: 1, |
203 |
columns: { library_code: { is_hidden: 1 } }, |
167 |
columns: { library_code: { is_hidden: 1 } }, |
204 |
}); |
168 |
}); |
Lines 226-232
describe("kohaTable (using REST API)", () => {
Link Here
|
226 |
|
190 |
|
227 |
cy.visit("/cgi-bin/koha/admin/branches.pl"); |
191 |
cy.visit("/cgi-bin/koha/admin/branches.pl"); |
228 |
|
192 |
|
229 |
mock_table_settings({ |
193 |
cy.mock_table_settings({ |
230 |
default_save_state: 1, |
194 |
default_save_state: 1, |
231 |
columns: { library_code: { is_hidden: 1 } }, |
195 |
columns: { library_code: { is_hidden: 1 } }, |
232 |
}); |
196 |
}); |
Lines 246-252
describe("kohaTable (using REST API)", () => {
Link Here
|
246 |
build_libraries().then(() => { |
210 |
build_libraries().then(() => { |
247 |
cy.visit("/cgi-bin/koha/admin/branches.pl"); |
211 |
cy.visit("/cgi-bin/koha/admin/branches.pl"); |
248 |
|
212 |
|
249 |
mock_table_settings({ |
213 |
cy.mock_table_settings({ |
250 |
default_save_state: 1, |
214 |
default_save_state: 1, |
251 |
columns: { library_code: { is_hidden: 1 } }, |
215 |
columns: { library_code: { is_hidden: 1 } }, |
252 |
}); |
216 |
}); |
Lines 476-795
describe("ERM ", () => {
Link Here
|
476 |
}); |
440 |
}); |
477 |
}); |
441 |
}); |
478 |
}); |
442 |
}); |
479 |
|
|
|
480 |
describe("Hit all tables", () => { |
481 |
beforeEach(() => { |
482 |
cy.login(); |
483 |
cy.title().should("eq", "Koha staff interface"); |
484 |
cy.window().then(win => { |
485 |
win.localStorage.clear(); |
486 |
}); |
487 |
}); |
488 |
|
489 |
describe("catalogue/detail/holdings_table", () => { |
490 |
const table_id = "holdings_table"; |
491 |
beforeEach(() => { |
492 |
// FIXME All the following code should not be reused as it |
493 |
// It must be moved to a Cypress command or task "buildSampleBiblio" or even "insertSampleBiblio" |
494 |
let generated_objects = {}; |
495 |
const objects = [{ object: "library" }, { object: "item_type" }]; |
496 |
cy.wrap(Promise.resolve()) |
497 |
.then(() => { |
498 |
return objects.reduce((chain, { object }) => { |
499 |
return chain.then(() => { |
500 |
return cy |
501 |
.task("buildSampleObject", { object }) |
502 |
.then(attributes => { |
503 |
generated_objects[object] = attributes; |
504 |
}); |
505 |
}); |
506 |
}, Promise.resolve()); |
507 |
}) |
508 |
.then(() => { |
509 |
const library = generated_objects["library"]; |
510 |
const item_type = generated_objects["item_type"]; |
511 |
const queries = [ |
512 |
{ |
513 |
query: "INSERT INTO branches(branchcode, branchname) VALUES (?, ?)", |
514 |
values: [library.library_id, library.name], |
515 |
}, |
516 |
{ |
517 |
query: "INSERT INTO itemtypes(itemtype, description) VALUES (?, ?)", |
518 |
values: [ |
519 |
item_type.item_type_id, |
520 |
item_type.description, |
521 |
], |
522 |
}, |
523 |
]; |
524 |
cy.wrap(Promise.resolve()) |
525 |
.then(() => { |
526 |
return queries.reduce( |
527 |
(chain, { query, values }) => { |
528 |
return chain.then(() => |
529 |
cy.query(query, values) |
530 |
); |
531 |
}, |
532 |
Promise.resolve() |
533 |
); |
534 |
}) |
535 |
.then(() => { |
536 |
let biblio = { |
537 |
leader: " nam a22 7a 4500", |
538 |
fields: [ |
539 |
{ "005": "20250120101920.0" }, |
540 |
{ |
541 |
"245": { |
542 |
ind1: "", |
543 |
ind2: "", |
544 |
subfields: [ |
545 |
{ a: "Some boring read" }, |
546 |
], |
547 |
}, |
548 |
}, |
549 |
{ |
550 |
"100": { |
551 |
ind1: "", |
552 |
ind2: "", |
553 |
subfields: [ |
554 |
{ c: "Some boring author" }, |
555 |
], |
556 |
}, |
557 |
}, |
558 |
{ |
559 |
"942": { |
560 |
ind1: "", |
561 |
ind2: "", |
562 |
subfields: [ |
563 |
{ c: item_type.item_type_id }, |
564 |
], |
565 |
}, |
566 |
}, |
567 |
], |
568 |
}; |
569 |
cy.request({ |
570 |
method: "POST", |
571 |
url: "/api/v1/biblios", |
572 |
headers: { |
573 |
"Content-Type": "application/marc-in-json", |
574 |
"x-confirm-not-duplicate": 1, |
575 |
}, |
576 |
body: biblio, |
577 |
}).then(response => { |
578 |
const biblio_id = response.body.id; |
579 |
cy.wrap(biblio_id).as("biblio_id"); |
580 |
cy.request({ |
581 |
method: "POST", |
582 |
url: `/api/v1/biblios/${biblio_id}/items`, |
583 |
headers: { |
584 |
"Content-Type": "application/json", |
585 |
}, |
586 |
body: { |
587 |
home_library_id: library.library_id, |
588 |
holding_library_id: library.library_id, |
589 |
}, |
590 |
}); |
591 |
}); |
592 |
}); |
593 |
}); |
594 |
cy.query( |
595 |
"SELECT value FROM systempreferences WHERE variable='AlwaysShowHoldingsTableFilters'" |
596 |
).then(value => { |
597 |
cy.wrap(value).as("syspref_AlwaysShowHoldingsTableFilters"); |
598 |
}); |
599 |
}); |
600 |
|
601 |
afterEach( |
602 |
() => |
603 |
function () { |
604 |
cleanup(); |
605 |
cy.set_syspref( |
606 |
"AlwaysShowHoldingsTableFilters", |
607 |
this.syspref_AlwaysShowHoldingsTableFilters |
608 |
); |
609 |
} |
610 |
); |
611 |
|
612 |
it("Correctly init the table", function () { |
613 |
// Do not use `() => {` or this.biblio_id won't be retrieved |
614 |
const biblio_id = this.biblio_id; |
615 |
cy.task("buildSampleObjects", { |
616 |
object: "item", |
617 |
count: RESTdefaultPageSize, |
618 |
values: { |
619 |
biblio_id, |
620 |
checkout: null, |
621 |
transfer: null, |
622 |
lost_status: 0, |
623 |
withdrawn: 0, |
624 |
damaged_status: 0, |
625 |
not_for_loan_status: 0, |
626 |
course_item: null, |
627 |
cover_image_ids: [], |
628 |
}, |
629 |
}).then(items => { |
630 |
cy.intercept("get", `/api/v1/biblios/${biblio_id}/items*`, { |
631 |
statuscode: 200, |
632 |
body: items, |
633 |
headers: { |
634 |
"X-Base-Total-Count": baseTotalCount, |
635 |
"X-Total-Count": baseTotalCount, |
636 |
}, |
637 |
}); |
638 |
|
639 |
cy.visit( |
640 |
"/cgi-bin/koha/catalogue/detail.pl?biblionumber=" + |
641 |
biblio_id |
642 |
); |
643 |
|
644 |
cy.window().then(win => { |
645 |
win.libraries_map = items.reduce((map, i) => { |
646 |
map[i.library_id] = i.library_id; |
647 |
return map; |
648 |
}, {}); |
649 |
}); |
650 |
|
651 |
cy.get(`#${table_id}_wrapper tbody tr`).should( |
652 |
"have.length", |
653 |
RESTdefaultPageSize |
654 |
); |
655 |
|
656 |
cy.get(`#${table_id}_wrapper .dt-info`).contains( |
657 |
`Showing 1 to ${RESTdefaultPageSize} of ${baseTotalCount} entries` |
658 |
); |
659 |
}); |
660 |
}); |
661 |
|
662 |
it("Show filters", function () { |
663 |
// Do not use `() => {` or this.biblio_id won't be retrieved |
664 |
const biblio_id = this.biblio_id; |
665 |
cy.task("buildSampleObjects", { |
666 |
object: "item", |
667 |
count: RESTdefaultPageSize, |
668 |
values: { |
669 |
biblio_id, |
670 |
checkout: null, |
671 |
transfer: null, |
672 |
lost_status: 0, |
673 |
withdrawn: 0, |
674 |
damaged_status: 0, |
675 |
not_for_loan_status: 0, |
676 |
course_item: null, |
677 |
cover_image_ids: [], |
678 |
}, |
679 |
}).then(items => { |
680 |
cy.intercept("get", `/api/v1/biblios/${biblio_id}/items*`, { |
681 |
statuscode: 200, |
682 |
body: items, |
683 |
headers: { |
684 |
"X-Base-Total-Count": baseTotalCount, |
685 |
"X-Total-Count": baseTotalCount, |
686 |
}, |
687 |
}); |
688 |
|
689 |
cy.set_syspref("AlwaysShowHoldingsTableFilters", 0).then(() => { |
690 |
cy.visit( |
691 |
"/cgi-bin/koha/catalogue/detail.pl?biblionumber=" + |
692 |
biblio_id |
693 |
); |
694 |
|
695 |
// Hide the 'URL' column |
696 |
mock_table_settings( |
697 |
{ |
698 |
columns: { uri: { is_hidden: 1 } }, |
699 |
}, |
700 |
"items_table_settings.holdings" |
701 |
); |
702 |
|
703 |
cy.window().then(win => { |
704 |
win.libraries_map = items.reduce((map, i) => { |
705 |
map[i.library_id] = i.library_id; |
706 |
return map; |
707 |
}, {}); |
708 |
}); |
709 |
|
710 |
cy.get("@columns").then(columns => { |
711 |
cy.get(`#${table_id}_wrapper tbody tr`).should( |
712 |
"have.length", |
713 |
RESTdefaultPageSize |
714 |
); |
715 |
|
716 |
// Filters are not displayed |
717 |
cy.get(`#${table_id} thead tr`).should( |
718 |
"have.length", |
719 |
1 |
720 |
); |
721 |
|
722 |
cy.get(`#${table_id} th`).contains("Status"); |
723 |
cy.get(`#${table_id} th`) |
724 |
.contains("URL") |
725 |
.should("not.exist"); |
726 |
cy.get(`#${table_id} th`) |
727 |
.contains("Course reserves") |
728 |
.should("not.exist"); |
729 |
|
730 |
cy.get(".show_filters").click(); |
731 |
cy.get(`#${table_id}_wrapper .dt-info`).contains( |
732 |
`Showing 1 to ${RESTdefaultPageSize} of ${baseTotalCount} entries` |
733 |
); |
734 |
// Filters are displayed |
735 |
cy.get(`#${table_id} thead tr`).should( |
736 |
"have.length", |
737 |
2 |
738 |
); |
739 |
|
740 |
cy.get(`#${table_id} th`).contains("Status"); |
741 |
cy.get(`#${table_id} th`) |
742 |
.contains("URL") |
743 |
.should("not.exist"); |
744 |
cy.get(`#${table_id} th`) |
745 |
.contains("Course reserves") |
746 |
.should("not.exist"); |
747 |
}); |
748 |
}); |
749 |
|
750 |
cy.set_syspref("AlwaysShowHoldingsTableFilters", 1).then(() => { |
751 |
cy.visit( |
752 |
"/cgi-bin/koha/catalogue/detail.pl?biblionumber=" + |
753 |
biblio_id |
754 |
); |
755 |
|
756 |
// Hide the 'URL' column |
757 |
mock_table_settings( |
758 |
{ |
759 |
columns: { uri: { is_hidden: 1 } }, |
760 |
}, |
761 |
"items_table_settings.holdings" |
762 |
); |
763 |
|
764 |
cy.window().then(win => { |
765 |
win.libraries_map = items.reduce((map, i) => { |
766 |
map[i.library_id] = i.library_id; |
767 |
return map; |
768 |
}, {}); |
769 |
}); |
770 |
|
771 |
cy.get("@columns").then(columns => { |
772 |
cy.get(`#${table_id}_wrapper tbody tr`).should( |
773 |
"have.length", |
774 |
RESTdefaultPageSize |
775 |
); |
776 |
|
777 |
// Filters are displayed |
778 |
cy.get(`#${table_id} thead tr`).should( |
779 |
"have.length", |
780 |
2 |
781 |
); |
782 |
|
783 |
cy.get(".hide_filters").click(); |
784 |
|
785 |
// Filters are not displayed |
786 |
cy.get(`#${table_id} thead tr`).should( |
787 |
"have.length", |
788 |
1 |
789 |
); |
790 |
}); |
791 |
}); |
792 |
}); |
793 |
}); |
794 |
}); |
795 |
}); |