1 import { mount } from "@cypress/vue";
2 const dayjs = require("dayjs"); /* Cannot use our calendar JS code, it's in an include file (!)
3 Also note that moment.js is deprecated */
5 function get_packages_to_relate() {
9 description: "a package",
10 name: "first package name",
14 description: "a second package",
15 name: "second package name",
20 describe("Title CRUD operations", () => {
23 cy.title().should("eq", "Koha staff interface");
26 "/cgi-bin/koha/svc/config/systempreferences/?pref=ERMModule",
31 "/cgi-bin/koha/svc/config/systempreferences/?pref=ERMProviders",
36 it("Import titles", () => {
37 let erm_title = cy.get_title();
38 let resource = erm_title.resources[0];
40 // Create a list in case none exists
41 cy.visit("/cgi-bin/koha/virtualshelves/shelves.pl");
42 cy.contains("New list").click();
43 cy.get("#shelfname").type("list name");
44 cy.contains("Save").click();
46 // First attempt to import list has no packages
47 cy.intercept("GET", "/api/v1/erm/eholdings/local/packages*", {
50 }).as("get-empty-packages");
51 cy.visit("/cgi-bin/koha/erm/eholdings/local/titles");
53 cy.get("#toolbar a").contains("Import from list").click();
54 cy.get("h2").contains("Import from a list");
55 cy.get("#package_list .vs__selected").should("not.exist");
57 // Make sure packages are returned
58 cy.intercept("GET", "/api/v1/erm/eholdings/local/packages*", {
60 body: get_packages_to_relate(),
61 }).as("get-related-packages");
62 cy.visit("/cgi-bin/koha/erm/eholdings/local/titles");
63 cy.get("#toolbar a").contains("Import from list").click();
64 cy.get("h2").contains("Import from a list");
67 // Prepare background job response to the POST
68 cy.intercept("POST", "/api/v1/erm/eholdings/local/titles/import", {
71 }).as("get-job-response");
72 cy.get("#list_list tbody tr:first td a").contains("Import").click();
73 cy.get("main div[class='dialog message']").contains(
74 "Import in progress, see job #1"
78 it("List title", () => {
79 // GET title returns 500
80 cy.intercept("GET", "/api/v1/erm/eholdings/local/titles*", {
82 error: "Something went wrong",
84 cy.visit("/cgi-bin/koha/erm/erm.pl");
85 cy.get("#navmenulist").contains("Titles").click();
86 cy.get("main div[class='dialog alert']").contains(
87 /Something went wrong/
90 // GET titles returns empty list
91 cy.intercept("GET", "/api/v1/erm/eholdings/local/titles*", {
95 "X-Base-Total-Count": "0",
99 cy.visit("/cgi-bin/koha/erm/eholdings/local/titles");
100 cy.get("#titles_list").contains("There are no titles defined");
102 // GET titles returns something
103 let erm_title = cy.get_title();
104 let titles = [erm_title];
106 cy.intercept("GET", "/api/v1/erm/eholdings/local/titles*", {
110 "X-Base-Total-Count": "1",
111 "X-Total-Count": "1",
114 cy.visit("/cgi-bin/koha/erm/eholdings/local/titles");
115 cy.get("#titles_list").contains("Showing 1 to 1 of 1 entries");
118 it("Add title", () => {
122 url: "/api/v1/erm/eholdings/local/packages*",
130 // Click the button in the toolbar
131 cy.visit("/cgi-bin/koha/erm/eholdings/local/titles");
132 cy.wait(500); // Cypress is too fast! Vue hasn't populated the form yet!
133 cy.contains("New title").click();
134 cy.get("#titles_add h2").contains("New title");
136 // Fill in the form for normal attributes
137 let erm_title = cy.get_title();
139 cy.get("#titles_add").contains("Submit").click();
140 cy.get("input:invalid,textarea:invalid,select:invalid").should(
144 cy.get("#title_publication_title").type(erm_title.publication_title);
145 cy.get("#title_print_identifier").type(erm_title.print_identifier);
146 cy.get("#title_online_identifier").type(erm_title.online_identifier);
147 cy.get("#title_date_first_issue_online").type(
148 erm_title.date_first_issue_online
150 cy.get("#title_num_first_vol_online").type(
151 erm_title.num_first_vol_online
153 cy.get("#title_num_first_issue_online").type(
154 erm_title.num_first_issue_online
156 cy.get("#title_date_last_issue_online").type(
157 erm_title.date_last_issue_online
159 cy.get("#title_num_last_vol_online").type(
160 erm_title.num_last_vol_online
162 cy.get("#title_num_last_issue_online").type(
163 erm_title.num_last_issue_online
165 cy.get("#title_title_url").type(erm_title.title_url);
166 cy.get("#title_first_author").type(erm_title.first_author);
167 cy.get("#title_embargo_info").type(erm_title.embargo_info);
168 cy.get("#title_coverage_depth").type(erm_title.coverage_depth);
169 cy.get("#title_notes").type(erm_title.notes);
170 cy.get("#title_publisher_name").type(erm_title.publisher_name);
171 cy.get("#title_publication_type .vs__search").type(
172 erm_title.publication_type + "{enter}",
175 cy.get("#title_date_monograph_published_print").type(
176 erm_title.date_monograph_published_print
178 cy.get("#title_date_monograph_published_online").type(
179 erm_title.date_monograph_published_online
181 cy.get("#title_monograph_volume").type(erm_title.monograph_volume);
182 cy.get("#title_monograph_edition").type(erm_title.monograph_edition);
183 cy.get("#title_first_editor").type(erm_title.first_editor);
184 cy.get("#title_parent_publication_title_id").type(
185 erm_title.parent_publication_title_id
187 cy.get("#title_preceding_publication_title_id").type(
188 erm_title.preceding_publication_title_id
190 cy.get("#title_access_type").type(erm_title.access_type);
192 cy.get("#resources").contains("There are no packages created yet");
194 // Submit the form, get 500
195 cy.intercept("POST", "/api/v1/erm/eholdings/local/titles", {
197 error: "Something went wrong",
199 cy.get("#titles_add").contains("Submit").click();
200 cy.get("main div[class='dialog alert']").contains(
201 "Something went wrong: SyntaxError: Unexpected end of JSON input"
204 // Submit the form, success!
205 cy.intercept("POST", "/api/v1/erm/eholdings/local/titles", {
209 cy.get("#titles_add").contains("Submit").click();
210 cy.get("main div[class='dialog message']").contains("Title created");
212 // Add new related package (resource)
213 let related_package = erm_title.resources[0];
214 cy.intercept("GET", "/api/v1/erm/eholdings/local/packages*", {
216 body: get_packages_to_relate(),
217 }).as("get-related-packages");
218 cy.visit("/cgi-bin/koha/erm/eholdings/local/titles/add");
219 cy.get("#resources").contains("Add to another package").click();
220 cy.get("#resources").contains("Package 1");
221 cy.get("#resources #resource_package_id_0 .vs__search").type(
222 related_package.package.name
224 cy.get("#resources #resource_package_id_0 .vs__dropdown-menu li")
226 .click({ force: true }); //click first package suggestion
229 it("Edit title", () => {
230 let erm_title = cy.get_title();
231 let titles = [erm_title];
232 // Click the 'Edit' button from the list
233 cy.intercept("GET", "/api/v1/erm/eholdings/local/titles*", {
237 "X-Base-Total-Count": "1",
238 "X-Total-Count": "1",
243 "/api/v1/erm/eholdings/local/titles/*",
246 cy.visit("/cgi-bin/koha/erm/eholdings/local/titles");
247 // Intercept related packages request after entering title edit
248 cy.intercept("GET", "/api/v1/erm/eholdings/local/packages*", {
250 body: get_packages_to_relate(),
251 }).as("get-related-packages");
253 cy.get("#titles_list table tbody tr:first").contains("Edit").click();
254 cy.wait("@get-title");
255 cy.wait(500); // Cypress is too fast! Vue hasn't populated the form yet!
256 cy.get("#titles_add h2").contains("Edit title");
258 // Form has been correctly filled in
259 cy.get("#title_publication_title").should(
261 erm_title.publication_title
263 cy.get("#title_print_identifier").should(
265 erm_title.print_identifier
267 cy.get("#title_online_identifier").should(
269 erm_title.online_identifier
271 cy.get("#title_date_first_issue_online").should(
273 erm_title.date_first_issue_online
275 cy.get("#title_num_first_vol_online").should(
277 erm_title.num_first_vol_online
279 cy.get("#title_num_first_issue_online").should(
281 erm_title.num_first_issue_online
283 cy.get("#title_date_last_issue_online").should(
285 erm_title.date_last_issue_online
287 cy.get("#title_num_last_vol_online").should(
289 erm_title.num_last_vol_online
291 cy.get("#title_num_last_issue_online").should(
293 erm_title.num_last_issue_online
295 cy.get("#title_title_url").should("have.value", erm_title.title_url);
296 cy.get("#title_first_author").should(
298 erm_title.first_author
300 cy.get("#title_embargo_info").should(
302 erm_title.embargo_info
304 cy.get("#title_coverage_depth").should(
306 erm_title.coverage_depth
308 cy.get("#title_notes").should("have.value", erm_title.notes);
309 cy.get("#title_publisher_name").should(
311 erm_title.publisher_name
313 cy.get("#title_publication_type .vs__selected").contains("Journal");
314 cy.get("#title_date_monograph_published_print").should(
316 erm_title.date_monograph_published_print
318 cy.get("#title_date_monograph_published_online").should(
320 erm_title.date_monograph_published_online
322 cy.get("#title_monograph_volume").should(
324 erm_title.monograph_volume
326 cy.get("#title_monograph_edition").should(
328 erm_title.monograph_edition
330 cy.get("#title_first_editor").should(
332 erm_title.first_editor
334 cy.get("#title_parent_publication_title_id").should(
336 erm_title.parent_publication_title_id
338 cy.get("#title_preceding_publication_title_id").should(
340 erm_title.preceding_publication_title_id
342 cy.get("#title_access_type").should(
344 erm_title.access_type
347 //Test related content
348 cy.get("#resources #resource_package_id_0 .vs__selected").contains(
352 // Submit the form, get 500
353 cy.intercept("PUT", "/api/v1/erm/eholdings/local/titles/*", {
355 error: "Something went wrong",
357 cy.get("#titles_add").contains("Submit").click();
358 cy.get("main div[class='dialog alert']").contains(
359 "Something went wrong: SyntaxError: Unexpected end of JSON input"
362 // Submit the form, success!
363 cy.intercept("PUT", "/api/v1/erm/eholdings/local/titles/*", {
367 cy.get("#titles_add").contains("Submit").click();
368 cy.get("main div[class='dialog message']").contains("Title updated");
371 it("Show title", () => {
372 let erm_title = cy.get_title();
373 let titles = [erm_title];
374 // Click the "name" link from the list
375 cy.intercept("GET", "/api/v1/erm/eholdings/local/titles*", {
379 "X-Base-Total-Count": "1",
380 "X-Total-Count": "1",
383 // Title with empty resources.
387 url: "/api/v1/erm/eholdings/local/titles/*",
392 publication_title: "publication title",
398 cy.visit("/cgi-bin/koha/erm/eholdings/local/titles");
399 let title_link = cy.get("#titles_list table tbody tr:first td:first a");
402 erm_title.publication_title + " (#" + erm_title.title_id + ")"
404 cy.get("#titles_list table tbody tr:first td:first a").click();
405 cy.wait("@get-title");
406 cy.wait(500); // Cypress is too fast! Vue hasn't populated the form yet!
407 cy.get("#eholdings_title_show h2").contains(
408 "Title #" + erm_title.title_id
410 // There are no packages, the table should not be displayed
411 cy.contains("Packages (0)");
412 cy.get("#table#package_list").should("not.exist");
414 // Test now with all values
417 "/api/v1/erm/eholdings/local/titles/*",
422 cy.visit("/cgi-bin/koha/erm/eholdings/local/titles/1");
423 cy.contains("Packages (1)");
427 let related_package = erm_title.resources[0];
428 // cy.get("#package_list tbody tr:first td a").contains("first package name").click();
431 "/api/v1/erm/eholdings/local/resources/" +
432 related_package.resource_id,
434 ).as("get-related-package");
435 cy.get("table#package_list").contains("first package name").click();
436 cy.contains("Resource #" + related_package.resource_id);
437 cy.contains(related_package.package.name);
440 it("Delete title", () => {
441 let erm_title = cy.get_title();
442 let titles = [erm_title];
444 // Click the 'Delete' button from the list
445 cy.intercept("GET", "/api/v1/erm/eholdings/local/titles*", {
449 "X-Base-Total-Count": "1",
450 "X-Total-Count": "1",
453 cy.intercept("GET", "/api/v1/erm/eholdings/local/titles/*", erm_title);
454 cy.visit("/cgi-bin/koha/erm/eholdings/local/titles");
456 cy.get("#titles_list table tbody tr:first").contains("Delete").click();
457 cy.get(".dialog.alert.confirmation h1").contains("remove this title");
458 cy.contains(erm_title.publication_title);
460 // Accept the confirmation dialog, get 500
461 cy.intercept("DELETE", "/api/v1/erm/eholdings/local/titles/*", {
463 error: "Something went wrong",
465 cy.contains("Yes, delete").click();
466 cy.get("main div[class='dialog alert']").contains(
467 "Something went wrong: SyntaxError: Unexpected end of JSON input"
470 // Accept the confirmation dialog, success!
471 cy.intercept("DELETE", "/api/v1/erm/eholdings/local/titles/*", {
475 cy.get("#titles_list table tbody tr:first").contains("Delete").click();
476 cy.get(".dialog.alert.confirmation h1").contains("remove this title");
477 cy.contains("Yes, delete").click();
478 cy.get("main div[class='dialog message']")
479 .contains("Local title")
480 .contains("deleted");
483 // Click the "name" link from the list
484 cy.intercept("GET", "/api/v1/erm/eholdings/local/titles*", {
488 "X-Base-Total-Count": "1",
489 "X-Total-Count": "1",
492 // Title with empty resources.
496 url: "/api/v1/erm/eholdings/local/titles/*",
501 publication_title: "publication title",
507 cy.visit("/cgi-bin/koha/erm/eholdings/local/titles");
508 let title_link = cy.get("#titles_list table tbody tr:first td:first a");
511 erm_title.publication_title + " (#" + erm_title.title_id + ")"
513 cy.get("#titles_list table tbody tr:first td:first a").click();
514 cy.wait("@get-title");
515 cy.wait(500); // Cypress is too fast! Vue hasn't populated the form yet!
516 cy.get("#eholdings_title_show h2").contains(
517 "Title #" + erm_title.title_id
520 cy.get("#eholdings_title_show .action_links .fa-trash").click();
521 cy.get(".dialog.alert.confirmation h1").contains("remove this title");
522 cy.contains("Yes, delete").click();
524 //Make sure we return to list after deleting from show
525 cy.get("#titles_list table tbody tr:first");