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

(-)a/t/cypress/integration/ILL/Batches_spec.ts (-1 / +264 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
describe("ILL Batches", () => {
128
    let original_plugin_restricted;
129
    let kohaconf = "/etc/koha/sites/kohadev/koha-conf.xml";
130
    beforeEach(() => {
131
        cy.login();
132
        cy.task("query", {
133
            sql: "SELECT value FROM systempreferences WHERE variable='ILLModule'",
134
        }).then(rows => {
135
            cy.wrap(rows[0].value).as("syspref_ILLModule");
136
        });
137
        cy.set_syspref("ILLModule", 1);
138
        cy.task("readXmlElementValue", {
139
            filePath: kohaconf,
140
            element: "plugins_restricted",
141
        }).then(value => {
142
            original_plugin_restricted = value;
143
            if (value == "1") {
144
                cy.task("modifyXmlElement", {
145
                    filePath: kohaconf,
146
                    element: "plugins_restricted",
147
                    value: "0",
148
                });
149
            }
150
        });
151
        cy.title().should("eq", "Koha staff interface");
152
        cy.get("a.icon_administration").contains("Koha administration").click();
153
        cy.get("a").contains("Manage plugins").click();
154
        cy.get("a#upload_plugin").contains("Upload plugin").click();
155
156
        cy.get("#uploadfile").click();
157
        cy.get("#uploadfile").selectFile(
158
            "t/cypress/fixtures/koha-plugin-ill-metadata-enrichment.kpz"
159
        );
160
        cy.get("input").contains("Upload").click();
161
    });
162
    afterEach(function () {
163
        //Restore ILLModule sys pref original value
164
        cy.set_syspref("ILLModule", this.syspref_ILLModule);
165
        //Restore plugins_restricted original value
166
        cy.task("modifyXmlElement", {
167
            filePath: kohaconf,
168
            element: "plugins_restricted",
169
            value: original_plugin_restricted,
170
        });
171
        //Clean-up created test batches
172
        cy.task("query", {
173
            sql: "DELETE from illbatches",
174
        });
175
        //Clean-up installed plugin(s)
176
        cy.task("query", {
177
            sql: "DELETE from plugin_data",
178
        });
179
        cy.task("query", {
180
            sql: "DELETE from plugin_methods",
181
        });
182
    });
183
    it("ILL requests batch modal", function () {
184
        cy.visit("/cgi-bin/koha/mainpage.pl");
185
        cy.get("a.icon_ill").contains("ILL requests");
186
        cy.get("a.icon_ill").click();
187
188
        // Open batch modal
189
        cy.get("#ill-batch-backend-dropdown")
190
            .contains("New ILL requests batch")
191
            .click();
192
        cy.get(".dropdown-menu.show a").contains("Standard").click();
193
        cy.get("#ill-batch-modal").should("be.visible");
194
        cy.get("#ill-batch-modal #button_create_batch")
195
            .should("exist")
196
            .and("be.disabled");
197
198
        // Create batch
199
        cy.get("#ill-batch-modal #name").type("test batch");
200
        cy.get("#ill-batch-modal #batchcardnumber").type("42");
201
        cy.get("#ill-batch-modal #branchcode").select("Centerville");
202
        cy.get("#ill-batch-modal #button_create_batch")
203
            .should("exist")
204
            .and("not.be.disabled");
205
        cy.get("#ill-batch-modal #button_create_batch").click();
206
        cy.get("#ill-batch-modal #add_batch_items").should("be.visible");
207
208
        // Close modal
209
        cy.get("#ill-batch-modal #button_cancel_batch").click();
210
        cy.get("#ill-batch-modal").should("not.be.visible");
211
212
        // Reopen modal, button_create_batch must exist and be disabled
213
        cy.get("#ill-batch-backend-dropdown")
214
            .contains("New ILL requests batch")
215
            .click();
216
        cy.get(".dropdown-menu.show a").contains("Standard").click();
217
        cy.get("#ill-batch-modal #button_create_batch")
218
            .should("exist")
219
            .and("be.disabled");
220
221
        // Create a new batch
222
        cy.get("#ill-batch-modal #name").type("second test batch");
223
        cy.get("#ill-batch-modal #batchcardnumber").type("42");
224
        cy.get("#ill-batch-modal #branchcode").select("Centerville");
225
        cy.get("#ill-batch-modal #button_create_batch")
226
            .should("exist")
227
            .and("not.be.disabled");
228
        cy.get("#ill-batch-modal #button_create_batch").click();
229
        cy.get("#ill-batch-modal #add_batch_items").should("be.visible");
230
231
        // Add identifiers + Mock plugin (pubmedid) API responses
232
        let pubmedid = "123";
233
        cy.intercept(
234
            "GET",
235
            "/api/v1/contrib/pubmed/esummary?pmid=" + pubmedid,
236
            {
237
                statusCode: 200,
238
                body: pubmedid_metadata_response,
239
            }
240
        ).as("get-pubmedid-metadata");
241
        cy.intercept("POST", "/api/v1/contrib/pubmed/parse_to_ill", {
242
            statusCode: 200,
243
            body: parse_to_ill_response,
244
        }).as("get-parse_to_ill");
245
        cy.get("#ill-batch-modal #identifiers_input").type(pubmedid);
246
        cy.get("#ill-batch-modal #process-button")
247
            .contains("Process identifiers")
248
            .click();
249
        cy.wait("@get-pubmedid-metadata");
250
        cy.wait("@get-parse_to_ill");
251
        cy.get("#ill-batch-modal #create-requests-button").should("exist");
252
253
        // Close modal
254
        cy.get("#ill-batch-modal #button_cancel_batch").click();
255
        cy.get("#ill-batch-modal").should("not.be.visible");
256
257
        // Reopen modal, #identifier-table_wrapper must not be visible
258
        cy.get("#ill-batch-backend-dropdown")
259
            .contains("New ILL requests batch")
260
            .click();
261
        cy.get(".dropdown-menu.show a").contains("Standard").click();
262
        cy.get("#identifier-table_wrapper").should("not.be.visible");
263
    });
264
});

Return to bug 41247