forked from folio-org/ui-testing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpers.js
180 lines (174 loc) · 6.46 KB
/
helpers.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/* global it */
/* eslint no-unused-vars: ["error", { "argsIgnorePattern": "^type" }] */
module.exports.login = (nightmare, config, done, un, pw) => {
nightmare
.on('page', (type = 'alert', message) => {
throw new Error(message);
})
.goto(config.url)
// .wait(Number(config.login_wait))
.wait(config.select.username)
.insert(config.select.username, (un || config.username))
.insert(config.select.password, (pw || config.password))
.click('#clickable-login')
.wait('#clickable-logout')
.then(() => { done(); })
.catch(done);
};
module.exports.logout = (nightmare, config, done) => {
nightmare
.click('#clickable-logout') // logout
.wait('#clickable-login') // login page
.wait(parseInt(process.env.FOLIO_UI_DEBUG, 10) ? parseInt(config.debug_sleep / 3, 10) : 0) // debugging
.end()
.then(() => { done(); })
.catch(done);
};
module.exports.openApp = (nightmare, config, done, app, testVersion) => function opena() {
nightmare
.wait(`#clickable-${app}-module`)
.click(`#clickable-${app}-module`)
.wait(`#${app}-module-display`)
.evaluate((mapp) => {
const metadata = document.querySelector(`#${mapp}-module-display`);
return {
moduleName: metadata.getAttribute('data-module'),
moduleVersion: metadata.getAttribute('data-version'),
};
}, app)
.then((meta) => {
if (testVersion !== undefined) {
console.log(` Test suite ${testVersion}`); // eslint-disable-line
console.log(` Live module ${meta.moduleName}:${meta.moduleVersion} (${config.url})`); // eslint-disable-line
}
done();
return meta;
})
.catch(done);
};
module.exports.getUsers = (nightmare, config, done) => function getu() {
nightmare
.click('#clickable-users-module')
.wait('#list-users div[role="listitem"]')
.evaluate(() => {
const udata = [];
const users = document.querySelectorAll('#list-users div[role="listitem"]');
for (let x = 0; x < users.length; x++) {
const st = users[x].querySelector('div:nth-of-type(1)').innerText;
const nm = users[x].querySelector('div:nth-of-type(2)').innerText;
const bc = users[x].querySelector('div:nth-of-type(3)').innerText;
const pg = users[x].querySelector('div:nth-of-type(4)').innerText;
const id = users[x].querySelector('div:nth-of-type(5)').innerText;
const em = users[x].querySelector('div:nth-of-type(6)').innerText;
if (bc.match(/\d/)) {
udata.push({ status: st, name: nm, barcode: bc, group: pg, id, email: em });
}
}
return udata;
})
.then((u) => {
done();
return u;
})
.catch(done);
};
module.exports.createInventory = (nightmare, config, title, holdingsOnly) => {
const ti = title || 'New test title';
const barcode = new Date().valueOf();
if (!holdingsOnly) {
it('should create inventory record', (done) => {
nightmare
.click('#clickable-inventory-module')
.wait('#clickable-newinventory')
.click('#clickable-newinventory')
.wait('#input_instance_title')
.insert('#input_instance_title', ti)
.type('#select_instance_type', 'o')
.click('#clickable-create-instance')
.waitUntilNetworkIdle(500)
.then(done)
.catch(done);
});
}
it('should create holdings record', (done) => {
nightmare
.wait('#clickable-new-holdings-record')
.click('#clickable-new-holdings-record')
.wait('#additem_permanentlocation')
.type('#additem_permanentlocation', 'm')
.insert('#additem_callnumber', 'ZZ39.50')
.click('#clickable-create-item')
.wait('#clickable-new-item')
.then(done)
.catch(done);
});
it('should create item record', (done) => {
nightmare
.click('#clickable-new-item')
.wait('#additem_materialType option:nth-of-type(2)')
.type('#additem_materialType ', 'b')
.wait('#additem_loanTypePerm option:nth-of-type(2)')
.type('#additem_loanTypePerm', 'cc')
.insert('#additem_barcode', barcode)
.wait(500)
.click('#clickable-create-item')
.then(done)
.catch(done);
});
return barcode;
};
module.exports.namegen = () => {
const ts = new Date().valueOf();
const fn = ['Emma', 'Olivia', 'Ava', 'Sophia', 'Isabella', 'Liam', 'Noah', 'Mason', 'Lucas', 'Oliver'];
const ln = ['Smith', 'Johnson', 'Williams', 'Brown', 'Jones', 'Miller', 'Davis', 'Garcia', 'Rodriquez', 'Wilson'];
const ad = [{ city: 'Chicago', zip: '60609', address: '5 Wacker Dr', country: 'United States', state: 'IL', phone: '13125552121' },
{ city: 'New York', zip: '10002-2341', address: '425 Bowery', country: 'United States', state: 'NY', phone: '12125554444' },
{ city: 'San Francisco', zip: '94016', address: '39 Green Street', country: 'United States', state: 'CA', phone: '12153338888' },
{ city: 'København', zip: '1208', address: 'Nybrogade 30', country: 'Denmark', state: 'K', phone: '453332229999' }];
const fnpos = Math.floor(Math.random() * fn.length);
const lnpos = Math.floor(Math.random() * ln.length);
const adpos = Math.floor(Math.random() * ad.length);
const firstname = fn[fnpos];
const lastname = ln[lnpos];
return {
id: firstname.substr(0, 1).toLowerCase() + lastname.toLowerCase() + ts,
firstname,
lastname,
email: `${firstname.toLowerCase()}.${lastname.toLowerCase()}@someserver.org`,
barcode: ts,
password: 'P@$$w0rd23',
address: ad[adpos],
};
};
/**
* Visit "settings > circulation > other settings" to tick the checkboxes
* for "barcode" and "username".
*/
module.exports.circSettingsCheckoutByBarcodeAndUsername = (nightmare, config, done) => {
nightmare
.wait(config.select.settings)
.click(config.select.settings)
.wait('#clickable-settings')
.wait('a[href="/settings/circulation"]')
.click('a[href="/settings/circulation"]')
.wait('a[href="/settings/circulation/checkout"]')
.click('a[href="/settings/circulation/checkout"]')
.wait('#username-checkbox')
.wait(222)
.evaluate(() => {
const list = document.querySelectorAll('[data-checked="true"]');
list.forEach(el => (el.click()));
})
.then(() => {
nightmare
.wait(222)
.wait('#barcode-checkbox')
.click('#barcode-checkbox')
.wait('#username-checkbox')
.click('#username-checkbox')
.wait('#clickable-savescanid')
.click('#clickable-savescanid')
.then(done)
.catch(done);
});
};