Lines 338-343
function get_agreements_additional_fields() {
Link Here
|
338 |
]; |
338 |
]; |
339 |
} |
339 |
} |
340 |
|
340 |
|
|
|
341 |
function get_no_additional_fields_package() { |
342 |
return { |
343 |
package_id: 1, |
344 |
name: "package 1", |
345 |
notes: "my first package", |
346 |
content_type: "", |
347 |
created_on: "2024-09-12T10:26:40+00:00", |
348 |
external_id: null, |
349 |
package_agreements: [], |
350 |
package_type: "", |
351 |
provider: null, |
352 |
resources_count: 0, |
353 |
vendor_id: 1, |
354 |
vendor: [cy.get_vendors_to_relate()[0]], |
355 |
extended_attributes: [], |
356 |
_strings: { |
357 |
"additional_field_values": [] |
358 |
}, |
359 |
}; |
360 |
} |
361 |
function get_package() { |
362 |
return { |
363 |
package_id: 1, |
364 |
name: "package 1", |
365 |
notes: "my first package", |
366 |
content_type: "", |
367 |
created_on: "2024-09-12T10:26:40+00:00", |
368 |
external_id: null, |
369 |
package_agreements: [], |
370 |
package_type: "", |
371 |
provider: null, |
372 |
resources_count: 0, |
373 |
vendor_id: 1, |
374 |
vendor: [cy.get_vendors_to_relate()[0]], |
375 |
extended_attributes: [ |
376 |
{ |
377 |
field_id: 1, |
378 |
id: "1", |
379 |
record_id: "1", |
380 |
value: "REF", |
381 |
}, |
382 |
{ |
383 |
field_id: 1, |
384 |
id: "2", |
385 |
record_id: "1", |
386 |
value: "NFIC", |
387 |
}, |
388 |
{ |
389 |
field_id: 2, |
390 |
id: "3", |
391 |
record_id: "1", |
392 |
value: "some text", |
393 |
}, |
394 |
{ |
395 |
field_id: 3, |
396 |
id: "4", |
397 |
record_id: "1", |
398 |
value: "some repeatable text", |
399 |
}, |
400 |
{ |
401 |
field_id: 4, |
402 |
id: "5", |
403 |
record_id: "1", |
404 |
value: "AF", |
405 |
}, |
406 |
], |
407 |
_strings: { |
408 |
additional_field_values: [ |
409 |
{ |
410 |
field_id: 1, |
411 |
field_label: "AV Repeatable", |
412 |
type: "av", |
413 |
value_str: "Reference, Non-fiction", |
414 |
}, |
415 |
{ |
416 |
field_id: 2, |
417 |
field_label: "Text non-repeatable", |
418 |
type: "text", |
419 |
value_str: "some text", |
420 |
}, |
421 |
{ |
422 |
field_id: 3, |
423 |
field_label: "Text repeatable", |
424 |
type: "text", |
425 |
value_str: "some repeatable text", |
426 |
}, |
427 |
{ |
428 |
field_id: 4, |
429 |
field_label: "AV Searchable", |
430 |
type: "av", |
431 |
value_str: "Afghanistan", |
432 |
}, |
433 |
], |
434 |
}, |
435 |
}; |
436 |
} |
437 |
|
438 |
function get_packages_additional_fields() { |
439 |
return [ |
440 |
{ |
441 |
authorised_value_category_name: "CCODE", |
442 |
extended_attribute_type_id: 1, |
443 |
marcfield: "", |
444 |
marcfield_mode: "get", |
445 |
name: "AV Repeatable", |
446 |
repeatable: true, |
447 |
searchable: true, |
448 |
resource_type: "package", |
449 |
}, |
450 |
{ |
451 |
authorised_value_category_name: null, |
452 |
extended_attribute_type_id: 2, |
453 |
marcfield: "", |
454 |
marcfield_mode: "get", |
455 |
name: "Text non-repeatable", |
456 |
repeatable: false, |
457 |
searchable: false, |
458 |
resource_type: "package", |
459 |
}, |
460 |
{ |
461 |
authorised_value_category_name: null, |
462 |
extended_attribute_type_id: 3, |
463 |
marcfield: "", |
464 |
marcfield_mode: "get", |
465 |
name: "Text repeatable", |
466 |
repeatable: true, |
467 |
searchable: false, |
468 |
resource_type: "package", |
469 |
}, |
470 |
{ |
471 |
authorised_value_category_name: "COUNTRY", |
472 |
extended_attribute_type_id: 4, |
473 |
marcfield: "", |
474 |
marcfield_mode: "get", |
475 |
name: "AV Searchable", |
476 |
repeatable: false, |
477 |
searchable: true, |
478 |
resource_type: "package", |
479 |
}, |
480 |
]; |
481 |
} |
482 |
|
341 |
function get_av_cats() { |
483 |
function get_av_cats() { |
342 |
return [ |
484 |
return [ |
343 |
{ |
485 |
{ |
Lines 1208-1211
describe("Additional Fields operations", () => {
Link Here
|
1208 |
).should("have.length", 2); |
1350 |
).should("have.length", 2); |
1209 |
}); |
1351 |
}); |
1210 |
|
1352 |
|
|
|
1353 |
// |
1354 |
// for packages |
1355 |
// |
1356 |
|
1357 |
it("Additional Fields display - Table (eHoldings packages)", () => { |
1358 |
let eholdings_package = get_package(); |
1359 |
let eholdings_packages = [eholdings_package]; |
1360 |
let eholdings_package_additional_fields = get_packages_additional_fields(); |
1361 |
let av_cats = get_av_cats(); |
1362 |
|
1363 |
cy.intercept("GET", "/api/v1/extended_attribute_types*", { |
1364 |
body: eholdings_package_additional_fields, |
1365 |
statusCode: 200, |
1366 |
}); |
1367 |
|
1368 |
cy.intercept("GET", "/api/v1/erm/eholdings/local/packages*", { |
1369 |
statusCode: 200, |
1370 |
body: eholdings_packages, |
1371 |
headers: { |
1372 |
"X-Base-Total-Count": "1", |
1373 |
"X-Total-Count": "1", |
1374 |
}, |
1375 |
}); |
1376 |
cy.intercept("GET", "/api/v1/erm/eholdings/local/packages/*", eholdings_package); |
1377 |
cy.visit("/cgi-bin/koha/erm/eholdings/local/packages"); |
1378 |
cy.get("#packages_list").contains("Showing 1 to 1 of 1 entries"); |
1379 |
|
1380 |
cy.get("#packages_list table tbody tr:first").contains( |
1381 |
get_description_from_av_value( |
1382 |
av_cats, |
1383 |
eholdings_package.extended_attributes[0] |
1384 |
) |
1385 |
); |
1386 |
cy.get("#packages_list table tbody tr:first").contains( |
1387 |
get_description_from_av_value( |
1388 |
av_cats, |
1389 |
eholdings_package.extended_attributes[0] |
1390 |
) + |
1391 |
", " + |
1392 |
get_description_from_av_value( |
1393 |
av_cats, |
1394 |
eholdings_package.extended_attributes[1] |
1395 |
) |
1396 |
); |
1397 |
}); |
1398 |
|
1399 |
it("Additional Fields display - Show (eHoldings packages)", () => { |
1400 |
let empty_eholdings_package = get_no_additional_fields_package(); |
1401 |
let eholdings_package = get_package(); |
1402 |
let eholdings_packages = [eholdings_package]; |
1403 |
let vendors = cy.get_vendors_to_relate(); |
1404 |
let eholdings_package_additional_fields = get_packages_additional_fields(); |
1405 |
let av_cats = get_av_cats(); |
1406 |
|
1407 |
// Click the 'Edit' button from the list |
1408 |
cy.intercept("GET", "/api/v1/erm/eholdings/local/packages*", { |
1409 |
statusCode: 200, |
1410 |
body: eholdings_packages, |
1411 |
headers: { |
1412 |
"X-Base-Total-Count": "1", |
1413 |
"X-Total-Count": "1", |
1414 |
}, |
1415 |
}); |
1416 |
cy.intercept("GET", "/api/v1/erm/eholdings/local/packages/*", empty_eholdings_package).as( |
1417 |
"get-empty-eholdings-package" |
1418 |
); |
1419 |
|
1420 |
//Intercept vendors request |
1421 |
cy.intercept("GET", "/api/v1/acquisitions/vendors*", { |
1422 |
statusCode: 200, |
1423 |
body: vendors, |
1424 |
}); |
1425 |
cy.intercept("GET", "/api/v1/extended_attribute_types*", { |
1426 |
body: [], |
1427 |
statusCode: 200, |
1428 |
}).as("empty-additional-fields"); |
1429 |
|
1430 |
//Empty additional fields, should not display |
1431 |
cy.visit("/cgi-bin/koha/erm/eholdings/local/packages"); |
1432 |
cy.get("#packages_list table tbody tr:first td:first a").click(); |
1433 |
cy.wait("@get-empty-eholdings-package"); |
1434 |
cy.get("#packages_list #additional_fields").should("not.exist"); |
1435 |
|
1436 |
cy.intercept("GET", "/api/v1/extended_attribute_types*", { |
1437 |
body: eholdings_package_additional_fields, |
1438 |
statusCode: 200, |
1439 |
}).as("existing-additional-fields"); |
1440 |
|
1441 |
cy.intercept( |
1442 |
{ |
1443 |
pathname: "/api/v1/authorised_value_categories", |
1444 |
query: { |
1445 |
q: '{"me.category_name":["CCODE", "COUNTRY"]}', |
1446 |
}, |
1447 |
}, |
1448 |
{ |
1449 |
body: av_cats, |
1450 |
statusCode: 200, |
1451 |
} |
1452 |
).as("avcategories"); |
1453 |
|
1454 |
cy.intercept("GET", "/api/v1/erm/eholdings/local/packages/*", eholdings_package).as( |
1455 |
"get-eholdings-package" |
1456 |
); |
1457 |
|
1458 |
// There are additional fields, fieldset should exist |
1459 |
cy.visit("/cgi-bin/koha/erm/eholdings/local/packages"); |
1460 |
cy.get("#packages_list table tbody tr:first td:first a").click(); |
1461 |
cy.wait("@get-eholdings-package"); |
1462 |
cy.get("#packages_show #additional_fields").should("exist"); |
1463 |
|
1464 |
// All fields are presented correctly |
1465 |
cy.get( |
1466 |
"#packages_show #additional_fields label[for='additional_field_1']" |
1467 |
).contains(eholdings_package_additional_fields[0].name); |
1468 |
cy.get( |
1469 |
"#packages_show #additional_fields label[for='additional_field_1']" |
1470 |
) |
1471 |
.parent() |
1472 |
.children("span") |
1473 |
.contains( |
1474 |
get_description_from_av_value( |
1475 |
av_cats, |
1476 |
eholdings_package.extended_attributes[0] |
1477 |
) + |
1478 |
", " + |
1479 |
get_description_from_av_value( |
1480 |
av_cats, |
1481 |
eholdings_package.extended_attributes[1] |
1482 |
) |
1483 |
); |
1484 |
|
1485 |
cy.get( |
1486 |
"#packages_show #additional_fields label[for='additional_field_2']" |
1487 |
).contains(eholdings_package_additional_fields[1].name); |
1488 |
cy.get( |
1489 |
"#packages_show #additional_fields label[for='additional_field_2']" |
1490 |
) |
1491 |
.parent() |
1492 |
.children("span") |
1493 |
.contains(eholdings_package.extended_attributes[2].value); |
1494 |
|
1495 |
cy.get( |
1496 |
"#packages_show #additional_fields label[for='additional_field_3']" |
1497 |
).contains(eholdings_package_additional_fields[2].name); |
1498 |
cy.get( |
1499 |
"#packages_show #additional_fields label[for='additional_field_3']" |
1500 |
) |
1501 |
.parent() |
1502 |
.children("span") |
1503 |
.contains(eholdings_package.extended_attributes[3].value); |
1504 |
|
1505 |
cy.get( |
1506 |
"#packages_show #additional_fields label[for='additional_field_4']" |
1507 |
).contains(eholdings_package_additional_fields[3].name); |
1508 |
cy.get( |
1509 |
"#packages_show #additional_fields label[for='additional_field_4']" |
1510 |
) |
1511 |
.parent() |
1512 |
.children("span") |
1513 |
.contains( |
1514 |
get_description_from_av_value( |
1515 |
av_cats, |
1516 |
eholdings_package.extended_attributes[4] |
1517 |
) |
1518 |
); |
1519 |
}); |
1520 |
|
1521 |
it("Additional Fields entry - Add (eHoldings packages)", () => { |
1522 |
let vendors = cy.get_vendors_to_relate(); |
1523 |
let eholdings_package_additional_fields = get_packages_additional_fields(); |
1524 |
let av_cats = get_av_cats(); |
1525 |
|
1526 |
//Intercept vendors request |
1527 |
cy.intercept("GET", "/api/v1/acquisitions/vendors*", { |
1528 |
statusCode: 200, |
1529 |
body: vendors, |
1530 |
}); |
1531 |
cy.intercept("GET", "/api/v1/extended_attribute_types*", { |
1532 |
body: [], |
1533 |
statusCode: 200, |
1534 |
}).as("empty-additional-fields"); |
1535 |
|
1536 |
// No additional fields, fieldset should not exist |
1537 |
cy.visit("/cgi-bin/koha/erm/eholdings/local/packages/add"); |
1538 |
cy.get("#packages_add form #additional_fields").should("not.exist"); |
1539 |
|
1540 |
cy.intercept("GET", "/api/v1/extended_attribute_types*", { |
1541 |
body: eholdings_package_additional_fields, |
1542 |
statusCode: 200, |
1543 |
}).as("existing-additional-fields"); |
1544 |
|
1545 |
cy.intercept( |
1546 |
{ |
1547 |
pathname: "/api/v1/authorised_value_categories", |
1548 |
query: { |
1549 |
q: '{"me.category_name":["CCODE", "COUNTRY"]}', |
1550 |
}, |
1551 |
}, |
1552 |
{ |
1553 |
body: av_cats, |
1554 |
statusCode: 200, |
1555 |
} |
1556 |
).as("avcategories"); |
1557 |
// There are additional fields, fieldset should exist |
1558 |
cy.visit("/cgi-bin/koha/erm/eholdings/local/packages/add"); |
1559 |
cy.get("#packages_add form #additional_fields").should("exist"); |
1560 |
|
1561 |
// All additional fields should be listed |
1562 |
cy.get( |
1563 |
"#packages_add form #additional_fields label[for='additional_field_1']" |
1564 |
).contains(eholdings_package_additional_fields[0].name); |
1565 |
cy.get( |
1566 |
"#packages_add form #additional_fields label[for='additional_field_2']" |
1567 |
).contains(eholdings_package_additional_fields[1].name); |
1568 |
cy.get( |
1569 |
"#packages_add form #additional_fields label[for='additional_field_3']" |
1570 |
).contains(eholdings_package_additional_fields[2].name); |
1571 |
cy.get( |
1572 |
"#packages_add form #additional_fields label[for='additional_field_4']" |
1573 |
).contains(eholdings_package_additional_fields[3].name); |
1574 |
|
1575 |
cy.get("#additional_fields #additional_field_1 .vs__selected").should( |
1576 |
"not.exist" |
1577 |
); //new package, no pre-selected value |
1578 |
|
1579 |
// Pick one value |
1580 |
cy.get("#additional_fields #additional_field_1 .vs__search").click(); |
1581 |
cy.get( |
1582 |
"#additional_fields #additional_field_1 #vs4__option-0" |
1583 |
).contains(av_cats[0].authorised_values[0].description); |
1584 |
cy.get("#additional_fields #additional_field_1 #vs4__option-0").click(); |
1585 |
cy.get("#additional_fields #additional_field_1 .vs__selected").contains( |
1586 |
av_cats[0].authorised_values[0].description |
1587 |
); |
1588 |
cy.get("#additional_fields #additional_field_1 .vs__selected").should( |
1589 |
"have.length", |
1590 |
1 |
1591 |
); |
1592 |
|
1593 |
// Pick a second value for the same repeatable AV field |
1594 |
cy.get("#additional_fields #additional_field_1 .vs__search").click(); |
1595 |
cy.get( |
1596 |
"#additional_fields #additional_field_1 #vs4__option-1" |
1597 |
).contains(av_cats[0].authorised_values[1].description); |
1598 |
cy.get("#additional_fields #additional_field_1 #vs4__option-1").click(); |
1599 |
cy.get("#additional_fields #additional_field_1 .vs__selected").contains( |
1600 |
av_cats[0].authorised_values[1].description |
1601 |
); |
1602 |
cy.get("#additional_fields #additional_field_1 .vs__selected").should( |
1603 |
"have.length", |
1604 |
2 |
1605 |
); |
1606 |
|
1607 |
// Attempt to pick the same value again - should not be possible |
1608 |
cy.get("#additional_fields #additional_field_1 .vs__search").click(); |
1609 |
cy.get( |
1610 |
"#additional_fields #additional_field_1 #vs4__option-1" |
1611 |
).contains(av_cats[0].authorised_values[1].description); |
1612 |
cy.get("#additional_fields #additional_field_1 #vs4__option-1").click(); |
1613 |
cy.get("#additional_fields #additional_field_1 .vs__selected").should( |
1614 |
"have.length", |
1615 |
2 |
1616 |
); |
1617 |
|
1618 |
// Remove the second selected value |
1619 |
cy.get( |
1620 |
"#additional_fields #additional_field_1 .vs__selected button[title='Deselect " + |
1621 |
av_cats[0].authorised_values[1].description + |
1622 |
"'" |
1623 |
).click(); |
1624 |
cy.get("#additional_fields #additional_field_1 .vs__selected").should( |
1625 |
"have.length", |
1626 |
1 |
1627 |
); |
1628 |
cy.get("#additional_fields #additional_field_1 .vs__selected").contains( |
1629 |
av_cats[0].authorised_values[0].description |
1630 |
); |
1631 |
}); |
1632 |
|
1633 |
it("Additional Fields entry - Edit (eHoldings packages)", () => { |
1634 |
let eholdings_package = get_package(); |
1635 |
let eholdings_packages = [eholdings_package]; |
1636 |
let vendors = cy.get_vendors_to_relate(); |
1637 |
let eholdings_package_additional_fields = get_packages_additional_fields(); |
1638 |
let av_cats = get_av_cats(); |
1639 |
|
1640 |
// Click the 'Edit' button from the list |
1641 |
cy.intercept("GET", "/api/v1/erm/eholdings/local/packages*", { |
1642 |
statusCode: 200, |
1643 |
body: eholdings_packages, |
1644 |
headers: { |
1645 |
"X-Base-Total-Count": "1", |
1646 |
"X-Total-Count": "1", |
1647 |
}, |
1648 |
}); |
1649 |
cy.intercept("GET", "/api/v1/erm/eholdings/local/packages/*", eholdings_package).as( |
1650 |
"get-eholdings-package" |
1651 |
); |
1652 |
|
1653 |
//Intercept vendors request |
1654 |
cy.intercept("GET", "/api/v1/acquisitions/vendors*", { |
1655 |
statusCode: 200, |
1656 |
body: vendors, |
1657 |
}); |
1658 |
|
1659 |
cy.intercept("GET", "/api/v1/extended_attribute_types*", { |
1660 |
body: eholdings_package_additional_fields, |
1661 |
statusCode: 200, |
1662 |
}).as("existing-additional-fields"); |
1663 |
|
1664 |
cy.intercept( |
1665 |
{ |
1666 |
pathname: "/api/v1/authorised_value_categories", |
1667 |
query: { |
1668 |
q: '{"me.category_name":["CCODE", "COUNTRY"]}', |
1669 |
}, |
1670 |
}, |
1671 |
{ |
1672 |
body: av_cats, |
1673 |
statusCode: 200, |
1674 |
} |
1675 |
).as("avcategories"); |
1676 |
|
1677 |
cy.visit("/cgi-bin/koha/erm/eholdings/local/packages"); |
1678 |
cy.get("#packages_list table tbody tr:first").contains("Edit").click(); |
1679 |
cy.wait("@get-eholdings-package"); |
1680 |
cy.wait(500); // Cypress is too fast! Vue hasn't populated the form yet! |
1681 |
|
1682 |
// All additional fields should be pre-populated |
1683 |
cy.get("#additional_fields #additional_field_1 .vs__selected").contains( |
1684 |
get_description_from_av_value( |
1685 |
av_cats, |
1686 |
eholdings_package.extended_attributes[0] |
1687 |
) |
1688 |
); |
1689 |
cy.get("#additional_fields #additional_field_1 .vs__selected").contains( |
1690 |
get_description_from_av_value( |
1691 |
av_cats, |
1692 |
eholdings_package.extended_attributes[1] |
1693 |
) |
1694 |
); |
1695 |
|
1696 |
cy.get( |
1697 |
"#packages_add form #additional_fields label[for='additional_field_2']" |
1698 |
) |
1699 |
.parent() |
1700 |
.children("input") |
1701 |
.should("have.value", eholdings_package.extended_attributes[2].value); |
1702 |
|
1703 |
cy.get( |
1704 |
"#packages_add form #additional_fields label[for='additional_field_3']" |
1705 |
) |
1706 |
.parent() |
1707 |
.children("input") |
1708 |
.should("have.value", eholdings_package.extended_attributes[3].value); |
1709 |
|
1710 |
cy.get("#additional_fields #additional_field_4 .vs__selected").contains( |
1711 |
get_description_from_av_value( |
1712 |
av_cats, |
1713 |
eholdings_package.extended_attributes[4] |
1714 |
) |
1715 |
); |
1716 |
|
1717 |
// Clear text field works |
1718 |
cy.get( |
1719 |
"#packages_add form #additional_fields label[for='additional_field_2']" |
1720 |
) |
1721 |
.parent() |
1722 |
.children(".clear_attribute") |
1723 |
.click(); |
1724 |
cy.get( |
1725 |
"#packages_add form #additional_fields label[for='additional_field_2']" |
1726 |
) |
1727 |
.parent() |
1728 |
.children("input") |
1729 |
.should("have.value", ""); |
1730 |
|
1731 |
// "+New" text field works |
1732 |
cy.get( |
1733 |
"#packages_add form #additional_fields label[for='additional_field_3']" |
1734 |
).should("have.length", 1); |
1735 |
cy.get( |
1736 |
"#packages_add form #additional_fields label[for='additional_field_3']" |
1737 |
) |
1738 |
.parent() |
1739 |
.children(".clone_attribute") |
1740 |
.click(); |
1741 |
cy.get( |
1742 |
"#packages_add form #additional_fields label[for='additional_field_3']" |
1743 |
).should("have.length", 2); |
1744 |
}); |
1745 |
|
1211 |
}); |
1746 |
}); |
1212 |
- |
|
|