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

(-)a/t/cypress/integration/Patron/Format.ts (-1 / +118 lines)
Line 0 Link Here
0
- 
1
describe("Display patron - search", () => {
2
    beforeEach(() => {
3
        cy.login();
4
        cy.title().should("eq", "Koha staff interface");
5
    });
6
7
    const table_id = "memberresultst";
8
9
    it("should display all patron info", function () {
10
        cy.task("buildSampleObjects", {
11
            object: "patron",
12
            count: 2,
13
            values: {},
14
        }).then(patrons => {
15
            // Needs more properties to not explode
16
            // account_balace: balance_str.escapeHtml(...).format_price is not a function
17
            patrons = patrons.map(p => ({ ...p, account_balance: 0 }));
18
19
            cy.intercept("GET", "/api/v1/patrons*", {
20
                statusCode: 200,
21
                body: patrons,
22
                headers: {
23
                    "X-Base-Total-Count": "2",
24
                    "X-Total-Count": "2",
25
                },
26
            });
27
28
            cy.visit("/cgi-bin/koha/members/members-home.pl");
29
30
            cy.window().then(win => {
31
                win.categories_map = patrons.reduce((map, p) => {
32
                    map[p.category_id.toLowerCase()] = p.category_id;
33
                    return map;
34
                }, {});
35
            });
36
37
            cy.get("form.patron_search_form input[type='submit']").click();
38
39
            const patron = patrons[0];
40
            // invert_name is set
41
            cy.get(`#${table_id} tbody tr:eq(0) td:eq(2)`).should($el => {
42
                let re = new RegExp(
43
                    `${patron.surname}, ${patron.preferred_name} ${patron.middle_name} \\(${patron.other_name}\\)`
44
                );
45
                const displayedText = $el.text().replace(/ /g, " ").trim();
46
                expect(displayedText).to.match(re);
47
                re = new RegExp(patron.cardnumber);
48
                expect(displayedText).to.not.match(re);
49
            });
50
        });
51
    });
52
});
53
54
describe("Display patron - autocomplete", () => {
55
    beforeEach(() => {
56
        cy.login();
57
        cy.title().should("eq", "Koha staff interface");
58
    });
59
60
    it("should display all patron info", function () {
61
        cy.task("buildSampleObjects", {
62
            object: "patron",
63
            count: 1,
64
            values: {},
65
        }).then(patrons => {
66
            cy.intercept("GET", "/api/v1/patrons*", {
67
                statusCode: 200,
68
                body: patrons,
69
                headers: {
70
                    "X-Base-Total-Count": "1",
71
                    "X-Total-Count": "1",
72
                },
73
            });
74
75
            cy.visit("/cgi-bin/koha/mainpage.pl");
76
77
            const patron = patrons[0];
78
            cy.get("#findborrower").type(patron.surname);
79
80
            // invert_name is set
81
            cy.get(`ul.ui-autocomplete li a`).should($el => {
82
                let re = new RegExp(
83
                    `${patron.surname}, ${patron.preferred_name} ${patron.middle_name} \\(${patron.other_name}\\) \\(${patron.cardnumber}\\)`
84
                );
85
                const displayedText = $el.text().replace(/ /g, " ").trim();
86
                expect(displayedText).to.match(re);
87
            });
88
        });
89
    });
90
});
91
92
describe("Display patron - no search", () => {
93
    beforeEach(() => {
94
        cy.login();
95
        cy.title().should("eq", "Koha staff interface");
96
        cy.task("insertSamplePatron").then(objects_patron => {
97
            cy.wrap(objects_patron).as("objects_patron");
98
        });
99
    });
100
101
    afterEach(function () {
102
        cy.task("deleteSampleObjects", this.objects_patron);
103
    });
104
105
    it("should display all patron info", function () {
106
        const patron = this.objects_patron.patron;
107
        cy.visit(
108
            `/cgi-bin/koha/members/moremember.pl?borrowernumber=${patron.patron_id}`
109
        );
110
        cy.get(".row .col-sm-12 h1").should($el => {
111
            const re = new RegExp(
112
                `${patron.title} ${patron.preferred_name} ${patron.middle_name} \\(${patron.other_name}\\) ${patron.surname} \\(${patron.cardnumber}\\)`
113
            );
114
            const displayedText = $el.text().replace(/ /g, " ").trim();
115
            expect(displayedText).to.match(re);
116
        });
117
    });
118
});

Return to bug 41003