2021-02-17 04:57:10 +08:00
|
|
|
const Page = require('../core/page');
|
2021-08-20 04:22:31 +08:00
|
|
|
const e = require('../core/elements');
|
2021-10-20 04:12:00 +08:00
|
|
|
const util = require('./util');
|
2021-10-23 03:22:34 +08:00
|
|
|
const utilPresentation = require('../presentation/util');
|
2021-10-22 23:37:37 +08:00
|
|
|
const { ELEMENT_WAIT_TIME, ELEMENT_WAIT_LONGER_TIME } = require('../core/constants');
|
|
|
|
const { checkElement, checkElementLengthEqualTo, checkElementTextIncludes } = require('../core/util');
|
2021-02-17 04:57:10 +08:00
|
|
|
|
2021-10-20 04:12:00 +08:00
|
|
|
class Polling {
|
2021-02-17 04:57:10 +08:00
|
|
|
constructor() {
|
2021-10-20 04:12:00 +08:00
|
|
|
this.modPage = new Page();
|
|
|
|
this.userPage = new Page();
|
2021-02-17 04:57:10 +08:00
|
|
|
}
|
|
|
|
|
2021-10-20 04:12:00 +08:00
|
|
|
async initPages(testName) {
|
|
|
|
await this.initModPage(testName);
|
|
|
|
await this.initUserPage(testName);
|
|
|
|
}
|
|
|
|
|
|
|
|
async initModPage(testName) {
|
|
|
|
await this.modPage.init(true, true, testName, 'Moderator');
|
|
|
|
}
|
|
|
|
|
|
|
|
async initUserPage(testName) {
|
|
|
|
await this.userPage.init(false, true, testName, 'Attendee', this.modPage.meetingId);
|
|
|
|
}
|
|
|
|
|
|
|
|
async createPoll(testName) {
|
2021-02-17 04:57:10 +08:00
|
|
|
try {
|
2021-10-20 04:12:00 +08:00
|
|
|
await util.startPoll(this.modPage);
|
|
|
|
await this.modPage.screenshot(testName, '01-before-chat-message-send');
|
2021-08-14 04:33:27 +08:00
|
|
|
|
2021-10-20 04:12:00 +08:00
|
|
|
const resp = this.modPage.page.evaluate(checkElementLengthEqualTo, e.pollMenuButton, 1);
|
2021-02-17 04:57:10 +08:00
|
|
|
return resp;
|
2021-08-26 22:13:18 +08:00
|
|
|
} catch (err) {
|
2021-10-20 04:12:00 +08:00
|
|
|
await this.modPage.logger(err);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-21 22:11:43 +08:00
|
|
|
async pollAnonymous(testName) {
|
|
|
|
try {
|
|
|
|
await this.modPage.waitForSelector(e.whiteboard);
|
|
|
|
await this.modPage.screenshot(testName, '01-before-start-anonymous-poll');
|
|
|
|
await util.startPoll(this.modPage, false, true);
|
|
|
|
await this.modPage.screenshot(testName, '02-after-start-anonymous-poll');
|
|
|
|
await this.modPage.waitForSelector(e.publishPollingLabel);
|
|
|
|
await this.userPage.waitAndClick(e.pollAnswerOptionBtn);
|
|
|
|
await this.modPage.screenshot(testName, '03-after-receive-answer');
|
|
|
|
const resp = !await this.modPage.page.evaluate(checkElement, e.receivedAnswer);
|
|
|
|
|
|
|
|
return resp === true;
|
|
|
|
} catch (err) {
|
|
|
|
await this.modPage.logger(err);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-22 23:37:37 +08:00
|
|
|
async quickPoll(testName) {
|
|
|
|
try {
|
|
|
|
await this.modPage.waitForSelector(e.whiteboard);
|
|
|
|
await this.modPage.screenshot(testName, '01-after-close-audio-modal');
|
|
|
|
await this.modPage.waitAndClick(e.actions);
|
|
|
|
await this.modPage.waitAndClick(e.uploadPresentation);
|
|
|
|
await this.modPage.waitForSelector(e.fileUpload);
|
|
|
|
|
2021-10-23 03:22:34 +08:00
|
|
|
await utilPresentation.uploadPresentation(this.modPage, e.questionSlideFileName);
|
2021-10-22 23:37:37 +08:00
|
|
|
|
|
|
|
await this.modPage.waitAndClick(e.quickPoll);
|
2021-10-23 03:22:34 +08:00
|
|
|
await this.modPage.screenshot(testName, '02-after-start-quick-poll');
|
2021-10-22 23:37:37 +08:00
|
|
|
await this.modPage.waitForSelector(e.pollMenuButton);
|
|
|
|
const resp = await this.userPage.hasElement(e.pollingContainer);
|
2021-10-23 03:22:34 +08:00
|
|
|
await this.userPage.screenshot(testName, '03-userPage-after-poll-created');
|
2021-10-22 23:37:37 +08:00
|
|
|
|
|
|
|
return resp === true;
|
|
|
|
} catch (err) {
|
|
|
|
await this.modPage.logger(err);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-23 01:21:17 +08:00
|
|
|
async stopPoll(testName) {
|
|
|
|
try {
|
|
|
|
await this.modPage.waitForSelector(e.whiteboard);
|
|
|
|
await this.modPage.screenshot(testName, '01-after-close-audio-modal');
|
|
|
|
await util.startPoll(this.modPage);
|
|
|
|
await this.modPage.screenshot(testName, '02-after-create-poll');
|
|
|
|
await this.userPage.waitForSelector(e.pollingContainer);
|
|
|
|
await this.userPage.screenshot(testName, '03-userPage-after-receive-polling-options');
|
|
|
|
|
|
|
|
await this.modPage.waitAndClick(e.closePollingMenu);
|
|
|
|
const resp = await this.userPage.wasRemoved(e.pollingContainer);
|
|
|
|
|
|
|
|
return resp === true;
|
|
|
|
} catch (err) {
|
|
|
|
await this.modPage.logger(err);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-20 04:12:00 +08:00
|
|
|
async pollResultsOnChat(testName) {
|
|
|
|
try {
|
|
|
|
await this.modPage.screenshot(testName, '01-before-chat-message-send');
|
|
|
|
await util.startPoll(this.modPage, true);
|
|
|
|
await this.modPage.waitAndClick(e.chatButton);
|
|
|
|
|
|
|
|
// Check poll result message
|
|
|
|
const resp = await this.modPage.hasElement(e.chatPollMessageText);
|
|
|
|
|
|
|
|
return resp === true;
|
|
|
|
} catch (err) {
|
|
|
|
await this.modPage.logger(err);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-21 01:39:36 +08:00
|
|
|
async pollResultsOnWhiteboard(testName) {
|
|
|
|
try {
|
|
|
|
await this.modPage.waitForSelector(e.whiteboard);
|
|
|
|
await this.modPage.screenshot(testName, '01-before-start-poll');
|
|
|
|
await util.startPoll(this.modPage, true);
|
|
|
|
|
|
|
|
// Check poll result on whiteboard
|
|
|
|
const resp = await this.modPage.hasElement(e.pollResults);
|
|
|
|
|
|
|
|
return resp === true;
|
|
|
|
} catch (err) {
|
|
|
|
await this.modPage.logger(err);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-23 03:22:34 +08:00
|
|
|
async pollResultsInDifferentPresentation(testName) {
|
|
|
|
try {
|
|
|
|
await this.modPage.waitForSelector(e.whiteboard);
|
|
|
|
await this.modPage.screenshot(testName, '01-before-start-poll');
|
|
|
|
await util.startPoll(this.modPage);
|
|
|
|
await this.modPage.screenshot(testName, '02-after-start-poll');
|
|
|
|
|
|
|
|
await utilPresentation.uploadPresentation(this.modPage, e.questionSlideFileName);
|
|
|
|
await this.modPage.screenshot(testName, '03-after-upload-presentation');
|
|
|
|
await this.modPage.waitAndClick(e.publishPollingLabel);
|
|
|
|
|
|
|
|
// Check poll results
|
|
|
|
const resp = await this.modPage.hasElement(e.pollResults);
|
|
|
|
|
|
|
|
return resp === true;
|
|
|
|
} catch (err) {
|
|
|
|
await this.modPage.logger(err);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-20 04:12:00 +08:00
|
|
|
async randomPoll(testName) {
|
|
|
|
try {
|
|
|
|
await this.modPage.startRecording(testName);
|
|
|
|
await this.userPage.startRecording(testName);
|
|
|
|
|
|
|
|
await this.modPage.waitAndClick(e.actions);
|
|
|
|
await this.modPage.waitAndClick(e.polling);
|
|
|
|
await this.modPage.waitForSelector(e.pollQuestionArea);
|
|
|
|
await this.modPage.page.focus(e.pollQuestionArea);
|
|
|
|
await this.modPage.page.keyboard.type(e.pollQuestion);
|
|
|
|
|
|
|
|
const chosenRandomNb = await this.modPage.page.evaluate((responseTypes) => {
|
|
|
|
const responseTypesDiv = document.querySelector(responseTypes);
|
|
|
|
const buttons = responseTypesDiv.querySelectorAll('button');
|
|
|
|
const countButtons = buttons.length;
|
|
|
|
const randomNb = Math.floor(Math.random() * countButtons) + 1;
|
|
|
|
const chosenRandomNb = randomNb - 1;
|
|
|
|
responseTypesDiv.querySelectorAll('button')[chosenRandomNb].click();
|
|
|
|
return chosenRandomNb;
|
|
|
|
}, e.responseTypes);
|
|
|
|
|
|
|
|
const customs = {
|
|
|
|
0: e.uncertain,
|
|
|
|
1: 0,
|
|
|
|
2: 'ABSTENTION',
|
|
|
|
3: 'All good!',
|
|
|
|
};
|
|
|
|
switch (chosenRandomNb) {
|
|
|
|
case 0:
|
|
|
|
// Adding a poll option
|
|
|
|
await this.modPage.waitForSelector(e.responseChoices);
|
|
|
|
await this.modPage.waitAndClick(e.addItem);
|
|
|
|
await this.modPage.waitAndClick(e.pollOptionItem);
|
|
|
|
await this.modPage.tab(2);
|
|
|
|
await this.modPage.page.keyboard.type(customs[0]);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
// Deleting a poll option
|
|
|
|
await this.modPage.waitForSelector(e.deletePollOption);
|
|
|
|
await this.modPage.clickNItem(e.deletePollOption, customs[1]);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
// Editing a poll option
|
|
|
|
await this.modPage.waitForSelector(e.responseChoices);
|
|
|
|
await this.modPage.clickNItem(e.pollOptionItem, 2);
|
|
|
|
await this.modPage.hold('Control');
|
|
|
|
await this.modPage.press('KeyA');
|
|
|
|
await this.modPage.release('Control');
|
|
|
|
await this.modPage.page.keyboard.type(customs[2]);
|
|
|
|
await this.modPage.tab(1);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
// Do nothing to let Users write their single response answer
|
|
|
|
await this.modPage.waitForSelector(e.responseChoices);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
const condition = chosenRandomNb === 0 || chosenRandomNb === 1 || chosenRandomNb === 2;
|
|
|
|
await this.modPage.waitAndClick(e.startPoll);
|
|
|
|
await this.userPage.waitForSelector(e.pollingContainer);
|
|
|
|
switch (condition) {
|
|
|
|
case true:
|
|
|
|
await this.userPage.clickNItem(e.pollAnswerOptionBtn, 2);
|
|
|
|
break;
|
|
|
|
case false:
|
|
|
|
await this.userPage.page.focus(e.pollAnswerOptionInput);
|
|
|
|
await this.userPage.page.keyboard.type(customs[3]);
|
|
|
|
await this.userPage.waitAndClick(e.pollSubmitAnswer);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
const receivedAnswerFound = await this.modPage.hasElement(e.receivedAnswer, true);
|
|
|
|
await this.modPage.waitAndClick(e.publishPollingLabel, ELEMENT_WAIT_TIME, true);
|
|
|
|
await this.modPage.waitForSelector(e.restartPoll);
|
|
|
|
const isPollResultsPublished = await this.modPage.hasElement(e.pollResults, true);
|
|
|
|
return receivedAnswerFound && isPollResultsPublished;
|
|
|
|
} catch (err) {
|
|
|
|
await this.modPage.logger(err);
|
2021-02-17 04:57:10 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = exports = Polling;
|