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");
42 '{"settings":{"ERMModule":"1","ERMProviders":["local"]}}'
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}", {
100 cy.get("#license_status .vs__search").type(license.status + "{enter}", {
104 cy.get("#started_on+input").click();
105 cy.get(".flatpickr-calendar")
108 .click({ force: true });
110 cy.get("#ended_on+input").click();
111 cy.get(".flatpickr-calendar")
118 cy.get("#documents").contains("Add new document").click();
119 cy.get("#document_0 input[id=file_0]").click();
120 cy.get("#document_0 input[id=file_0]").selectFile(
121 "t/cypress/fixtures/file.json"
123 cy.get("#document_0 .file_information span").contains("file.json");
124 cy.get("#document_0 input[id=file_description_0]").type(
127 cy.get("#document_0 input[id=physical_location_0]").type(
128 "file physical location"
130 cy.get("#document_0 input[id=uri_0]").type("file URI");
131 cy.get("#document_0 input[id=notes_0]").type("file notes");
133 // Submit the form, get 500
134 cy.intercept("POST", "/api/v1/erm/licenses", {
136 error: "Something went wrong",
138 cy.get("#licenses_add").contains("Submit").click();
139 cy.get("main div[class='dialog alert']").contains(
140 "Something went wrong: SyntaxError: Unexpected end of JSON input"
143 // Submit the form, success!
144 cy.intercept("POST", "/api/v1/erm/licenses", {
148 cy.get("#licenses_add").contains("Submit").click();
149 cy.get("main div[class='dialog message']").contains("License created");
152 it("Edit license", () => {
153 let license = get_license();
154 let licenses = [license];
155 // Click the 'Edit' button from the list
156 cy.intercept("GET", "/api/v1/erm/licenses*", {
160 "X-Base-Total-Count": "1",
161 "X-Total-Count": "1",
164 cy.intercept("GET", "/api/v1/erm/licenses/*", license).as(
167 cy.visit("/cgi-bin/koha/erm/licenses");
168 cy.get("#licenses_list table tbody tr:first").contains("Edit").click();
169 cy.wait("@get-license");
170 cy.wait(500); // Cypress is too fast! Vue hasn't populated the form yet!
171 cy.get("#licenses_add h2").contains("Edit license");
173 // Form has been correctly filled in
174 cy.get("#license_name").should("have.value", license.name);
175 cy.get("#license_description").should(
179 cy.get("#license_type .vs__selected").contains("Local");
180 cy.get("#license_status .vs__selected").contains("Active");
181 cy.get("#started_on").invoke("val").should("eq", dates["today_iso"]);
182 cy.get("#ended_on").invoke("val").should("eq", dates["tomorrow_iso"]);
184 // Test related document
185 cy.get("#document_0 .file_information span").contains("file.json");
187 // Submit the form, get 500
188 cy.intercept("PUT", "/api/v1/erm/licenses/*", {
190 error: "Something went wrong",
192 cy.get("#licenses_add").contains("Submit").click();
193 cy.get("main div[class='dialog alert']").contains(
194 "Something went wrong: SyntaxError: Unexpected end of JSON input"
197 // Submit the form, success!
198 cy.intercept("PUT", "/api/v1/erm/licenses/*", {
202 cy.get("#licenses_add").contains("Submit").click();
203 cy.get("main div[class='dialog message']").contains("License updated");
206 it("Show license", () => {
207 let license = get_license();
208 let licenses = [license];
209 // Click the "name" link from the list
210 cy.intercept("GET", "/api/v1/erm/licenses*", {
214 "X-Base-Total-Count": "1",
215 "X-Total-Count": "1",
218 cy.intercept("GET", "/api/v1/erm/licenses/*", license).as(
221 cy.visit("/cgi-bin/koha/erm/licenses");
222 let name_link = cy.get(
223 "#licenses_list table tbody tr:first td:first a"
227 license.name + " (#" + license.license_id + ")"
230 cy.wait("@get-license");
231 cy.wait(500); // Cypress is too fast! Vue hasn't populated the form yet!
232 cy.get("#licenses_show h2").contains("License #" + license.license_id);
235 it("Delete license", () => {
236 let license = get_license();
237 let licenses = [license];
239 // Click the 'Delete' button from the list
240 cy.intercept("GET", "/api/v1/erm/licenses*", {
244 "X-Base-Total-Count": "1",
245 "X-Total-Count": "1",
248 cy.intercept("GET", "/api/v1/erm/licenses/*", license);
249 cy.visit("/cgi-bin/koha/erm/licenses");
251 cy.get("#licenses_list table tbody tr:first")
254 cy.get(".dialog.alert.confirmation h1").contains("remove this license");
255 cy.contains(license.name);
257 // Accept the confirmation dialog, get 500
258 cy.intercept("DELETE", "/api/v1/erm/licenses/*", {
260 error: "Something went wrong",
262 cy.contains("Yes, delete").click();
263 cy.get("main div[class='dialog alert']").contains(
264 "Something went wrong: SyntaxError: Unexpected end of JSON input"
267 // Accept the confirmation dialog, success!
268 cy.intercept("DELETE", "/api/v1/erm/licenses/*", {
272 cy.get("#licenses_list table tbody tr:first")
275 cy.get(".dialog.alert.confirmation h1").contains("remove this license");
276 cy.contains("Yes, delete").click();
277 cy.get("main div[class='dialog message']")
279 .contains("deleted");
282 // Click the "name" link from the list
283 cy.intercept("GET", "/api/v1/erm/licenses*", {
287 "X-Base-Total-Count": "1",
288 "X-Total-Count": "1",
291 cy.intercept("GET", "/api/v1/erm/licenses/*", license).as(
294 cy.visit("/cgi-bin/koha/erm/licenses");
295 let name_link = cy.get(
296 "#licenses_list table tbody tr:first td:first a"
300 license.name + " (#" + license.license_id + ")"
303 cy.wait("@get-license");
304 cy.wait(500); // Cypress is too fast! Vue hasn't populated the form yet!
305 cy.get("#licenses_show h2").contains("License #" + license.license_id);
307 cy.get("#licenses_show .action_links .fa-trash").click();
308 cy.get(".dialog.alert.confirmation h1").contains("remove this license");
309 cy.contains("Yes, delete").click();
311 //Make sure we return to list after deleting from show
312 cy.get("#licenses_list table tbody tr:first");