|
Line 0
Link Here
|
| 0 |
- |
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 |
describe("Breadcrumbs tests", () => { |
| 6 |
beforeEach(() => { |
| 7 |
cy.login(); |
| 8 |
cy.title().should("eq", "Koha staff interface"); |
| 9 |
}); |
| 10 |
|
| 11 |
it("Breadcrumbs", () => { |
| 12 |
cy.visit("/cgi-bin/koha/admin/admin-home.pl"); |
| 13 |
cy.contains("Record sources").click(); |
| 14 |
cy.get("#breadcrumbs").contains("Administration"); |
| 15 |
cy.get(".item-last").contains("Record sources"); |
| 16 |
// use the 'New' button |
| 17 |
cy.contains("New record source").click(); |
| 18 |
cy.wait(500); |
| 19 |
cy.get(".current").contains("Add record source"); |
| 20 |
cy.get("#breadcrumbs") |
| 21 |
.contains("Record sources") |
| 22 |
.should("have.attr", "href") |
| 23 |
.and("equal", "/cgi-bin/koha/admin/record_sources"); |
| 24 |
}); |
| 25 |
}); |
| 26 |
|
| 27 |
describe("Record sources CRUD tests", () => { |
| 28 |
beforeEach(() => { |
| 29 |
cy.login(); |
| 30 |
cy.title().should("eq", "Koha staff interface"); |
| 31 |
}); |
| 32 |
|
| 33 |
it("Add", () => { |
| 34 |
cy.visit("/cgi-bin/koha/admin/admin-home.pl"); |
| 35 |
cy.contains("Record sources").click(); |
| 36 |
cy.contains("New record source").click(); |
| 37 |
cy.get("#name").type("Poop"); |
| 38 |
|
| 39 |
// Submit the form, get 201 |
| 40 |
cy.intercept("POST", "/api/v1/record_sources", { |
| 41 |
statusCode: 201, |
| 42 |
body: {}, |
| 43 |
}); |
| 44 |
cy.get("#record_source_edit").contains("Submit").click(); |
| 45 |
|
| 46 |
cy.get("main div[class='dialog message']").contains( |
| 47 |
"Record source created!" |
| 48 |
); |
| 49 |
}); |
| 50 |
|
| 51 |
it("List", () => { |
| 52 |
cy.intercept("GET", "/api/v1/record_sources*", { |
| 53 |
statusCode: 200, |
| 54 |
body: [], |
| 55 |
headers: { |
| 56 |
"X-Base-Total-Count": "0", |
| 57 |
"X-Total-Count": "0", |
| 58 |
}, |
| 59 |
}); |
| 60 |
cy.visit("/cgi-bin/koha/admin/record_sources"); |
| 61 |
cy.get("#record_sources_list").contains( |
| 62 |
"There are no record sources defined" |
| 63 |
); |
| 64 |
|
| 65 |
cy.intercept("GET", "/api/v1/record_sources*", { |
| 66 |
statusCode: 200, |
| 67 |
body: [ |
| 68 |
{ record_source_id: 1, name: "Source 1", can_be_edited: true }, |
| 69 |
{ record_source_id: 2, name: "Source 2", can_be_edited: false }, |
| 70 |
{ record_source_id: 3, name: "Source 3", can_be_edited: true }, |
| 71 |
], |
| 72 |
headers: { |
| 73 |
"X-Base-Total-Count": "3", |
| 74 |
"X-Total-Count": "3", |
| 75 |
}, |
| 76 |
}); |
| 77 |
cy.visit("/cgi-bin/koha/admin/record_sources"); |
| 78 |
cy.get("#record_sources_list").contains("Showing 1 to 3 of 3 entries"); |
| 79 |
|
| 80 |
// Test true => "Yes" |
| 81 |
let row_1 = cy.get(".dataTable > tbody > tr:first-child"); |
| 82 |
row_1.get("td:nth-child(3n+3)").contains("Yes"); |
| 83 |
// Test false => "No" |
| 84 |
let row_2 = cy.get(".dataTable > tbody > tr:nth-child(2n+2)"); |
| 85 |
row_2.get("td:nth-child(3n+3)").contains("No"); |
| 86 |
|
| 87 |
// Action buttons displayed |
| 88 |
row_1.get("td:last-child").contains("Edit"); |
| 89 |
row_1.get("td:last-child").contains("Delete"); |
| 90 |
}); |
| 91 |
|
| 92 |
it("Edit", () => { |
| 93 |
cy.intercept("GET", "/api/v1/record_sources*", { |
| 94 |
statusCode: 200, |
| 95 |
body: [ |
| 96 |
{ record_source_id: 1, name: "Source 1", can_be_edited: true }, |
| 97 |
{ record_source_id: 2, name: "Source 2", can_be_edited: false }, |
| 98 |
{ record_source_id: 3, name: "Source 3", can_be_edited: true }, |
| 99 |
], |
| 100 |
headers: { |
| 101 |
"X-Base-Total-Count": "3", |
| 102 |
"X-Total-Count": "3", |
| 103 |
}, |
| 104 |
}); |
| 105 |
cy.visit("/cgi-bin/koha/admin/record_sources"); |
| 106 |
cy.intercept("GET", "/api/v1/record_sources/1", { |
| 107 |
statusCode: 200, |
| 108 |
body: { |
| 109 |
record_source_id: 1, |
| 110 |
name: "Source 1", |
| 111 |
can_be_edited: true, |
| 112 |
}, |
| 113 |
}); |
| 114 |
cy.get("#record_sources_list table tbody tr:first") |
| 115 |
.contains("Edit") |
| 116 |
.click(); |
| 117 |
cy.wait(500); |
| 118 |
cy.get("#name").should("have.value", "Source 1"); |
| 119 |
cy.get("#can_be_edited").should("be.checked"); |
| 120 |
|
| 121 |
cy.intercept("GET", "/api/v1/record_sources/1", { |
| 122 |
statusCode: 200, |
| 123 |
body: { |
| 124 |
record_source_id: 1, |
| 125 |
name: "Source 1", |
| 126 |
can_be_edited: false, |
| 127 |
}, |
| 128 |
}); |
| 129 |
cy.visit("/cgi-bin/koha/admin/record_sources/1"); |
| 130 |
cy.get("#name").should("have.value", "Source 1"); |
| 131 |
cy.get("#can_be_edited").should("not.be.checked"); |
| 132 |
|
| 133 |
// Submit the form, get 500 |
| 134 |
cy.intercept("PUT", "/api/v1/record_sources/1", { |
| 135 |
statusCode: 201, |
| 136 |
body: { |
| 137 |
record_source_id: 1, |
| 138 |
name: "Poop", |
| 139 |
can_be_edited: false, |
| 140 |
}, |
| 141 |
}); |
| 142 |
cy.get("#record_source_edit").contains("Submit").click(); |
| 143 |
}); |
| 144 |
|
| 145 |
it("Delete", () => { |
| 146 |
cy.intercept("GET", "/api/v1/record_sources*", { |
| 147 |
statusCode: 200, |
| 148 |
body: [ |
| 149 |
{ record_source_id: 1, name: "Source 1", can_be_edited: true }, |
| 150 |
{ record_source_id: 2, name: "Source 2", can_be_edited: false }, |
| 151 |
{ record_source_id: 3, name: "Source 3", can_be_edited: true }, |
| 152 |
], |
| 153 |
headers: { |
| 154 |
"X-Base-Total-Count": "3", |
| 155 |
"X-Total-Count": "3", |
| 156 |
}, |
| 157 |
}); |
| 158 |
cy.visit("/cgi-bin/koha/admin/record_sources"); |
| 159 |
cy.intercept("DELETE", "/api/v1/record_sources/2", { |
| 160 |
statusCode: 204, |
| 161 |
body: {}, |
| 162 |
}); |
| 163 |
cy.get("#record_sources_list table tbody tr:nth-child(2n+2)") |
| 164 |
.contains("Delete") |
| 165 |
.click(); |
| 166 |
cy.get(".dialog.alert.confirmation h1").contains( |
| 167 |
"Are you sure you want to remove this record source?" |
| 168 |
); |
| 169 |
cy.contains("Source 2"); |
| 170 |
cy.contains("No, do not remove").click(); |
| 171 |
|
| 172 |
cy.get("#record_sources_list table tbody tr:nth-child(2n+2)") |
| 173 |
.contains("Delete") |
| 174 |
.click(); |
| 175 |
cy.contains("Source 2"); |
| 176 |
cy.contains("Yes, remove").click(); |
| 177 |
cy.get("main div[class='dialog message']").contains( |
| 178 |
"Record source 'Source 2' removed" |
| 179 |
); |
| 180 |
}); |
| 181 |
}); |