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"],
23 describe("License CRUD operations", () => {
25 cy.login("koha", "koha");
26 cy.title().should("eq", "Koha staff interface");
29 it("List license", () => {
30 // GET license returns 500
31 cy.intercept("GET", "/api/v1/erm/licenses", {
33 error: "Something went wrong",
35 cy.visit("/cgi-bin/koha/erm/erm.pl");
36 cy.get("#navmenulist").contains("Licenses").click();
37 cy.get("main div[class='dialog alert']").contains(
38 /Something went wrong/
41 // GET licenses returns empty list
42 cy.intercept("GET", "/api/v1/erm/licenses*", []);
43 cy.visit("/cgi-bin/koha/erm/licenses");
44 cy.get("#licenses_list").contains("There are no licenses defined.");
46 // GET licenses returns something
47 let license = get_license();
48 let licenses = [license];
50 cy.intercept("GET", "/api/v1/erm/licenses*", {
54 "X-Base-Total-Count": "1",
58 cy.intercept("GET", "/api/v1/erm/licenses/*", license);
59 cy.visit("/cgi-bin/koha/erm/licenses");
60 cy.get("#licenses_list").contains("Showing 1 to 1 of 1 entries");
63 it("Add license", () => {
64 // Click the button in the toolbar
65 cy.visit("/cgi-bin/koha/erm/licenses");
66 cy.contains("New license").click();
67 cy.get("#licenses_add h2").contains("New license");
69 // Fill in the form for normal attributes
70 let license = get_license();
72 cy.get("#licenses_add").contains("Submit").click();
73 cy.get("input:invalid,textarea:invalid,select:invalid").should(
77 cy.get("#license_name").type(license.name);
78 cy.get("#license_description").type(license.description);
79 cy.get("#licenses_add").contains("Submit").click();
80 cy.get("#license_type .vs__search").type(license.type + '{enter}',{force:true});
81 cy.get("#license_status .vs__search").type(license.status + '{enter}',{force:true});
83 cy.get("#started_on+input").click();
84 cy.get(".flatpickr-calendar")
87 .click({ force: true });
89 cy.get("#ended_on+input").click();
90 cy.get(".flatpickr-calendar")
96 // Submit the form, get 500
97 cy.intercept("POST", "/api/v1/erm/licenses", {
99 error: "Something went wrong",
101 cy.get("#licenses_add").contains("Submit").click();
102 cy.get("main div[class='dialog alert']").contains(
103 "Something went wrong: Internal Server Error"
106 // Submit the form, success!
107 cy.intercept("POST", "/api/v1/erm/licenses", {
111 cy.get("#licenses_add").contains("Submit").click();
112 cy.get("main div[class='dialog message']").contains(
117 it("Edit license", () => {
118 let license = get_license();
119 let licenses = [license];
120 // Click the 'Edit' button from the list
121 cy.intercept("GET", "/api/v1/erm/licenses*", {
125 "X-Base-Total-Count": "1",
126 "X-Total-Count": "1",
129 cy.intercept("GET", "/api/v1/erm/licenses/*", license).as(
132 cy.visit("/cgi-bin/koha/erm/licenses");
133 cy.get("#licenses_list table tbody tr:first")
136 cy.wait("@get-license");
137 cy.wait(500); // Cypress is too fast! Vue hasn't populated the form yet!
138 cy.get("#licenses_add h2").contains("Edit license");
140 // Form has been correctly filled in
141 cy.get("#license_name").should("have.value", license.name);
142 cy.get("#license_description").should(
146 cy.get("#license_type .vs__selected").contains("Local");
147 cy.get("#license_status .vs__selected").contains("Active");
148 cy.get("#started_on").invoke("val").should("eq", dates["today_iso"]);
149 cy.get("#ended_on").invoke("val").should("eq", dates["tomorrow_iso"]);
151 // Submit the form, get 500
152 cy.intercept("PUT", "/api/v1/erm/licenses/*", {
154 error: "Something went wrong",
156 cy.get("#licenses_add").contains("Submit").click();
157 cy.get("main div[class='dialog alert']").contains(
158 "Something went wrong: Internal Server Error"
161 // Submit the form, success!
162 cy.intercept("PUT", "/api/v1/erm/licenses/*", {
166 cy.get("#licenses_add").contains("Submit").click();
167 cy.get("main div[class='dialog message']").contains(
172 it("Show license", () => {
173 let license = get_license();
174 let licenses = [license];
175 // Click the "name" link from the list
176 cy.intercept("GET", "/api/v1/erm/licenses*", {
180 "X-Base-Total-Count": "1",
181 "X-Total-Count": "1",
184 cy.intercept("GET", "/api/v1/erm/licenses/*", license).as(
187 cy.visit("/cgi-bin/koha/erm/licenses");
188 let name_link = cy.get(
189 "#licenses_list table tbody tr:first td:first a"
193 license.name + " (#" + license.license_id + ")"
196 cy.wait("@get-license");
197 cy.wait(500); // Cypress is too fast! Vue hasn't populated the form yet!
198 cy.get("#licenses_show h2").contains(
199 "License #" + license.license_id
203 it("Delete license", () => {
204 let license = get_license();
205 let licenses = [license];
207 // Click the 'Delete' button from the list
208 cy.intercept("GET", "/api/v1/erm/licenses*", {
212 "X-Base-Total-Count": "1",
213 "X-Total-Count": "1",
216 cy.intercept("GET", "/api/v1/erm/licenses/*", license);
217 cy.visit("/cgi-bin/koha/erm/licenses");
219 cy.get("#licenses_list table tbody tr:first")
222 cy.get("#licenses_confirm_delete h2").contains("Delete license");
223 cy.contains("License name: " + license.name);
225 // Submit the form, get 500
226 cy.intercept("DELETE", "/api/v1/erm/licenses/*", {
228 error: "Something went wrong",
230 cy.contains("Yes, delete").click();
231 cy.get("main div[class='dialog alert']").contains(
232 "Something went wrong: Internal Server Error"
235 // Submit the form, success!
236 cy.intercept("DELETE", "/api/v1/erm/licenses/*", {
240 cy.contains("Yes, delete").click();
241 cy.get("main div[class='dialog message']").contains(