|
Lines 1-5
Link Here
|
| 1 |
const RESTdefaultPageSize = "20"; // FIXME Mock this |
1 |
const RESTdefaultPageSize = "20"; // FIXME Mock this |
| 2 |
const baseTotalCount = "42"; |
2 |
const baseTotalCount = "21"; |
| 3 |
|
3 |
|
| 4 |
describe("catalogue/detail/holdings_table with items", () => { |
4 |
describe("catalogue/detail/holdings_table with items", () => { |
| 5 |
const table_id = "holdings_table"; |
5 |
const table_id = "holdings_table"; |
|
Lines 10-117
describe("catalogue/detail/holdings_table with items", () => {
Link Here
|
| 10 |
win.localStorage.clear(); |
10 |
win.localStorage.clear(); |
| 11 |
}); |
11 |
}); |
| 12 |
|
12 |
|
| 13 |
// FIXME All the following code should not be reused as it |
|
|
| 14 |
// It must be moved to a Cypress command or task "buildSampleBiblio" or even "insertSampleBiblio" |
| 15 |
let generated_objects = {}; |
| 16 |
const objects = [{ object: "library" }, { object: "item_type" }]; |
| 17 |
cy.wrap(Promise.resolve()) |
| 18 |
.then(() => { |
| 19 |
return objects.reduce((chain, { object }) => { |
| 20 |
return chain.then(() => { |
| 21 |
return cy |
| 22 |
.task("buildSampleObject", { object }) |
| 23 |
.then(attributes => { |
| 24 |
generated_objects[object] = attributes; |
| 25 |
}); |
| 26 |
}); |
| 27 |
}, Promise.resolve()); |
| 28 |
}) |
| 29 |
.then(() => { |
| 30 |
const library = generated_objects["library"]; |
| 31 |
const item_type = generated_objects["item_type"]; |
| 32 |
const queries = [ |
| 33 |
{ |
| 34 |
query: "INSERT INTO branches(branchcode, branchname) VALUES (?, ?)", |
| 35 |
values: [library.library_id, library.name], |
| 36 |
}, |
| 37 |
{ |
| 38 |
query: "INSERT INTO itemtypes(itemtype, description) VALUES (?, ?)", |
| 39 |
values: [item_type.item_type_id, item_type.description], |
| 40 |
}, |
| 41 |
]; |
| 42 |
cy.wrap(Promise.resolve()) |
| 43 |
.then(() => { |
| 44 |
return queries.reduce((chain, { query, values }) => { |
| 45 |
return chain.then(() => |
| 46 |
cy.task("query", { sql: query, values }) |
| 47 |
); |
| 48 |
}, Promise.resolve()); |
| 49 |
}) |
| 50 |
.then(() => { |
| 51 |
let biblio = { |
| 52 |
leader: " nam a22 7a 4500", |
| 53 |
fields: [ |
| 54 |
{ "005": "20250120101920.0" }, |
| 55 |
{ |
| 56 |
"245": { |
| 57 |
ind1: "", |
| 58 |
ind2: "", |
| 59 |
subfields: [{ a: "Some boring read" }], |
| 60 |
}, |
| 61 |
}, |
| 62 |
{ |
| 63 |
"100": { |
| 64 |
ind1: "", |
| 65 |
ind2: "", |
| 66 |
subfields: [ |
| 67 |
{ c: "Some boring author" }, |
| 68 |
], |
| 69 |
}, |
| 70 |
}, |
| 71 |
{ |
| 72 |
"942": { |
| 73 |
ind1: "", |
| 74 |
ind2: "", |
| 75 |
subfields: [ |
| 76 |
{ c: item_type.item_type_id }, |
| 77 |
], |
| 78 |
}, |
| 79 |
}, |
| 80 |
], |
| 81 |
}; |
| 82 |
cy.request({ |
| 83 |
method: "POST", |
| 84 |
url: "/api/v1/biblios", |
| 85 |
headers: { |
| 86 |
"Content-Type": "application/marc-in-json", |
| 87 |
"x-confirm-not-duplicate": 1, |
| 88 |
}, |
| 89 |
body: biblio, |
| 90 |
}).then(response => { |
| 91 |
const biblio_id = response.body.id; |
| 92 |
cy.wrap(biblio_id).as("biblio_id"); |
| 93 |
cy.request({ |
| 94 |
method: "POST", |
| 95 |
url: `/api/v1/biblios/${biblio_id}/items`, |
| 96 |
headers: { |
| 97 |
"Content-Type": "application/json", |
| 98 |
}, |
| 99 |
body: { |
| 100 |
home_library_id: library.library_id, |
| 101 |
holding_library_id: library.library_id, |
| 102 |
}, |
| 103 |
}); |
| 104 |
}); |
| 105 |
}); |
| 106 |
}); |
| 107 |
cy.task("query", { |
13 |
cy.task("query", { |
| 108 |
sql: "SELECT value FROM systempreferences WHERE variable='AlwaysShowHoldingsTableFilters'", |
14 |
sql: "SELECT value FROM systempreferences WHERE variable='AlwaysShowHoldingsTableFilters'", |
| 109 |
}).then(value => { |
15 |
}).then(value => { |
| 110 |
cy.wrap(value).as("syspref_AlwaysShowHoldingsTableFilters"); |
16 |
cy.wrap(value).as("syspref_AlwaysShowHoldingsTableFilters"); |
| 111 |
}); |
17 |
}); |
|
|
18 |
|
| 19 |
cy.task("insertSampleBiblio", { item_count: baseTotalCount }).then( |
| 20 |
objects => { |
| 21 |
cy.wrap(objects).as("objects"); |
| 22 |
} |
| 23 |
); |
| 112 |
}); |
24 |
}); |
| 113 |
|
25 |
|
| 114 |
afterEach(function () { |
26 |
afterEach(function () { |
|
|
27 |
cy.task("deleteSampleObjects", this.objects); |
| 115 |
cy.set_syspref( |
28 |
cy.set_syspref( |
| 116 |
"AlwaysShowHoldingsTableFilters", |
29 |
"AlwaysShowHoldingsTableFilters", |
| 117 |
this.syspref_AlwaysShowHoldingsTableFilters |
30 |
this.syspref_AlwaysShowHoldingsTableFilters |
|
Lines 119-151
describe("catalogue/detail/holdings_table with items", () => {
Link Here
|
| 119 |
}); |
32 |
}); |
| 120 |
|
33 |
|
| 121 |
it("Correctly init the table", function () { |
34 |
it("Correctly init the table", function () { |
| 122 |
// Do not use `() => {` or this.biblio_id won't be retrieved |
35 |
// Do not use `() => {` or this.objets won't be retrieved |
| 123 |
const biblio_id = this.biblio_id; |
36 |
const biblio_id = this.objects.biblio.biblio_id; |
| 124 |
cy.task("buildSampleObjects", { |
37 |
cy.set_syspref("AlwaysShowHoldingsTableFilters", 1).then(() => { |
| 125 |
object: "item", |
|
|
| 126 |
count: RESTdefaultPageSize, |
| 127 |
values: { |
| 128 |
biblio_id, |
| 129 |
checkout: null, |
| 130 |
transfer: null, |
| 131 |
lost_status: 0, |
| 132 |
withdrawn: 0, |
| 133 |
damaged_status: 0, |
| 134 |
not_for_loan_status: 0, |
| 135 |
course_item: null, |
| 136 |
cover_image_ids: [], |
| 137 |
_status: ["available"], |
| 138 |
}, |
| 139 |
}).then(items => { |
| 140 |
cy.intercept("get", `/api/v1/biblios/${biblio_id}/items*`, { |
| 141 |
statuscode: 200, |
| 142 |
body: items, |
| 143 |
headers: { |
| 144 |
"X-Base-Total-Count": baseTotalCount, |
| 145 |
"X-Total-Count": baseTotalCount, |
| 146 |
}, |
| 147 |
}); |
| 148 |
|
| 149 |
cy.visit( |
38 |
cy.visit( |
| 150 |
"/cgi-bin/koha/catalogue/detail.pl?biblionumber=" + biblio_id |
39 |
"/cgi-bin/koha/catalogue/detail.pl?biblionumber=" + biblio_id |
| 151 |
); |
40 |
); |
|
Lines 162-409
describe("catalogue/detail/holdings_table with items", () => {
Link Here
|
| 162 |
}); |
51 |
}); |
| 163 |
|
52 |
|
| 164 |
it("Show filters", function () { |
53 |
it("Show filters", function () { |
| 165 |
// Do not use `() => {` or this.biblio_id won't be retrieved |
54 |
// Do not use `() => {` or this.objects won't be retrieved |
| 166 |
const biblio_id = this.biblio_id; |
55 |
const biblio_id = this.objects.biblio.biblio_id; |
| 167 |
cy.task("buildSampleObjects", { |
|
|
| 168 |
object: "item", |
| 169 |
count: RESTdefaultPageSize, |
| 170 |
values: { |
| 171 |
biblio_id, |
| 172 |
checkout: null, |
| 173 |
transfer: null, |
| 174 |
lost_status: 0, |
| 175 |
withdrawn: 0, |
| 176 |
damaged_status: 0, |
| 177 |
not_for_loan_status: 0, |
| 178 |
course_item: null, |
| 179 |
cover_image_ids: [], |
| 180 |
_status: ["available"], |
| 181 |
}, |
| 182 |
}).then(items => { |
| 183 |
cy.intercept("get", `/api/v1/biblios/${biblio_id}/items*`, { |
| 184 |
statuscode: 200, |
| 185 |
body: items, |
| 186 |
headers: { |
| 187 |
"X-Base-Total-Count": baseTotalCount, |
| 188 |
"X-Total-Count": baseTotalCount, |
| 189 |
}, |
| 190 |
}); |
| 191 |
|
56 |
|
| 192 |
cy.set_syspref("AlwaysShowHoldingsTableFilters", 0).then(() => { |
57 |
cy.set_syspref("AlwaysShowHoldingsTableFilters", 0).then(() => { |
| 193 |
cy.visit( |
58 |
cy.visit( |
| 194 |
"/cgi-bin/koha/catalogue/detail.pl?biblionumber=" + |
59 |
"/cgi-bin/koha/catalogue/detail.pl?biblionumber=" + biblio_id |
| 195 |
biblio_id |
60 |
); |
| 196 |
); |
|
|
| 197 |
|
61 |
|
| 198 |
// Hide the 'URL' column |
62 |
// Hide the 'URL' column |
| 199 |
cy.mock_table_settings( |
63 |
cy.mock_table_settings( |
| 200 |
{ |
64 |
{ |
| 201 |
columns: { uri: { is_hidden: 1 } }, |
65 |
columns: { uri: { is_hidden: 1 } }, |
| 202 |
}, |
66 |
}, |
| 203 |
"items_table_settings.holdings" |
67 |
"items_table_settings.holdings" |
| 204 |
); |
68 |
); |
| 205 |
|
69 |
|
| 206 |
cy.get("@columns").then(columns => { |
70 |
cy.get("@columns").then(columns => { |
| 207 |
cy.get(`#${table_id}_wrapper tbody tr`).should( |
71 |
cy.get(`#${table_id}_wrapper tbody tr`).should( |
| 208 |
"have.length", |
72 |
"have.length", |
| 209 |
RESTdefaultPageSize |
73 |
RESTdefaultPageSize |
| 210 |
); |
74 |
); |
| 211 |
|
75 |
|
| 212 |
// Filters are not displayed |
76 |
// Filters are not displayed |
| 213 |
cy.get(`#${table_id} thead tr`).should("have.length", 1); |
77 |
cy.get(`#${table_id} thead tr`).should("have.length", 1); |
| 214 |
|
78 |
|
| 215 |
cy.get(`#${table_id} th`).contains("Status"); |
79 |
cy.get(`#${table_id} th`).contains("Status"); |
| 216 |
cy.get(`#${table_id} th`) |
80 |
cy.get(`#${table_id} th`).contains("URL").should("not.exist"); |
| 217 |
.contains("URL") |
81 |
cy.get(`#${table_id} th`) |
| 218 |
.should("not.exist"); |
82 |
.contains("Course reserves") |
| 219 |
cy.get(`#${table_id} th`) |
83 |
.should("not.exist"); |
| 220 |
.contains("Course reserves") |
|
|
| 221 |
.should("not.exist"); |
| 222 |
|
84 |
|
| 223 |
cy.get(`.${table_id}_table_controls .show_filters`).click(); |
85 |
cy.get(`.${table_id}_table_controls .show_filters`).click(); |
| 224 |
cy.get(`#${table_id}_wrapper .dt-info`).contains( |
86 |
cy.get(`#${table_id}_wrapper .dt-info`).contains( |
| 225 |
`Showing 1 to ${RESTdefaultPageSize} of ${baseTotalCount} entries` |
87 |
`Showing 1 to ${RESTdefaultPageSize} of ${baseTotalCount} entries` |
| 226 |
); |
88 |
); |
| 227 |
// Filters are displayed |
89 |
// Filters are displayed |
| 228 |
cy.get(`#${table_id} thead tr`).should("have.length", 2); |
90 |
cy.get(`#${table_id} thead tr`).should("have.length", 2); |
| 229 |
|
91 |
|
| 230 |
cy.get(`#${table_id} th`).contains("Status"); |
92 |
cy.get(`#${table_id} th`).contains("Status"); |
| 231 |
cy.get(`#${table_id} th`) |
93 |
cy.get(`#${table_id} th`).contains("URL").should("not.exist"); |
| 232 |
.contains("URL") |
94 |
cy.get(`#${table_id} th`) |
| 233 |
.should("not.exist"); |
95 |
.contains("Course reserves") |
| 234 |
cy.get(`#${table_id} th`) |
96 |
.should("not.exist"); |
| 235 |
.contains("Course reserves") |
|
|
| 236 |
.should("not.exist"); |
| 237 |
}); |
| 238 |
}); |
97 |
}); |
|
|
98 |
}); |
| 239 |
|
99 |
|
| 240 |
cy.set_syspref("AlwaysShowHoldingsTableFilters", 1).then(() => { |
100 |
cy.set_syspref("AlwaysShowHoldingsTableFilters", 1).then(() => { |
| 241 |
cy.visit( |
101 |
cy.visit( |
| 242 |
"/cgi-bin/koha/catalogue/detail.pl?biblionumber=" + |
102 |
"/cgi-bin/koha/catalogue/detail.pl?biblionumber=" + biblio_id |
| 243 |
biblio_id |
103 |
); |
| 244 |
); |
|
|
| 245 |
|
104 |
|
| 246 |
// Hide the 'URL' column |
105 |
// Hide the 'URL' column |
| 247 |
cy.mock_table_settings( |
106 |
cy.mock_table_settings( |
| 248 |
{ |
107 |
{ |
| 249 |
columns: { uri: { is_hidden: 1 } }, |
108 |
columns: { uri: { is_hidden: 1 } }, |
| 250 |
}, |
109 |
}, |
| 251 |
"items_table_settings.holdings" |
110 |
"items_table_settings.holdings" |
| 252 |
); |
111 |
); |
| 253 |
|
112 |
|
| 254 |
cy.get("@columns").then(columns => { |
113 |
cy.get("@columns").then(columns => { |
| 255 |
cy.get(`#${table_id}_wrapper tbody tr`).should( |
114 |
cy.get(`#${table_id}_wrapper tbody tr`).should( |
| 256 |
"have.length", |
115 |
"have.length", |
| 257 |
RESTdefaultPageSize |
116 |
RESTdefaultPageSize |
| 258 |
); |
117 |
); |
| 259 |
|
118 |
|
| 260 |
// Filters are displayed |
119 |
// Filters are displayed |
| 261 |
cy.get(`#${table_id} thead tr`).should("have.length", 2); |
120 |
cy.get(`#${table_id} thead tr`).should("have.length", 2); |
| 262 |
|
121 |
|
| 263 |
cy.get(`.${table_id}_table_controls .hide_filters`).click(); |
122 |
cy.get(`.${table_id}_table_controls .hide_filters`).click(); |
| 264 |
|
123 |
|
| 265 |
// Filters are not displayed |
124 |
// Filters are not displayed |
| 266 |
cy.get(`#${table_id} thead tr`).should("have.length", 1); |
125 |
cy.get(`#${table_id} thead tr`).should("have.length", 1); |
| 267 |
}); |
|
|
| 268 |
}); |
126 |
}); |
| 269 |
}); |
127 |
}); |
| 270 |
}); |
128 |
}); |
| 271 |
|
129 |
|
| 272 |
it("Filters by code and description", function () { |
130 |
it("Filters by code and description", function () { |
| 273 |
// Do not use `() => {` or this.biblio_id won't be retrieved |
131 |
// Do not use `() => {` or this.objects won't be retrieved |
| 274 |
const biblio_id = this.biblio_id; |
132 |
const biblio_id = this.objects.biblio.biblio_id; |
| 275 |
cy.task("buildSampleObjects", { |
|
|
| 276 |
object: "item", |
| 277 |
count: RESTdefaultPageSize, |
| 278 |
values: { |
| 279 |
biblio_id, |
| 280 |
checkout: null, |
| 281 |
transfer: null, |
| 282 |
lost_status: 0, |
| 283 |
withdrawn: 0, |
| 284 |
damaged_status: 0, |
| 285 |
not_for_loan_status: 0, |
| 286 |
course_item: null, |
| 287 |
cover_image_ids: [], |
| 288 |
_status: ["available"], |
| 289 |
}, |
| 290 |
}).then(items => { |
| 291 |
cy.intercept("get", `/api/v1/biblios/${biblio_id}/items*`, { |
| 292 |
statuscode: 200, |
| 293 |
body: items, |
| 294 |
headers: { |
| 295 |
"X-Base-Total-Count": baseTotalCount, |
| 296 |
"X-Total-Count": baseTotalCount, |
| 297 |
}, |
| 298 |
}).as("searchItems"); |
| 299 |
|
133 |
|
| 300 |
cy.visit( |
134 |
cy.intercept("get", `/api/v1/biblios/${biblio_id}/items*`).as( |
| 301 |
"/cgi-bin/koha/catalogue/detail.pl?biblionumber=" + biblio_id |
135 |
"searchItems" |
| 302 |
); |
136 |
); |
| 303 |
|
137 |
|
| 304 |
cy.window().then(win => { |
138 |
cy.visit("/cgi-bin/koha/catalogue/detail.pl?biblionumber=" + biblio_id); |
| 305 |
win.coded_values.library = new Map( |
139 |
|
| 306 |
items.map(i => [ |
140 |
cy.wait("@searchItems"); |
| 307 |
i.home_library.name, |
|
|
| 308 |
i.home_library.library_id, |
| 309 |
]) |
| 310 |
); |
| 311 |
win.coded_values.item_type = new Map( |
| 312 |
items.map(i => [ |
| 313 |
i.item_type.description, |
| 314 |
i.item_type.item_type_id, |
| 315 |
]) |
| 316 |
); |
| 317 |
}); |
| 318 |
cy.wait("@searchItems"); |
| 319 |
|
| 320 |
let library_id = items[0].home_library.library_id; |
| 321 |
let library_name = items[0].home_library.name; |
| 322 |
cy.get(`#${table_id}_wrapper input.dt-input`).type(library_id); |
| 323 |
|
| 324 |
cy.wait("@searchItems").then(interception => { |
| 325 |
const q = interception.request.query.q; |
| 326 |
expect(q).to.match( |
| 327 |
new RegExp( |
| 328 |
`"me.home_library_id":{"like":"%${library_id}%"}` |
| 329 |
) |
| 330 |
); |
| 331 |
}); |
| 332 |
|
141 |
|
| 333 |
cy.get(`#${table_id}_wrapper input.dt-input`).clear(); |
142 |
cy.task("query", { |
| 334 |
cy.wait("@searchItems"); |
143 |
sql: "SELECT homebranch FROM items WHERE biblionumber=? LIMIT 1", |
| 335 |
cy.get(`#${table_id}_wrapper input.dt-input`).type(library_name); |
144 |
values: [biblio_id], |
|
|
145 |
}).then(result => { |
| 146 |
let library_id = result[0].homebranch; |
| 147 |
cy.task("query", { |
| 148 |
sql: "SELECT branchname FROM branches WHERE branchcode=?", |
| 149 |
values: [library_id], |
| 150 |
}).then(result => { |
| 151 |
let library_name = result[0].branchname; |
| 152 |
cy.get(`#${table_id}_wrapper input.dt-input`).type(library_id); |
| 153 |
|
| 154 |
cy.wait("@searchItems").then(interception => { |
| 155 |
const q = interception.request.query.q; |
| 156 |
expect(q).to.match( |
| 157 |
new RegExp( |
| 158 |
`"me.home_library_id":{"like":"%${library_id}%"}` |
| 159 |
) |
| 160 |
); |
| 161 |
}); |
| 336 |
|
162 |
|
| 337 |
cy.wait("@searchItems").then(interception => { |
163 |
cy.get(`#${table_id}_wrapper input.dt-input`).clear(); |
| 338 |
const q = interception.request.query.q; |
164 |
cy.wait("@searchItems"); |
| 339 |
expect(q).to.match( |
165 |
cy.get(`#${table_id}_wrapper input.dt-input`).type( |
| 340 |
new RegExp(`"me.home_library_id":\\["${library_id}"\\]`) |
166 |
library_name |
| 341 |
); |
167 |
); |
| 342 |
}); |
|
|
| 343 |
|
168 |
|
| 344 |
let item_type_id = items[0].item_type.item_type_id; |
169 |
cy.wait("@searchItems").then(interception => { |
| 345 |
let item_type_description = items[0].item_type.description; |
170 |
const q = interception.request.query.q; |
| 346 |
cy.get(`#${table_id}_wrapper input.dt-input`).clear(); |
171 |
expect(q).to.match( |
| 347 |
cy.wait("@searchItems"); |
172 |
new RegExp(`"me.home_library_id":\\["${library_id}"\\]`) |
| 348 |
cy.get(`#${table_id}_wrapper input.dt-input`).type(item_type_id); |
173 |
); |
|
|
174 |
}); |
| 175 |
}); |
| 176 |
}); |
| 349 |
|
177 |
|
| 350 |
cy.wait("@searchItems").then(interception => { |
178 |
cy.task("query", { |
| 351 |
const q = interception.request.query.q; |
179 |
sql: "SELECT itype FROM items WHERE biblionumber=? LIMIT 1", |
| 352 |
expect(q).to.match( |
180 |
values: [biblio_id], |
| 353 |
new RegExp(`"me.item_type_id":{"like":"%${item_type_id}%"}`) |
181 |
}).then(result => { |
|
|
182 |
let item_type_id = result[0].itype; |
| 183 |
cy.task("query", { |
| 184 |
sql: "SELECT description FROM itemtypes WHERE itemtype=?", |
| 185 |
values: [item_type_id], |
| 186 |
}).then(result => { |
| 187 |
let item_type_description = result[0].description; |
| 188 |
|
| 189 |
cy.get(`#${table_id}_wrapper input.dt-input`).clear(); |
| 190 |
cy.wait("@searchItems"); |
| 191 |
cy.get(`#${table_id}_wrapper input.dt-input`).type( |
| 192 |
item_type_id |
| 354 |
); |
193 |
); |
| 355 |
}); |
|
|
| 356 |
|
194 |
|
| 357 |
cy.get(`#${table_id}_wrapper input.dt-input`).clear(); |
195 |
cy.wait("@searchItems").then(interception => { |
| 358 |
cy.wait("@searchItems"); |
196 |
const q = interception.request.query.q; |
| 359 |
cy.get(`#${table_id}_wrapper input.dt-input`).type( |
197 |
expect(q).to.match( |
| 360 |
item_type_description |
198 |
new RegExp( |
| 361 |
); |
199 |
`"me.item_type_id":{"like":"%${item_type_id}%"}` |
|
|
200 |
) |
| 201 |
); |
| 202 |
}); |
| 362 |
|
203 |
|
| 363 |
cy.wait("@searchItems").then(interception => { |
204 |
cy.get(`#${table_id}_wrapper input.dt-input`).clear(); |
| 364 |
const q = interception.request.query.q; |
205 |
cy.wait("@searchItems"); |
| 365 |
expect(q).to.match( |
206 |
cy.get(`#${table_id}_wrapper input.dt-input`).type( |
| 366 |
new RegExp(`"me.item_type_id":\\["${item_type_id}"\\]`) |
207 |
item_type_description |
| 367 |
); |
208 |
); |
| 368 |
}); |
|
|
| 369 |
|
209 |
|
| 370 |
cy.viewport(2999, 2999); |
210 |
cy.wait("@searchItems").then(interception => { |
| 371 |
cy.get(`#${table_id}_wrapper input.dt-input`).clear(); |
211 |
const q = interception.request.query.q; |
| 372 |
cy.wait("@searchItems"); |
212 |
expect(q).to.match( |
| 373 |
// Show filters if not there already |
213 |
new RegExp(`"me.item_type_id":\\["${item_type_id}"\\]`) |
| 374 |
cy.get(`.${table_id}_table_controls .show_filters`) |
214 |
); |
| 375 |
.then(link => { |
215 |
}); |
| 376 |
if (link.is(":visible")) { |
216 |
|
| 377 |
cy.wrap(link).click(); |
217 |
cy.viewport(2999, 2999); |
| 378 |
cy.wait("@searchItems"); |
218 |
cy.get(`#${table_id}_wrapper input.dt-input`).clear(); |
| 379 |
} |
219 |
cy.wait("@searchItems"); |
| 380 |
}) |
220 |
// Show filters if not there already |
| 381 |
.then(() => { |
221 |
cy.get(`.${table_id}_table_controls .show_filters`) |
| 382 |
// Select first (non-empty) option |
222 |
.then(link => { |
| 383 |
cy.get( |
223 |
if (link.is(":visible")) { |
| 384 |
`#${table_id}_wrapper th#holdings_itype select` |
224 |
cy.wrap(link).click(); |
| 385 |
).then(select => { |
225 |
cy.wait("@searchItems"); |
| 386 |
const raw_value = select.find("option").eq(1).val(); |
226 |
} |
| 387 |
expect(raw_value).to.match(/^\^/); |
227 |
}) |
| 388 |
expect(raw_value).to.match(/\$$/); |
228 |
.then(() => { |
| 389 |
item_type_id = raw_value.replace(/^\^|\$$/g, ""); // Remove ^ and $ |
229 |
// Select first (non-empty) option |
| 390 |
}); |
230 |
cy.get( |
| 391 |
cy.get( |
231 |
`#${table_id}_wrapper th#holdings_itype select` |
| 392 |
`#${table_id}_wrapper th#holdings_itype select option` |
232 |
).then(select => { |
| 393 |
) |
233 |
const raw_value = select.find("option").eq(1).val(); |
| 394 |
.eq(1) |
234 |
expect(raw_value).to.match(/^\^/); |
| 395 |
.then(o => { |
235 |
expect(raw_value).to.match(/\$$/); |
| 396 |
cy.get( |
236 |
item_type_id = raw_value.replace(/^\^|\$$/g, ""); // Remove ^ and $ |
| 397 |
`#${table_id}_wrapper th#holdings_itype select` |
237 |
}); |
| 398 |
).select(o.val(), { force: true }); |
238 |
cy.get( |
|
|
239 |
`#${table_id}_wrapper th#holdings_itype select option` |
| 240 |
) |
| 241 |
.eq(1) |
| 242 |
.then(o => { |
| 243 |
cy.get( |
| 244 |
`#${table_id}_wrapper th#holdings_itype select` |
| 245 |
).select(o.val(), { force: true }); |
| 246 |
}); |
| 247 |
cy.wait("@searchItems").then(interception => { |
| 248 |
const q = interception.request.query.q; |
| 249 |
expect(q).to.match( |
| 250 |
new RegExp( |
| 251 |
`{"me.item_type_id":"${item_type_id}"}` |
| 252 |
) |
| 253 |
); |
| 399 |
}); |
254 |
}); |
| 400 |
cy.wait("@searchItems").then(interception => { |
|
|
| 401 |
const q = interception.request.query.q; |
| 402 |
expect(q).to.match( |
| 403 |
new RegExp(`{"me.item_type_id":"${item_type_id}"}`) |
| 404 |
); |
| 405 |
}); |
255 |
}); |
| 406 |
}); |
256 |
}); |
| 407 |
}); |
257 |
}); |
| 408 |
}); |
258 |
}); |
| 409 |
}); |
259 |
}); |
|
Lines 417-508
describe("catalogue/detail/holdings_table without items", () => {
Link Here
|
| 417 |
win.localStorage.clear(); |
267 |
win.localStorage.clear(); |
| 418 |
}); |
268 |
}); |
| 419 |
|
269 |
|
| 420 |
// FIXME All the following code should not be reused as it |
|
|
| 421 |
// It must be moved to a Cypress command or task "buildSampleBiblio" or even "insertSampleBiblio" |
| 422 |
let generated_objects = {}; |
| 423 |
const objects = [{ object: "library" }, { object: "item_type" }]; |
| 424 |
cy.wrap(Promise.resolve()) |
| 425 |
.then(() => { |
| 426 |
return objects.reduce((chain, { object }) => { |
| 427 |
return chain.then(() => { |
| 428 |
return cy |
| 429 |
.task("buildSampleObject", { object }) |
| 430 |
.then(attributes => { |
| 431 |
generated_objects[object] = attributes; |
| 432 |
}); |
| 433 |
}); |
| 434 |
}, Promise.resolve()); |
| 435 |
}) |
| 436 |
.then(() => { |
| 437 |
const item_type = generated_objects["item_type"]; |
| 438 |
const queries = [ |
| 439 |
{ |
| 440 |
sql: "INSERT INTO itemtypes(itemtype, description) VALUES (?, ?)", |
| 441 |
values: [item_type.item_type_id, item_type.description], |
| 442 |
}, |
| 443 |
]; |
| 444 |
cy.wrap(Promise.resolve()) |
| 445 |
.then(() => { |
| 446 |
return queries.reduce((chain, { sql, values }) => { |
| 447 |
return chain.then(() => |
| 448 |
cy.task("query", { sql, values }) |
| 449 |
); |
| 450 |
}, Promise.resolve()); |
| 451 |
}) |
| 452 |
.then(() => { |
| 453 |
let biblio = { |
| 454 |
leader: " nam a22 7a 4500", |
| 455 |
fields: [ |
| 456 |
{ "005": "20250120101920.0" }, |
| 457 |
{ |
| 458 |
"245": { |
| 459 |
ind1: "", |
| 460 |
ind2: "", |
| 461 |
subfields: [{ a: "Some boring read" }], |
| 462 |
}, |
| 463 |
}, |
| 464 |
{ |
| 465 |
"100": { |
| 466 |
ind1: "", |
| 467 |
ind2: "", |
| 468 |
subfields: [ |
| 469 |
{ c: "Some boring author" }, |
| 470 |
], |
| 471 |
}, |
| 472 |
}, |
| 473 |
{ |
| 474 |
"942": { |
| 475 |
ind1: "", |
| 476 |
ind2: "", |
| 477 |
subfields: [ |
| 478 |
{ c: item_type.item_type_id }, |
| 479 |
], |
| 480 |
}, |
| 481 |
}, |
| 482 |
], |
| 483 |
}; |
| 484 |
cy.request({ |
| 485 |
method: "POST", |
| 486 |
url: "/api/v1/biblios", |
| 487 |
headers: { |
| 488 |
"Content-Type": "application/marc-in-json", |
| 489 |
"x-confirm-not-duplicate": 1, |
| 490 |
}, |
| 491 |
body: biblio, |
| 492 |
}).then(response => { |
| 493 |
const biblio_id = response.body.id; |
| 494 |
cy.wrap(biblio_id).as("biblio_id"); |
| 495 |
}); |
| 496 |
}); |
| 497 |
}); |
| 498 |
cy.task("query", { |
270 |
cy.task("query", { |
| 499 |
sql: "SELECT value FROM systempreferences WHERE variable='AlwaysShowHoldingsTableFilters'", |
271 |
sql: "SELECT value FROM systempreferences WHERE variable='AlwaysShowHoldingsTableFilters'", |
| 500 |
}).then(value => { |
272 |
}).then(value => { |
| 501 |
cy.wrap(value).as("syspref_AlwaysShowHoldingsTableFilters"); |
273 |
cy.wrap(value).as("syspref_AlwaysShowHoldingsTableFilters"); |
| 502 |
}); |
274 |
}); |
|
|
275 |
|
| 276 |
cy.task("insertSampleBiblio", { item_count: 0 }).then(objects => { |
| 277 |
cy.wrap(objects).as("objects"); |
| 278 |
}); |
| 503 |
}); |
279 |
}); |
| 504 |
|
280 |
|
| 505 |
afterEach(function () { |
281 |
afterEach(function () { |
|
|
282 |
cy.task("deleteSampleObjects", this.objects); |
| 506 |
cy.set_syspref( |
283 |
cy.set_syspref( |
| 507 |
"AlwaysShowHoldingsTableFilters", |
284 |
"AlwaysShowHoldingsTableFilters", |
| 508 |
this.syspref_AlwaysShowHoldingsTableFilters |
285 |
this.syspref_AlwaysShowHoldingsTableFilters |
|
Lines 510-517
describe("catalogue/detail/holdings_table without items", () => {
Link Here
|
| 510 |
}); |
287 |
}); |
| 511 |
|
288 |
|
| 512 |
it("Do not display the table", function () { |
289 |
it("Do not display the table", function () { |
| 513 |
// Do not use `() => {` or this.biblio_id won't be retrieved |
290 |
// Do not use `() => {` or this.objects won't be retrieved |
| 514 |
const biblio_id = this.biblio_id; |
291 |
const biblio_id = this.objects.biblio.biblio_id; |
| 515 |
|
292 |
|
| 516 |
cy.visit("/cgi-bin/koha/catalogue/detail.pl?biblionumber=" + biblio_id); |
293 |
cy.visit("/cgi-bin/koha/catalogue/detail.pl?biblionumber=" + biblio_id); |
| 517 |
|
294 |
|