View | Details | Raw Unified | Return to bug 35919
Collapse All | Expand All

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

Return to bug 35919