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 1124-1127
describe("Additional Fields operations", () => {
Link Here
|
1124 |
"#agreements_add form #additional_fields label[for='additional_field_3']" |
1266 |
"#agreements_add form #additional_fields label[for='additional_field_3']" |
1125 |
).should("have.length", 2); |
1267 |
).should("have.length", 2); |
1126 |
}); |
1268 |
}); |
|
|
1269 |
|
1270 |
// |
1271 |
// for packages |
1272 |
// |
1273 |
|
1274 |
it("Additional Fields display - Table (eHoldings packages)", () => { |
1275 |
let eholdings_package = get_package(); |
1276 |
let eholdings_packages = [eholdings_package]; |
1277 |
let eholdings_package_additional_fields = get_packages_additional_fields(); |
1278 |
let av_cats = get_av_cats(); |
1279 |
|
1280 |
cy.intercept("GET", "/api/v1/extended_attribute_types*", { |
1281 |
body: eholdings_package_additional_fields, |
1282 |
statusCode: 200, |
1283 |
}); |
1284 |
|
1285 |
cy.intercept("GET", "/api/v1/erm/eholdings/local/packages*", { |
1286 |
statusCode: 200, |
1287 |
body: eholdings_packages, |
1288 |
headers: { |
1289 |
"X-Base-Total-Count": "1", |
1290 |
"X-Total-Count": "1", |
1291 |
}, |
1292 |
}); |
1293 |
cy.intercept("GET", "/api/v1/erm/eholdings/local/packages/*", eholdings_package); |
1294 |
cy.visit("/cgi-bin/koha/erm/eholdings/local/packages"); |
1295 |
cy.get("#packages_list").contains("Showing 1 to 1 of 1 entries"); |
1296 |
|
1297 |
cy.get("#packages_list table tbody tr:first").contains( |
1298 |
get_description_from_av_value( |
1299 |
av_cats, |
1300 |
eholdings_package.extended_attributes[0] |
1301 |
) |
1302 |
); |
1303 |
cy.get("#packages_list table tbody tr:first").contains( |
1304 |
get_description_from_av_value( |
1305 |
av_cats, |
1306 |
eholdings_package.extended_attributes[0] |
1307 |
) + |
1308 |
", " + |
1309 |
get_description_from_av_value( |
1310 |
av_cats, |
1311 |
eholdings_package.extended_attributes[1] |
1312 |
) |
1313 |
); |
1314 |
}); |
1315 |
|
1316 |
it("Additional Fields display - Show (eHoldings packages)", () => { |
1317 |
let empty_eholdings_package = get_no_additional_fields_package(); |
1318 |
let eholdings_package = get_package(); |
1319 |
let eholdings_packages = [eholdings_package]; |
1320 |
let vendors = cy.get_vendors_to_relate(); |
1321 |
let eholdings_package_additional_fields = get_packages_additional_fields(); |
1322 |
let av_cats = get_av_cats(); |
1323 |
|
1324 |
// Click the 'Edit' button from the list |
1325 |
cy.intercept("GET", "/api/v1/erm/eholdings/local/packages*", { |
1326 |
statusCode: 200, |
1327 |
body: eholdings_packages, |
1328 |
headers: { |
1329 |
"X-Base-Total-Count": "1", |
1330 |
"X-Total-Count": "1", |
1331 |
}, |
1332 |
}); |
1333 |
cy.intercept("GET", "/api/v1/erm/eholdings/local/packages/*", empty_eholdings_package).as( |
1334 |
"get-empty-eholdings-package" |
1335 |
); |
1336 |
|
1337 |
//Intercept vendors request |
1338 |
cy.intercept("GET", "/api/v1/acquisitions/vendors*", { |
1339 |
statusCode: 200, |
1340 |
body: vendors, |
1341 |
}); |
1342 |
cy.intercept("GET", "/api/v1/extended_attribute_types*", { |
1343 |
body: [], |
1344 |
statusCode: 200, |
1345 |
}).as("empty-additional-fields"); |
1346 |
|
1347 |
//Empty additional fields, should not display |
1348 |
cy.visit("/cgi-bin/koha/erm/eholdings/local/packages"); |
1349 |
cy.get("#packages_list table tbody tr:first td:first a").click(); |
1350 |
cy.wait("@get-empty-eholdings-package"); |
1351 |
cy.get("#packages_list #additional_fields").should("not.exist"); |
1352 |
|
1353 |
cy.intercept("GET", "/api/v1/extended_attribute_types*", { |
1354 |
body: eholdings_package_additional_fields, |
1355 |
statusCode: 200, |
1356 |
}).as("existing-additional-fields"); |
1357 |
|
1358 |
cy.intercept( |
1359 |
{ |
1360 |
pathname: "/api/v1/authorised_value_categories", |
1361 |
query: { |
1362 |
q: '{"me.category_name":["CCODE", "COUNTRY"]}', |
1363 |
}, |
1364 |
}, |
1365 |
{ |
1366 |
body: av_cats, |
1367 |
statusCode: 200, |
1368 |
} |
1369 |
).as("avcategories"); |
1370 |
|
1371 |
cy.intercept("GET", "/api/v1/erm/eholdings/local/packages/*", eholdings_package).as( |
1372 |
"get-eholdings-package" |
1373 |
); |
1374 |
|
1375 |
// There are additional fields, fieldset should exist |
1376 |
cy.visit("/cgi-bin/koha/erm/eholdings/local/packages"); |
1377 |
cy.get("#packages_list table tbody tr:first td:first a").click(); |
1378 |
cy.wait("@get-eholdings-package"); |
1379 |
cy.get("#packages_show #additional_fields").should("exist"); |
1380 |
|
1381 |
// All fields are presented correctly |
1382 |
cy.get( |
1383 |
"#packages_show #additional_fields label[for='additional_field_1']" |
1384 |
).contains(eholdings_package_additional_fields[0].name); |
1385 |
cy.get( |
1386 |
"#packages_show #additional_fields label[for='additional_field_1']" |
1387 |
) |
1388 |
.parent() |
1389 |
.children("span") |
1390 |
.contains( |
1391 |
get_description_from_av_value( |
1392 |
av_cats, |
1393 |
eholdings_package.extended_attributes[0] |
1394 |
) + |
1395 |
", " + |
1396 |
get_description_from_av_value( |
1397 |
av_cats, |
1398 |
eholdings_package.extended_attributes[1] |
1399 |
) |
1400 |
); |
1401 |
|
1402 |
cy.get( |
1403 |
"#packages_show #additional_fields label[for='additional_field_2']" |
1404 |
).contains(eholdings_package_additional_fields[1].name); |
1405 |
cy.get( |
1406 |
"#packages_show #additional_fields label[for='additional_field_2']" |
1407 |
) |
1408 |
.parent() |
1409 |
.children("span") |
1410 |
.contains(eholdings_package.extended_attributes[2].value); |
1411 |
|
1412 |
cy.get( |
1413 |
"#packages_show #additional_fields label[for='additional_field_3']" |
1414 |
).contains(eholdings_package_additional_fields[2].name); |
1415 |
cy.get( |
1416 |
"#packages_show #additional_fields label[for='additional_field_3']" |
1417 |
) |
1418 |
.parent() |
1419 |
.children("span") |
1420 |
.contains(eholdings_package.extended_attributes[3].value); |
1421 |
|
1422 |
cy.get( |
1423 |
"#packages_show #additional_fields label[for='additional_field_4']" |
1424 |
).contains(eholdings_package_additional_fields[3].name); |
1425 |
cy.get( |
1426 |
"#packages_show #additional_fields label[for='additional_field_4']" |
1427 |
) |
1428 |
.parent() |
1429 |
.children("span") |
1430 |
.contains( |
1431 |
get_description_from_av_value( |
1432 |
av_cats, |
1433 |
eholdings_package.extended_attributes[4] |
1434 |
) |
1435 |
); |
1436 |
}); |
1437 |
|
1438 |
it("Additional Fields entry - Add (eHoldings packages)", () => { |
1439 |
let vendors = cy.get_vendors_to_relate(); |
1440 |
let eholdings_package_additional_fields = get_packages_additional_fields(); |
1441 |
let av_cats = get_av_cats(); |
1442 |
|
1443 |
//Intercept vendors request |
1444 |
cy.intercept("GET", "/api/v1/acquisitions/vendors*", { |
1445 |
statusCode: 200, |
1446 |
body: vendors, |
1447 |
}); |
1448 |
cy.intercept("GET", "/api/v1/extended_attribute_types*", { |
1449 |
body: [], |
1450 |
statusCode: 200, |
1451 |
}).as("empty-additional-fields"); |
1452 |
|
1453 |
// No additional fields, fieldset should not exist |
1454 |
cy.visit("/cgi-bin/koha/erm/eholdings/local/packages/add"); |
1455 |
cy.get("#packages_add form #additional_fields").should("not.exist"); |
1456 |
|
1457 |
cy.intercept("GET", "/api/v1/extended_attribute_types*", { |
1458 |
body: eholdings_package_additional_fields, |
1459 |
statusCode: 200, |
1460 |
}).as("existing-additional-fields"); |
1461 |
|
1462 |
cy.intercept( |
1463 |
{ |
1464 |
pathname: "/api/v1/authorised_value_categories", |
1465 |
query: { |
1466 |
q: '{"me.category_name":["CCODE", "COUNTRY"]}', |
1467 |
}, |
1468 |
}, |
1469 |
{ |
1470 |
body: av_cats, |
1471 |
statusCode: 200, |
1472 |
} |
1473 |
).as("avcategories"); |
1474 |
// There are additional fields, fieldset should exist |
1475 |
cy.visit("/cgi-bin/koha/erm/eholdings/local/packages/add"); |
1476 |
cy.get("#packages_add form #additional_fields").should("exist"); |
1477 |
|
1478 |
// All additional fields should be listed |
1479 |
cy.get( |
1480 |
"#packages_add form #additional_fields label[for='additional_field_1']" |
1481 |
).contains(eholdings_package_additional_fields[0].name); |
1482 |
cy.get( |
1483 |
"#packages_add form #additional_fields label[for='additional_field_2']" |
1484 |
).contains(eholdings_package_additional_fields[1].name); |
1485 |
cy.get( |
1486 |
"#packages_add form #additional_fields label[for='additional_field_3']" |
1487 |
).contains(eholdings_package_additional_fields[2].name); |
1488 |
cy.get( |
1489 |
"#packages_add form #additional_fields label[for='additional_field_4']" |
1490 |
).contains(eholdings_package_additional_fields[3].name); |
1491 |
|
1492 |
cy.get("#additional_fields #additional_field_1 .vs__selected").should( |
1493 |
"not.exist" |
1494 |
); //new package, no pre-selected value |
1495 |
|
1496 |
// Pick one value |
1497 |
cy.get("#additional_fields #additional_field_1 .vs__search").click(); |
1498 |
cy.get( |
1499 |
"#additional_fields #additional_field_1 #vs4__option-0" |
1500 |
).contains(av_cats[0].authorised_values[0].description); |
1501 |
cy.get("#additional_fields #additional_field_1 #vs4__option-0").click(); |
1502 |
cy.get("#additional_fields #additional_field_1 .vs__selected").contains( |
1503 |
av_cats[0].authorised_values[0].description |
1504 |
); |
1505 |
cy.get("#additional_fields #additional_field_1 .vs__selected").should( |
1506 |
"have.length", |
1507 |
1 |
1508 |
); |
1509 |
|
1510 |
// Pick a second value for the same repeatable AV field |
1511 |
cy.get("#additional_fields #additional_field_1 .vs__search").click(); |
1512 |
cy.get( |
1513 |
"#additional_fields #additional_field_1 #vs4__option-1" |
1514 |
).contains(av_cats[0].authorised_values[1].description); |
1515 |
cy.get("#additional_fields #additional_field_1 #vs4__option-1").click(); |
1516 |
cy.get("#additional_fields #additional_field_1 .vs__selected").contains( |
1517 |
av_cats[0].authorised_values[1].description |
1518 |
); |
1519 |
cy.get("#additional_fields #additional_field_1 .vs__selected").should( |
1520 |
"have.length", |
1521 |
2 |
1522 |
); |
1523 |
|
1524 |
// Attempt to pick the same value again - should not be possible |
1525 |
cy.get("#additional_fields #additional_field_1 .vs__search").click(); |
1526 |
cy.get( |
1527 |
"#additional_fields #additional_field_1 #vs4__option-1" |
1528 |
).contains(av_cats[0].authorised_values[1].description); |
1529 |
cy.get("#additional_fields #additional_field_1 #vs4__option-1").click(); |
1530 |
cy.get("#additional_fields #additional_field_1 .vs__selected").should( |
1531 |
"have.length", |
1532 |
2 |
1533 |
); |
1534 |
|
1535 |
// Remove the second selected value |
1536 |
cy.get( |
1537 |
"#additional_fields #additional_field_1 .vs__selected button[title='Deselect " + |
1538 |
av_cats[0].authorised_values[1].description + |
1539 |
"'" |
1540 |
).click(); |
1541 |
cy.get("#additional_fields #additional_field_1 .vs__selected").should( |
1542 |
"have.length", |
1543 |
1 |
1544 |
); |
1545 |
cy.get("#additional_fields #additional_field_1 .vs__selected").contains( |
1546 |
av_cats[0].authorised_values[0].description |
1547 |
); |
1548 |
}); |
1549 |
|
1550 |
it("Additional Fields entry - Edit (eHoldings packages)", () => { |
1551 |
let eholdings_package = get_package(); |
1552 |
let eholdings_packages = [eholdings_package]; |
1553 |
let vendors = cy.get_vendors_to_relate(); |
1554 |
let eholdings_package_additional_fields = get_packages_additional_fields(); |
1555 |
let av_cats = get_av_cats(); |
1556 |
|
1557 |
// Click the 'Edit' button from the list |
1558 |
cy.intercept("GET", "/api/v1/erm/eholdings/local/packages*", { |
1559 |
statusCode: 200, |
1560 |
body: eholdings_packages, |
1561 |
headers: { |
1562 |
"X-Base-Total-Count": "1", |
1563 |
"X-Total-Count": "1", |
1564 |
}, |
1565 |
}); |
1566 |
cy.intercept("GET", "/api/v1/erm/eholdings/local/packages/*", eholdings_package).as( |
1567 |
"get-eholdings-package" |
1568 |
); |
1569 |
|
1570 |
//Intercept vendors request |
1571 |
cy.intercept("GET", "/api/v1/acquisitions/vendors*", { |
1572 |
statusCode: 200, |
1573 |
body: vendors, |
1574 |
}); |
1575 |
|
1576 |
cy.intercept("GET", "/api/v1/extended_attribute_types*", { |
1577 |
body: eholdings_package_additional_fields, |
1578 |
statusCode: 200, |
1579 |
}).as("existing-additional-fields"); |
1580 |
|
1581 |
cy.intercept( |
1582 |
{ |
1583 |
pathname: "/api/v1/authorised_value_categories", |
1584 |
query: { |
1585 |
q: '{"me.category_name":["CCODE", "COUNTRY"]}', |
1586 |
}, |
1587 |
}, |
1588 |
{ |
1589 |
body: av_cats, |
1590 |
statusCode: 200, |
1591 |
} |
1592 |
).as("avcategories"); |
1593 |
|
1594 |
cy.visit("/cgi-bin/koha/erm/eholdings/local/packages"); |
1595 |
cy.get("#packages_list table tbody tr:first").contains("Edit").click(); |
1596 |
cy.wait("@get-eholdings-package"); |
1597 |
cy.wait(500); // Cypress is too fast! Vue hasn't populated the form yet! |
1598 |
|
1599 |
// All additional fields should be pre-populated |
1600 |
cy.get("#additional_fields #additional_field_1 .vs__selected").contains( |
1601 |
get_description_from_av_value( |
1602 |
av_cats, |
1603 |
eholdings_package.extended_attributes[0] |
1604 |
) |
1605 |
); |
1606 |
cy.get("#additional_fields #additional_field_1 .vs__selected").contains( |
1607 |
get_description_from_av_value( |
1608 |
av_cats, |
1609 |
eholdings_package.extended_attributes[1] |
1610 |
) |
1611 |
); |
1612 |
|
1613 |
cy.get( |
1614 |
"#packages_add form #additional_fields label[for='additional_field_2']" |
1615 |
) |
1616 |
.parent() |
1617 |
.children("input") |
1618 |
.should("have.value", eholdings_package.extended_attributes[2].value); |
1619 |
|
1620 |
cy.get( |
1621 |
"#packages_add form #additional_fields label[for='additional_field_3']" |
1622 |
) |
1623 |
.parent() |
1624 |
.children("input") |
1625 |
.should("have.value", eholdings_package.extended_attributes[3].value); |
1626 |
|
1627 |
cy.get("#additional_fields #additional_field_4 .vs__selected").contains( |
1628 |
get_description_from_av_value( |
1629 |
av_cats, |
1630 |
eholdings_package.extended_attributes[4] |
1631 |
) |
1632 |
); |
1633 |
|
1634 |
// Clear text field works |
1635 |
cy.get( |
1636 |
"#packages_add form #additional_fields label[for='additional_field_2']" |
1637 |
) |
1638 |
.parent() |
1639 |
.children(".clear_attribute") |
1640 |
.click(); |
1641 |
cy.get( |
1642 |
"#packages_add form #additional_fields label[for='additional_field_2']" |
1643 |
) |
1644 |
.parent() |
1645 |
.children("input") |
1646 |
.should("have.value", ""); |
1647 |
|
1648 |
// "+New" text field works |
1649 |
cy.get( |
1650 |
"#packages_add form #additional_fields label[for='additional_field_3']" |
1651 |
).should("have.length", 1); |
1652 |
cy.get( |
1653 |
"#packages_add form #additional_fields label[for='additional_field_3']" |
1654 |
) |
1655 |
.parent() |
1656 |
.children(".clone_attribute") |
1657 |
.click(); |
1658 |
cy.get( |
1659 |
"#packages_add form #additional_fields label[for='additional_field_3']" |
1660 |
).should("have.length", 2); |
1661 |
}); |
1662 |
|
1127 |
}); |
1663 |
}); |
1128 |
- |
|
|