bigbluebutton-Github/bigbluebutton-tests/playwright/chat/chat.js

391 lines
20 KiB
JavaScript
Raw Permalink Normal View History

2022-03-29 21:53:07 +08:00
const { expect, default: test } = require('@playwright/test');
const { openPublicChat, openPrivateChat, checkLastMessageSent } = require('./util');
2022-01-20 03:50:59 +08:00
const p = require('../core/parameters');
const e = require('../core/elements');
2022-03-21 23:04:43 +08:00
const { checkTextContent } = require('../core/util');
2022-03-29 21:53:07 +08:00
const { getSettings } = require('../core/settings');
2023-04-27 20:36:19 +08:00
const { MultiUsers } = require('../user/multiusers');
const { sleep } = require('../core/helpers');
const { ELEMENT_WAIT_LONGER_TIME } = require('../core/constants');
2022-01-20 03:50:59 +08:00
2023-04-27 20:36:19 +08:00
class Chat extends MultiUsers {
constructor(browser, context) {
super(browser, context);
2022-01-20 03:50:59 +08:00
}
async sendPublicMessage() {
await openPublicChat(this.modPage);
await this.modPage.checkElementCount(e.chatUserMessageText, 0, 'should have none message on the public chat');
2022-01-20 03:50:59 +08:00
2023-04-27 20:36:19 +08:00
await this.modPage.type(e.chatBox, e.message);
await this.userPage.hasElement(e.typingIndicator, 'should display the typing indicator element');
await this.modPage.page.click(e.sendButton);
await this.modPage.checkElementCount(e.chatUserMessageText, 1, 'should have on message on the public chat');
2023-04-27 20:36:19 +08:00
}
async sendPrivateMessage() {
await openPrivateChat(this.modPage);
await this.modPage.hasElement(e.hidePrivateChat, 'should display the hide private chat element when opening a private chat');
2023-04-27 20:36:19 +08:00
await sleep(500); // prevent a race condition when running on a deployed server
// modPage send message
await this.modPage.type(e.chatBox, e.message1);
await this.modPage.waitAndClick(e.sendButton);
await this.userPage.waitUntilHaveCountSelector(e.chatButton, 2);
await this.userPage.waitAndClickElement(e.chatButton, 1);
await this.userPage.hasElement(e.hidePrivateChat, 'should display the hide private chat element when opening a private chat');
2023-04-27 20:36:19 +08:00
// check sent messages
await this.modPage.hasText(e.chatUserMessageText, e.message1, 'should display the message sent by the moderator');
await this.userPage.hasText(e.chatUserMessageText, e.message1, 'should display the message sent by the moderator for the attende');
2023-04-27 20:36:19 +08:00
// userPage send message
await this.userPage.type(e.chatBox, e.message2);
await this.modPage.hasElement(e.typingIndicator, 'should display the typing indicator for the moderator');
2023-04-27 20:36:19 +08:00
await this.userPage.waitAndClick(e.sendButton);
// check sent messages
await this.modPage.hasText(`${e.chatUserMessageText}>>nth=1`, e.message2, 'should display the message "Hello User1" for the moderator');
await this.userPage.hasText(`${e.chatUserMessageText}>>nth=1`, e.message2, 'should display the message "Hello User1" for the moderator');
2023-04-27 20:36:19 +08:00
await this.modPage.waitAndClick(e.chatButton);
await this.userPage.waitAndClick(e.chatButton);
2022-01-20 03:50:59 +08:00
}
async clearChat() {
await openPublicChat(this.modPage);
2022-01-20 03:50:59 +08:00
2023-04-27 20:36:19 +08:00
const userMessageTextCount = await this.modPage.getSelectorCount(e.chatUserMessageText);
await this.modPage.type(e.chatBox, e.message);
await this.modPage.waitAndClick(e.sendButton);
await this.modPage.hasElement(e.chatUserMessageText, 'should display a message sent by the moderator');
2022-01-20 03:50:59 +08:00
// 1 message
await this.modPage.checkElementCount(e.chatUserMessageText, userMessageTextCount + 1, 'should display one message');
2022-01-20 03:50:59 +08:00
// clear
2023-04-27 20:36:19 +08:00
await this.modPage.waitAndClick(e.chatOptions);
await this.modPage.waitAndClick(e.chatClear);
await this.modPage.hasText(e.chatNotificationMessageText, 'The public chat history was cleared by a moderator', 'should display the message where the chat has been cleared');
2022-01-20 03:50:59 +08:00
}
async copyChat() {
2022-03-29 21:53:07 +08:00
const { publicChatOptionsEnabled } = getSettings();
2022-01-20 03:50:59 +08:00
await openPublicChat(this.modPage);
2023-10-31 20:31:01 +08:00
if(!publicChatOptionsEnabled) {
2023-11-16 20:00:22 +08:00
await this.modPage.waitAndClick(e.chatOptions);
await this.modPage.hasElement(e.chatClear, 'should display the option to clear the chat');
return this.modPage.wasRemoved(e.chatCopy, 'should not display the option to copy the chat');
2023-10-31 20:31:01 +08:00
}
2022-01-20 03:50:59 +08:00
// sending a message
2023-04-27 20:36:19 +08:00
await this.modPage.type(e.chatBox, e.message);
await this.modPage.waitAndClick(e.sendButton);
2022-01-20 03:50:59 +08:00
2023-04-27 20:36:19 +08:00
await this.modPage.waitAndClick(e.chatOptions);
2022-01-20 03:50:59 +08:00
await this.modPage.hasElement(e.chatUserMessageText, 'should display the message sent by the moderator');
2023-04-27 20:36:19 +08:00
await this.modPage.waitAndClick(e.chatCopy);
2022-01-20 03:50:59 +08:00
// enable access to browser context clipboard
const copiedText = await this.modPage.getCopiedText(this.modPage.context);
2022-01-20 03:50:59 +08:00
const check = copiedText.includes(`${p.fullName}: ${e.message}`);
await expect(check, 'should display on the copied chat the same message that was sent on the public chat').toBeTruthy();
2022-01-20 03:50:59 +08:00
}
2022-03-21 23:04:43 +08:00
async saveChat(testInfo) {
2022-03-29 21:53:07 +08:00
const { publicChatOptionsEnabled } = getSettings();
await openPublicChat(this.modPage);
2023-10-31 20:31:01 +08:00
if(!publicChatOptionsEnabled) {
await this.modPage.waitAndClick(e.chatOptions);
return this.modPage.wasRemoved(e.chatSave, 'chat save option should not be displayed');
2023-10-31 20:31:01 +08:00
}
2023-04-27 20:36:19 +08:00
await this.modPage.type(e.chatBox, e.message);
await this.modPage.waitAndClick(e.sendButton);
await this.modPage.hasElement(e.chatUserMessageText, 'should display the message sent by the moderator on the public chat');
2023-04-27 20:36:19 +08:00
await this.modPage.waitAndClick(e.chatOptions);
const chatSaveLocator = this.modPage.getLocator(e.chatSave);
const { content } = await this.modPage.handleDownload(chatSaveLocator, testInfo);
2022-03-21 23:04:43 +08:00
const dataToCheck = [
2023-04-27 20:36:19 +08:00
this.modPage.meetingId,
this.modPage.username,
2022-03-21 23:04:43 +08:00
e.message,
];
await checkTextContent(content, dataToCheck, 'should display the same message on the saved chat message and the message sent on the public chat');
2022-01-20 03:50:59 +08:00
}
async characterLimit() {
await openPublicChat(this.modPage);
2022-01-20 03:50:59 +08:00
2022-03-29 21:53:07 +08:00
const { maxMessageLength } = getSettings();
const initialMessagesCount = await this.modPage.getSelectorCount(e.chatUserMessageText);
2023-04-27 20:36:19 +08:00
await this.modPage.page.fill(e.chatBox, e.uniqueCharacterMessage.repeat(maxMessageLength));
await this.modPage.waitAndClick(e.sendButton);
await this.modPage.hasElement(e.chatUserMessageText, 'should display only one message text sent by the user on the public chat');
await this.modPage.checkElementCount(e.chatUserMessageText, initialMessagesCount + 1);
2023-04-27 20:36:19 +08:00
await this.modPage.page.fill(e.chatBox, e.uniqueCharacterMessage.repeat(maxMessageLength));
await this.modPage.type(e.chatBox, '123'); // it should has no effect
await this.modPage.hasElement(e.errorTypingIndicator, 'Should appear the warning message below the chat box');
2023-04-27 20:36:19 +08:00
await this.modPage.waitAndClick(e.sendButton);
await this.modPage.checkElementCount(e.chatUserMessageText, initialMessagesCount + 2);
2022-01-20 03:50:59 +08:00
}
async emptyMessage() {
await openPublicChat(this.modPage);
2022-01-20 03:50:59 +08:00
2023-04-27 20:36:19 +08:00
const userMessageTextCount = await this.modPage.getSelectorCount(e.chatUserMessageText);
await this.modPage.waitAndClick(e.sendButton);
await this.modPage.checkElementCount(e.chatUserMessageText, userMessageTextCount, 'should have none messages on the chat');
2023-04-27 20:36:19 +08:00
}
async copyPastePublicMessage() {
await this.modPage.type(e.chatBox, 'test');
await this.modPage.waitAndClick(e.sendButton);
await checkLastMessageSent(this.modPage, /test/);
const text = await this.modPage.getLocator(e.chatUserMessageText).last().boundingBox();
await this.modPage.mouseDoubleClick(text.x, text.y);
await this.modPage.press('Control+KeyC');
await this.modPage.getLocator(e.chatBox).focus();
await this.modPage.press('Control+KeyV');
await this.modPage.type(e.chatBox, '2');
2023-04-27 20:36:19 +08:00
await this.modPage.waitAndClick(e.sendButton);
await checkLastMessageSent(this.modPage, /test2/);
2022-01-20 03:50:59 +08:00
}
2022-08-30 20:28:34 +08:00
2022-09-17 04:26:47 +08:00
async sendEmoji() {
const { emojiPickerEnabled } = getSettings();
await openPublicChat(this.modPage);
2023-11-01 20:26:35 +08:00
if(!emojiPickerEnabled) {
await this.modPage.hasElement(e.chatBox, 'should display the chat box element');
return this.modPage.wasRemoved(e.emojiPickerButton, 'should not display the emoji picker button element');
2023-11-01 20:26:35 +08:00
}
2023-04-27 20:36:19 +08:00
const message = this.modPage.getLocator(e.chatUserMessageText);
await expect(message, 'should not display any messages on the public chat').toHaveCount(0);
2024-08-01 04:31:59 +08:00
2023-04-27 20:36:19 +08:00
await this.modPage.waitAndClick(e.emojiPickerButton);
await this.modPage.waitAndClick(e.emojiSent);
await this.modPage.waitAndClick(e.sendButton);
2022-09-17 04:26:47 +08:00
2023-04-27 20:36:19 +08:00
await this.modPage.waitForSelector(e.chatUserMessageText);
await expect(message, 'should display only one message that contains an emoji on the public chat').toHaveCount(1);
2022-09-17 04:26:47 +08:00
}
async emojiCopyChat(context) {
const { emojiPickerEnabled } = getSettings();
await openPublicChat(this);
2023-11-01 20:26:35 +08:00
if(!emojiPickerEnabled) {
await this.modPage.hasElement(e.chatBox, 'should display the chat box element on the public chat');
return this.modPage.wasRemoved(e.emojiPickerButton, 'should not display the emoji picker button on the public chat');
2023-11-01 20:26:35 +08:00
}
2022-09-17 04:26:47 +08:00
await this.waitAndClick(e.emojiPickerButton);
await this.waitAndClick(e.emojiSent);
await this.waitAndClick(e.sendButton);
await this.waitAndClick(e.chatOptions);
await this.hasElement(e.chatUserMessageText, 'should have one message that contains an emoji on the public chat');
2022-09-17 04:26:47 +08:00
await this.waitAndClick(e.chatCopy);
const copiedText = await this.getCopiedText(context);
const check = copiedText.includes(`${p.fullName}: ${e.frequentlyUsedEmoji}`);
await expect(check, 'should the copied text be the same as the message on the chat').toBeTruthy();
2022-09-17 04:26:47 +08:00
}
2023-04-27 20:36:19 +08:00
async closePrivateChat() {
await openPrivateChat(this.modPage);
await this.modPage.waitUntilHaveCountSelector(e.chatButton, 2);
const privateChatLocator = this.modPage.getLocatorByIndex(e.chatButton, -1);
expect(privateChatLocator, 'should the private chat contain the user name').toContainText(this.userPage.username);
2023-04-27 20:36:19 +08:00
const chatMessageCount = await this.modPage.getSelectorCount(e.chatUserMessageText);
await this.modPage.hasElement(e.hidePrivateChat, 'the private chat should display the hide private chat element when opened');
await this.modPage.hasElement(e.closePrivateChat, 'the private chat should display the close private chat element when opened');
2023-04-27 20:36:19 +08:00
await this.modPage.checkElementCount(e.chatUserMessageText, chatMessageCount);
await this.modPage.type(e.chatBox, e.message1);
await this.modPage.waitAndClick(e.sendButton);
await this.userPage.waitUntilHaveCountSelector(e.chatButton, 2);
await this.modPage.waitAndClick(e.closePrivateChat);
await this.modPage.wasRemoved(e.hidePrivateChat, 'should the hide private chat element not be displayed');
2023-04-27 20:36:19 +08:00
await this.modPage.waitUntilHaveCountSelector(e.chatButton, 1, ELEMENT_WAIT_LONGER_TIME);
const userChatCount = await this.userPage.getSelectorCount(e.chatButton);
await this.modPage.waitAndClick(e.chatButton);
expect(userChatCount, '').toBe(2);
2023-04-27 20:36:19 +08:00
}
2022-09-17 04:26:47 +08:00
async emojiSaveChat(testInfo) {
const { emojiPickerEnabled } = getSettings();
2023-11-01 20:26:35 +08:00
await openPublicChat(this.modPage);
if(!emojiPickerEnabled) {
await this.modPage.hasElement(e.chatBox, 'should display the public chat box');
return this.modPage.wasRemoved(e.emojiPickerButton, 'should not display the emoji picker button');
2023-11-01 20:26:35 +08:00
}
await this.modPage.waitAndClick(e.emojiPickerButton);
await this.modPage.waitAndClick(e.emojiSent);
await this.modPage.waitAndClick(e.sendButton);
await this.modPage.hasElement(e.chatUserMessageText, 'should display a message on the public chat with an emoji');
2023-11-01 20:26:35 +08:00
await this.modPage.waitAndClick(e.chatOptions);
const chatSaveLocator = this.modPage.getLocator(e.chatSave);
const { content } = await this.modPage.handleDownload(chatSaveLocator, testInfo);
2022-09-17 04:26:47 +08:00
const dataToCheck = [
2023-11-01 20:26:35 +08:00
this.modPage.meetingId,
this.modPage.username,
2022-09-17 04:26:47 +08:00
e.frequentlyUsedEmoji,
];
await checkTextContent(content, dataToCheck, 'should the save chat message with an emoji be the same as message sent on the public chat');
2022-09-17 04:26:47 +08:00
}
2023-04-27 20:36:19 +08:00
async emojiSendPrivateChat() {
const { emojiPickerEnabled } = getSettings();
await openPrivateChat(this.modPage);
await this.modPage.hasElement(e.hidePrivateChat, 'should display the hide private chat element when a private chat is open');
2023-04-27 20:36:19 +08:00
await sleep(500); // prevent a race condition when running on a deployed server
// modPage send message
2023-11-01 20:26:35 +08:00
if(!emojiPickerEnabled) {
await this.modPage.hasElement(e.chatBox, 'should display the public chat box');
return this.modPage.wasRemoved(e.emojiPickerButton, 'should not display the emoji picker button on the public chat');
2023-11-01 20:26:35 +08:00
}
2023-04-27 20:36:19 +08:00
await this.modPage.waitAndClick(e.emojiPickerButton);
await this.modPage.waitAndClick(e.emojiSent);
await this.modPage.waitAndClick(e.sendButton);
await this.userPage.waitUntilHaveCountSelector(e.chatButton, 2);
await this.userPage.waitAndClickElement(e.chatButton, 1);
await this.userPage.hasElement(e.hidePrivateChat, 'should display the hide private chat element when the attende opens the private chat');
2023-04-27 20:36:19 +08:00
// check sent messages
await this.modPage.hasText(e.chatUserMessageText, e.frequentlyUsedEmoji, 'should display the emoji sent by the moderator on the private chat');
await this.userPage.hasText(e.chatUserMessageText, e.frequentlyUsedEmoji, 'should display for the user the emoji sent by the moderator on the private chat');
2023-04-27 20:36:19 +08:00
// userPage send message
await this.userPage.waitAndClick(e.emojiPickerButton);
await this.userPage.waitAndClick(e.emojiSent);
await this.userPage.waitAndClick(e.sendButton);
// check sent messages
await this.modPage.hasText(e.privateChat, e.frequentlyUsedEmoji, 'should display the emoji sent by the attendee on the private chat');
await this.userPage.hasText(e.privateChat, e.frequentlyUsedEmoji, 'should display the emoji on the private chat for the user');
2023-04-27 20:36:19 +08:00
await this.modPage.waitAndClick(e.chatButton);
}
2022-09-17 04:26:47 +08:00
async autoConvertEmojiPublicChat() {
const { autoConvertEmojiEnabled } = getSettings();
2023-04-27 20:36:19 +08:00
try {
await this.modPage.hasElement(e.hidePrivateChat, 'should display the hide private chat element for the moderator when private chat is open');
2023-04-27 20:36:19 +08:00
await this.modPage.waitAndClick(e.chatButton);
} catch {
await this.modPage.hasElement(e.hidePublicChat, 'should display the hide public chat element for the moderator when public chat is open');
2023-04-27 20:36:19 +08:00
}
2022-09-17 04:26:47 +08:00
await this.modPage.waitAndClick(e.chatOptions);
await this.modPage.waitAndClick(e.chatClear);
await this.modPage.checkElementCount(e.chatUserMessageText, 1, 'should display only one message on the public chat');
2023-04-27 20:36:19 +08:00
await this.modPage.type(e.chatBox, e.autoConvertEmojiMessage);
await this.modPage.waitAndClick(e.sendButton);
2023-11-01 20:26:35 +08:00
if(!autoConvertEmojiEnabled) {
await this.modPage.hasElement(e.chatBox, 'should display a chat box on the public chat');
return this.modPage.hasText(`${e.chatUserMessageText}>>nth=1`, ":)", 'should not display the emoji converted');
2023-11-01 20:26:35 +08:00
}
await this.modPage.hasElement(e.chatUserMessageText, 'should display the user messages sent on the chat');
await this.modPage.checkElementCount(e.chatUserMessageText, 2, 'should display two messages on the public chat');
2022-09-17 04:26:47 +08:00
}
async autoConvertEmojiCopyChat(context) {
const { autoConvertEmojiEnabled } = getSettings();
await openPublicChat(this.modPage);
await this.modPage.type(e.chatBox, e.autoConvertEmojiMessage);
await this.modPage.waitAndClick(e.sendButton);
2023-11-08 19:50:16 +08:00
if(!autoConvertEmojiEnabled) {
await this.modPage.hasElement(e.chatBox, 'should display chat box on the public chat for the moderator');
return this.modPage.hasText(`${e.chatUserMessageText}>>nth=1`, ":)", 'should display a message on the public chat with an emoji no converted');
2023-11-08 19:50:16 +08:00
}
await this.modPage.waitAndClick(e.chatOptions);
2022-09-17 04:26:47 +08:00
await this.modPage.hasElement(e.chatUserMessageText, 'should display a message sent by user on the public chat');
await this.modPage.waitAndClick(e.chatCopy);
2022-09-17 04:26:47 +08:00
const copiedText = await this.modPage.getCopiedText(context);
2022-09-17 04:26:47 +08:00
const check = copiedText.includes(`${p.fullName}: ${e.convertedEmojiMessage}`);
2022-09-17 05:02:32 +08:00
await expect(check).toBeTruthy();
2022-09-17 04:26:47 +08:00
}
async autoConvertEmojiSaveChat(testInfo) {
const { autoConvertEmojiEnabled } = getSettings();
await openPublicChat(this.modPage);
2023-04-27 20:36:19 +08:00
await this.modPage.type(e.chatBox, e.autoConvertEmojiMessage);
await this.modPage.waitAndClick(e.sendButton);
2023-11-01 20:26:35 +08:00
if(!autoConvertEmojiEnabled) {
await this.modPage.hasElement(e.chatBox, 'should display the chat box on the public chat');
return this.modPage.hasText(`${e.chatUserMessageText}>>nth=1`, ':)', 'should display a message containing the emoji not converted');
2023-11-01 20:26:35 +08:00
}
await this.modPage.hasElement(e.chatUserMessageText, 'should display a message on the public chat');
2023-04-27 20:36:19 +08:00
await this.modPage.waitAndClick(e.chatOptions);
const chatSaveLocator = this.modPage.getLocator(e.chatSave);
const { content } = await this.modPage.handleDownload(chatSaveLocator, testInfo);
2022-09-17 04:26:47 +08:00
const dataToCheck = [
2023-04-27 20:36:19 +08:00
this.modPage.meetingId,
this.modPage.username,
2022-09-17 04:26:47 +08:00
e.convertedEmojiMessage,
];
await checkTextContent(content, dataToCheck, 'should the saved emoji from the chat be the same as the emoji sent on the chat');
2022-09-17 04:26:47 +08:00
}
2022-12-01 19:19:03 +08:00
2023-04-27 20:36:19 +08:00
async autoConvertEmojiSendPrivateChat() {
2023-11-01 22:28:38 +08:00
const { autoConvertEmojiEnabled, emojiPickerEnabled } = getSettings();
2022-12-01 19:19:03 +08:00
2023-04-27 20:36:19 +08:00
await openPrivateChat(this.modPage);
await this.modPage.hasElement(e.hidePrivateChat, 'should display the hide private chat element when the moderator has the private chat opened');
2023-04-27 20:36:19 +08:00
await sleep(500); // prevent a race condition when running on a deployed server
// modPage send message
await this.modPage.type(e.chatBox, e.autoConvertEmojiMessage);
await this.modPage.waitAndClick(e.sendButton);
2023-11-01 22:28:38 +08:00
if(!autoConvertEmojiEnabled && !emojiPickerEnabled) {
await this.modPage.hasElement(e.chatBox, 'should display the chat box on the private chat');
return this.modPage.hasText(`${e.chatUserMessageText}>>nth=0`, ":)", 'should display the message that the emoji is not converted');
2023-11-01 22:28:38 +08:00
} else if (!autoConvertEmojiEnabled) {
await this.modPage.hasElement(e.chatBox, 'should the chat box be displayed on the private chat');
return this.modPage.hasText(`${e.chatUserMessageText}>>nth=2`, ":)", 'should display the emoji not converted on the private chat');
2023-11-01 20:26:35 +08:00
}
2023-04-27 20:36:19 +08:00
await this.userPage.waitUntilHaveCountSelector(e.chatButton, 2);
await this.userPage.waitAndClickElement(e.chatButton, 1);
await this.userPage.hasElement(e.hidePrivateChat, 'should display the hide private chat element for the attende when the private chat is opened');
2023-04-27 20:36:19 +08:00
// check sent messages
await checkLastMessageSent(this.modPage, e.convertedEmojiMessage);
2023-04-27 20:36:19 +08:00
await checkLastMessageSent(this.userPage, e.convertedEmojiMessage);
// userPage send message
await this.userPage.type(e.chatBox, e.autoConvertEmojiMessage);
await this.userPage.waitAndClick(e.sendButton);
// check sent messages
const lastMessageLocator = await this.modPage.getLocator(e.chatUserMessageText).last();
await expect(lastMessageLocator, 'should the last message sent on private chat to be the auto converted emoji').toHaveText(e.convertedEmojiMessage);
const lastMessageLocatorUser = await this.userPage.getLocator(e.chatUserMessageText).last();
await expect(lastMessageLocatorUser, 'should the last message sent on private chat to be the auto converted emoji').toHaveText(e.convertedEmojiMessage);
2022-12-01 19:19:03 +08:00
}
2023-04-27 20:36:19 +08:00
async chatDisabledUserLeaves() {
await openPrivateChat(this.modPage);
await this.modPage.hasElement(e.sendButton, 'should display the send button on the private chat');
await this.userPage.logoutFromMeeting();
await this.modPage.hasElement(e.partnerDisconnectedMessage, 'should the attende be disconnected', ELEMENT_WAIT_LONGER_TIME);
await this.modPage.wasRemoved(e.sendButton, 'should the send button be removed because the attende left the meeting');
2023-04-27 20:36:19 +08:00
}
2022-01-20 03:50:59 +08:00
}
exports.Chat = Chat;