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

(-)a/t/cypress/support/cypress_builder.pl (+33 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Koha::Database;
21
22
use t::lib::TestBuilder;
23
use JSON qw( decode_json );
24
use Getopt::Long;
25
26
my %data;
27
my $class;
28
29
GetOptions( "data=s" => \%data, "class=s" => \$class );
30
31
my $builder = t::lib::TestBuilder->new;
32
33
my $koha_object = $builder->build_object({ class => $class, value => \%data });
(-)a/t/cypress/support/e2e.js (-1 / +47 lines)
Lines 43-48 Cypress.Commands.add('login', (username, password) => { Link Here
43
Cypress.Commands.add('left_menu_active_item_is', (label) => {
43
Cypress.Commands.add('left_menu_active_item_is', (label) => {
44
    cy.get("#navmenulist a.current:not(.disabled)").should('have.length',1).contains(label);
44
    cy.get("#navmenulist a.current:not(.disabled)").should('have.length',1).contains(label);
45
})
45
})
46
47
/**
48
 * Builds an object based on the provided class and data.
49
 *
50
 * @param {string} objectClass - The class of the object to be built.
51
 * @param {Object} data - The data used to build the object. If not provided, a default object will be built.
52
 * @return {void} This function does not return anything.
53
 */
54
Cypress.Commands.add('buildObject', (objectClass, data) => {
55
    if (!objectClass) return
56
    if (!data) {
57
        const buildCommand = `perl t/cypress/support/cypress_builder.pl --class ${objectClass}`
58
        cy.exec(buildCommand)
59
        return
60
    }
61
    const properties = Object.keys(data)
62
    const buildValues = properties.map(prop => ` --data ${prop}=${data[prop]}`)
63
    const buildCommand = `perl t/cypress/support/cypress_builder.pl --class ${objectClass}${buildValues.join('')}`
64
    cy.exec(buildCommand)
65
})
66
67
const tableMappings = {
68
    'Koha::Patrons': { tableName: 'borrowers', primaryKey: 'borrowernumber'}
69
}
70
71
/**
72
 * Deletes one or more rows from a database table based on the given className and delete parameters.
73
 *
74
 * @param {string} className - The name of the class to delete rows from.
75
 * @param {Object} deleteParameters - The parameters used to filter the rows to be deleted.
76
 * @param {number} numberOfRows - The number of rows to delete. If provided, rows will be deleted in descending order up to the value of numberOfRows.
77
 * @return {void} This function does not return anything.
78
 */
79
Cypress.Commands.add('deleteDbRow', (className, deleteParameters, numberOfRows) => {
80
    if(!className) return
81
    if(numberOfRows) {
82
        const sql = `DELETE from ${tableMappings[className].tableName} ORDER BY ${tableMappings[className].primaryKey} DESC LIMIT ${numberOfRows}`
83
        cy.query(sql);
84
        return
85
    }
86
    const properties = Object.keys(deleteParameters)
87
    const deleteFilters = properties.map(prop => `${prop}=?`)
88
    const deleteValues = properties.map(prop => deleteParameters[prop])
89
    const sql = `DELETE from ${tableMappings[className].tableName} WHERE ${deleteFilters.join(' AND ')}`
90
    cy.query(sql, deleteValues);
91
})
92
46
const dayjs = require("dayjs") /* Cannot use our calendar JS code, it's in an include file (!)
93
const dayjs = require("dayjs") /* Cannot use our calendar JS code, it's in an include file (!)
47
                                   Also note that moment.js is deprecated */
94
                                   Also note that moment.js is deprecated */
48
95
49
- 

Return to bug 36607