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

(-)a/t/cypress/integration/PatronSearch_spec.ts (+116 lines)
Line 0 Link Here
1
import { mount } from "@cypress/vue";
2
3
const RESTdefaultPageSize = "20"; // FIXME Mock this
4
const baseTotalCount = "42";
5
6
const ExtendedPatronAttributes = 42;
7
8
const patron_attr_type = "attribute_type4TEST";
9
10
function cleanup() {
11
    const sql = "DELETE FROM borrower_attribute_types WHERE code=?";
12
    cy.query(sql, patron_attr_type);
13
}
14
describe("ExtendedPatronAttributes", () => {
15
    beforeEach(() => {
16
        cleanup();
17
        cy.login();
18
        cy.title().should("eq", "Koha staff interface");
19
        cy.window().then(win => {
20
            win.localStorage.clear();
21
        });
22
        cy.query(
23
            "SELECT value FROM systempreferences WHERE variable='ExtendedPatronAttributes'"
24
        ).then(value => {
25
            cy.wrap(value).as("syspref_ExtendedPatronAttributes");
26
        });
27
    });
28
29
    afterEach(
30
        () =>
31
            function () {
32
                cleanup();
33
                cy.set_syspref(
34
                    "ExtendedPatronAttributes",
35
                    this.syspref_ExtendedPatronAttributes
36
                );
37
            }
38
    );
39
40
    const table_id = "memberresultst";
41
42
    it("ExtendedPatronAttributes=0", () => {
43
        cy.intercept("GET", "/api/v1/patrons*").as("searchPatrons");
44
45
        cy.set_syspref("ExtendedPatronAttributes", 0).then(() => {
46
            cy.visit("/cgi-bin/koha/members/members-home.pl");
47
48
            cy.get("#search_patron_filter").type("something");
49
            cy.get("form.patron_search_form input[type='submit']").click();
50
51
            cy.query(
52
                "select count(*) as nb_searchable from borrower_attribute_types where staff_searchable=1"
53
            ).then(result => {
54
                const has_searchable = result[0].nb_searchable;
55
                cy.wait("@searchPatrons").then(interception => {
56
                    const q = interception.request.query.q;
57
                    expect(q).to.not.match(/extended_attributes/);
58
                });
59
            });
60
61
            cy.query(
62
                "INSERT INTO borrower_attribute_types(code, description, staff_searchable, searched_by_default) VALUES (?, 'only for tests', 1, 1)",
63
                patron_attr_type
64
            ).then(() => {
65
                cy.visit("/cgi-bin/koha/members/members-home.pl");
66
67
                cy.get("#search_patron_filter").type("something");
68
                cy.get("form.patron_search_form input[type='submit']").click();
69
70
                cy.wait("@searchPatrons").then(interception => {
71
                    const q = interception.request.query.q;
72
                    expect(q).to.not.match(/extended_attributes/);
73
                });
74
            });
75
        });
76
    });
77
    it("ExtendedPatronAttributes=1", () => {
78
        cy.intercept("GET", "/api/v1/patrons*").as("searchPatrons");
79
80
        cy.set_syspref("ExtendedPatronAttributes", 1).then(() => {
81
            cy.visit("/cgi-bin/koha/members/members-home.pl");
82
83
            cy.get("#search_patron_filter").type("something");
84
            cy.get("form.patron_search_form input[type='submit']").click();
85
86
            cy.query(
87
                "select count(*) as nb_searchable from borrower_attribute_types where staff_searchable=1 AND searched_by_default=1"
88
            ).then(result => {
89
                const has_searchable = result[0].nb_searchable;
90
                cy.wait("@searchPatrons").then(interception => {
91
                    const q = interception.request.query.q;
92
                    if (has_searchable) {
93
                        expect(q).to.match(/extended_attributes/);
94
                    } else {
95
                        expect(q).to.not.match(/extended_attributes/);
96
                    }
97
                });
98
            });
99
100
            cy.query(
101
                "INSERT INTO borrower_attribute_types(code, description, staff_searchable, searched_by_default) VALUES (?, 'only for tests', 1, 1)",
102
                patron_attr_type
103
            ).then(() => {
104
                cy.visit("/cgi-bin/koha/members/members-home.pl");
105
106
                cy.get("#search_patron_filter").type("something");
107
                cy.get("form.patron_search_form input[type='submit']").click();
108
109
                cy.wait("@searchPatrons").then(interception => {
110
                    const q = interception.request.query.q;
111
                    expect(q).to.match(/extended_attributes/);
112
                });
113
            });
114
        });
115
    });
116
});
(-)a/t/cypress/support/e2e.js (-1 / +7 lines)
Lines 1815-1817 cy.getSushiService = () => { Link Here
1815
1815
1816
const mysql = require("cypress-mysql");
1816
const mysql = require("cypress-mysql");
1817
mysql.addCommands();
1817
mysql.addCommands();
1818
- 
1818
1819
Cypress.Commands.add('set_syspref', (variable, value) => {
1820
    cy.window().then(win => {
1821
        const client = win.APIClient.syspref;
1822
        return client.sysprefs.update(variable, value);
1823
    });
1824
});

Return to bug 36025