bigbluebutton-Github/bigbluebutton-tests/playwright/polling/poll.js

348 lines
14 KiB
JavaScript
Raw Normal View History

2022-06-08 02:52:22 +08:00
const { expect, test } = require('@playwright/test');
const { MultiUsers } = require('../user/multiusers');
2021-11-26 02:23:58 +08:00
const e = require('../core/elements');
const util = require('./util.js');
const { ELEMENT_WAIT_LONGER_TIME, ELEMENT_WAIT_TIME, ELEMENT_WAIT_EXTRA_LONG_TIME } = require('../core/constants');
2022-06-08 02:52:22 +08:00
const { getSettings } = require('../core/settings');
const { waitAndClearDefaultPresentationNotification } = require('../notifications/util');
const { uploadSinglePresentation, skipSlide } = require('../presentation/util');
const { sleep } = require('../core/helpers.js');
2021-11-26 02:23:58 +08:00
class Polling extends MultiUsers {
2021-11-26 02:23:58 +08:00
constructor(browser, context) {
super(browser, context);
2021-11-26 02:23:58 +08:00
this.newInputText = 'new option';
}
async createPoll() {
await util.startPoll(this.modPage);
await this.modPage.hasElement(e.pollMenuButton);
await this.modPage.hasElement(e.publishPollingLabel);
await this.modPage.hasElement(e.cancelPollBtn);
await this.userPage.hasElement(e.pollingContainer);
2023-04-28 20:30:29 +08:00
await this.modPage.waitAndClick(e.closePollingBtn);
2023-05-09 20:41:08 +08:00
await this.modPage.wasRemoved(e.closePollingBtn);
2021-11-26 02:23:58 +08:00
}
async pollAnonymous() {
await this.modPage.waitForSelector(e.whiteboard, ELEMENT_WAIT_LONGER_TIME);
2024-03-05 00:44:47 +08:00
await util.startPoll(this.modPage, true);
2021-11-26 02:23:58 +08:00
await this.modPage.waitForSelector(e.publishPollingLabel);
await this.userPage.waitAndClick(e.pollAnswerOptionBtn);
2021-12-01 22:02:26 +08:00
await this.userPage.wasRemoved(e.receivedAnswer);
2023-04-28 20:30:29 +08:00
await this.modPage.waitAndClick(e.closePollingBtn);
2023-05-09 20:41:08 +08:00
await this.modPage.wasRemoved(e.closePollingBtn);
2021-11-26 02:23:58 +08:00
}
async quickPoll() {
await util.uploadSPresentationForTestingPolls(this.modPage, e.questionSlideFileName);
2021-11-26 02:23:58 +08:00
// The slide needs to be uploaded and converted, so wait a bit longer for this step
await this.modPage.waitAndClick(e.quickPoll, ELEMENT_WAIT_LONGER_TIME);
2021-11-26 02:23:58 +08:00
await this.modPage.waitForSelector(e.pollMenuButton);
await this.userPage.hasElement(e.pollingContainer);
2023-04-28 20:30:29 +08:00
await this.modPage.waitAndClick(e.closePollingBtn);
2023-05-09 20:41:08 +08:00
await this.modPage.wasRemoved(e.closePollingBtn);
2021-11-26 02:23:58 +08:00
}
async pollUserResponse() {
await this.modPage.waitForSelector(e.whiteboard);
await util.openPoll(this.modPage);
await this.modPage.type(e.pollQuestionArea, e.pollQuestion);
await this.modPage.waitAndClick(e.userResponseBtn);
await this.modPage.waitAndClick(e.startPoll);
await this.userPage.waitForSelector(e.pollingContainer);
await this.userPage.type(e.pollAnswerOptionInput, e.answerMessage);
await this.userPage.waitAndClick(e.pollSubmitAnswer);
await this.modPage.hasText(e.userVoteLiveResult, e.answerMessage);
2021-11-26 02:23:58 +08:00
await this.modPage.waitAndClick(e.publishPollingLabel);
await this.modPage.wasRemoved(e.pollingContainer);
2021-11-26 02:23:58 +08:00
await this.modPage.hasElement(e.wbPollShape, ELEMENT_WAIT_LONGER_TIME);
await this.userPage.hasElement(e.wbPollShape);
2021-11-26 02:23:58 +08:00
}
async stopPoll() {
await this.modPage.waitForSelector(e.whiteboard, ELEMENT_WAIT_LONGER_TIME);
await util.startPoll(this.modPage);
await this.userPage.waitForSelector(e.pollingContainer);
await this.modPage.waitAndClick(e.cancelPollBtn);
await this.userPage.wasRemoved(e.pollingContainer);
2022-03-29 21:53:07 +08:00
2023-04-28 20:30:29 +08:00
await this.modPage.waitAndClick(e.closePollingBtn);
2023-05-09 20:41:08 +08:00
await this.modPage.wasRemoved(e.closePollingBtn);
2021-11-26 02:23:58 +08:00
}
async manageResponseChoices() {
await this.modPage.waitForSelector(e.whiteboard, ELEMENT_WAIT_LONGER_TIME);
await this.startNewPoll();
const initialRespCount = await this.modPage.getSelectorCount(e.pollOptionItem);
// Add
await this.modPage.waitAndClick(e.addPollItem);
await this.typeOnLastChoiceInput();
await this.modPage.waitAndClick(e.startPoll);
await expect(initialRespCount + 1).toEqual(await this.getAnswerOptionCount());
await this.checkLastOptionText();
// Delete
await this.startNewPoll();
await this.modPage.waitAndClick(e.deletePollOption);
await this.modPage.waitAndClick(e.startPoll);
await expect(initialRespCount - 1).toEqual(await this.getAnswerOptionCount());
// Edit
await this.startNewPoll();
await this.typeOnLastChoiceInput();
await this.modPage.waitAndClick(e.startPoll);
await expect(initialRespCount).toEqual(await this.getAnswerOptionCount());
await this.checkLastOptionText();
2023-04-28 20:30:29 +08:00
await this.modPage.waitAndClick(e.closePollingBtn);
2021-11-26 02:23:58 +08:00
}
2023-04-28 20:30:29 +08:00
async notAbleStartNewPollWithoutPresentation() {
await this.modPage.waitForSelector(e.whiteboard, ELEMENT_WAIT_LONGER_TIME);
2023-04-28 20:30:29 +08:00
await this.modPage.waitAndClick(e.actions);
await this.modPage.waitAndClick(e.managePresentations);
const allRemovePresentationBtn = await this.modPage.getLocator(e.removePresentation).all();
// reversing the order of clicking is needed to avoid failure as the tooltip shows in front of the below button
const reversedRemovePresentationButtons = allRemovePresentationBtn.reverse();
for (const removeBtn of reversedRemovePresentationButtons) {
await removeBtn.click({ timeout: ELEMENT_WAIT_TIME });
}
await this.modPage.waitAndClick(e.confirmManagePresentation);
2023-04-28 20:30:29 +08:00
await this.modPage.waitAndClick(e.actions);
await this.modPage.waitAndClick(e.polling);
await this.modPage.hasElement(e.noPresentation);
}
2023-05-06 02:12:32 +08:00
async customInput() {
await util.uploadSPresentationForTestingPolls(this.modPage, e.uploadPresentationFileName);
await this.modPage.waitForSelector(e.whiteboard, 20000);
2022-10-26 04:12:59 +08:00
await this.modPage.waitAndClick(e.actions);
await this.modPage.waitAndClick(e.polling);
await this.modPage.waitAndClickElement(e.autoOptioningPollBtn);
await this.modPage.type(e.pollQuestionArea, 'Test');
await this.modPage.waitAndClick(e.addPollItem);
await this.modPage.type(e.pollOptionItem, 'test1');
await this.modPage.waitAndClick(e.addPollItem);
await this.modPage.type(e.pollOptionItem2, 'test2');
2022-10-26 04:12:59 +08:00
await this.modPage.waitAndClick(e.startPoll);
await this.userPage.hasElement(e.pollingContainer);
await this.userPage.waitAndClick(e.pollAnswerOptionBtn);
2022-10-26 04:12:59 +08:00
await this.modPage.hasText(e.currentPollQuestion, /Test/);
await this.modPage.hasText(e.userVoteLiveResult, '1');
2023-05-06 02:12:32 +08:00
await this.modPage.waitAndClick(e.closePollingBtn);
2023-05-09 20:41:08 +08:00
await this.modPage.wasRemoved(e.closePollingBtn);
2022-10-26 04:12:59 +08:00
}
async allowMultipleChoices() {
await this.modPage.waitAndClick(e.actions);
await this.modPage.waitAndClick(e.polling);
await this.modPage.waitAndClickElement(e.autoOptioningPollBtn);
await this.modPage.type(e.pollQuestionArea, 'Test');
await this.modPage.waitAndClickElement(e.allowMultiple);
await this.modPage.waitAndClick(e.addPollItem);
await this.modPage.waitAndClick(e.startPoll);
await this.modPage.hasElement(e.errorNoValueInput);
await this.modPage.type(e.pollOptionItem1, 'test1');
await this.modPage.waitAndClick(e.addPollItem);
await this.modPage.type(e.pollOptionItem2, 'test2');
await this.modPage.waitAndClick(e.startPoll);
await this.modPage.hasText(e.currentPollQuestion, /Test/);
2023-02-14 21:59:46 +08:00
await this.userPage.waitAndClick(e.firstPollAnswerOptionBtn);
await this.userPage.waitAndClick(e.secondPollAnswerOptionBtn);
2022-10-26 04:12:59 +08:00
await this.userPage.waitAndClickElement(e.submitAnswersMultiple);
await this.modPage.hasText(e.userVoteLiveResult, '1');
await this.modPage.hasText(e.userVoteLiveResult, '2');
2023-05-06 02:12:32 +08:00
await this.modPage.waitAndClick(e.closePollingBtn);
2023-05-09 20:41:08 +08:00
await this.modPage.wasRemoved(e.closePollingBtn);
2022-10-26 04:12:59 +08:00
}
async smartSlidesQuestions() {
2023-02-14 21:59:46 +08:00
await this.modPage.hasElement(e.whiteboard, ELEMENT_WAIT_LONGER_TIME);
await util.uploadSPresentationForTestingPolls(this.modPage, e.smartSlides1);
2023-09-12 00:37:23 +08:00
await this.userPage.hasElement(e.userListItem);
2022-11-26 03:54:32 +08:00
2023-05-25 23:58:44 +08:00
// Type Response
await this.modPage.waitAndClick(e.quickPoll, ELEMENT_WAIT_LONGER_TIME);
2022-10-26 04:12:59 +08:00
await this.userPage.hasElement(e.responsePollQuestion);
await this.userPage.type(e.pollAnswerOptionInput, 'test');
await this.userPage.waitAndClick(e.pollSubmitAnswer);
2023-05-06 02:12:32 +08:00
await this.userPage.wasRemoved(e.pollingContainer, ELEMENT_WAIT_LONGER_TIME);
await this.modPage.hasText(e.userVoteLiveResult, 'test');
2022-10-27 04:25:48 +08:00
2022-10-26 04:12:59 +08:00
await this.modPage.waitAndClick(e.publishPollingLabel);
await this.modPage.wasRemoved(e.pollingContainer);
2023-05-06 02:12:32 +08:00
2023-05-25 23:58:44 +08:00
// Multiple Choices
await sleep(500); // avoid error when the tooltip is in front of the button due to layout shift
await skipSlide(this.modPage);
2022-10-26 04:12:59 +08:00
await this.modPage.waitAndClick(e.quickPoll);
2023-05-06 02:12:32 +08:00
await this.userPage.waitAndClick(e.firstPollAnswerDescOption);
2023-05-25 23:58:44 +08:00
await this.userPage.waitAndClick(e.secondPollAnswerDescOption);
2022-10-26 04:12:59 +08:00
await this.userPage.waitAndClick(e.submitAnswersMultiple);
await this.modPage.hasText(e.userVoteLiveResult, 'A) 2222');
await this.modPage.hasText(e.userVoteLiveResult, 'B) 3333');
2022-11-26 03:54:32 +08:00
2022-10-26 04:12:59 +08:00
await this.modPage.waitAndClick(e.publishPollingLabel);
await this.modPage.wasRemoved(e.pollingContainer);
2023-05-25 23:58:44 +08:00
// One option answer
await sleep(500); // avoid error when the tooltip is in front of the button due to layout shift
await skipSlide(this.modPage);
2022-10-26 04:12:59 +08:00
await this.modPage.waitAndClick(e.quickPoll);
2023-05-25 23:58:44 +08:00
await this.userPage.waitAndClick(e.pollAnswerOptionE);
await this.modPage.hasText(e.userVoteLiveResult, 'E) 22222');
2023-05-25 23:58:44 +08:00
await this.modPage.waitAndClick(e.publishPollingLabel);
await this.modPage.wasRemoved(e.pollingContainer);
2022-10-26 04:12:59 +08:00
2023-05-25 23:58:44 +08:00
// Yes/No/Abstention
await sleep(500); // avoid error when the tooltip is in front of the button due to layout shift
await skipSlide(this.modPage);
2023-05-25 23:58:44 +08:00
await this.modPage.waitAndClick(e.yesNoOption);
await this.modPage.waitAndClick(e.yesNoAbstentionOption)
2023-05-06 02:12:32 +08:00
await this.userPage.waitAndClick(e.pollAnswerOptionBtn);
await this.modPage.hasText(e.userVoteLiveResult, 'Yes');
2022-11-26 03:54:32 +08:00
2022-10-26 04:12:59 +08:00
await this.modPage.waitAndClick(e.publishPollingLabel);
await this.modPage.wasRemoved(e.pollingContainer);
2022-10-26 04:12:59 +08:00
2023-05-25 23:58:44 +08:00
// True/False
await sleep(500); // avoid error when the tooltip is in front of the button due to layout shift
await skipSlide(this.modPage);
2022-10-26 04:12:59 +08:00
await this.modPage.waitAndClick(e.quickPoll);
2023-05-06 02:12:32 +08:00
await this.userPage.waitAndClick(e.pollAnswerOptionBtn);
await this.modPage.hasText(e.userVoteLiveResult, 'True');
2023-05-25 23:58:44 +08:00
await this.modPage.waitAndClick(e.publishPollingLabel);
2022-10-26 04:12:59 +08:00
await this.modPage.hasElementDisabled(e.nextSlide);
await this.modPage.wasRemoved(e.pollingContainer);
2022-10-26 04:12:59 +08:00
}
2023-05-06 02:12:32 +08:00
async pollResultsOnChat() {
const { pollChatMessage } = getSettings();
2023-11-08 19:50:16 +08:00
2023-05-06 02:12:32 +08:00
await this.modPage.waitForSelector(e.whiteboard, ELEMENT_WAIT_LONGER_TIME);
2024-02-28 22:34:23 +08:00
await util.startPoll(this.modPage);
await this.modPage.hasElementDisabled(e.publishPollingLabel);
await this.userPage.waitAndClick(e.pollAnswerOptionBtn);
await this.modPage.hasElement(e.publishPollingLabel);
await this.modPage.waitAndClick(e.publishPollingLabel);
2023-05-06 02:12:32 +08:00
const lastChatPollMessageTextModerator = await this.modPage.getLocator(e.chatPollMessageText).last();
2023-11-08 19:50:16 +08:00
if(!pollChatMessage) {
return expect(lastChatPollMessageTextModerator).toBeHidden({ ELEMENT_WAIT_TIME });
2023-11-08 19:50:16 +08:00
}
await expect(lastChatPollMessageTextModerator).toBeVisible();
const lastChatPollMessageTextUser = await this.userPage.getLocator(e.chatPollMessageText).last();
await expect(lastChatPollMessageTextUser).toBeVisible();
2023-05-06 02:12:32 +08:00
}
async pollResultsOnWhiteboard() {
await this.modPage.waitForSelector(e.whiteboard, ELEMENT_WAIT_LONGER_TIME);
2024-02-28 22:34:23 +08:00
await util.startPoll(this.modPage);
const wbDrawnRectangleLocator = await this.modPage.getLocator(e.wbPollShape);
const initialWbDrawnRectangleCount = await wbDrawnRectangleLocator.count();
2024-02-28 22:34:23 +08:00
await this.modPage.hasElementDisabled(e.publishPollingLabel);
await this.userPage.waitAndClick(e.pollAnswerOptionBtn);
await this.modPage.hasElement(e.publishPollingLabel);
await this.modPage.waitAndClick(e.publishPollingLabel);
await expect(wbDrawnRectangleLocator).toHaveCount(initialWbDrawnRectangleCount + 1);
2024-02-28 22:34:23 +08:00
const lastWbDrawnRectangleLocator = await wbDrawnRectangleLocator.last();
await expect(lastWbDrawnRectangleLocator).toBeVisible({ timeout: ELEMENT_WAIT_TIME});
2023-07-28 20:16:07 +08:00
const modWbLocator = this.modPage.getLocator(e.whiteboard);
const wbBox = await modWbLocator.boundingBox();
// poll results should be editable by the presenter
await lastWbDrawnRectangleLocator.dblclick({ timeout: ELEMENT_WAIT_TIME });
2023-07-28 20:16:07 +08:00
await this.modPage.page.mouse.down();
await this.modPage.page.mouse.move(wbBox.x + 0.7 * wbBox.width, wbBox.y + 0.7 * wbBox.height);
await this.modPage.page.mouse.up();
await lastWbDrawnRectangleLocator.dblclick({ timeout: ELEMENT_WAIT_TIME });
2023-07-28 20:16:07 +08:00
await this.modPage.page.keyboard.type('test');
await expect(lastWbDrawnRectangleLocator).toContainText('test');
2023-07-28 20:16:07 +08:00
// user turns to presenter to edit the poll results
await this.modPage.waitAndClick(e.userListItem);
await this.modPage.waitAndClick(e.makePresenter);
2024-02-28 22:34:23 +08:00
await this.userPage.waitAndClick(e.zoomInButton);
await this.userPage.waitAndClick(e.resetZoomButton);
const wbDrawnRectangleUserLocator = await this.userPage.getLocator(e.wbPollShape).last();
await wbDrawnRectangleUserLocator.dblclick({ timeout: ELEMENT_WAIT_TIME });
2023-07-28 20:16:07 +08:00
await this.userPage.page.keyboard.type('testUser');
await expect(wbDrawnRectangleUserLocator).toContainText('testUser');
2023-07-28 20:16:07 +08:00
await this.modPage.waitAndClick(e.currentUser);
await this.modPage.waitAndClick(e.takePresenter);
await this.userPage.waitAndClick(e.hidePublicChat);
2023-05-06 02:12:32 +08:00
}
async pollResultsInDifferentPresentation() {
await util.startPoll(this.modPage);
await this.userPage.waitAndClick(e.pollAnswerOptionBtn);
await util.uploadSPresentationForTestingPolls(this.modPage, e.questionSlideFileName);
2024-05-15 05:07:58 +08:00
await this.modPage.hasElement(e.quickPoll, ELEMENT_WAIT_LONGER_TIME);
2023-05-06 02:12:32 +08:00
await this.modPage.waitAndClick(e.publishPollingLabel);
// Check poll results
await this.modPage.hasElement(e.wbPollShape);
}
2023-05-06 02:12:32 +08:00
async startNewPoll() {
const hasPollStarted = await this.modPage.checkElement(e.pollMenuButton);
if (hasPollStarted) {
await this.modPage.waitAndClick(e.cancelPollBtn);
await this.userPage.wasRemoved(e.pollingContainer);
}
await util.openPoll(this.modPage);
}
async getAnswerOptionCount() {
await this.userPage.waitForSelector(e.pollingContainer);
return this.userPage.getSelectorCount(e.pollAnswerOptionBtn);
}
async typeOnLastChoiceInput() {
const lastInput = this.modPage.getLocatorByIndex(e.pollOptionItem, -1);
await lastInput.fill(this.newInputText);
}
async checkLastOptionText() {
await this.userPage.waitForSelector(e.pollingContainer);
const lastOptionText = this.userPage.getLocatorByIndex(e.pollAnswerOptionBtn, -1);
await expect(lastOptionText).toHaveText(this.newInputText);
}
2021-11-26 02:23:58 +08:00
}
2021-12-04 01:01:36 +08:00
exports.Polling = Polling;