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

(-)a/t/cypress/integration/KohaTable_spec.ts (-65 / +101 lines)
Lines 8-101 describe("kohaTable (using REST API)", () => { Link Here
8
8
9
    afterEach(() => {});
9
    afterEach(() => {});
10
10
11
    const RESTdefaultPageSize = 20; // FIXME Mock this
11
    const RESTdefaultPageSize = "20"; // FIXME Mock this
12
    const baseTotalCount = "42";
12
13
13
    it("Simple tables", () => {
14
    describe("Simple tables", () => {
14
        const table_id = "libraries";
15
        const table_id = "libraries";
15
16
16
        it("Input search bar and clear filter ", () => {
17
        it("Input search bar and clear filter ", () => {
17
            cy.visit("/cgi-bin/koha/admin/branches.pl");
18
            cy.task("buildSampleObjects", {
19
                object: "library",
20
                count: RESTdefaultPageSize,
21
                values: { library_hours: [] },
22
            }).then(libraries => {
23
                cy.intercept("GET", "/api/v1/libraries*", {
24
                    statusCode: 200,
25
                    body: libraries,
26
                    headers: {
27
                        "X-Base-Total-Count": baseTotalCount,
28
                        "X-Total-Count": baseTotalCount,
29
                    },
30
                });
31
32
                cy.visit("/cgi-bin/koha/admin/branches.pl");
18
33
19
            cy.query("SELECT COUNT(*) as count FROM branches").then(result => {
20
                let count = result[0].count;
21
                let display = Math.min(RESTdefaultPageSize, count);
22
                cy.get(`#${table_id}_wrapper .dt-info`).contains(
34
                cy.get(`#${table_id}_wrapper .dt-info`).contains(
23
                    `Showing 1 to ${display} of ${count} entries`
35
                    `Showing 1 to ${RESTdefaultPageSize} of ${baseTotalCount} entries`
24
                );
36
                );
25
            });
26
37
27
            // Should be disabled by default - empty search bar
38
                // Should be disabled by default - empty search bar
28
            cy.get(`#${table_id}_wrapper .dt_button_clear_filter`).should(
39
                cy.get(`#${table_id}_wrapper .dt_button_clear_filter`).should(
29
                "have.class",
40
                    "have.class",
30
                "disabled"
41
                    "disabled"
31
            );
42
                );
32
43
33
            // Type something in the input search bar
44
                // Type something in the input search bar
34
            cy.get(`#${table_id}_wrapper input.dt-input`).type("centerville");
45
                cy.get(`#${table_id}_wrapper input.dt-input`).type(
35
            cy.get(`#${table_id}_wrapper input.dt-input`).should(
46
                    "centerville"
36
                "have.value",
47
                );
37
                "centerville"
48
                cy.get(`#${table_id}_wrapper input.dt-input`).should(
38
            );
49
                    "have.value",
50
                    "centerville"
51
                );
39
52
40
            // Should no longer be disabled
53
                // Should no longer be disabled
41
            cy.get(`#${table_id}_wrapper .dt_button_clear_filter`).should(
54
                cy.get(`#${table_id}_wrapper .dt_button_clear_filter`).should(
42
                "not.have.class",
55
                    "not.have.class",
43
                "disabled"
56
                    "disabled"
44
            );
57
                );
45
58
46
            // Click the clear_filter button
59
                // Click the clear_filter button
47
            cy.get(`#${table_id}_wrapper .dt_button_clear_filter`).click();
60
                cy.get(`#${table_id}_wrapper .dt_button_clear_filter`).click();
48
            cy.get(`#${table_id}_wrapper input.dt-input`).should(
61
                cy.get(`#${table_id}_wrapper input.dt-input`).should(
49
                "have.value",
62
                    "have.value",
50
                ""
63
                    ""
51
            );
64
                );
65
            });
52
        });
66
        });
53
    });
67
    });
54
68
55
    it("Patrons search", () => {
69
    describe("Patrons search", () => {
56
        const table_id = "memberresultst";
70
        const table_id = "memberresultst";
57
71
58
        it("Input search bar and clear filter ", () => {
72
        it("Input search bar and clear filter ", () => {
59
            cy.visit("/cgi-bin/koha/members/members-home.pl");
73
            cy.task("buildSampleObjects", {
60
74
                object: "patron",
61
            cy.get("form.patron_search_form input[type='submit']").click();
75
                count: RESTdefaultPageSize,
76
                values: {},
77
            }).then(patrons => {
78
                // Needs more properties to not explode
79
                // account_balace: balance_str.escapeHtml(...).format_price is not a function
80
                patrons = patrons.map(p => ({ ...p, account_balance: 0 }));
81
82
                cy.intercept("GET", "/api/v1/patrons*", {
83
                    statusCode: 200,
84
                    body: patrons,
85
                    headers: {
86
                        "X-Base-Total-Count": baseTotalCount,
87
                        "X-Total-Count": baseTotalCount,
88
                    },
89
                });
90
91
                cy.visit("/cgi-bin/koha/members/members-home.pl");
92
93
                cy.window().then(win => {
94
                    win.categories_map = patrons.reduce((map, p) => {
95
                        map[p.category_id] = p.category_id;
96
                        return map;
97
                    }, {});
98
                });
99
                cy.get("form.patron_search_form input[type='submit']").click();
62
100
63
            cy.query("SELECT COUNT(*) as count FROM borrowers").then(result => {
64
                let count = result[0].count;
65
                let display = Math.min(RESTdefaultPageSize, count);
66
                cy.get(`#${table_id}_wrapper .dt-info`).contains(
101
                cy.get(`#${table_id}_wrapper .dt-info`).contains(
67
                    `Showing 1 to ${display} of ${count} entries`
102
                    `Showing 1 to ${RESTdefaultPageSize} of ${baseTotalCount} entries`
68
                );
103
                );
69
            });
70
104
71
            // Should be disabled by default - empty search bar
105
                // Should be disabled by default - empty search bar
72
            cy.get(`#${table_id}_wrapper .dt_button_clear_filter`).should(
106
                cy.get(`#${table_id}_wrapper .dt_button_clear_filter`).should(
73
                "have.class",
107
                    "have.class",
74
                "disabled"
108
                    "disabled"
75
            );
109
                );
76
110
77
            // Type something in the input search bar
111
                // Type something in the input search bar
78
            cy.get(`#${table_id}_wrapper input.dt-input`).type(
112
                cy.get(`#${table_id}_wrapper input.dt-input`).type(
79
                "edna",
113
                    "edna",
80
                { force: true } // Needs to force because of sticky header? It's not clear what's happening, Cypress bug?
114
                    { force: true } // Needs to force because of sticky header? It's not clear what's happening, Cypress bug?
81
            );
115
                );
82
            cy.get(`#${table_id}_wrapper input.dt-input`).should(
116
                cy.get(`#${table_id}_wrapper input.dt-input`).should(
83
                "have.value",
117
                    "have.value",
84
                "edna"
118
                    "edna"
85
            );
119
                );
86
120
87
            // Should no longer be disabled
121
                // Should no longer be disabled
88
            cy.get(`#${table_id}_wrapper .dt_button_clear_filter`).should(
122
                cy.get(`#${table_id}_wrapper .dt_button_clear_filter`).should(
89
                "not.have.class",
123
                    "not.have.class",
90
                "disabled"
124
                    "disabled"
91
            );
125
                );
92
126
93
            // Click the clear_filter button
127
                // Click the clear_filter button
94
            cy.get(`#${table_id}_wrapper .dt_button_clear_filter`).click();
128
                cy.get(`#${table_id}_wrapper .dt_button_clear_filter`).click({
95
            cy.get(`#${table_id}_wrapper input.dt-input`).should(
129
                    force: true,
96
                "have.value",
130
                }); // #searchheader is on top of it
97
                ""
131
                cy.get(`#${table_id}_wrapper input.dt-input`).should(
98
            );
132
                    "have.value",
133
                    ""
134
                );
135
            });
99
        });
136
        });
100
    });
137
    });
101
});
138
});
102
- 

Return to bug 38461