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.fetch_initial_ERM_sys_pref_value();
38 cy.set_ERM_sys_pref_value(true);
42 cy.login("koha", "koha");
43 cy.title().should("eq", "Koha staff interface");
47 cy.reset_initial_ERM_sys_pref_value();
50 it("List license", () => {
51 // GET license returns 500
52 cy.intercept("GET", "/api/v1/erm/licenses", {
54 error: "Something went wrong",
56 cy.visit("/cgi-bin/koha/erm/erm.pl");
57 cy.get("#navmenulist").contains("Licenses").click();
58 cy.get("main div[class='dialog alert']").contains(
59 /Something went wrong/
62 // GET licenses returns empty list
63 cy.intercept("GET", "/api/v1/erm/licenses*", []);
64 cy.visit("/cgi-bin/koha/erm/licenses");
65 cy.get("#licenses_list").contains("There are no licenses defined");
67 // GET licenses returns something
68 let license = get_license();
69 let licenses = [license];
71 cy.intercept("GET", "/api/v1/erm/licenses*", {
75 "X-Base-Total-Count": "1",
79 cy.intercept("GET", "/api/v1/erm/licenses/*", license);
80 cy.visit("/cgi-bin/koha/erm/licenses");
81 cy.get("#licenses_list").contains("Showing 1 to 1 of 1 entries");
84 it("Add license", () => {
85 // Click the button in the toolbar
86 cy.visit("/cgi-bin/koha/erm/licenses");
87 cy.contains("New license").click();
88 cy.get("#licenses_add h2").contains("New license");
90 // Fill in the form for normal attributes
91 let license = get_license();
93 cy.get("#licenses_add").contains("Submit").click();
94 cy.get("input:invalid,textarea:invalid,select:invalid").should(
98 cy.get("#license_name").type(license.name);
99 cy.get("#license_description").type(license.description);
100 cy.get("#licenses_add").contains("Submit").click();
101 cy.get("#license_type .vs__search").type(license.type + '{enter}',{force:true});
102 cy.get("#license_status .vs__search").type(license.status + '{enter}',{force:true});
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('t/cypress/fixtures/file.json');
121 cy.get("#document_0 .file_information span").contains("file.json");
122 cy.get('#document_0 input[id=file_description_0]').type('file description');
123 cy.get('#document_0 input[id=physical_location_0]').type('file physical location');
124 cy.get('#document_0 input[id=uri_0]').type('file URI');
125 cy.get('#document_0 input[id=notes_0]').type('file notes');
127 // Submit the form, get 500
128 cy.intercept("POST", "/api/v1/erm/licenses", {
130 error: "Something went wrong",
132 cy.get("#licenses_add").contains("Submit").click();
133 cy.get("main div[class='dialog alert']").contains(
134 "Something went wrong: Internal Server Error"
137 // Submit the form, success!
138 cy.intercept("POST", "/api/v1/erm/licenses", {
142 cy.get("#licenses_add").contains("Submit").click();
143 cy.get("main div[class='dialog message']").contains(
148 it("Edit license", () => {
149 let license = get_license();
150 let licenses = [license];
151 // Click the 'Edit' button from the list
152 cy.intercept("GET", "/api/v1/erm/licenses*", {
156 "X-Base-Total-Count": "1",
157 "X-Total-Count": "1",
160 cy.intercept("GET", "/api/v1/erm/licenses/*", license).as(
163 cy.visit("/cgi-bin/koha/erm/licenses");
164 cy.get("#licenses_list table tbody tr:first")
167 cy.wait("@get-license");
168 cy.wait(500); // Cypress is too fast! Vue hasn't populated the form yet!
169 cy.get("#licenses_add h2").contains("Edit license");
171 // Form has been correctly filled in
172 cy.get("#license_name").should("have.value", license.name);
173 cy.get("#license_description").should(
177 cy.get("#license_type .vs__selected").contains("Local");
178 cy.get("#license_status .vs__selected").contains("Active");
179 cy.get("#started_on").invoke("val").should("eq", dates["today_iso"]);
180 cy.get("#ended_on").invoke("val").should("eq", dates["tomorrow_iso"]);
182 // Test related document
183 cy.get("#document_0 .file_information span").contains("file.json" );
185 // Submit the form, get 500
186 cy.intercept("PUT", "/api/v1/erm/licenses/*", {
188 error: "Something went wrong",
190 cy.get("#licenses_add").contains("Submit").click();
191 cy.get("main div[class='dialog alert']").contains(
192 "Something went wrong: Internal Server Error"
195 // Submit the form, success!
196 cy.intercept("PUT", "/api/v1/erm/licenses/*", {
200 cy.get("#licenses_add").contains("Submit").click();
201 cy.get("main div[class='dialog message']").contains(
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(
233 "License #" + license.license_id
237 it("Delete license", () => {
238 let license = get_license();
239 let licenses = [license];
241 // Click the 'Delete' button from the list
242 cy.intercept("GET", "/api/v1/erm/licenses*", {
246 "X-Base-Total-Count": "1",
247 "X-Total-Count": "1",
250 cy.intercept("GET", "/api/v1/erm/licenses/*", license);
251 cy.visit("/cgi-bin/koha/erm/licenses");
253 cy.get("#licenses_list table tbody tr:first")
256 cy.get("#licenses_confirm_delete h2").contains("Delete license");
257 cy.contains("License name: " + license.name);
259 // Submit the form, get 500
260 cy.intercept("DELETE", "/api/v1/erm/licenses/*", {
262 error: "Something went wrong",
264 cy.contains("Yes, delete").click();
265 cy.get("main div[class='dialog alert']").contains(
266 "Something went wrong: Internal Server Error"
269 // Submit the form, success!
270 cy.intercept("DELETE", "/api/v1/erm/licenses/*", {
274 cy.contains("Yes, delete").click();
275 cy.get("main div[class='dialog message']").contains(