|
Line 0
Link Here
|
|
|
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 */ |
| 4 |
|
| 5 |
const dates = { |
| 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"), |
| 10 |
}; |
| 11 |
|
| 12 |
const createLicenses = start => { |
| 13 |
const licenses = []; |
| 14 |
for (let i = start; i < start + 20; i++) { |
| 15 |
const newLicense = { |
| 16 |
license_id: i, |
| 17 |
name: "License " + i, |
| 18 |
description: "A test license", |
| 19 |
type: "local", |
| 20 |
status: "active", |
| 21 |
started_on: dates["today_iso"], |
| 22 |
ended_on: dates["tomorrow_iso"], |
| 23 |
user_roles: [], |
| 24 |
}; |
| 25 |
licenses.push(newLicense); |
| 26 |
} |
| 27 |
return licenses; |
| 28 |
}; |
| 29 |
|
| 30 |
describe("Infinite scroll", () => { |
| 31 |
beforeEach(() => { |
| 32 |
cy.login(); |
| 33 |
cy.title().should("eq", "Koha staff interface"); |
| 34 |
cy.intercept( |
| 35 |
"GET", |
| 36 |
"/api/v1/erm/config", |
| 37 |
'{"settings":{"ERMModule":"1","ERMProviders":["local"]}}' |
| 38 |
); |
| 39 |
}); |
| 40 |
|
| 41 |
it("Should load the next page on scroll", () => { |
| 42 |
const pageOne = createLicenses(1); |
| 43 |
const pageTwo = createLicenses(21); |
| 44 |
const pageThree = createLicenses(41); |
| 45 |
const agreement = cy.get_agreement(); |
| 46 |
const vendors = cy.get_vendors_to_relate(); |
| 47 |
|
| 48 |
// No agreement, no license yet |
| 49 |
cy.intercept("GET", "/api/v1/erm/agreements*", { |
| 50 |
statusCode: 200, |
| 51 |
body: [], |
| 52 |
}); |
| 53 |
cy.intercept("GET", "/api/v1/erm/licenses*", { |
| 54 |
statusCode: 200, |
| 55 |
body: [], |
| 56 |
}); |
| 57 |
//Intercept vendors request |
| 58 |
cy.intercept("GET", "/api/v1/acquisitions/vendors*", { |
| 59 |
statusCode: 200, |
| 60 |
body: vendors, |
| 61 |
}); |
| 62 |
cy.intercept("GET", "/api/v1/erm/licenses*", { |
| 63 |
statusCode: 200, |
| 64 |
body: pageOne, |
| 65 |
headers: { |
| 66 |
"X-Base-Total-Count": "20", |
| 67 |
"X-Total-Count": "20", |
| 68 |
}, |
| 69 |
}); |
| 70 |
|
| 71 |
// Click the button in the toolbar |
| 72 |
cy.visit("/cgi-bin/koha/erm/agreements"); |
| 73 |
cy.contains("New agreement").click(); |
| 74 |
|
| 75 |
cy.get("#agreement_licenses").contains("Add new license").click(); |
| 76 |
cy.get("#license_id_0 .vs__open-indicator").click(); |
| 77 |
cy.get("#license_id_0").find("li").as("options"); |
| 78 |
cy.get("@options").should("have.length", 20); |
| 79 |
|
| 80 |
cy.intercept("GET", "/api/v1/erm/licenses*", { |
| 81 |
statusCode: 200, |
| 82 |
body: pageTwo, |
| 83 |
headers: { |
| 84 |
"X-Base-Total-Count": "20", |
| 85 |
"X-Total-Count": "20", |
| 86 |
}, |
| 87 |
}); |
| 88 |
// Scroll the dropdown |
| 89 |
cy.get(".vs__dropdown-menu").scrollTo("bottom"); |
| 90 |
cy.get("@options").should("have.length", 40); |
| 91 |
|
| 92 |
cy.intercept("GET", "/api/v1/erm/licenses*", { |
| 93 |
statusCode: 200, |
| 94 |
body: pageThree, |
| 95 |
headers: { |
| 96 |
"X-Base-Total-Count": "20", |
| 97 |
"X-Total-Count": "20", |
| 98 |
}, |
| 99 |
}); |
| 100 |
// Scroll the dropdown again |
| 101 |
cy.get(".vs__dropdown-menu").scrollTo("bottom"); |
| 102 |
cy.get("@options").should("have.length", 60); |
| 103 |
}); |
| 104 |
|
| 105 |
it("Should correctly submit the form", () => { |
| 106 |
const pageOne = createLicenses(1); |
| 107 |
const vendors = cy.get_vendors_to_relate(); |
| 108 |
let agreement = cy.get_agreement(); |
| 109 |
|
| 110 |
// No agreement, no license yet |
| 111 |
cy.intercept("GET", "/api/v1/erm/agreements*", { |
| 112 |
statusCode: 200, |
| 113 |
body: [], |
| 114 |
}); |
| 115 |
cy.intercept("GET", "/api/v1/erm/licenses*", { |
| 116 |
statusCode: 200, |
| 117 |
body: [], |
| 118 |
}); |
| 119 |
//Intercept vendors request |
| 120 |
cy.intercept("GET", "/api/v1/acquisitions/vendors*", { |
| 121 |
statusCode: 200, |
| 122 |
body: vendors, |
| 123 |
}); |
| 124 |
cy.intercept("GET", "/api/v1/erm/licenses*", { |
| 125 |
statusCode: 200, |
| 126 |
body: pageOne, |
| 127 |
headers: { |
| 128 |
"X-Base-Total-Count": "20", |
| 129 |
"X-Total-Count": "20", |
| 130 |
}, |
| 131 |
}); |
| 132 |
|
| 133 |
// Click the button in the toolbar |
| 134 |
cy.visit("/cgi-bin/koha/erm/agreements"); |
| 135 |
cy.contains("New agreement").click(); |
| 136 |
|
| 137 |
cy.get("#agreement_licenses").contains("Add new license").click(); |
| 138 |
cy.get("#license_id_0 .vs__open-indicator").click(); |
| 139 |
|
| 140 |
cy.get("#agreement_license_0 #license_id_0 .vs__dropdown-menu li") |
| 141 |
.eq(0) |
| 142 |
.click({ force: true }); //click first license suggestion |
| 143 |
|
| 144 |
// Fill in the other required fields |
| 145 |
cy.get("#agreement_name").type(agreement.name); |
| 146 |
cy.get("#agreement_status .vs__search").type( |
| 147 |
agreement.status + "{enter}", |
| 148 |
{ force: true } |
| 149 |
); |
| 150 |
cy.get("#agreement_license_0 #license_status_0 .vs__search").type( |
| 151 |
agreement.agreement_licenses[0].status + "{enter}", |
| 152 |
{ force: true } |
| 153 |
); |
| 154 |
|
| 155 |
cy.intercept("POST", "/api/v1/erm/agreements", { |
| 156 |
statusCode: 201, |
| 157 |
body: agreement, |
| 158 |
}); |
| 159 |
// Submit the form, no error should be thrown as the select has correctly set the license id |
| 160 |
cy.get("#agreements_add").contains("Submit").click(); |
| 161 |
cy.get("main div[class='dialog message']").contains( |
| 162 |
"Agreement created" |
| 163 |
); |
| 164 |
}); |
| 165 |
|
| 166 |
it("Should correctly display labels", () => { |
| 167 |
const pageOne = createLicenses(1); |
| 168 |
const pageTwo = createLicenses(21); |
| 169 |
const pageThree = createLicenses(41); |
| 170 |
const vendors = cy.get_vendors_to_relate(); |
| 171 |
|
| 172 |
// No agreement, no license yet |
| 173 |
cy.intercept("GET", "/api/v1/erm/agreements*", { |
| 174 |
statusCode: 200, |
| 175 |
body: [], |
| 176 |
}); |
| 177 |
cy.intercept("GET", "/api/v1/erm/licenses*", { |
| 178 |
statusCode: 200, |
| 179 |
body: [], |
| 180 |
}); |
| 181 |
//Intercept vendors request |
| 182 |
cy.intercept("GET", "/api/v1/acquisitions/vendors*", { |
| 183 |
statusCode: 200, |
| 184 |
body: vendors, |
| 185 |
}); |
| 186 |
cy.intercept("GET", "/api/v1/erm/licenses*", { |
| 187 |
statusCode: 200, |
| 188 |
body: pageOne, |
| 189 |
headers: { |
| 190 |
"X-Base-Total-Count": "20", |
| 191 |
"X-Total-Count": "20", |
| 192 |
}, |
| 193 |
}); |
| 194 |
|
| 195 |
// Click the button in the toolbar |
| 196 |
cy.visit("/cgi-bin/koha/erm/agreements"); |
| 197 |
cy.contains("New agreement").click(); |
| 198 |
|
| 199 |
cy.get("#agreement_licenses").contains("Add new license").click(); |
| 200 |
cy.get("#license_id_0 .vs__open-indicator").click(); |
| 201 |
cy.get("#license_id_0").find("li").as("options"); |
| 202 |
cy.get("@options").should("have.length", 20); |
| 203 |
|
| 204 |
cy.intercept("GET", "/api/v1/erm/licenses*", { |
| 205 |
statusCode: 200, |
| 206 |
body: pageTwo, |
| 207 |
headers: { |
| 208 |
"X-Base-Total-Count": "20", |
| 209 |
"X-Total-Count": "20", |
| 210 |
}, |
| 211 |
}); |
| 212 |
// Scroll the dropdown |
| 213 |
cy.get(".vs__dropdown-menu").scrollTo("bottom"); |
| 214 |
|
| 215 |
cy.intercept("GET", "/api/v1/erm/licenses*", { |
| 216 |
statusCode: 200, |
| 217 |
body: pageThree, |
| 218 |
headers: { |
| 219 |
"X-Base-Total-Count": "20", |
| 220 |
"X-Total-Count": "20", |
| 221 |
}, |
| 222 |
}).as("finalPage"); |
| 223 |
// Scroll the dropdown again |
| 224 |
cy.get(".vs__dropdown-menu").scrollTo("bottom"); |
| 225 |
cy.wait("@finalPage"); |
| 226 |
|
| 227 |
// Select a license that is not in the first page of results |
| 228 |
cy.get("#agreement_license_0 #license_id_0 .vs__search").type( |
| 229 |
"License 50{enter}", |
| 230 |
{ force: true } |
| 231 |
); |
| 232 |
cy.get("#agreement_license_0").contains("License 50"); |
| 233 |
|
| 234 |
// Re-open the dropdown, License 50 will no longer be in the dataset but the label should still show |
| 235 |
cy.intercept("GET", "/api/v1/erm/licenses*", { |
| 236 |
statusCode: 200, |
| 237 |
body: pageOne, |
| 238 |
headers: { |
| 239 |
"X-Base-Total-Count": "20", |
| 240 |
"X-Total-Count": "20", |
| 241 |
}, |
| 242 |
}); |
| 243 |
cy.get("#license_id_0 .vs__open-indicator").click(); |
| 244 |
cy.get("#agreement_licenses").click(); |
| 245 |
cy.get("#agreement_license_0").contains("License 50"); |
| 246 |
|
| 247 |
// Select a different license |
| 248 |
cy.get("#license_id_0 .vs__open-indicator").click(); |
| 249 |
cy.get("#agreement_license_0 #license_id_0 .vs__search").type( |
| 250 |
"License 10{enter}", |
| 251 |
{ force: true } |
| 252 |
); |
| 253 |
cy.get("#agreement_license_0").contains("License 10"); |
| 254 |
}); |
| 255 |
|
| 256 |
it("Should correctly display the label when editing", () => { |
| 257 |
let agreement = cy.get_agreement(); |
| 258 |
let agreements = [agreement]; |
| 259 |
let licenses_to_relate = cy.get_licenses_to_relate(); |
| 260 |
let vendors = cy.get_vendors_to_relate(); |
| 261 |
|
| 262 |
// Intercept vendors request |
| 263 |
cy.intercept("GET", "/api/v1/acquisitions/vendors*", { |
| 264 |
statusCode: 200, |
| 265 |
body: vendors, |
| 266 |
}).as("get-vendor-options"); |
| 267 |
|
| 268 |
// Intercept initial /agreements request once |
| 269 |
cy.intercept( |
| 270 |
{ |
| 271 |
method: "GET", |
| 272 |
url: "/api/v1/erm/agreements*", |
| 273 |
times: 1, |
| 274 |
}, |
| 275 |
{ |
| 276 |
body: agreements, |
| 277 |
} |
| 278 |
); |
| 279 |
// Intercept follow-up 'search' request after entering /agreements |
| 280 |
cy.intercept("GET", "/api/v1/erm/agreements?_page*", { |
| 281 |
statusCode: 200, |
| 282 |
body: agreements, |
| 283 |
headers: { |
| 284 |
"X-Base-Total-Count": "1", |
| 285 |
"X-Total-Count": "1", |
| 286 |
}, |
| 287 |
}).as("get-single-agreement-search-result"); |
| 288 |
cy.visit("/cgi-bin/koha/erm/agreements"); |
| 289 |
cy.wait("@get-single-agreement-search-result"); |
| 290 |
|
| 291 |
// Intercept request after edit click |
| 292 |
cy.intercept("GET", "/api/v1/erm/agreements/*", agreement).as( |
| 293 |
"get-agreement" |
| 294 |
); |
| 295 |
|
| 296 |
// Intercept related licenses request after entering agreement edit |
| 297 |
let licenses_count = licenses_to_relate.length.toString(); |
| 298 |
cy.intercept("GET", "/api/v1/erm/licenses*", { |
| 299 |
statusCode: 200, |
| 300 |
body: licenses_to_relate, |
| 301 |
headers: { |
| 302 |
"X-Base-Total-Count": licenses_count, |
| 303 |
"X-Total-Count": licenses_count, |
| 304 |
}, |
| 305 |
}).as("get-related-licenses"); |
| 306 |
|
| 307 |
// Intercept related agreements request after entering agreement edit |
| 308 |
cy.intercept("GET", "/api/v1/erm/agreements*", { |
| 309 |
statusCode: 200, |
| 310 |
body: cy.get_agreements_to_relate(), |
| 311 |
}).as("get-related-agreements"); |
| 312 |
|
| 313 |
// Click the 'Edit' button from the list |
| 314 |
cy.get("#agreements_list table tbody tr:first") |
| 315 |
.contains("Edit") |
| 316 |
.click(); |
| 317 |
cy.wait("@get-agreement"); |
| 318 |
cy.wait(500); // Cypress is too fast! Vue hasn't populated the form yet! |
| 319 |
|
| 320 |
// Licenses should be labelled correctly |
| 321 |
cy.get("#agreement_license_0 #license_id_0 .vs__selected").contains( |
| 322 |
"first license name" |
| 323 |
); |
| 324 |
cy.get("#agreement_license_1 #license_id_1 .vs__selected").contains( |
| 325 |
"second license name" |
| 326 |
); |
| 327 |
}); |
| 328 |
}); |