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 */
6 today_iso: dayjs().format("YYYY-MM-DD"),
7 today_us: dayjs().format("MM/DD/YYYY"),
8 tomorrow_iso: dayjs().add(1, "day").format("YYYY-MM-DD"),
9 tomorrow_us: dayjs().add(1, "day").format("MM/DD/YYYY"),
11 function get_license() {
15 description: "my first license",
18 started_on: dates["today_iso"],
19 ended_on: dates["tomorrow_iso"],
24 file_description: "file description",
25 file_name: "file.json",
27 physical_location: "file physical location",
29 uploaded_on: "2022-10-27T11:57:02+00:00"
35 describe("License CRUD operations", () => {
37 cy.intercept("GET", "/cgi-bin/koha/svc/config/systempreferences/?pref=ERMModule", '{"value":"1"}');
38 cy.intercept("GET", "/cgi-bin/koha/svc/config/systempreferences/?pref=ERMProviders", '{"value":"local"}');
43 cy.title().should("eq", "Koha staff interface");
46 it("List license", () => {
47 // GET license returns 500
48 cy.intercept("GET", "/api/v1/erm/licenses*", {
50 error: "Something went wrong",
52 cy.visit("/cgi-bin/koha/erm/erm.pl");
53 cy.get("#navmenulist").contains("Licenses").click();
54 cy.get("main div[class='dialog alert']").contains(
55 /Something went wrong/
58 // GET licenses returns empty list
59 cy.intercept("GET", "/api/v1/erm/licenses*", []);
60 cy.visit("/cgi-bin/koha/erm/licenses");
61 cy.get("#licenses_list").contains("There are no licenses defined");
63 // GET licenses returns something
64 let license = get_license();
65 let licenses = [license];
67 cy.intercept("GET", "/api/v1/erm/licenses*", {
71 "X-Base-Total-Count": "1",
75 cy.intercept("GET", "/api/v1/erm/licenses/*", license);
76 cy.visit("/cgi-bin/koha/erm/licenses");
77 cy.get("#licenses_list").contains("Showing 1 to 1 of 1 entries");
80 it("Add license", () => {
81 // Click the button in the toolbar
82 cy.visit("/cgi-bin/koha/erm/licenses");
83 cy.contains("New license").click();
84 cy.get("#licenses_add h2").contains("New license");
86 // Fill in the form for normal attributes
87 let license = get_license();
89 cy.get("#licenses_add").contains("Submit").click();
90 cy.get("input:invalid,textarea:invalid,select:invalid").should(
94 cy.get("#license_name").type(license.name);
95 cy.get("#license_description").type(license.description);
96 cy.get("#licenses_add").contains("Submit").click();
97 cy.get("#license_type .vs__search").type(license.type + '{enter}',{force:true});
98 cy.get("#license_status .vs__search").type(license.status + '{enter}',{force:true});
100 cy.get("#started_on+input").click();
101 cy.get(".flatpickr-calendar")
104 .click({ force: true });
106 cy.get("#ended_on+input").click();
107 cy.get(".flatpickr-calendar")
114 cy.get("#documents").contains("Add new document").click();
115 cy.get("#document_0 input[id=file_0]").click();
116 cy.get('#document_0 input[id=file_0]').selectFile('t/cypress/fixtures/file.json');
117 cy.get("#document_0 .file_information span").contains("file.json");
118 cy.get('#document_0 input[id=file_description_0]').type('file description');
119 cy.get('#document_0 input[id=physical_location_0]').type('file physical location');
120 cy.get('#document_0 input[id=uri_0]').type('file URI');
121 cy.get('#document_0 input[id=notes_0]').type('file notes');
123 // Submit the form, get 500
124 cy.intercept("POST", "/api/v1/erm/licenses", {
126 error: "Something went wrong",
128 cy.get("#licenses_add").contains("Submit").click();
129 cy.get("main div[class='dialog alert']").contains(
130 "Something went wrong: Error: Internal Server Error"
133 // Submit the form, success!
134 cy.intercept("POST", "/api/v1/erm/licenses", {
138 cy.get("#licenses_add").contains("Submit").click();
139 cy.get("main div[class='dialog message']").contains(
144 it("Edit license", () => {
145 let license = get_license();
146 let licenses = [license];
147 // Click the 'Edit' button from the list
148 cy.intercept("GET", "/api/v1/erm/licenses*", {
152 "X-Base-Total-Count": "1",
153 "X-Total-Count": "1",
156 cy.intercept("GET", "/api/v1/erm/licenses/*", license).as(
159 cy.visit("/cgi-bin/koha/erm/licenses");
160 cy.get("#licenses_list table tbody tr:first")
163 cy.wait("@get-license");
164 cy.wait(500); // Cypress is too fast! Vue hasn't populated the form yet!
165 cy.get("#licenses_add h2").contains("Edit license");
167 // Form has been correctly filled in
168 cy.get("#license_name").should("have.value", license.name);
169 cy.get("#license_description").should(
173 cy.get("#license_type .vs__selected").contains("Local");
174 cy.get("#license_status .vs__selected").contains("Active");
175 cy.get("#started_on").invoke("val").should("eq", dates["today_iso"]);
176 cy.get("#ended_on").invoke("val").should("eq", dates["tomorrow_iso"]);
178 // Test related document
179 cy.get("#document_0 .file_information span").contains("file.json" );
181 // Submit the form, get 500
182 cy.intercept("PUT", "/api/v1/erm/licenses/*", {
184 error: "Something went wrong",
186 cy.get("#licenses_add").contains("Submit").click();
187 cy.get("main div[class='dialog alert']").contains(
188 "Something went wrong: Error: Internal Server Error"
191 // Submit the form, success!
192 cy.intercept("PUT", "/api/v1/erm/licenses/*", {
196 cy.get("#licenses_add").contains("Submit").click();
197 cy.get("main div[class='dialog message']").contains(
202 it("Show license", () => {
203 let license = get_license();
204 let licenses = [license];
205 // Click the "name" link from the list
206 cy.intercept("GET", "/api/v1/erm/licenses*", {
210 "X-Base-Total-Count": "1",
211 "X-Total-Count": "1",
214 cy.intercept("GET", "/api/v1/erm/licenses/*", license).as(
217 cy.visit("/cgi-bin/koha/erm/licenses");
218 let name_link = cy.get(
219 "#licenses_list table tbody tr:first td:first a"
223 license.name + " (#" + license.license_id + ")"
226 cy.wait("@get-license");
227 cy.wait(500); // Cypress is too fast! Vue hasn't populated the form yet!
228 cy.get("#licenses_show h2").contains(
229 "License #" + license.license_id
233 it("Delete license", () => {
234 let license = get_license();
235 let licenses = [license];
237 // Click the 'Delete' button from the list
238 cy.intercept("GET", "/api/v1/erm/licenses*", {
242 "X-Base-Total-Count": "1",
243 "X-Total-Count": "1",
246 cy.intercept("GET", "/api/v1/erm/licenses/*", license);
247 cy.visit("/cgi-bin/koha/erm/licenses");
249 cy.get("#licenses_list table tbody tr:first")
252 cy.get(".dialog.alert.confirmation h1").contains("remove this license");
253 cy.contains(license.name);
255 // Accept the confirmation dialog, get 500
256 cy.intercept("DELETE", "/api/v1/erm/licenses/*", {
258 error: "Something went wrong",
260 cy.contains("Yes, delete").click();
261 cy.get("main div[class='dialog alert']").contains(
262 "Something went wrong: Error: Internal Server Error"
265 // Accept the confirmation dialog, success!
266 cy.intercept("DELETE", "/api/v1/erm/licenses/*", {
270 cy.get("#licenses_list table tbody tr:first")
273 cy.get(".dialog.alert.confirmation h1").contains("remove this license");
274 cy.contains("Yes, delete").click();
275 cy.get("main div[class='dialog message']").contains("License").contains("deleted");
278 // Click the "name" link from the list
279 cy.intercept("GET", "/api/v1/erm/licenses*", {
283 "X-Base-Total-Count": "1",
284 "X-Total-Count": "1",
287 cy.intercept("GET", "/api/v1/erm/licenses/*", license).as(
290 cy.visit("/cgi-bin/koha/erm/licenses");
291 let name_link = cy.get(
292 "#licenses_list table tbody tr:first td:first a"
296 license.name + " (#" + license.license_id + ")"
299 cy.wait("@get-license");
300 cy.wait(500); // Cypress is too fast! Vue hasn't populated the form yet!
301 cy.get("#licenses_show h2").contains(
302 "License #" + license.license_id
305 cy.get('#licenses_show .action_links .fa-trash').click();
306 cy.get(".dialog.alert.confirmation h1").contains("remove this license");
307 cy.contains("Yes, delete").click();
309 //Make sure we return to list after deleting from show
310 cy.get("#licenses_list table tbody tr:first")