2021-12-15 01:10:44 +08:00
|
|
|
const { expect } = require('@playwright/test');
|
|
|
|
const e = require('../core/elements');
|
|
|
|
const c = require('./constants');
|
2024-01-20 00:42:01 +08:00
|
|
|
const { ELEMENT_WAIT_LONGER_TIME } = require('../core/constants');
|
2021-12-15 01:10:44 +08:00
|
|
|
|
|
|
|
async function forceListenOnly(test) {
|
|
|
|
await test.wasRemoved(e.echoYesButton);
|
2022-01-20 03:50:59 +08:00
|
|
|
await test.hasText(e.toastContainer, e.joiningMessageToast);
|
2021-12-15 01:10:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function hexToRgb(hex) {
|
|
|
|
const bigint = parseInt(hex, 16);
|
|
|
|
const r = (bigint >> 16) & 255;
|
|
|
|
const g = (bigint >> 8) & 255;
|
|
|
|
const b = bigint & 255;
|
|
|
|
return `rgb(${r}, ${g}, ${b})`;
|
|
|
|
}
|
|
|
|
|
|
|
|
async function zoomIn(test) {
|
|
|
|
try {
|
2021-12-15 05:16:37 +08:00
|
|
|
await test.page.evaluate((selector) => {
|
2021-12-15 01:10:44 +08:00
|
|
|
setInterval(() => {
|
2021-12-15 05:16:37 +08:00
|
|
|
document.querySelector(selector).scrollBy(0, 10);
|
2021-12-15 01:10:44 +08:00
|
|
|
}, 100);
|
2022-01-20 21:03:18 +08:00
|
|
|
}, e.zoomInBtn);
|
2021-12-15 01:10:44 +08:00
|
|
|
return true;
|
|
|
|
} catch (err) {
|
|
|
|
console.log(err);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function zoomOut(test) {
|
|
|
|
try {
|
2021-12-15 05:16:37 +08:00
|
|
|
await test.page.evaluate((selector) => {
|
2021-12-15 01:10:44 +08:00
|
|
|
setInterval(() => {
|
2021-12-15 05:16:37 +08:00
|
|
|
document.querySelector(selector).scrollBy(10, 0);
|
2021-12-15 01:10:44 +08:00
|
|
|
}, 100);
|
2022-01-20 21:03:18 +08:00
|
|
|
}, e.zoomInBtn);
|
2021-12-15 01:10:44 +08:00
|
|
|
return true;
|
|
|
|
} catch (err) {
|
|
|
|
console.log(err);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function poll(page1, page2) {
|
|
|
|
await page1.waitForSelector(e.whiteboard, ELEMENT_WAIT_LONGER_TIME);
|
|
|
|
await page1.waitAndClick(e.actions);
|
|
|
|
await page1.waitAndClick(e.polling);
|
|
|
|
await page1.waitAndClick(e.pollYesNoAbstentionBtn);
|
|
|
|
await page1.waitAndClick(e.startPoll);
|
|
|
|
await page2.waitForSelector(e.pollingContainer);
|
2022-01-20 21:03:18 +08:00
|
|
|
await page2.waitAndClickElement(e.pollAnswerOptionBtn);
|
2021-12-15 01:10:44 +08:00
|
|
|
await page1.waitAndClick(e.publishPollingLabel);
|
|
|
|
}
|
|
|
|
|
|
|
|
async function previousSlide(test) {
|
|
|
|
await test.waitAndClick(e.prevSlide);
|
|
|
|
}
|
|
|
|
|
|
|
|
async function nextSlide(test) {
|
|
|
|
await test.waitAndClick(e.nextSlide);
|
|
|
|
}
|
|
|
|
|
|
|
|
async function annotation(test) {
|
2022-07-02 04:55:32 +08:00
|
|
|
await test.waitAndClick(e.wbPencilShape);
|
2021-12-15 01:10:44 +08:00
|
|
|
await test.waitAndClick(e.whiteboard);
|
2024-09-13 00:51:26 +08:00
|
|
|
await test.hasElement(e.wbPencilShape, 'should the presentation displays the tool drawn line');
|
2021-12-15 01:10:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function encodeCustomParams(param) {
|
|
|
|
try {
|
2024-01-20 00:42:01 +08:00
|
|
|
let splitted = param.split('=');
|
|
|
|
if (splitted.length > 2) {
|
|
|
|
const aux = splitted.shift();
|
|
|
|
splitted[1] = splitted.join('=');
|
|
|
|
splitted[0] = aux;
|
2022-03-01 03:46:13 +08:00
|
|
|
}
|
2024-01-20 00:42:01 +08:00
|
|
|
splitted[1] = encodeURIComponent(splitted[1]).replace();
|
|
|
|
return splitted.join('=');
|
2021-12-15 01:10:44 +08:00
|
|
|
} catch (err) {
|
|
|
|
console.log(err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function getAllShortcutParams() {
|
|
|
|
const getParams = (shortcutArray) => {
|
2021-12-15 05:16:37 +08:00
|
|
|
return Object.values(shortcutArray.map(elem => `"${elem.param}"`));
|
2021-12-15 01:10:44 +08:00
|
|
|
}
|
|
|
|
return c.shortcuts.replace('$', [...getParams(c.initialShortcuts), ...getParams(c.laterShortcuts)]);
|
|
|
|
}
|
|
|
|
|
|
|
|
async function checkAccesskey(test, key) {
|
|
|
|
return test.checkElement(`[accesskey="${key}"]`);
|
|
|
|
}
|
|
|
|
|
|
|
|
async function checkShortcutsArray(test, shortcut) {
|
2022-07-02 04:55:32 +08:00
|
|
|
for (const { key, param } of shortcut) {
|
2021-12-15 01:10:44 +08:00
|
|
|
const resp = await checkAccesskey(test, key);
|
2022-07-02 04:55:32 +08:00
|
|
|
await expect.soft(resp, `Shortcut to ${param} (key ${key}) failed`).toBeTruthy();
|
2021-12-15 01:10:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.zoomIn = zoomIn;
|
|
|
|
exports.zoomOut = zoomOut;
|
|
|
|
exports.poll = poll;
|
|
|
|
exports.previousSlide = previousSlide;
|
|
|
|
exports.nextSlide = nextSlide;
|
|
|
|
exports.annotation = annotation;
|
|
|
|
exports.hexToRgb = hexToRgb;
|
|
|
|
exports.forceListenOnly = forceListenOnly;
|
|
|
|
exports.encodeCustomParams = encodeCustomParams;
|
|
|
|
exports.getAllShortcutParams = getAllShortcutParams;
|
|
|
|
exports.checkAccesskey = checkAccesskey;
|
|
|
|
exports.checkShortcutsArray = checkShortcutsArray;
|