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

(-)a/t/cypress/integration/ILL/Batches_spec.ts (-1 / +298 lines)
Line 0 Link Here
0
- 
1
const pubmedid_metadata_response = {
2
    errors: [],
3
    results: {
4
        result: {
5
            header: {
6
                type: "esummary",
7
                version: "0.3",
8
            },
9
            result: {
10
                "123": {
11
                    articleids: [
12
                        {
13
                            idtype: "pubmed",
14
                            idtypen: 1,
15
                            value: "123",
16
                        },
17
                        {
18
                            idtype: "doi",
19
                            idtypen: 3,
20
                            value: "10.1002\/bjs.1800621024",
21
                        },
22
                    ],
23
                    attributes: ["Has Abstract"],
24
                    authors: [
25
                        {
26
                            authtype: "Author",
27
                            clusterid: "",
28
                            name: "Keighley MR",
29
                        },
30
                        {
31
                            authtype: "Author",
32
                            clusterid: "",
33
                            name: "Asquith P",
34
                        },
35
                        {
36
                            authtype: "Author",
37
                            clusterid: "",
38
                            name: "Edwards JA",
39
                        },
40
                        {
41
                            authtype: "Author",
42
                            clusterid: "",
43
                            name: "Alexander-Williams J",
44
                        },
45
                    ],
46
                    availablefromurl: "",
47
                    bookname: "",
48
                    booktitle: "",
49
                    chapter: "",
50
                    doccontriblist: [],
51
                    docdate: "",
52
                    doctype: "citation",
53
                    edition: "",
54
                    elocationid: "",
55
                    epubdate: "",
56
                    essn: "",
57
                    fulljournalname: "The British journal of surgery",
58
                    history: [
59
                        {
60
                            date: "1975\/10\/01 00:00",
61
                            pubstatus: "pubmed",
62
                        },
63
                        {
64
                            date: "1975\/10\/01 00:01",
65
                            pubstatus: "medline",
66
                        },
67
                        {
68
                            date: "1975\/10\/01 00:00",
69
                            pubstatus: "entrez",
70
                        },
71
                    ],
72
                    issn: "0007-1323",
73
                    issue: "10",
74
                    lang: ["eng"],
75
                    lastauthor: "Alexander-Williams J",
76
                    locationlabel: "",
77
                    medium: "",
78
                    nlmuniqueid: "0372553",
79
                    pages: "845-9",
80
                    pmcrefcount: "",
81
                    pubdate: "1975 Oct",
82
                    publisherlocation: "",
83
                    publishername: "",
84
                    pubstatus: "4",
85
                    pubtype: ["Journal Article"],
86
                    recordstatus: "PubMed - indexed for MEDLINE",
87
                    references: [],
88
                    reportnumber: "",
89
                    sortfirstauthor: "Keighley MR",
90
                    sortpubdate: "1975\/10\/01 00:00",
91
                    sorttitle:
92
                        "importance of an innervated and intact antrum and pylorus in preventing postoperative duodenogastric reflux and gastritis",
93
                    source: "Br J Surg",
94
                    srccontriblist: [],
95
                    srcdate: "",
96
                    title: "The importance of an innervated and intact antrum and pylorus in preventing postoperative duodenogastric reflux and gastritis.",
97
                    uid: "123",
98
                    vernaculartitle: "",
99
                    volume: "62",
100
                },
101
                uids: ["123"],
102
            },
103
        },
104
    },
105
};
106
107
const parse_to_ill_response = {
108
    errors: [],
109
    results: {
110
        result: {
111
            article_title:
112
                "The importance of an innervated and intact antrum and pylorus in preventing postoperative duodenogastric reflux and gastritis.",
113
            associated_id: "123",
114
            author: "Keighley MR; Asquith P; Edwards JA; Alexander-Williams J",
115
            issn: "0007-1323",
116
            issue: "10",
117
            pages: "845-9",
118
            publisher: "",
119
            pubmedid: "123",
120
            title: "The British journal of surgery",
121
            volume: "62",
122
            year: "1975",
123
        },
124
    },
125
};
126
127
const batchstatuses = [
128
  {
129
    "code": "NEW",
130
    "id": 1,
131
    "is_system": true,
132
    "name": "New"
133
  },
134
  {
135
    "code": "IN_PROGRESS",
136
    "id": 2,
137
    "is_system": true,
138
    "name": "In progress"
139
  },
140
  {
141
    "code": "COMPLETED",
142
    "id": 3,
143
    "is_system": true,
144
    "name": "Completed"
145
  },
146
  {
147
    "code": "UNKNOWN",
148
    "id": 4,
149
    "is_system": true,
150
    "name": "Unknown"
151
  }
152
];
153
154
describe("ILL Batches", () => {
155
    let original_plugin_restricted;
156
    let kohaconf = "/etc/koha/sites/kohadev/koha-conf.xml";
157
    beforeEach(() => {
158
        cy.login();
159
        cy.task("query", {
160
            sql: "SELECT value FROM systempreferences WHERE variable='ILLModule'",
161
        }).then(rows => {
162
            cy.wrap(rows[0].value).as("syspref_ILLModule");
163
        });
164
        cy.set_syspref("ILLModule", 1);
165
        cy.task("readXmlElementValue", {
166
            filePath: kohaconf,
167
            element: "plugins_restricted",
168
        }).then(value => {
169
            original_plugin_restricted = value;
170
            if (value == "1") {
171
                cy.task("modifyXmlElement", {
172
                    filePath: kohaconf,
173
                    element: "plugins_restricted",
174
                    value: "0",
175
                });
176
            }
177
        });
178
        cy.title().should("eq", "Koha staff interface");
179
        cy.get("a.icon_administration").contains("Koha administration").click();
180
        cy.get("a").contains("Manage plugins").click();
181
        cy.get("a#upload_plugin").contains("Upload plugin").click();
182
183
        cy.get("#uploadfile").click();
184
        cy.get("#uploadfile").selectFile(
185
            "t/cypress/fixtures/koha-plugin-ill-metadata-enrichment.kpz"
186
        );
187
        cy.get("input").contains("Upload").click();
188
189
        cy.intercept("GET", "/api/v1/ill/batchstatuses", {
190
            statusCode: 200,
191
            body: batchstatuses
192
        }).as("get-batchstatuses");
193
194
    });
195
    afterEach(function () {
196
        //Restore ILLModule sys pref original value
197
        cy.set_syspref("ILLModule", this.syspref_ILLModule);
198
        //Restore plugins_restricted original value
199
        cy.task("modifyXmlElement", {
200
            filePath: kohaconf,
201
            element: "plugins_restricted",
202
            value: original_plugin_restricted,
203
        });
204
        //Clean-up created test batches
205
        cy.task("query", {
206
            sql: "DELETE from illbatches",
207
        });
208
        //Clean-up installed plugin(s)
209
        cy.task("query", {
210
            sql: "DELETE from plugin_data",
211
        });
212
        cy.task("query", {
213
            sql: "DELETE from plugin_methods",
214
        });
215
    });
216
    it("ILL requests batch modal", function () {
217
        cy.visit("/cgi-bin/koha/mainpage.pl");
218
        cy.get("a.icon_ill").contains("ILL requests");
219
        cy.get("a.icon_ill").click();
220
221
        // Open batch modal
222
        cy.get("#ill-batch-backend-dropdown")
223
            .contains("New ILL requests batch")
224
            .click();
225
        cy.get(".dropdown-menu.show a").contains("Standard").click();
226
        cy.wait("@get-batchstatuses");
227
        cy.get("#ill-batch-modal").should("be.visible");
228
        cy.get("#ill-batch-modal #button_create_batch")
229
            .should("exist")
230
            .and("be.disabled");
231
232
        // Create batch
233
        cy.get("#ill-batch-modal #name").type("test batch");
234
        cy.get("#ill-batch-modal #batchcardnumber").type("42");
235
        cy.get("#ill-batch-modal #branchcode").select("Centerville");
236
        cy.get("#ill-batch-modal #button_create_batch")
237
            .should("exist")
238
            .and("not.be.disabled");
239
        cy.get("#ill-batch-modal #button_create_batch").click();
240
        cy.get("#ill-batch-modal #add_batch_items").should("be.visible");
241
242
        // Close modal
243
        cy.get("#ill-batch-modal #button_cancel_batch").click();
244
        cy.get("#ill-batch-modal").should("not.be.visible");
245
246
        // Reopen modal, button_create_batch must exist and be disabled
247
        cy.get("#ill-batch-backend-dropdown")
248
            .contains("New ILL requests batch")
249
            .click();
250
        cy.get(".dropdown-menu.show a").contains("Standard").click();
251
        cy.get("#ill-batch-modal #button_create_batch")
252
            .should("exist")
253
            .and("be.disabled");
254
255
        // Create a new batch
256
        cy.get("#ill-batch-modal #name").type("second test batch");
257
        cy.get("#ill-batch-modal #batchcardnumber").type("42");
258
        cy.get("#ill-batch-modal #branchcode").select("Centerville");
259
        cy.get("#ill-batch-modal #button_create_batch")
260
            .should("exist")
261
            .and("not.be.disabled");
262
        cy.get("#ill-batch-modal #button_create_batch").click();
263
        cy.get("#ill-batch-modal #add_batch_items").should("be.visible");
264
265
        // Add identifiers + Mock plugin (pubmedid) API responses
266
        let pubmedid = "123";
267
        cy.intercept(
268
            "GET",
269
            "/api/v1/contrib/pubmed/esummary?pmid=" + pubmedid,
270
            {
271
                statusCode: 200,
272
                body: pubmedid_metadata_response,
273
            }
274
        ).as("get-pubmedid-metadata");
275
        cy.intercept("POST", "/api/v1/contrib/pubmed/parse_to_ill", {
276
            statusCode: 200,
277
            body: parse_to_ill_response,
278
        }).as("get-parse_to_ill");
279
        cy.get("#ill-batch-modal #identifiers_input").type(pubmedid);
280
        cy.get("#ill-batch-modal #process-button")
281
            .contains("Process identifiers")
282
            .click();
283
        cy.wait("@get-pubmedid-metadata");
284
        cy.wait("@get-parse_to_ill");
285
        cy.get("#ill-batch-modal #create-requests-button").should("exist");
286
287
        // Close modal
288
        cy.get("#ill-batch-modal #button_cancel_batch").click();
289
        cy.get("#ill-batch-modal").should("not.be.visible");
290
291
        // Reopen modal, #identifier-table_wrapper must not be visible
292
        cy.get("#ill-batch-backend-dropdown")
293
            .contains("New ILL requests batch")
294
            .click();
295
        cy.get(".dropdown-menu.show a").contains("Standard").click();
296
        cy.get("#identifier-table_wrapper").should("not.be.visible");
297
    });
298
});

Return to bug 41247