|
Line 0
Link Here
|
| 0 |
- |
1 |
const getVendor = () => { |
|
|
2 |
return { |
| 3 |
accountnumber: "69823", |
| 4 |
active: true, |
| 5 |
address1: "6897 Library Rd", |
| 6 |
address2: "Springfield, MA 44224", |
| 7 |
address3: null, |
| 8 |
address4: null, |
| 9 |
aliases: [{ alias: "Test alias" }], |
| 10 |
baskets: [], |
| 11 |
contacts: [ |
| 12 |
{ |
| 13 |
name: "Test contact", |
| 14 |
position: "Test", |
| 15 |
email: "test@email.com", |
| 16 |
phone: "0123456789", |
| 17 |
notes: "Some interesting notes", |
| 18 |
altphone: "9876543210", |
| 19 |
fax: "Who uses fax these days?", |
| 20 |
acqprimary: false, |
| 21 |
orderacquisition: false, |
| 22 |
claimacquisition: false, |
| 23 |
serialsprimary: false, |
| 24 |
claimissues: false, |
| 25 |
}, |
| 26 |
], |
| 27 |
deliverytime: 3, |
| 28 |
discount: 10, |
| 29 |
external_id: "test1234", |
| 30 |
fax: "555-555-9999", |
| 31 |
gst: false, |
| 32 |
id: 1, |
| 33 |
interfaces: [ |
| 34 |
{ |
| 35 |
type: "interface", |
| 36 |
name: "fancy website", |
| 37 |
uri: "www.uri.com", |
| 38 |
login: "login", |
| 39 |
password: "password", |
| 40 |
account_email: "email@email.com", |
| 41 |
notes: "This is a website", |
| 42 |
}, |
| 43 |
], |
| 44 |
invoice_currency: "USD", |
| 45 |
invoice_includes_gst: false, |
| 46 |
list_currency: "USD", |
| 47 |
list_includes_gst: false, |
| 48 |
name: "My Vendor", |
| 49 |
notes: "Sample vendor", |
| 50 |
phone: "555-555-5555", |
| 51 |
postal: "567 Main St. PO Box 25 Springfield, MA 44224", |
| 52 |
subscriptions: [], |
| 53 |
tax_rate: 0.1965, |
| 54 |
type: "Print books", |
| 55 |
url: "https://koha-community.org/", |
| 56 |
}; |
| 57 |
}; |
| 58 |
|
| 59 |
describe("Vendor CRUD operations", () => { |
| 60 |
beforeEach(() => { |
| 61 |
cy.login(); |
| 62 |
cy.title().should("eq", "Koha staff interface"); |
| 63 |
}); |
| 64 |
|
| 65 |
it("should list vendors", () => { |
| 66 |
cy.visit("/cgi-bin/koha/acqui/acqui-home.pl"); |
| 67 |
cy.get("#acqui_acqui_home_order").contains("Vendor list").click(); |
| 68 |
|
| 69 |
cy.intercept("GET", "/api/v1/acquisitions/vendors*", []); |
| 70 |
cy.visit("/cgi-bin/koha/vendors"); |
| 71 |
cy.get("#vendors_list").contains("There are no vendors defined"); |
| 72 |
|
| 73 |
const vendor = getVendor(); |
| 74 |
cy.intercept("GET", "/api/v1/acquisitions/vendors*", { |
| 75 |
statusCode: 200, |
| 76 |
body: [vendor], |
| 77 |
headers: { |
| 78 |
"X-Base-Total-Count": "1", |
| 79 |
"X-Total-Count": "1", |
| 80 |
}, |
| 81 |
}); |
| 82 |
cy.intercept("GET", "/api/v1/acquisitions/vendors/*", vendor); |
| 83 |
cy.visit("/cgi-bin/koha/vendors"); |
| 84 |
cy.get("#vendors_list").contains("Showing 1 to 1 of 1 entries"); |
| 85 |
}); |
| 86 |
|
| 87 |
it("should add a vendor", () => { |
| 88 |
const vendor = getVendor(); |
| 89 |
|
| 90 |
cy.intercept("GET", "/api/v1/acquisitions/vendors*", { |
| 91 |
statusCode: 200, |
| 92 |
body: [], |
| 93 |
}); |
| 94 |
|
| 95 |
// Click the button in the toolbar |
| 96 |
cy.visit("/cgi-bin/koha/vendors"); |
| 97 |
cy.contains("New vendor").click(); |
| 98 |
cy.get("#vendor_add h2").contains("New vendor"); |
| 99 |
|
| 100 |
// Fill in the form for normal attributes |
| 101 |
cy.get("#vendor_add").contains("Submit").click(); |
| 102 |
cy.get("input:invalid,textarea:invalid,select:invalid").should( |
| 103 |
"have.length", |
| 104 |
1 |
| 105 |
); |
| 106 |
|
| 107 |
// Vendor details |
| 108 |
cy.get("#vendor_name").type(vendor.name); |
| 109 |
cy.get("#vendor_postal").type(vendor.postal); |
| 110 |
cy.get("#vendor_physical").type( |
| 111 |
`${vendor.address1}\n${vendor.address2}` |
| 112 |
); |
| 113 |
cy.get("#vendor_fax").type(vendor.fax); |
| 114 |
cy.get("#vendor_phone").type(vendor.phone); |
| 115 |
cy.get("#vendor_website").type(vendor.url); |
| 116 |
cy.get("#vendor_type").type(vendor.type); |
| 117 |
cy.get("#vendor_accountnumber").type(vendor.accountnumber); |
| 118 |
cy.get("#vendor_aliases").type(vendor.aliases[0].alias); |
| 119 |
cy.get(".aliasAction").click(); |
| 120 |
|
| 121 |
// Vendor ordering information |
| 122 |
cy.get("#activestatus_active").check(); |
| 123 |
cy.get("#list_currency .vs__search").type( |
| 124 |
vendor.list_currency + "{enter}", |
| 125 |
{ |
| 126 |
force: true, |
| 127 |
} |
| 128 |
); |
| 129 |
cy.get("#invoice_currency .vs__search").type( |
| 130 |
vendor.invoice_currency + "{enter}", |
| 131 |
{ |
| 132 |
force: true, |
| 133 |
} |
| 134 |
); |
| 135 |
cy.get("#gst_yes").check(); |
| 136 |
cy.get("#tax_rate .vs__search").type( |
| 137 |
`${(vendor.tax_rate * 100).toFixed(2)}` + "{enter}", |
| 138 |
{ |
| 139 |
force: true, |
| 140 |
} |
| 141 |
); |
| 142 |
cy.get("#invoice_gst_yes").check(); |
| 143 |
cy.get("#list_gst_yes").check(); |
| 144 |
cy.get("#discount").type(vendor.discount.toString()); |
| 145 |
cy.get("#deliverytime").type(vendor.deliverytime.toString()); |
| 146 |
cy.get("#notes").type(vendor.notes); |
| 147 |
|
| 148 |
// Vendor contacts |
| 149 |
cy.contains("Add new contact").click(); |
| 150 |
cy.get("#contact_0_name").type(vendor.contacts[0].name); |
| 151 |
cy.get("#contact_0_email").type(vendor.contacts[0].email); |
| 152 |
cy.get("#contact_0_fax").type(vendor.contacts[0].fax); |
| 153 |
cy.get("#contact_0_altphone").type(vendor.contacts[0].altphone); |
| 154 |
cy.get("#contact_0_phone").type(vendor.contacts[0].phone); |
| 155 |
cy.get("#contact_0_position").type(vendor.contacts[0].position); |
| 156 |
cy.get("#contact_0_notes").type(vendor.contacts[0].notes); |
| 157 |
cy.get("#contact_acqprimary_0").check(); |
| 158 |
cy.get("#contact_serialsprimary_0").check(); |
| 159 |
|
| 160 |
// Vendor interfaces |
| 161 |
cy.contains("Add new interface").click(); |
| 162 |
cy.get("#vendorInterface_0_name").type(vendor.interfaces[0].name); |
| 163 |
cy.get("#vendorInterface_0_uri").type(vendor.interfaces[0].uri); |
| 164 |
cy.get("#vendorInterface_0_login").type(vendor.interfaces[0].login); |
| 165 |
cy.get("#vendorInterface_0_password").type( |
| 166 |
vendor.interfaces[0].password |
| 167 |
); |
| 168 |
cy.get("#vendorInterface_0_accountemail").type( |
| 169 |
vendor.interfaces[0].account_email |
| 170 |
); |
| 171 |
cy.get("#vendorInterface_0_notes").type(vendor.interfaces[0].notes); |
| 172 |
|
| 173 |
cy.intercept("POST", "/api/v1/acquisitions/vendors", { |
| 174 |
statusCode: 201, |
| 175 |
body: vendor, |
| 176 |
}); |
| 177 |
cy.get("#vendor_add").contains("Submit").click(); |
| 178 |
cy.get("main div[class='alert alert-info']").contains("Vendor created"); |
| 179 |
}); |
| 180 |
|
| 181 |
it("should edit a vendor", () => { |
| 182 |
const vendor = getVendor(); |
| 183 |
|
| 184 |
cy.visit("/cgi-bin/koha/vendors"); |
| 185 |
cy.intercept("GET", "/api/v1/acquisitions/vendors/*", vendor).as( |
| 186 |
"get-vendor" |
| 187 |
); |
| 188 |
|
| 189 |
// Click the 'Edit' button from the list |
| 190 |
cy.get("#vendors_list table tbody tr:first").contains("Edit").click(); |
| 191 |
cy.wait("@get-vendor"); |
| 192 |
cy.wait(500); // Cypress is too fast! Vue hasn't populated the form yet! |
| 193 |
cy.get("#vendor_add h2").contains("Edit vendor"); |
| 194 |
|
| 195 |
// Form has been correctly filled in |
| 196 |
cy.get("#vendor_name").should("have.value", vendor.name); |
| 197 |
cy.get("#vendor_phone").should("have.value", vendor.phone); |
| 198 |
cy.get("#alias0").should("have.text", vendor.aliases[0].alias); |
| 199 |
cy.get("#activestatus_active").should("be.checked"); |
| 200 |
|
| 201 |
// Submit the form, success! |
| 202 |
cy.intercept("PUT", "/api/v1/acquisitions/vendors/*", { |
| 203 |
statusCode: 200, |
| 204 |
body: vendor, |
| 205 |
}); |
| 206 |
cy.get("#vendor_add").contains("Submit").click(); |
| 207 |
cy.get("main div[class='alert alert-info']").contains("Vendor updated"); |
| 208 |
}); |
| 209 |
|
| 210 |
it("should show a vendor", () => { |
| 211 |
const vendor = getVendor(); |
| 212 |
|
| 213 |
// Click the "name" link from the list |
| 214 |
cy.intercept("GET", "/api/v1/acquisitions/vendors*", { |
| 215 |
statusCode: 200, |
| 216 |
body: [vendor], |
| 217 |
headers: { |
| 218 |
"X-Base-Total-Count": "1", |
| 219 |
"X-Total-Count": "1", |
| 220 |
}, |
| 221 |
}); |
| 222 |
cy.visit("/cgi-bin/koha/vendors"); |
| 223 |
const name_link = cy.get( |
| 224 |
"#vendors_list table tbody tr:first td:first a" |
| 225 |
); |
| 226 |
name_link.should("have.text", vendor.name + " (#" + vendor.id + ")"); |
| 227 |
name_link.click(); |
| 228 |
cy.wait(500); // Cypress is too fast! Vue hasn't populated the form yet! |
| 229 |
cy.get("#vendors_show h1").contains(vendor.name); |
| 230 |
|
| 231 |
// TODO Test contracts table |
| 232 |
}); |
| 233 |
|
| 234 |
it("should delete a vendor", () => { |
| 235 |
const vendor = getVendor(); |
| 236 |
|
| 237 |
// Delete from list |
| 238 |
// Click the 'Delete' button from the list |
| 239 |
cy.intercept("GET", "/api/v1/acquisitions/vendors*", { |
| 240 |
statusCode: 200, |
| 241 |
body: [vendor], |
| 242 |
headers: { |
| 243 |
"X-Base-Total-Count": "1", |
| 244 |
"X-Total-Count": "1", |
| 245 |
}, |
| 246 |
}); |
| 247 |
cy.intercept("GET", "/api/v1/acquisitions/vendors/*", vendor); |
| 248 |
cy.visit("/cgi-bin/koha/vendors"); |
| 249 |
|
| 250 |
cy.get("#vendors_list table tbody tr:first").contains("Delete").click(); |
| 251 |
cy.get(".alert-warning.confirmation h1").contains("remove this vendor"); |
| 252 |
cy.contains(vendor.name); |
| 253 |
|
| 254 |
// Accept the confirmation dialog, get 500 |
| 255 |
cy.intercept("DELETE", "/api/v1/acquisitions/vendors/*", { |
| 256 |
statusCode: 500, |
| 257 |
}); |
| 258 |
cy.contains("Yes, delete").click(); |
| 259 |
cy.get("main div[class='alert alert-warning']").contains( |
| 260 |
"Something went wrong: Error: Internal Server Error" |
| 261 |
); |
| 262 |
|
| 263 |
// Accept the confirmation dialog, success! |
| 264 |
cy.intercept("DELETE", "/api/v1/acquisitions/vendors/*", { |
| 265 |
statusCode: 204, |
| 266 |
body: null, |
| 267 |
}); |
| 268 |
cy.get("#vendors_list table tbody tr:first").contains("Delete").click(); |
| 269 |
cy.get(".alert-warning.confirmation h1").contains("remove this vendor"); |
| 270 |
cy.contains("Yes, delete").click(); |
| 271 |
cy.get("main div[class='alert alert-info']") |
| 272 |
.contains("Vendor") |
| 273 |
.contains("deleted"); |
| 274 |
}); |
| 275 |
}); |
| 276 |
|
| 277 |
describe("External URLs", () => { |
| 278 |
beforeEach(() => { |
| 279 |
cy.login(); |
| 280 |
cy.title().should("eq", "Koha staff interface"); |
| 281 |
}); |
| 282 |
|
| 283 |
it("should navigate to the receive shipments page", () => { |
| 284 |
cy.visit("/cgi-bin/koha/acqui/acqui-home.pl"); |
| 285 |
cy.get("#acqui_acqui_home_order").contains("Vendor list").click(); |
| 286 |
|
| 287 |
const vendor = getVendor(); |
| 288 |
cy.intercept("GET", "/api/v1/acquisitions/vendors*", { |
| 289 |
statusCode: 200, |
| 290 |
body: [vendor], |
| 291 |
headers: { |
| 292 |
"X-Base-Total-Count": "1", |
| 293 |
"X-Total-Count": "1", |
| 294 |
}, |
| 295 |
}); |
| 296 |
cy.intercept("GET", "/api/v1/acquisitions/vendors/*", vendor); |
| 297 |
cy.visit("/cgi-bin/koha/vendors"); |
| 298 |
const name_link = cy.get( |
| 299 |
"#vendors_list table tbody tr:first td:first a" |
| 300 |
); |
| 301 |
name_link.should("have.text", vendor.name + " (#" + vendor.id + ")"); |
| 302 |
name_link.click(); |
| 303 |
|
| 304 |
cy.get("#vendors_show").contains("Receive shipments").click(); |
| 305 |
cy.get("h1").contains("Receive shipment from vendor " + vendor.name); |
| 306 |
}); |
| 307 |
}); |