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

(-)a/t/cypress/integration/ERM/Agreements_spec.ts (-107 / +7 lines)
Lines 8-113 const dates = { Link Here
8
    tomorrow_iso: dayjs().add(1, "day").format("YYYY-MM-DD"),
8
    tomorrow_iso: dayjs().add(1, "day").format("YYYY-MM-DD"),
9
    tomorrow_us: dayjs().add(1, "day").format("MM/DD/YYYY"),
9
    tomorrow_us: dayjs().add(1, "day").format("MM/DD/YYYY"),
10
};
10
};
11
function get_agreement() {
12
    let licenses = get_licenses_to_relate();
13
    return {
14
        agreement_id: 1,
15
        closure_reason: "",
16
        description: "my first agreement",
17
        is_perpetual: false,
18
        license_info: "",
19
        name: "agreement 1",
20
        renewal_priority: "",
21
        status: "active",
22
        vendor_id: 1,
23
        vendor: [cy.get_vendors_to_relate()[0]],
24
        periods: [
25
            {
26
                started_on: dates["today_iso"],
27
                ended_on: dates["tomorrow_iso"],
28
                cancellation_deadline: null,
29
                notes: null,
30
            },
31
            {
32
                started_on: dates["today_iso"],
33
                ended_on: null,
34
                cancellation_deadline: dates["tomorrow_iso"],
35
                notes: "this is a note",
36
            },
37
        ],
38
        user_roles: [],
39
        agreement_licenses: [
40
            {
41
                agreement_id: 1,
42
                agreement_license_id: 3,
43
                license: licenses[0],
44
                license_id: licenses[0].license_id,
45
                notes: "license notes",
46
                physical_location: "cupboard",
47
                status: "controlling",
48
                uri: "license uri",
49
            },
50
            {
51
                agreement_id: 1,
52
                agreement_license_id: 4,
53
                license: licenses[1],
54
                license_id: licenses[1].license_id,
55
                notes: "second license notes",
56
                physical_location: "cupboard",
57
                status: "future",
58
                uri: "license uri",
59
            },
60
        ],
61
        agreement_relationships: [
62
            {
63
                agreement_id: 1,
64
                notes: "related agreement notes",
65
                related_agreement: {
66
                    agreement_id: 2,
67
                    description: "agreement description",
68
                    name: "agreement name",
69
                },
70
                related_agreement_id: 2,
71
                relationship: "supersedes",
72
            },
73
        ],
74
        agreement_packages: [],
75
        documents: [
76
            {
77
                agreement_id: 1,
78
                file_description: "file description",
79
                file_name: "file.json",
80
                notes: "file notes",
81
                physical_location: "file physical location",
82
                uri: "file uri",
83
                uploaded_on: "2022-10-27T11:57:02+00:00",
84
            },
85
        ],
86
    };
87
}
88
89
function get_licenses_to_relate() {
90
    return [
91
        {
92
            license_id: 1,
93
            description: "license description",
94
            license_id: 1,
95
            name: "first license name",
96
            status: "expired",
97
            type: "alliance",
98
        },
99
        {
100
            license_id: 2,
101
            description: "a second license",
102
            name: "second license name",
103
        },
104
        {
105
            license_id: 3,
106
            description: "a third license",
107
            name: "third license name",
108
        },
109
    ];
110
}
111
11
112
describe("Agreement CRUD operations", () => {
12
describe("Agreement CRUD operations", () => {
113
    beforeEach(() => {
13
    beforeEach(() => {
Lines 137-143 describe("Agreement CRUD operations", () => { Link Here
137
        cy.get("#agreements_list").contains("There are no agreements defined");
37
        cy.get("#agreements_list").contains("There are no agreements defined");
138
38
139
        // GET agreements returns something
39
        // GET agreements returns something
140
        let agreement = get_agreement();
40
        let agreement = cy.get_agreement();
141
        let agreements = [agreement];
41
        let agreements = [agreement];
142
42
143
        cy.intercept("GET", "/api/v1/erm/agreements*", {
43
        cy.intercept("GET", "/api/v1/erm/agreements*", {
Lines 233-239 describe("Agreement CRUD operations", () => { Link Here
233
    });
133
    });
234
134
235
    it("Add agreement", () => {
135
    it("Add agreement", () => {
236
        let agreement = get_agreement();
136
        let agreement = cy.get_agreement();
237
        let vendors = cy.get_vendors_to_relate();
137
        let vendors = cy.get_vendors_to_relate();
238
        // No agreement, no license yet
138
        // No agreement, no license yet
239
        cy.intercept("GET", "/api/v1/erm/agreements*", {
139
        cy.intercept("GET", "/api/v1/erm/agreements*", {
Lines 399-405 describe("Agreement CRUD operations", () => { Link Here
399
        });
299
        });
400
300
401
        // Add new license
301
        // Add new license
402
        let licenses_to_relate = get_licenses_to_relate();
302
        let licenses_to_relate = cy.get_licenses_to_relate();
403
        let related_license = agreement.agreement_licenses[0];
303
        let related_license = agreement.agreement_licenses[0];
404
        let licenses_count = licenses_to_relate.length.toString();
304
        let licenses_count = licenses_to_relate.length.toString();
405
        cy.intercept("GET", "/api/v1/erm/licenses*", {
305
        cy.intercept("GET", "/api/v1/erm/licenses*", {
Lines 460-467 describe("Agreement CRUD operations", () => { Link Here
460
    });
360
    });
461
361
462
    it("Edit agreement", () => {
362
    it("Edit agreement", () => {
463
        let licenses_to_relate = get_licenses_to_relate();
363
        let licenses_to_relate = cy.get_licenses_to_relate();
464
        let agreement = get_agreement();
364
        let agreement = cy.get_agreement();
465
        let agreements = [agreement];
365
        let agreements = [agreement];
466
        let vendors = cy.get_vendors_to_relate();
366
        let vendors = cy.get_vendors_to_relate();
467
367
Lines 599-605 describe("Agreement CRUD operations", () => { Link Here
599
    });
499
    });
600
500
601
    it("Show agreement", () => {
501
    it("Show agreement", () => {
602
        let agreement = get_agreement();
502
        let agreement = cy.get_agreement();
603
        let agreements = [agreement];
503
        let agreements = [agreement];
604
        // Click the "name" link from the list
504
        // Click the "name" link from the list
605
        cy.intercept("GET", "/api/v1/erm/agreements*", {
505
        cy.intercept("GET", "/api/v1/erm/agreements*", {
Lines 636-642 describe("Agreement CRUD operations", () => { Link Here
636
        // Tables for periods and users
536
        // Tables for periods and users
637
    });
537
    });
638
    it("Delete agreement", () => {
538
    it("Delete agreement", () => {
639
        let agreement = get_agreement();
539
        let agreement = cy.get_agreement();
640
        let agreements = [agreement];
540
        let agreements = [agreement];
641
541
642
        // Delete from list
542
        // Delete from list
(-)a/t/cypress/integration/InfiniteScrollSelect_spec.ts (+328 lines)
Line 0 Link Here
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
const dates = {
6
    today_iso: dayjs().format("YYYY-MM-DD"),
7
    today_us: dayjs().format("MM/DD/YYYY"),
8
    tomorrow_iso: dayjs().add(1, "day").format("YYYY-MM-DD"),
9
    tomorrow_us: dayjs().add(1, "day").format("MM/DD/YYYY"),
10
};
11
12
const createLicenses = start => {
13
    const licenses = [];
14
    for (let i = start; i < start + 20; i++) {
15
        const newLicense = {
16
            license_id: i,
17
            name: "License " + i,
18
            description: "A test license",
19
            type: "local",
20
            status: "active",
21
            started_on: dates["today_iso"],
22
            ended_on: dates["tomorrow_iso"],
23
            user_roles: [],
24
        };
25
        licenses.push(newLicense);
26
    }
27
    return licenses;
28
};
29
30
describe("Infinite scroll", () => {
31
    beforeEach(() => {
32
        cy.login();
33
        cy.title().should("eq", "Koha staff interface");
34
        cy.intercept(
35
            "GET",
36
            "/api/v1/erm/config",
37
            '{"settings":{"ERMModule":"1","ERMProviders":["local"]}}'
38
        );
39
    });
40
41
    it("Should load the next page on scroll", () => {
42
        const pageOne = createLicenses(1);
43
        const pageTwo = createLicenses(21);
44
        const pageThree = createLicenses(41);
45
        const agreement = cy.get_agreement();
46
        const vendors = cy.get_vendors_to_relate();
47
48
        // No agreement, no license yet
49
        cy.intercept("GET", "/api/v1/erm/agreements*", {
50
            statusCode: 200,
51
            body: [],
52
        });
53
        cy.intercept("GET", "/api/v1/erm/licenses*", {
54
            statusCode: 200,
55
            body: [],
56
        });
57
        //Intercept vendors request
58
        cy.intercept("GET", "/api/v1/acquisitions/vendors*", {
59
            statusCode: 200,
60
            body: vendors,
61
        });
62
        cy.intercept("GET", "/api/v1/erm/licenses*", {
63
            statusCode: 200,
64
            body: pageOne,
65
            headers: {
66
                "X-Base-Total-Count": "20",
67
                "X-Total-Count": "20",
68
            },
69
        });
70
71
        // Click the button in the toolbar
72
        cy.visit("/cgi-bin/koha/erm/agreements");
73
        cy.contains("New agreement").click();
74
75
        cy.get("#agreement_licenses").contains("Add new license").click();
76
        cy.get("#license_id_0 .vs__open-indicator").click();
77
        cy.get("#license_id_0").find("li").as("options");
78
        cy.get("@options").should("have.length", 20);
79
80
        cy.intercept("GET", "/api/v1/erm/licenses*", {
81
            statusCode: 200,
82
            body: pageTwo,
83
            headers: {
84
                "X-Base-Total-Count": "20",
85
                "X-Total-Count": "20",
86
            },
87
        });
88
        // Scroll the dropdown
89
        cy.get(".vs__dropdown-menu").scrollTo("bottom");
90
        cy.get("@options").should("have.length", 40);
91
92
        cy.intercept("GET", "/api/v1/erm/licenses*", {
93
            statusCode: 200,
94
            body: pageThree,
95
            headers: {
96
                "X-Base-Total-Count": "20",
97
                "X-Total-Count": "20",
98
            },
99
        });
100
        // Scroll the dropdown again
101
        cy.get(".vs__dropdown-menu").scrollTo("bottom");
102
        cy.get("@options").should("have.length", 60);
103
    });
104
105
    it("Should correctly submit the form", () => {
106
        const pageOne = createLicenses(1);
107
        const vendors = cy.get_vendors_to_relate();
108
        let agreement = cy.get_agreement();
109
110
        // No agreement, no license yet
111
        cy.intercept("GET", "/api/v1/erm/agreements*", {
112
            statusCode: 200,
113
            body: [],
114
        });
115
        cy.intercept("GET", "/api/v1/erm/licenses*", {
116
            statusCode: 200,
117
            body: [],
118
        });
119
        //Intercept vendors request
120
        cy.intercept("GET", "/api/v1/acquisitions/vendors*", {
121
            statusCode: 200,
122
            body: vendors,
123
        });
124
        cy.intercept("GET", "/api/v1/erm/licenses*", {
125
            statusCode: 200,
126
            body: pageOne,
127
            headers: {
128
                "X-Base-Total-Count": "20",
129
                "X-Total-Count": "20",
130
            },
131
        });
132
133
        // Click the button in the toolbar
134
        cy.visit("/cgi-bin/koha/erm/agreements");
135
        cy.contains("New agreement").click();
136
137
        cy.get("#agreement_licenses").contains("Add new license").click();
138
        cy.get("#license_id_0 .vs__open-indicator").click();
139
140
        cy.get("#agreement_license_0 #license_id_0 .vs__dropdown-menu li")
141
            .eq(0)
142
            .click({ force: true }); //click first license suggestion
143
144
        // Fill in the other required fields
145
        cy.get("#agreement_name").type(agreement.name);
146
        cy.get("#agreement_status .vs__search").type(
147
            agreement.status + "{enter}",
148
            { force: true }
149
        );
150
        cy.get("#agreement_license_0 #license_status_0 .vs__search").type(
151
            agreement.agreement_licenses[0].status + "{enter}",
152
            { force: true }
153
        );
154
155
        cy.intercept("POST", "/api/v1/erm/agreements", {
156
            statusCode: 201,
157
            body: agreement,
158
        });
159
        // Submit the form, no error should be thrown as the select has correctly set the license id
160
        cy.get("#agreements_add").contains("Submit").click();
161
        cy.get("main div[class='dialog message']").contains(
162
            "Agreement created"
163
        );
164
    });
165
166
    it("Should correctly display labels", () => {
167
        const pageOne = createLicenses(1);
168
        const pageTwo = createLicenses(21);
169
        const pageThree = createLicenses(41);
170
        const vendors = cy.get_vendors_to_relate();
171
172
        // No agreement, no license yet
173
        cy.intercept("GET", "/api/v1/erm/agreements*", {
174
            statusCode: 200,
175
            body: [],
176
        });
177
        cy.intercept("GET", "/api/v1/erm/licenses*", {
178
            statusCode: 200,
179
            body: [],
180
        });
181
        //Intercept vendors request
182
        cy.intercept("GET", "/api/v1/acquisitions/vendors*", {
183
            statusCode: 200,
184
            body: vendors,
185
        });
186
        cy.intercept("GET", "/api/v1/erm/licenses*", {
187
            statusCode: 200,
188
            body: pageOne,
189
            headers: {
190
                "X-Base-Total-Count": "20",
191
                "X-Total-Count": "20",
192
            },
193
        });
194
195
        // Click the button in the toolbar
196
        cy.visit("/cgi-bin/koha/erm/agreements");
197
        cy.contains("New agreement").click();
198
199
        cy.get("#agreement_licenses").contains("Add new license").click();
200
        cy.get("#license_id_0 .vs__open-indicator").click();
201
        cy.get("#license_id_0").find("li").as("options");
202
        cy.get("@options").should("have.length", 20);
203
204
        cy.intercept("GET", "/api/v1/erm/licenses*", {
205
            statusCode: 200,
206
            body: pageTwo,
207
            headers: {
208
                "X-Base-Total-Count": "20",
209
                "X-Total-Count": "20",
210
            },
211
        });
212
        // Scroll the dropdown
213
        cy.get(".vs__dropdown-menu").scrollTo("bottom");
214
215
        cy.intercept("GET", "/api/v1/erm/licenses*", {
216
            statusCode: 200,
217
            body: pageThree,
218
            headers: {
219
                "X-Base-Total-Count": "20",
220
                "X-Total-Count": "20",
221
            },
222
        }).as("finalPage");
223
        // Scroll the dropdown again
224
        cy.get(".vs__dropdown-menu").scrollTo("bottom");
225
        cy.wait("@finalPage");
226
227
        // Select a  license that is not in the first page of results
228
        cy.get("#agreement_license_0 #license_id_0 .vs__search").type(
229
            "License 50{enter}",
230
            { force: true }
231
        );
232
        cy.get("#agreement_license_0").contains("License 50");
233
234
        // Re-open the dropdown, License 50 will no longer be in the dataset but the label should still show
235
        cy.intercept("GET", "/api/v1/erm/licenses*", {
236
            statusCode: 200,
237
            body: pageOne,
238
            headers: {
239
                "X-Base-Total-Count": "20",
240
                "X-Total-Count": "20",
241
            },
242
        });
243
        cy.get("#license_id_0 .vs__open-indicator").click();
244
        cy.get("#agreement_licenses").click();
245
        cy.get("#agreement_license_0").contains("License 50");
246
247
        // Select a different license
248
        cy.get("#license_id_0 .vs__open-indicator").click();
249
        cy.get("#agreement_license_0 #license_id_0 .vs__search").type(
250
            "License 10{enter}",
251
            { force: true }
252
        );
253
        cy.get("#agreement_license_0").contains("License 10");
254
    });
255
256
    it("Should correctly display the label when editing", () => {
257
        let agreement = cy.get_agreement();
258
        let agreements = [agreement];
259
        let licenses_to_relate = cy.get_licenses_to_relate();
260
        let vendors = cy.get_vendors_to_relate();
261
262
        // Intercept vendors request
263
        cy.intercept("GET", "/api/v1/acquisitions/vendors*", {
264
            statusCode: 200,
265
            body: vendors,
266
        }).as("get-vendor-options");
267
268
        // Intercept initial /agreements request once
269
        cy.intercept(
270
            {
271
                method: "GET",
272
                url: "/api/v1/erm/agreements*",
273
                times: 1,
274
            },
275
            {
276
                body: agreements,
277
            }
278
        );
279
        // Intercept follow-up 'search' request after entering /agreements
280
        cy.intercept("GET", "/api/v1/erm/agreements?_page*", {
281
            statusCode: 200,
282
            body: agreements,
283
            headers: {
284
                "X-Base-Total-Count": "1",
285
                "X-Total-Count": "1",
286
            },
287
        }).as("get-single-agreement-search-result");
288
        cy.visit("/cgi-bin/koha/erm/agreements");
289
        cy.wait("@get-single-agreement-search-result");
290
291
        // Intercept request after edit click
292
        cy.intercept("GET", "/api/v1/erm/agreements/*", agreement).as(
293
            "get-agreement"
294
        );
295
296
        // Intercept related licenses request after entering agreement edit
297
        let licenses_count = licenses_to_relate.length.toString();
298
        cy.intercept("GET", "/api/v1/erm/licenses*", {
299
            statusCode: 200,
300
            body: licenses_to_relate,
301
            headers: {
302
                "X-Base-Total-Count": licenses_count,
303
                "X-Total-Count": licenses_count,
304
            },
305
        }).as("get-related-licenses");
306
307
        // Intercept related agreements request after entering agreement edit
308
        cy.intercept("GET", "/api/v1/erm/agreements*", {
309
            statusCode: 200,
310
            body: cy.get_agreements_to_relate(),
311
        }).as("get-related-agreements");
312
313
        // Click the 'Edit' button from the list
314
        cy.get("#agreements_list table tbody tr:first")
315
            .contains("Edit")
316
            .click();
317
        cy.wait("@get-agreement");
318
        cy.wait(500); // Cypress is too fast! Vue hasn't populated the form yet!
319
320
        // Licenses should be labelled correctly
321
        cy.get("#agreement_license_0 #license_id_0 .vs__selected").contains(
322
            "first license name"
323
        );
324
        cy.get("#agreement_license_1 #license_id_1 .vs__selected").contains(
325
            "second license name"
326
        );
327
    });
328
});
(-)a/t/cypress/support/e2e.js (-1 / +101 lines)
Lines 53-58 const dates = { Link Here
53
    tomorrow_us: dayjs().add(1, "day").format("MM/DD/YYYY"),
53
    tomorrow_us: dayjs().add(1, "day").format("MM/DD/YYYY"),
54
}
54
}
55
55
56
cy.get_agreement = () => {
57
    let licenses = cy.get_licenses_to_relate();
58
    return {
59
        agreement_id: 1,
60
        closure_reason: "",
61
        description: "my first agreement",
62
        is_perpetual: false,
63
        license_info: "",
64
        name: "agreement 1",
65
        renewal_priority: "",
66
        status: "active",
67
        vendor_id: 1,
68
        vendor: [cy.get_vendors_to_relate()[0]],
69
        periods: [
70
            {
71
                started_on: dates["today_iso"],
72
                ended_on: dates["tomorrow_iso"],
73
                cancellation_deadline: null,
74
                notes: null,
75
            },
76
            {
77
                started_on: dates["today_iso"],
78
                ended_on: null,
79
                cancellation_deadline: dates["tomorrow_iso"],
80
                notes: "this is a note",
81
            },
82
        ],
83
        user_roles: [],
84
        agreement_licenses: [
85
            {
86
                agreement_id: 1,
87
                agreement_license_id: 3,
88
                license: licenses[0],
89
                license_id: licenses[0].license_id,
90
                notes: "license notes",
91
                physical_location: "cupboard",
92
                status: "controlling",
93
                uri: "license uri",
94
            },
95
            {
96
                agreement_id: 1,
97
                agreement_license_id: 4,
98
                license: licenses[1],
99
                license_id: licenses[1].license_id,
100
                notes: "second license notes",
101
                physical_location: "cupboard",
102
                status: "future",
103
                uri: "license uri",
104
            },
105
        ],
106
        agreement_relationships: [
107
            {
108
                agreement_id: 1,
109
                notes: "related agreement notes",
110
                related_agreement: {
111
                    agreement_id: 2,
112
                    description: "agreement description",
113
                    name: "agreement name",
114
                },
115
                related_agreement_id: 2,
116
                relationship: "supersedes",
117
            },
118
        ],
119
        agreement_packages: [],
120
        documents: [
121
            {
122
                agreement_id: 1,
123
                file_description: "file description",
124
                file_name: "file.json",
125
                notes: "file notes",
126
                physical_location: "file physical location",
127
                uri: "file uri",
128
                uploaded_on: "2022-10-27T11:57:02+00:00",
129
            },
130
        ],
131
    };
132
}
133
134
cy.get_licenses_to_relate = () => {
135
    return [
136
        {
137
            license_id: 1,
138
            description: "license description",
139
            license_id: 1,
140
            name: "first license name",
141
            status: "expired",
142
            type: "alliance",
143
        },
144
        {
145
            license_id: 2,
146
            description: "a second license",
147
            name: "second license name",
148
        },
149
        {
150
            license_id: 3,
151
            description: "a third license",
152
            name: "third license name",
153
        },
154
    ];
155
}
156
56
cy.get_title = () => {
157
cy.get_title = () => {
57
    return {
158
    return {
58
        access_type: "access type",
159
        access_type: "access type",
59
- 

Return to bug 32474