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

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

Return to bug 41247