Lines 253-258
function get_agreements_additional_fields() {
Link Here
|
253 |
]; |
253 |
]; |
254 |
} |
254 |
} |
255 |
|
255 |
|
|
|
256 |
function get_no_additional_fields_package() { |
257 |
return { |
258 |
package_id: 1, |
259 |
name: "package 1", |
260 |
notes: "my first package", |
261 |
content_type: "", |
262 |
created_on: "2024-09-12T10:26:40+00:00", |
263 |
external_id: null, |
264 |
package_agreements: [], |
265 |
package_type: "", |
266 |
provider: null, |
267 |
resources_count: 0, |
268 |
vendor_id: 1, |
269 |
vendor: [cy.get_vendors_to_relate()[0]], |
270 |
extended_attributes: [], |
271 |
_strings: { |
272 |
"additional_field_values": [] |
273 |
}, |
274 |
}; |
275 |
} |
276 |
function get_package() { |
277 |
return { |
278 |
package_id: 1, |
279 |
name: "package 1", |
280 |
notes: "my first package", |
281 |
content_type: "", |
282 |
created_on: "2024-09-12T10:26:40+00:00", |
283 |
external_id: null, |
284 |
package_agreements: [], |
285 |
package_type: "", |
286 |
provider: null, |
287 |
resources_count: 0, |
288 |
vendor_id: 1, |
289 |
vendor: [cy.get_vendors_to_relate()[0]], |
290 |
extended_attributes: [ |
291 |
{ |
292 |
field_id: 1, |
293 |
id: "1", |
294 |
record_id: "1", |
295 |
value: "REF", |
296 |
}, |
297 |
{ |
298 |
field_id: 1, |
299 |
id: "2", |
300 |
record_id: "1", |
301 |
value: "NFIC", |
302 |
}, |
303 |
{ |
304 |
field_id: 2, |
305 |
id: "3", |
306 |
record_id: "1", |
307 |
value: "some text", |
308 |
}, |
309 |
{ |
310 |
field_id: 3, |
311 |
id: "4", |
312 |
record_id: "1", |
313 |
value: "some repeatable text", |
314 |
}, |
315 |
{ |
316 |
field_id: 4, |
317 |
id: "5", |
318 |
record_id: "1", |
319 |
value: "AF", |
320 |
}, |
321 |
], |
322 |
_strings: { |
323 |
additional_field_values: [ |
324 |
{ |
325 |
field_id: 1, |
326 |
field_label: "AV Repeatable", |
327 |
type: "av", |
328 |
value_str: "Reference, Non-fiction", |
329 |
}, |
330 |
{ |
331 |
field_id: 2, |
332 |
field_label: "Text non-repeatable", |
333 |
type: "text", |
334 |
value_str: "some text", |
335 |
}, |
336 |
{ |
337 |
field_id: 3, |
338 |
field_label: "Text repeatable", |
339 |
type: "text", |
340 |
value_str: "some repeatable text", |
341 |
}, |
342 |
{ |
343 |
field_id: 4, |
344 |
field_label: "AV Searchable", |
345 |
type: "av", |
346 |
value_str: "Afghanistan", |
347 |
}, |
348 |
], |
349 |
}, |
350 |
}; |
351 |
} |
352 |
|
353 |
function get_packages_additional_fields() { |
354 |
return [ |
355 |
{ |
356 |
authorised_value_category_name: "CCODE", |
357 |
extended_attribute_type_id: 1, |
358 |
marcfield: "", |
359 |
marcfield_mode: "get", |
360 |
name: "AV Repeatable", |
361 |
repeatable: true, |
362 |
searchable: true, |
363 |
resource_type: "package", |
364 |
}, |
365 |
{ |
366 |
authorised_value_category_name: null, |
367 |
extended_attribute_type_id: 2, |
368 |
marcfield: "", |
369 |
marcfield_mode: "get", |
370 |
name: "Text non-repeatable", |
371 |
repeatable: false, |
372 |
searchable: false, |
373 |
resource_type: "package", |
374 |
}, |
375 |
{ |
376 |
authorised_value_category_name: null, |
377 |
extended_attribute_type_id: 3, |
378 |
marcfield: "", |
379 |
marcfield_mode: "get", |
380 |
name: "Text repeatable", |
381 |
repeatable: true, |
382 |
searchable: false, |
383 |
resource_type: "package", |
384 |
}, |
385 |
{ |
386 |
authorised_value_category_name: "COUNTRY", |
387 |
extended_attribute_type_id: 4, |
388 |
marcfield: "", |
389 |
marcfield_mode: "get", |
390 |
name: "AV Searchable", |
391 |
repeatable: false, |
392 |
searchable: true, |
393 |
resource_type: "package", |
394 |
}, |
395 |
]; |
396 |
} |
397 |
|
256 |
function get_av_cats() { |
398 |
function get_av_cats() { |
257 |
return [ |
399 |
return [ |
258 |
{ |
400 |
{ |
Lines 1123-1126
describe("Additional Fields operations", () => {
Link Here
|
1123 |
).should("have.length", 2); |
1265 |
).should("have.length", 2); |
1124 |
}); |
1266 |
}); |
1125 |
|
1267 |
|
|
|
1268 |
// |
1269 |
// for packages |
1270 |
// |
1271 |
|
1272 |
it("Additional Fields display - Table (eHoldings packages)", () => { |
1273 |
let eholdings_package = get_package(); |
1274 |
let eholdings_packages = [eholdings_package]; |
1275 |
let eholdings_package_additional_fields = get_packages_additional_fields(); |
1276 |
let av_cats = get_av_cats(); |
1277 |
|
1278 |
cy.intercept("GET", "/api/v1/extended_attribute_types*", { |
1279 |
body: eholdings_package_additional_fields, |
1280 |
statusCode: 200, |
1281 |
}); |
1282 |
|
1283 |
cy.intercept("GET", "/api/v1/erm/eholdings/local/packages*", { |
1284 |
statusCode: 200, |
1285 |
body: eholdings_packages, |
1286 |
headers: { |
1287 |
"X-Base-Total-Count": "1", |
1288 |
"X-Total-Count": "1", |
1289 |
}, |
1290 |
}); |
1291 |
cy.intercept("GET", "/api/v1/erm/eholdings/local/packages/*", eholdings_package); |
1292 |
cy.visit("/cgi-bin/koha/erm/eholdings/local/packages"); |
1293 |
cy.get("#packages_list").contains("Showing 1 to 1 of 1 entries"); |
1294 |
|
1295 |
cy.get("#packages_list table tbody tr:first").contains( |
1296 |
get_description_from_av_value( |
1297 |
av_cats, |
1298 |
eholdings_package.extended_attributes[0] |
1299 |
) |
1300 |
); |
1301 |
cy.get("#packages_list table tbody tr:first").contains( |
1302 |
get_description_from_av_value( |
1303 |
av_cats, |
1304 |
eholdings_package.extended_attributes[0] |
1305 |
) + |
1306 |
", " + |
1307 |
get_description_from_av_value( |
1308 |
av_cats, |
1309 |
eholdings_package.extended_attributes[1] |
1310 |
) |
1311 |
); |
1312 |
}); |
1313 |
|
1314 |
it("Additional Fields display - Show (eHoldings packages)", () => { |
1315 |
let empty_eholdings_package = get_no_additional_fields_package(); |
1316 |
let eholdings_package = get_package(); |
1317 |
let eholdings_packages = [eholdings_package]; |
1318 |
let vendors = cy.get_vendors_to_relate(); |
1319 |
let eholdings_package_additional_fields = get_packages_additional_fields(); |
1320 |
let av_cats = get_av_cats(); |
1321 |
|
1322 |
// Click the 'Edit' button from the list |
1323 |
cy.intercept("GET", "/api/v1/erm/eholdings/local/packages*", { |
1324 |
statusCode: 200, |
1325 |
body: eholdings_packages, |
1326 |
headers: { |
1327 |
"X-Base-Total-Count": "1", |
1328 |
"X-Total-Count": "1", |
1329 |
}, |
1330 |
}); |
1331 |
cy.intercept("GET", "/api/v1/erm/eholdings/local/packages/*", empty_eholdings_package).as( |
1332 |
"get-empty-eholdings-package" |
1333 |
); |
1334 |
|
1335 |
//Intercept vendors request |
1336 |
cy.intercept("GET", "/api/v1/acquisitions/vendors*", { |
1337 |
statusCode: 200, |
1338 |
body: vendors, |
1339 |
}); |
1340 |
cy.intercept("GET", "/api/v1/extended_attribute_types*", { |
1341 |
body: [], |
1342 |
statusCode: 200, |
1343 |
}).as("empty-additional-fields"); |
1344 |
|
1345 |
//Empty additional fields, should not display |
1346 |
cy.visit("/cgi-bin/koha/erm/eholdings/local/packages"); |
1347 |
cy.get("#packages_list table tbody tr:first td:first a").click(); |
1348 |
cy.wait("@get-empty-eholdings-package"); |
1349 |
cy.get("#packages_list #additional_fields").should("not.exist"); |
1350 |
|
1351 |
cy.intercept("GET", "/api/v1/extended_attribute_types*", { |
1352 |
body: eholdings_package_additional_fields, |
1353 |
statusCode: 200, |
1354 |
}).as("existing-additional-fields"); |
1355 |
|
1356 |
cy.intercept( |
1357 |
{ |
1358 |
pathname: "/api/v1/authorised_value_categories", |
1359 |
query: { |
1360 |
q: '{"me.category_name":["CCODE", "COUNTRY"]}', |
1361 |
}, |
1362 |
}, |
1363 |
{ |
1364 |
body: av_cats, |
1365 |
statusCode: 200, |
1366 |
} |
1367 |
).as("avcategories"); |
1368 |
|
1369 |
cy.intercept("GET", "/api/v1/erm/eholdings/local/packages/*", eholdings_package).as( |
1370 |
"get-eholdings-package" |
1371 |
); |
1372 |
|
1373 |
// There are additional fields, fieldset should exist |
1374 |
cy.visit("/cgi-bin/koha/erm/eholdings/local/packages"); |
1375 |
cy.get("#packages_list table tbody tr:first td:first a").click(); |
1376 |
cy.wait("@get-eholdings-package"); |
1377 |
cy.get("#packages_show #additional_fields").should("exist"); |
1378 |
|
1379 |
// All fields are presented correctly |
1380 |
cy.get( |
1381 |
"#packages_show #additional_fields label[for='additional_field_1']" |
1382 |
).contains(eholdings_package_additional_fields[0].name); |
1383 |
cy.get( |
1384 |
"#packages_show #additional_fields label[for='additional_field_1']" |
1385 |
) |
1386 |
.parent() |
1387 |
.children("span") |
1388 |
.contains( |
1389 |
get_description_from_av_value( |
1390 |
av_cats, |
1391 |
eholdings_package.extended_attributes[0] |
1392 |
) + |
1393 |
", " + |
1394 |
get_description_from_av_value( |
1395 |
av_cats, |
1396 |
eholdings_package.extended_attributes[1] |
1397 |
) |
1398 |
); |
1399 |
|
1400 |
cy.get( |
1401 |
"#packages_show #additional_fields label[for='additional_field_2']" |
1402 |
).contains(eholdings_package_additional_fields[1].name); |
1403 |
cy.get( |
1404 |
"#packages_show #additional_fields label[for='additional_field_2']" |
1405 |
) |
1406 |
.parent() |
1407 |
.children("span") |
1408 |
.contains(eholdings_package.extended_attributes[2].value); |
1409 |
|
1410 |
cy.get( |
1411 |
"#packages_show #additional_fields label[for='additional_field_3']" |
1412 |
).contains(eholdings_package_additional_fields[2].name); |
1413 |
cy.get( |
1414 |
"#packages_show #additional_fields label[for='additional_field_3']" |
1415 |
) |
1416 |
.parent() |
1417 |
.children("span") |
1418 |
.contains(eholdings_package.extended_attributes[3].value); |
1419 |
|
1420 |
cy.get( |
1421 |
"#packages_show #additional_fields label[for='additional_field_4']" |
1422 |
).contains(eholdings_package_additional_fields[3].name); |
1423 |
cy.get( |
1424 |
"#packages_show #additional_fields label[for='additional_field_4']" |
1425 |
) |
1426 |
.parent() |
1427 |
.children("span") |
1428 |
.contains( |
1429 |
get_description_from_av_value( |
1430 |
av_cats, |
1431 |
eholdings_package.extended_attributes[4] |
1432 |
) |
1433 |
); |
1434 |
}); |
1435 |
|
1436 |
it("Additional Fields entry - Add (eHoldings packages)", () => { |
1437 |
let vendors = cy.get_vendors_to_relate(); |
1438 |
let eholdings_package_additional_fields = get_packages_additional_fields(); |
1439 |
let av_cats = get_av_cats(); |
1440 |
|
1441 |
//Intercept vendors request |
1442 |
cy.intercept("GET", "/api/v1/acquisitions/vendors*", { |
1443 |
statusCode: 200, |
1444 |
body: vendors, |
1445 |
}); |
1446 |
cy.intercept("GET", "/api/v1/extended_attribute_types*", { |
1447 |
body: [], |
1448 |
statusCode: 200, |
1449 |
}).as("empty-additional-fields"); |
1450 |
|
1451 |
// No additional fields, fieldset should not exist |
1452 |
cy.visit("/cgi-bin/koha/erm/eholdings/local/packages/add"); |
1453 |
cy.get("#packages_add form #additional_fields").should("not.exist"); |
1454 |
|
1455 |
cy.intercept("GET", "/api/v1/extended_attribute_types*", { |
1456 |
body: eholdings_package_additional_fields, |
1457 |
statusCode: 200, |
1458 |
}).as("existing-additional-fields"); |
1459 |
|
1460 |
cy.intercept( |
1461 |
{ |
1462 |
pathname: "/api/v1/authorised_value_categories", |
1463 |
query: { |
1464 |
q: '{"me.category_name":["CCODE", "COUNTRY"]}', |
1465 |
}, |
1466 |
}, |
1467 |
{ |
1468 |
body: av_cats, |
1469 |
statusCode: 200, |
1470 |
} |
1471 |
).as("avcategories"); |
1472 |
// There are additional fields, fieldset should exist |
1473 |
cy.visit("/cgi-bin/koha/erm/eholdings/local/packages/add"); |
1474 |
cy.get("#packages_add form #additional_fields").should("exist"); |
1475 |
|
1476 |
// All additional fields should be listed |
1477 |
cy.get( |
1478 |
"#packages_add form #additional_fields label[for='additional_field_1']" |
1479 |
).contains(eholdings_package_additional_fields[0].name); |
1480 |
cy.get( |
1481 |
"#packages_add form #additional_fields label[for='additional_field_2']" |
1482 |
).contains(eholdings_package_additional_fields[1].name); |
1483 |
cy.get( |
1484 |
"#packages_add form #additional_fields label[for='additional_field_3']" |
1485 |
).contains(eholdings_package_additional_fields[2].name); |
1486 |
cy.get( |
1487 |
"#packages_add form #additional_fields label[for='additional_field_4']" |
1488 |
).contains(eholdings_package_additional_fields[3].name); |
1489 |
|
1490 |
cy.get("#additional_fields #additional_field_1 .vs__selected").should( |
1491 |
"not.exist" |
1492 |
); //new package, no pre-selected value |
1493 |
|
1494 |
// Pick one value |
1495 |
cy.get("#additional_fields #additional_field_1 .vs__search").click(); |
1496 |
cy.get( |
1497 |
"#additional_fields #additional_field_1 #vs4__option-0" |
1498 |
).contains(av_cats[0].authorised_values[0].description); |
1499 |
cy.get("#additional_fields #additional_field_1 #vs4__option-0").click(); |
1500 |
cy.get("#additional_fields #additional_field_1 .vs__selected").contains( |
1501 |
av_cats[0].authorised_values[0].description |
1502 |
); |
1503 |
cy.get("#additional_fields #additional_field_1 .vs__selected").should( |
1504 |
"have.length", |
1505 |
1 |
1506 |
); |
1507 |
|
1508 |
// Pick a second value for the same repeatable AV field |
1509 |
cy.get("#additional_fields #additional_field_1 .vs__search").click(); |
1510 |
cy.get( |
1511 |
"#additional_fields #additional_field_1 #vs4__option-1" |
1512 |
).contains(av_cats[0].authorised_values[1].description); |
1513 |
cy.get("#additional_fields #additional_field_1 #vs4__option-1").click(); |
1514 |
cy.get("#additional_fields #additional_field_1 .vs__selected").contains( |
1515 |
av_cats[0].authorised_values[1].description |
1516 |
); |
1517 |
cy.get("#additional_fields #additional_field_1 .vs__selected").should( |
1518 |
"have.length", |
1519 |
2 |
1520 |
); |
1521 |
|
1522 |
// Attempt to pick the same value again - should not be possible |
1523 |
cy.get("#additional_fields #additional_field_1 .vs__search").click(); |
1524 |
cy.get( |
1525 |
"#additional_fields #additional_field_1 #vs4__option-1" |
1526 |
).contains(av_cats[0].authorised_values[1].description); |
1527 |
cy.get("#additional_fields #additional_field_1 #vs4__option-1").click(); |
1528 |
cy.get("#additional_fields #additional_field_1 .vs__selected").should( |
1529 |
"have.length", |
1530 |
2 |
1531 |
); |
1532 |
|
1533 |
// Remove the second selected value |
1534 |
cy.get( |
1535 |
"#additional_fields #additional_field_1 .vs__selected button[title='Deselect " + |
1536 |
av_cats[0].authorised_values[1].description + |
1537 |
"'" |
1538 |
).click(); |
1539 |
cy.get("#additional_fields #additional_field_1 .vs__selected").should( |
1540 |
"have.length", |
1541 |
1 |
1542 |
); |
1543 |
cy.get("#additional_fields #additional_field_1 .vs__selected").contains( |
1544 |
av_cats[0].authorised_values[0].description |
1545 |
); |
1546 |
}); |
1547 |
|
1548 |
it("Additional Fields entry - Edit (eHoldings packages)", () => { |
1549 |
let eholdings_package = get_package(); |
1550 |
let eholdings_packages = [eholdings_package]; |
1551 |
let vendors = cy.get_vendors_to_relate(); |
1552 |
let eholdings_package_additional_fields = get_packages_additional_fields(); |
1553 |
let av_cats = get_av_cats(); |
1554 |
|
1555 |
// Click the 'Edit' button from the list |
1556 |
cy.intercept("GET", "/api/v1/erm/eholdings/local/packages*", { |
1557 |
statusCode: 200, |
1558 |
body: eholdings_packages, |
1559 |
headers: { |
1560 |
"X-Base-Total-Count": "1", |
1561 |
"X-Total-Count": "1", |
1562 |
}, |
1563 |
}); |
1564 |
cy.intercept("GET", "/api/v1/erm/eholdings/local/packages/*", eholdings_package).as( |
1565 |
"get-eholdings-package" |
1566 |
); |
1567 |
|
1568 |
//Intercept vendors request |
1569 |
cy.intercept("GET", "/api/v1/acquisitions/vendors*", { |
1570 |
statusCode: 200, |
1571 |
body: vendors, |
1572 |
}); |
1573 |
|
1574 |
cy.intercept("GET", "/api/v1/extended_attribute_types*", { |
1575 |
body: eholdings_package_additional_fields, |
1576 |
statusCode: 200, |
1577 |
}).as("existing-additional-fields"); |
1578 |
|
1579 |
cy.intercept( |
1580 |
{ |
1581 |
pathname: "/api/v1/authorised_value_categories", |
1582 |
query: { |
1583 |
q: '{"me.category_name":["CCODE", "COUNTRY"]}', |
1584 |
}, |
1585 |
}, |
1586 |
{ |
1587 |
body: av_cats, |
1588 |
statusCode: 200, |
1589 |
} |
1590 |
).as("avcategories"); |
1591 |
|
1592 |
cy.visit("/cgi-bin/koha/erm/eholdings/local/packages"); |
1593 |
cy.get("#packages_list table tbody tr:first").contains("Edit").click(); |
1594 |
cy.wait("@get-eholdings-package"); |
1595 |
cy.wait(500); // Cypress is too fast! Vue hasn't populated the form yet! |
1596 |
|
1597 |
// All additional fields should be pre-populated |
1598 |
cy.get("#additional_fields #additional_field_1 .vs__selected").contains( |
1599 |
get_description_from_av_value( |
1600 |
av_cats, |
1601 |
eholdings_package.extended_attributes[0] |
1602 |
) |
1603 |
); |
1604 |
cy.get("#additional_fields #additional_field_1 .vs__selected").contains( |
1605 |
get_description_from_av_value( |
1606 |
av_cats, |
1607 |
eholdings_package.extended_attributes[1] |
1608 |
) |
1609 |
); |
1610 |
|
1611 |
cy.get( |
1612 |
"#packages_add form #additional_fields label[for='additional_field_2']" |
1613 |
) |
1614 |
.parent() |
1615 |
.children("input") |
1616 |
.should("have.value", eholdings_package.extended_attributes[2].value); |
1617 |
|
1618 |
cy.get( |
1619 |
"#packages_add form #additional_fields label[for='additional_field_3']" |
1620 |
) |
1621 |
.parent() |
1622 |
.children("input") |
1623 |
.should("have.value", eholdings_package.extended_attributes[3].value); |
1624 |
|
1625 |
cy.get("#additional_fields #additional_field_4 .vs__selected").contains( |
1626 |
get_description_from_av_value( |
1627 |
av_cats, |
1628 |
eholdings_package.extended_attributes[4] |
1629 |
) |
1630 |
); |
1631 |
|
1632 |
// Clear text field works |
1633 |
cy.get( |
1634 |
"#packages_add form #additional_fields label[for='additional_field_2']" |
1635 |
) |
1636 |
.parent() |
1637 |
.children(".clear_attribute") |
1638 |
.click(); |
1639 |
cy.get( |
1640 |
"#packages_add form #additional_fields label[for='additional_field_2']" |
1641 |
) |
1642 |
.parent() |
1643 |
.children("input") |
1644 |
.should("have.value", ""); |
1645 |
|
1646 |
// "+New" text field works |
1647 |
cy.get( |
1648 |
"#packages_add form #additional_fields label[for='additional_field_3']" |
1649 |
).should("have.length", 1); |
1650 |
cy.get( |
1651 |
"#packages_add form #additional_fields label[for='additional_field_3']" |
1652 |
) |
1653 |
.parent() |
1654 |
.children(".clone_attribute") |
1655 |
.click(); |
1656 |
cy.get( |
1657 |
"#packages_add form #additional_fields label[for='additional_field_3']" |
1658 |
).should("have.length", 2); |
1659 |
}); |
1660 |
|
1126 |
}); |
1661 |
}); |
1127 |
- |
|
|