Bug 34319: Upgrade cypress 9.7.0 to 12.17.2
[koha.git] / t / cypress / support / e2e.js
1 // ***********************************************
2 // This example commands.js shows you how to
3 // create various custom commands and overwrite
4 // existing commands.
5 //
6 // For more comprehensive examples of custom
7 // commands please read more here:
8 // https://on.cypress.io/custom-commands
9 // ***********************************************
10 //
11 //
12 // -- This is a parent command --
13 // Cypress.Commands.add('login', (email, password) => { ... })
14 //
15 //
16 // -- This is a child command --
17 // Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
18 //
19 //
20 // -- This is a dual command --
21 // Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
22 //
23 //
24 // -- This will overwrite an existing command --
25 // Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
26
27 function get_fallback_login_value(param) {
28
29     var env_var = param == 'username' ? 'KOHA_USER' : 'KOHA_PASS';
30
31     return typeof Cypress.env(env_var) === 'undefined' ? 'koha' : Cypress.env(env_var);
32 }
33
34 Cypress.Commands.add('login', (username, password) => {
35     var user = typeof username === 'undefined' ? get_fallback_login_value('username') : username;
36     var pass = typeof password === 'undefined' ? get_fallback_login_value('password') : password;
37     cy.visit('/cgi-bin/koha/mainpage.pl?logout.x=1')
38     cy.get("#userid").type(user)
39     cy.get("#password").type(pass)
40     cy.get("#submit-button").click()
41 })
42
43 Cypress.Commands.add('left_menu_active_item_is', (label) => {
44     cy.get("#navmenulist a.current:not(.disabled)").should('have.length',1).contains(label);
45 })
46
47 cy.get_title = () => {
48     return {
49         access_type: "access type",
50         biblio_id: null,
51         coverage_depth: "coverage depth",
52         date_first_issue_online: "date first",
53         date_last_issue_online: "date last",
54         date_monograph_published_online: "date mono online",
55         date_monograph_published_print: "date mono print",
56         embargo_info: "embargo info",
57         external_id: "",
58         first_author: "first author",
59         first_editor: "first editor",
60         monograph_edition: "monograph edition",
61         monograph_volume: "monograph volume",
62         notes: "notes",
63         num_first_issue_online: "num first issue",
64         num_first_vol_online: "num first vol",
65         num_last_issue_online: "num last issue",
66         num_last_vol_online: "num last vol",
67         online_identifier: "online identifier",
68         parent_publication_title_id: "parent id",
69         preceeding_publication_title_id: "preceeding id",
70         print_identifier: "print identifier",
71         publication_title: "publication title",
72         publication_type: "journal",
73         publisher_name: "publication name",
74         resources: [
75             {
76                 ended_on: null,
77                 package: {
78                     content_type: "",
79                     package_id: 1,
80                     name: "first package name"
81                 },
82                 package_id: 1,
83                 resource_id: 2,
84                 title: {
85                     biblio_id: 439,
86                     title_id: 1,
87                 },
88                 title_id: 1
89             }
90         ],
91         title_id: 1,
92         title_url: "title url"
93       };
94 }
95
96 cy.get_agreements_to_relate = () => {
97     return [
98         {
99             agreement_id: 2,
100             description: "a second agreement",
101             name: "second agreement name"
102         },
103         {
104             agreement_id: 3,
105             description: "a third agreement",
106             name: "third agreement name"
107         },
108         {
109             agreement_id: 4,
110             description: "a fourth agreement",
111             name: "fourth agreement name"
112         },
113     ]
114 }