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-25 23:01:40 +08:00
|
|
|
const { ELEMENT_WAIT_TIME } = require('../core/constants');
|
|
|
|
const { checkElement, checkElementText, checkElementLengthEqualTo, getElementLength } = 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-10-25 23:01:40 +08:00
|
|
|
this.newInputText = 'new option';
|
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-25 23:01:40 +08:00
|
|
|
async pollUserResponse(testName) {
|
|
|
|
try {
|
|
|
|
await this.modPage.waitForSelector(e.whiteboard);
|
|
|
|
await this.modPage.screenshot(testName, '01-after-close-audio-modal');
|
|
|
|
await util.openPoll(this.modPage);
|
|
|
|
|
|
|
|
await this.modPage.type(e.pollQuestionArea, e.pollQuestion);
|
|
|
|
await this.modPage.waitAndClick(e.userResponseBtn);
|
|
|
|
await this.modPage.screenshot(testName, '02-before-start-poll');
|
|
|
|
await this.modPage.waitAndClick(e.startPoll);
|
|
|
|
|
|
|
|
await this.userPage.waitForSelector(e.pollingContainer);
|
|
|
|
await this.userPage.type(e.pollAnswerOptionInput, e.answerMessage);
|
|
|
|
await this.userPage.screenshot(testName, '03-userPage-before-submit-answer');
|
|
|
|
await this.userPage.waitAndClick(e.pollSubmitAnswer);
|
|
|
|
try {
|
|
|
|
await this.modPage.page.waitForFunction(checkElementText,
|
|
|
|
{ timeout: ELEMENT_WAIT_TIME },
|
|
|
|
e.receivedAnswer, e.answerMessage
|
|
|
|
);
|
|
|
|
await this.modPage.screenshot(testName, '04-success-to-receive-answer');
|
2021-11-03 00:55:13 +08:00
|
|
|
} catch (er) {
|
2021-10-25 23:01:40 +08:00
|
|
|
await this.modPage.screenshot(testName, '04-failed-to-receive-answer');
|
2021-11-03 00:55:13 +08:00
|
|
|
await this.modPage.logger(er);
|
2021-10-25 23:01:40 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
await this.modPage.waitAndClick(e.publishPollingLabel);
|
|
|
|
await this.modPage.waitForSelector(e.restartPoll);
|
|
|
|
const isPollResultsPublished = await this.modPage.hasElement(e.pollResults);
|
|
|
|
|
|
|
|
return isPollResultsPublished === 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-25 23:01:40 +08:00
|
|
|
async manageResponseChoices(testName) {
|
2021-10-20 04:12:00 +08:00
|
|
|
try {
|
2021-10-25 23:01:40 +08:00
|
|
|
await this.modPage.waitForSelector(e.whiteboard);
|
|
|
|
await this.modPage.screenshot(testName, '01-after-close-audio-modal');
|
|
|
|
await this.startNewPoll();
|
|
|
|
await this.modPage.screenshot(testName, '02-after-open-polling-menu');
|
|
|
|
const initialRespCount = await this.modPage.page.evaluate(getElementLength, e.pollOptionItem);
|
|
|
|
|
|
|
|
// Add
|
|
|
|
await this.modPage.waitAndClick(e.addPollItem);
|
|
|
|
await this.typeOnLastChoiceInput();
|
|
|
|
await this.modPage.screenshot(testName, '03-after-add-option');
|
|
|
|
await this.modPage.waitAndClick(e.startPoll);
|
|
|
|
await this.userPage.screenshot(testName, '03-userPage-options-after-add');
|
2021-10-20 04:12:00 +08:00
|
|
|
|
2021-10-25 23:01:40 +08:00
|
|
|
const optionWasAdded = (initialRespCount + 1 == await this.getAnswerOptionCount()) && await this.checkLastOptionText();
|
|
|
|
if (!optionWasAdded) {
|
|
|
|
await this.modPage.logger('Cannot add choice option');
|
|
|
|
return false;
|
2021-10-20 04:12:00 +08:00
|
|
|
}
|
2021-10-25 23:01:40 +08:00
|
|
|
|
|
|
|
// Delete
|
|
|
|
await this.startNewPoll();
|
|
|
|
await this.modPage.waitAndClick(e.deletePollOption);
|
|
|
|
await this.modPage.screenshot(testName, '04-after-delete-option');
|
2021-10-20 04:12:00 +08:00
|
|
|
await this.modPage.waitAndClick(e.startPoll);
|
2021-10-25 23:01:40 +08:00
|
|
|
await this.userPage.screenshot(testName, '04-userPage-options-after-delete');
|
|
|
|
|
|
|
|
const optionWasRemoved = initialRespCount - 1 == await this.getAnswerOptionCount();
|
|
|
|
if (!optionWasRemoved) {
|
|
|
|
await this.modPage.logger('Cannot delete choice option');
|
|
|
|
return false;
|
2021-10-20 04:12:00 +08:00
|
|
|
}
|
2021-10-25 23:01:40 +08:00
|
|
|
|
|
|
|
// Edit
|
|
|
|
await this.startNewPoll();
|
|
|
|
await this.typeOnLastChoiceInput();
|
|
|
|
await this.modPage.screenshot(testName, '05-after-edit-option');
|
|
|
|
await this.modPage.waitAndClick(e.startPoll);
|
|
|
|
await this.userPage.screenshot(testName, '05-userPage-options-after-edit');
|
|
|
|
|
|
|
|
const optionWasEdited = (initialRespCount == await this.getAnswerOptionCount()) && await this.checkLastOptionText();
|
|
|
|
if (!optionWasEdited) {
|
|
|
|
await this.modPage.logger('Cannot edit choice option');
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2021-10-20 04:12:00 +08:00
|
|
|
} catch (err) {
|
|
|
|
await this.modPage.logger(err);
|
2021-02-17 04:57:10 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2021-10-25 23:01:40 +08:00
|
|
|
|
|
|
|
async startNewPoll() {
|
|
|
|
const hasPollStarted = await this.modPage.page.evaluate(checkElement, e.pollMenuButton);
|
|
|
|
if (hasPollStarted) {
|
|
|
|
await this.modPage.waitAndClick(e.closePollingMenu);
|
|
|
|
await this.userPage.waitForElementHandleToBeRemoved(e.pollingContainer);
|
|
|
|
}
|
|
|
|
await util.openPoll(this.modPage);
|
|
|
|
}
|
|
|
|
|
|
|
|
async getAnswerOptionCount() {
|
|
|
|
await this.userPage.waitForSelector(e.pollingContainer);
|
|
|
|
return this.userPage.page.evaluate(getElementLength, e.pollAnswerOptionBtn);
|
|
|
|
}
|
|
|
|
|
|
|
|
async typeOnLastChoiceInput() {
|
|
|
|
const allInputs = await this.modPage.page.$$(e.pollOptionItem);
|
|
|
|
const lastInput = allInputs[allInputs.length - 1];
|
|
|
|
await this.modPage.page.evaluate(el => el.value = '', lastInput);
|
|
|
|
await lastInput.type(this.newInputText);
|
|
|
|
}
|
|
|
|
|
|
|
|
async checkLastOptionText() {
|
|
|
|
await this.userPage.waitForSelector(e.pollingContainer);
|
|
|
|
const answerOptions = await this.userPage.page.$$(e.pollAnswerOptionBtn);
|
|
|
|
const lastOptionText = await this.userPage.page.evaluate(el => el.textContent, answerOptions[answerOptions.length - 1]);
|
|
|
|
return lastOptionText == this.newInputText;
|
|
|
|
}
|
2021-02-17 04:57:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = exports = Polling;
|