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", () => {
38 cy.title().should("eq", "Koha staff interface");
41 "/cgi-bin/koha/svc/config/systempreferences/?pref=ERMModule",
46 "/cgi-bin/koha/svc/config/systempreferences/?pref=ERMProviders",
51 it("List license", () => {
52 // GET license returns 500
53 cy.intercept("GET", "/api/v1/erm/licenses*", {
55 error: "Something went wrong",
57 cy.visit("/cgi-bin/koha/erm/erm.pl");
58 cy.get("#navmenulist").contains("Licenses").click();
59 cy.get("main div[class='dialog alert']").contains(
60 /Something went wrong/
63 // GET licenses returns empty list
64 cy.intercept("GET", "/api/v1/erm/licenses*", []);
65 cy.visit("/cgi-bin/koha/erm/licenses");
66 cy.get("#licenses_list").contains("There are no licenses defined");
68 // GET licenses returns something
69 let license = get_license();
70 let licenses = [license];
72 cy.intercept("GET", "/api/v1/erm/licenses*", {
76 "X-Base-Total-Count": "1",
80 cy.intercept("GET", "/api/v1/erm/licenses/*", license);
81 cy.visit("/cgi-bin/koha/erm/licenses");
82 cy.get("#licenses_list").contains("Showing 1 to 1 of 1 entries");
85 it("Add license", () => {
86 // Click the button in the toolbar
87 cy.visit("/cgi-bin/koha/erm/licenses");
88 cy.contains("New license").click();
89 cy.get("#licenses_add h2").contains("New license");
91 // Fill in the form for normal attributes
92 let license = get_license();
94 cy.get("#licenses_add").contains("Submit").click();
95 cy.get("input:invalid,textarea:invalid,select:invalid").should(
99 cy.get("#license_name").type(license.name);
100 cy.get("#license_description").type(license.description);
101 cy.get("#licenses_add").contains("Submit").click();
102 cy.get("#license_type .vs__search").type(license.type + "{enter}", {
105 cy.get("#license_status .vs__search").type(license.status + "{enter}", {
109 cy.get("#started_on+input").click();
110 cy.get(".flatpickr-calendar")
113 .click({ force: true });
115 cy.get("#ended_on+input").click();
116 cy.get(".flatpickr-calendar")
123 cy.get("#documents").contains("Add new document").click();
124 cy.get("#document_0 input[id=file_0]").click();
125 cy.get("#document_0 input[id=file_0]").selectFile(
126 "t/cypress/fixtures/file.json"
128 cy.get("#document_0 .file_information span").contains("file.json");
129 cy.get("#document_0 input[id=file_description_0]").type(
132 cy.get("#document_0 input[id=physical_location_0]").type(
133 "file physical location"
135 cy.get("#document_0 input[id=uri_0]").type("file URI");
136 cy.get("#document_0 input[id=notes_0]").type("file notes");
138 // Submit the form, get 500
139 cy.intercept("POST", "/api/v1/erm/licenses", {
141 error: "Something went wrong",
143 cy.get("#licenses_add").contains("Submit").click();
144 cy.get("main div[class='dialog alert']").contains(
145 "Something went wrong: SyntaxError: Unexpected end of JSON input"
148 // Submit the form, success!
149 cy.intercept("POST", "/api/v1/erm/licenses", {
153 cy.get("#licenses_add").contains("Submit").click();
154 cy.get("main div[class='dialog message']").contains("License created");
157 it("Edit license", () => {
158 let license = get_license();
159 let licenses = [license];
160 // Click the 'Edit' button from the list
161 cy.intercept("GET", "/api/v1/erm/licenses*", {
165 "X-Base-Total-Count": "1",
166 "X-Total-Count": "1",
169 cy.intercept("GET", "/api/v1/erm/licenses/*", license).as(
172 cy.visit("/cgi-bin/koha/erm/licenses");
173 cy.get("#licenses_list table tbody tr:first").contains("Edit").click();
174 cy.wait("@get-license");
175 cy.wait(500); // Cypress is too fast! Vue hasn't populated the form yet!
176 cy.get("#licenses_add h2").contains("Edit license");
178 // Form has been correctly filled in
179 cy.get("#license_name").should("have.value", license.name);
180 cy.get("#license_description").should(
184 cy.get("#license_type .vs__selected").contains("Local");
185 cy.get("#license_status .vs__selected").contains("Active");
186 cy.get("#started_on").invoke("val").should("eq", dates["today_iso"]);
187 cy.get("#ended_on").invoke("val").should("eq", dates["tomorrow_iso"]);
189 // Test related document
190 cy.get("#document_0 .file_information span").contains("file.json");
192 // Submit the form, get 500
193 cy.intercept("PUT", "/api/v1/erm/licenses/*", {
195 error: "Something went wrong",
197 cy.get("#licenses_add").contains("Submit").click();
198 cy.get("main div[class='dialog alert']").contains(
199 "Something went wrong: SyntaxError: Unexpected end of JSON input"
202 // Submit the form, success!
203 cy.intercept("PUT", "/api/v1/erm/licenses/*", {
207 cy.get("#licenses_add").contains("Submit").click();
208 cy.get("main div[class='dialog message']").contains("License updated");
211 it("Show license", () => {
212 let license = get_license();
213 let licenses = [license];
214 // Click the "name" link from the list
215 cy.intercept("GET", "/api/v1/erm/licenses*", {
219 "X-Base-Total-Count": "1",
220 "X-Total-Count": "1",
223 cy.intercept("GET", "/api/v1/erm/licenses/*", license).as(
226 cy.visit("/cgi-bin/koha/erm/licenses");
227 let name_link = cy.get(
228 "#licenses_list table tbody tr:first td:first a"
232 license.name + " (#" + license.license_id + ")"
235 cy.wait("@get-license");
236 cy.wait(500); // Cypress is too fast! Vue hasn't populated the form yet!
237 cy.get("#licenses_show h2").contains("License #" + license.license_id);
240 it("Delete license", () => {
241 let license = get_license();
242 let licenses = [license];
244 // Click the 'Delete' button from the list
245 cy.intercept("GET", "/api/v1/erm/licenses*", {
249 "X-Base-Total-Count": "1",
250 "X-Total-Count": "1",
253 cy.intercept("GET", "/api/v1/erm/licenses/*", license);
254 cy.visit("/cgi-bin/koha/erm/licenses");
256 cy.get("#licenses_list table tbody tr:first")
259 cy.get(".dialog.alert.confirmation h1").contains("remove this license");
260 cy.contains(license.name);
262 // Accept the confirmation dialog, get 500
263 cy.intercept("DELETE", "/api/v1/erm/licenses/*", {
265 error: "Something went wrong",
267 cy.contains("Yes, delete").click();
268 cy.get("main div[class='dialog alert']").contains(
269 "Something went wrong: SyntaxError: Unexpected end of JSON input"
272 // Accept the confirmation dialog, success!
273 cy.intercept("DELETE", "/api/v1/erm/licenses/*", {
277 cy.get("#licenses_list table tbody tr:first")
280 cy.get(".dialog.alert.confirmation h1").contains("remove this license");
281 cy.contains("Yes, delete").click();
282 cy.get("main div[class='dialog message']")
284 .contains("deleted");
287 // Click the "name" link from the list
288 cy.intercept("GET", "/api/v1/erm/licenses*", {
292 "X-Base-Total-Count": "1",
293 "X-Total-Count": "1",
296 cy.intercept("GET", "/api/v1/erm/licenses/*", license).as(
299 cy.visit("/cgi-bin/koha/erm/licenses");
300 let name_link = cy.get(
301 "#licenses_list table tbody tr:first td:first a"
305 license.name + " (#" + license.license_id + ")"
308 cy.wait("@get-license");
309 cy.wait(500); // Cypress is too fast! Vue hasn't populated the form yet!
310 cy.get("#licenses_show h2").contains("License #" + license.license_id);
312 cy.get("#licenses_show .action_links .fa-trash").click();
313 cy.get(".dialog.alert.confirmation h1").contains("remove this license");
314 cy.contains("Yes, delete").click();
316 //Make sure we return to list after deleting from show
317 cy.get("#licenses_list table tbody tr:first");