-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathcontext-menu-test-utils.js
More file actions
62 lines (53 loc) · 2.37 KB
/
Copy pathcontext-menu-test-utils.js
File metadata and controls
62 lines (53 loc) · 2.37 KB
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
/**
* @license
* Copyright 2019-2020 CERN and copyright holders of ALICE O2.
* See http://alice-o2.web.cern.ch/copyright for details of the copyright holders.
* All rights not expressly granted are reserved.
*
* This software is distributed under the terms of the GNU General Public
* License v3 (GPL Version 3), copied verbatim in the file "COPYING".
*
* In applying this license CERN does not waive the privileges and immunities
* granted to it by virtue of its status as an Intergovernmental Organization
* or submit itself to any jurisdiction.
*/
const CONTEXT_MENU_RENDER_DELAY = 25; // delay to wait for context menu to render new actions after opening
const isContextMenuOpen = async (page) => await page.evaluate(() => window.model.log.contextMenu.isOpen);
const getMenuActionLabels = async (page) => page.evaluate(() =>
Array.from(document.querySelectorAll('.cell-context-menu-item .ph2.w-100'))
.map((el) => el.textContent.trim()));
const openContextMenu = async (page, field, value, x, y) => {
await page.evaluate((field, value, x, y) => {
window.model.log.contextMenu.show(field, value, x, y);
}, field, value, x, y);
await page.waitForSelector('.cell-context-menu');
await new Promise((resolve) => setTimeout(resolve, CONTEXT_MENU_RENDER_DELAY));
};
const isMenuItemDisabled = async (page, label) => await page.evaluate((label) => {
const item = Array.from(document.querySelectorAll('.cell-context-menu-item .ph2.w-100'))
.find((el) => el.textContent.trim() === label)
?.closest('.cell-context-menu-item');
return item?.classList.contains('disabled') ?? false;
}, label);
const clickMenuItemByLabel = async (page, label) => {
await page.waitForFunction((label) => {
const item = Array.from(document.querySelectorAll('.cell-context-menu-item .ph2.w-100'))
.find((el) => el.textContent.trim() === label)
?.closest('.cell-context-menu-item');
return Boolean(item) && !item.classList.contains('disabled');
}, {}, label);
await page.evaluate((label) => {
const item = Array.from(document.querySelectorAll('.cell-context-menu-item .ph2.w-100'))
.find((el) => el.textContent.trim() === label)
?.closest('.cell-context-menu-item');
item.click();
}, label);
};
module.exports = {
CONTEXT_MENU_RENDER_DELAY,
isContextMenuOpen,
getMenuActionLabels,
openContextMenu,
isMenuItemDisabled,
clickMenuItemByLabel,
};