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 */
7 access_type: "access type",
9 coverage_depth: "coverage depth",
10 date_first_issue_online: "date first",
11 date_last_issue_online: "date last",
12 date_monograph_published_online: "date mono online",
13 date_monograph_published_print: "date mono print",
14 embargo_info: "embargo info",
16 first_author: "first author",
17 first_editor: "first editor",
18 monograph_edition: "monograph edition",
19 monograph_volume: "monograph volume",
21 num_first_issue_online: "num first issue",
22 num_first_vol_online: "num first vol",
23 num_last_issue_online: "num last issue",
24 num_last_vol_online: "num last vol",
25 online_identifier: "online identifier",
26 parent_publication_title_id: "parent id",
27 preceeding_publication_title_id: "preceeding id",
28 print_identifier: "print identifier",
29 publication_title: "publication title",
30 publication_type: "journal",
31 publisher_name: "publication name",
38 name: "first package name"
50 title_url: "title url"
54 function get_packages_to_relate() {
58 description: "a package",
59 name: "first package name"
63 description: "a second package",
64 name: "second package name"
69 describe("Title CRUD operations", () => {
71 cy.login("koha", "koha");
72 cy.title().should("eq", "Koha staff interface");
75 it("Import titles", () => {
76 let erm_title = get_title();
77 let resource = erm_title.resources[0];
79 // Create a list in case none exists
80 cy.visit("/cgi-bin/koha/virtualshelves/shelves.pl");
81 cy.contains("New list").click();
82 cy.get("#shelfname").type('list name');
83 cy.contains("Save").click();
85 // First attempt to import list has no packages
86 cy.intercept("GET", "/api/v1/erm/eholdings/local/packages", {
89 }).as("get-empty-packages");
90 cy.visit("/cgi-bin/koha/erm/eholdings/local/titles");
92 cy.get("#toolbar a").contains("Import from list").click();
93 cy.get("h2").contains("Import from a list");
94 cy.get("#package_list .vs__selected").should('not.exist');
96 // Make sure packages are returned
97 cy.intercept("GET", "/api/v1/erm/eholdings/local/packages", {
99 body: get_packages_to_relate(),
100 }).as("get-related-packages");
101 cy.visit("/cgi-bin/koha/erm/eholdings/local/titles");
102 cy.get("#toolbar a").contains("Import from list").click();
103 cy.get("h2").contains("Import from a list");
106 // Prepare background job response to the POST
107 cy.intercept("POST", "/api/v1/erm/eholdings/local/titles/import", {
110 }).as("get-job-response");
111 cy.get("#list_list tbody tr:first td a").contains("Import").click();
112 cy.get("main div[class='dialog message']").contains("Import in progress, see job #1");
115 it("List title", () => {
116 // GET title returns 500
117 cy.intercept("GET", "/api/v1/erm/eholdings/local/titles", {
119 error: "Something went wrong",
121 cy.visit("/cgi-bin/koha/erm/erm.pl");
122 cy.get("#navmenulist").contains("Titles").click();
123 cy.get("main div[class='dialog alert']").contains(
124 /Something went wrong/
127 // GET titles returns empty list
128 cy.intercept("GET", "/api/v1/erm/eholdings/local/titles*", []);
129 cy.visit("/cgi-bin/koha/erm/eholdings/local/titles");
130 cy.get("#titles_list").contains("There are no titles defined");
132 // GET titles returns something
133 let erm_title = get_title();
134 let titles = [erm_title];
136 cy.intercept("GET", "/api/v1/erm/eholdings/local/titles*", {
140 "X-Base-Total-Count": "1",
141 "X-Total-Count": "1",
146 "/api/v1/erm/eholdings/local/titles/*",
149 cy.visit("/cgi-bin/koha/erm/eholdings/local/titles");
150 cy.get("#titles_list").contains("Showing 1 to 1 of 1 entries");
153 it("Add title", () => {
157 url: "/api/v1/erm/eholdings/local/packages",
164 // Click the button in the toolbar
165 cy.visit("/cgi-bin/koha/erm/eholdings/local/titles");
166 cy.wait(500); // Cypress is too fast! Vue hasn't populated the form yet!
167 cy.contains("New title").click();
168 cy.get("#titles_add h2").contains("New title");
170 // Fill in the form for normal attributes
171 let erm_title = get_title();
173 cy.get("#titles_add").contains("Submit").click();
174 cy.get("input:invalid,textarea:invalid,select:invalid").should(
178 cy.get("#title_publication_title").type(erm_title.publication_title);
179 cy.get("#title_print_identifier").type(erm_title.print_identifier);
180 cy.get("#title_online_identifier").type(erm_title.online_identifier);
181 cy.get("#title_date_first_issue_online").type(erm_title.date_first_issue_online);
182 cy.get("#title_num_first_vol_online").type(erm_title.num_first_vol_online);
183 cy.get("#title_num_first_issue_online").type(erm_title.num_first_issue_online);
184 cy.get("#title_date_last_issue_online").type(erm_title.date_last_issue_online);
185 cy.get("#title_num_last_vol_online").type(erm_title.num_last_vol_online);
186 cy.get("#title_num_last_issue_online").type(erm_title.num_last_issue_online);
187 cy.get("#title_title_url").type(erm_title.title_url);
188 cy.get("#title_first_author").type(erm_title.first_author);
189 cy.get("#title_embargo_info").type(erm_title.embargo_info);
190 cy.get("#title_coverage_depth").type(erm_title.coverage_depth);
191 cy.get("#title_notes").type(erm_title.notes);
192 cy.get("#title_publisher_name").type(erm_title.publisher_name);
193 cy.get("#title_publication_type .vs__search").type(
194 erm_title.publication_type + "{enter}",
197 cy.get("#title_date_monograph_published_print").type(erm_title.date_monograph_published_print);
198 cy.get("#title_date_monograph_published_online").type(erm_title.date_monograph_published_online);
199 cy.get("#title_monograph_volume").type(erm_title.monograph_volume);
200 cy.get("#title_monograph_edition").type(erm_title.monograph_edition);
201 cy.get("#title_first_editor").type(erm_title.first_editor);
202 cy.get("#title_parent_publication_title_id").type(erm_title.parent_publication_title_id);
203 cy.get("#title_preceeding_publication_title_id").type(erm_title.preceeding_publication_title_id);
204 cy.get("#title_access_type").type(erm_title.access_type);
206 cy.get("#resources").contains(
207 "There are no packages created yet"
210 // Submit the form, get 500
211 cy.intercept("POST", "/api/v1/erm/eholdings/local/titles", {
213 error: "Something went wrong",
215 cy.get("#titles_add").contains("Submit").click();
216 cy.get("main div[class='dialog alert']").contains(
217 "Something went wrong: Internal Server Error"
220 // Submit the form, success!
221 cy.intercept("POST", "/api/v1/erm/eholdings/local/titles", {
225 cy.get("#titles_add").contains("Submit").click();
226 cy.get("main div[class='dialog message']").contains("Title created");
228 // Add new related package (resource)
229 let related_package = erm_title.resources[0];
230 cy.intercept("GET", "/api/v1/erm/eholdings/local/packages", {
232 body: get_packages_to_relate(),
233 }).as('get-related-packages');
234 cy.visit("/cgi-bin/koha/erm/eholdings/local/titles/add");
235 cy.get("#resources").contains("Add to another package").click();
236 cy.get("#resources").contains("Package 1");
237 cy.get("#resources #resource_package_id_0 .vs__search").type(
238 related_package.package.name
240 cy.get("#resources #resource_package_id_0 .vs__dropdown-menu li").eq(0).click( { force: true } ); //click first package suggestion
243 it("Edit title", () => {
244 let erm_title = get_title();
245 let titles = [erm_title];
246 // Click the 'Edit' button from the list
247 cy.intercept("GET", "/api/v1/erm/eholdings/local/titles*", {
251 "X-Base-Total-Count": "1",
252 "X-Total-Count": "1",
257 "/api/v1/erm/eholdings/local/titles/*",
260 cy.visit("/cgi-bin/koha/erm/eholdings/local/titles");
261 // Intercept related packages request after entering title edit
262 cy.intercept("GET", "/api/v1/erm/eholdings/local/packages", {
264 body: get_packages_to_relate(),
265 }).as('get-related-packages');
267 cy.get("#titles_list table tbody tr:first").contains("Edit").click();
268 cy.wait("@get-title");
269 cy.wait(500); // Cypress is too fast! Vue hasn't populated the form yet!
270 cy.get("#titles_add h2").contains("Edit title");
272 // Form has been correctly filled in
273 cy.get("#title_publication_title").should("have.value", erm_title.publication_title);
274 cy.get("#title_print_identifier").should("have.value", erm_title.print_identifier);
275 cy.get("#title_online_identifier").should("have.value", erm_title.online_identifier);
276 cy.get("#title_date_first_issue_online").should("have.value", erm_title.date_first_issue_online);
277 cy.get("#title_num_first_vol_online").should("have.value", erm_title.num_first_vol_online);
278 cy.get("#title_num_first_issue_online").should("have.value", erm_title.num_first_issue_online);
279 cy.get("#title_date_last_issue_online").should("have.value", erm_title.date_last_issue_online);
280 cy.get("#title_num_last_vol_online").should("have.value", erm_title.num_last_vol_online);
281 cy.get("#title_num_last_issue_online").should("have.value", erm_title.num_last_issue_online);
282 cy.get("#title_title_url").should("have.value", erm_title.title_url);
283 cy.get("#title_first_author").should("have.value", erm_title.first_author);
284 cy.get("#title_embargo_info").should("have.value", erm_title.embargo_info);
285 cy.get("#title_coverage_depth").should("have.value", erm_title.coverage_depth);
286 cy.get("#title_notes").should("have.value", erm_title.notes);
287 cy.get("#title_publisher_name").should("have.value", erm_title.publisher_name);
288 cy.get("#title_publication_type .vs__selected").contains('Journal');
289 cy.get("#title_date_monograph_published_print").should("have.value", erm_title.date_monograph_published_print);
290 cy.get("#title_date_monograph_published_online").should("have.value", erm_title.date_monograph_published_online);
291 cy.get("#title_monograph_volume").should("have.value", erm_title.monograph_volume);
292 cy.get("#title_monograph_edition").should("have.value", erm_title.monograph_edition);
293 cy.get("#title_first_editor").should("have.value", erm_title.first_editor);
294 cy.get("#title_parent_publication_title_id").should("have.value", erm_title.parent_publication_title_id);
295 cy.get("#title_preceeding_publication_title_id").should("have.value", erm_title.preceeding_publication_title_id);
296 cy.get("#title_access_type").should("have.value", erm_title.access_type);
298 //Test related content
299 cy.get("#resources #resource_package_id_0 .vs__selected").contains("package name");
301 // Submit the form, get 500
302 cy.intercept("PUT", "/api/v1/erm/eholdings/local/titles/*", {
304 error: "Something went wrong",
306 cy.get("#titles_add").contains("Submit").click();
307 cy.get("main div[class='dialog alert']").contains(
308 "Something went wrong: Internal Server Error"
311 // Submit the form, success!
312 cy.intercept("PUT", "/api/v1/erm/eholdings/local/titles/*", {
316 cy.get("#titles_add").contains("Submit").click();
317 cy.get("main div[class='dialog message']").contains("Title updated");
320 it("Show title", () => {
321 let erm_title = get_title();
322 let titles = [erm_title];
323 // Click the "name" link from the list
324 cy.intercept("GET", "/api/v1/erm/eholdings/local/titles*", {
328 "X-Base-Total-Count": "1",
329 "X-Total-Count": "1",
332 // Title with empty resources.
336 url: "/api/v1/erm/eholdings/local/titles/*",
341 publication_title: "publication title",
347 cy.visit("/cgi-bin/koha/erm/eholdings/local/titles");
348 let title_link = cy.get(
349 "#titles_list table tbody tr:first td:first a"
353 erm_title.publication_title + " (#" + erm_title.title_id + ")"
356 "#titles_list table tbody tr:first td:first a"
358 cy.wait("@get-title");
359 cy.wait(500); // Cypress is too fast! Vue hasn't populated the form yet!
360 cy.get("#eholdings_title_show h2").contains(
361 "Title #" + erm_title.title_id
363 // There are no packages, the table should not be displayed
364 cy.contains("Packages (0)");
365 cy.get("#table#package_list").should("not.exist");
367 // Test now with all values
370 "/api/v1/erm/eholdings/local/titles/*",
375 cy.visit("/cgi-bin/koha/erm/eholdings/local/titles/1");
376 cy.contains("Packages (1)");
380 let related_package = erm_title.resources[0];
381 // cy.get("#package_list tbody tr:first td a").contains("first package name").click();
384 "/api/v1/erm/eholdings/local/resources/"+related_package.resource_id,
386 ).as("get-related-package");
387 cy.get("table#package_list").contains("first package name").click();
388 cy.contains("Resource #"+related_package.resource_id);
389 cy.contains(related_package.package.name);
392 it("Delete title", () => {
393 let erm_title = get_title();
394 let titles = [erm_title];
396 // Click the 'Delete' button from the list
397 cy.intercept("GET", "/api/v1/erm/eholdings/local/titles*", {
401 "X-Base-Total-Count": "1",
402 "X-Total-Count": "1",
407 "/api/v1/erm/eholdings/local/titles/*",
410 cy.visit("/cgi-bin/koha/erm/eholdings/local/titles");
412 cy.get("#titles_list table tbody tr:first")
415 cy.get("#eholdings_confirm_delete h2").contains("Delete title");
416 cy.contains("Title: " + erm_title.publication_title);
418 // Submit the form, get 500
419 cy.intercept("DELETE", "/api/v1/erm/eholdings/local/titles/*", {
421 error: "Something went wrong",
423 cy.contains("Yes, delete").click();
424 cy.get("main div[class='dialog alert']").contains(
425 "Something went wrong: Internal Server Error"
428 // Submit the form, success!
429 cy.intercept("DELETE", "/api/v1/erm/eholdings/local/titles/*", {
433 cy.contains("Yes, delete").click();
434 cy.get("main div[class='dialog message']").contains("Title deleted");