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

355 lines
14 KiB
JavaScript
Raw 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);
2023-04-27 20:36:19 +08:00
await this.modPage.checkElementCount(e.chatUserMessageText, 0);
2022-01-20 03:50:59 +08:00
2023-04-27 20:36:19 +08:00
await this.modPage.type(e.chatBox, e.message);
2023-10-06 20:09:20 +08:00
await this.userPage.hasElement(e.typingIndicator);
2023-04-27 20:36:19 +08:00
await this.modPage.waitAndClick(e.sendButton);
await this.modPage.checkElementCount(e.chatUserMessageText, 1);
}
async sendPrivateMessage() {
await openPrivateChat(this.modPage);
await this.modPage.waitForSelector(e.hidePrivateChat);
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.waitForSelector(e.hidePrivateChat);
// check sent messages
await this.modPage.hasText(e.chatUserMessageText, e.message1);
await this.userPage.hasText(e.chatUserMessageText, e.message1);
// userPage send message
await this.userPage.type(e.chatBox, e.message2);
2023-10-06 20:09:20 +08:00
await this.modPage.hasElement(e.typingIndicator);
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);
await this.userPage.hasText(`${e.chatUserMessageText}>>nth=1`, e.message2);
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.waitForSelector(e.chatUserMessageText);
2022-01-20 03:50:59 +08:00
// 1 message
2023-04-27 20:36:19 +08:00
await this.modPage.checkElementCount(e.chatUserMessageText, userMessageTextCount + 1);
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.chatUserMessageText, 'The public chat history was cleared by a moderator');
2022-01-20 03:50:59 +08:00
}
async copyChat(context) {
2022-03-29 21:53:07 +08:00
const { publicChatOptionsEnabled } = getSettings();
test.fail(!publicChatOptionsEnabled, 'Public chat options (save and copy) are disabled');
2022-01-20 03:50:59 +08:00
await openPublicChat(this.modPage);
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
2023-04-27 20:36:19 +08:00
await this.modPage.waitForSelector(e.chatUserMessageText);
await this.modPage.waitAndClick(e.chatCopy);
2022-01-20 03:50:59 +08:00
// enable access to browser context clipboard
2023-04-27 20:36:19 +08:00
const copiedText = await this.modPage.getCopiedText(context);
2022-01-20 03:50:59 +08:00
const check = copiedText.includes(`${p.fullName}: ${e.message}`);
2022-09-17 05:02:32 +08:00
await expect(check).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();
test.fail(!publicChatOptionsEnabled, 'Public chat options (save and copy) are disabled');
await openPublicChat(this.modPage);
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.waitForSelector(e.chatUserMessageText);
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);
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.waitForSelector(e.chatUserMessageText);
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.waitForSelector(e.errorTypingIndicator); // warning below input message saying it has exceeded the maximum of characters
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);
}
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();
test.fail(!emojiPickerEnabled, 'Emoji Picker is disabled');
await openPublicChat(this.modPage);
2023-04-27 20:36:19 +08:00
const message = this.modPage.getLocator(e.chatUserMessageText);
2022-09-17 04:26:47 +08:00
await expect(message).toHaveCount(0);
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);
2022-09-17 04:26:47 +08:00
await expect(message).toHaveCount(1);
}
async emojiCopyChat(context) {
const { emojiPickerEnabled } = getSettings();
test.fail(!emojiPickerEnabled, 'Emoji Picker is disabled');
await openPublicChat(this);
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.waitForSelector(e.chatUserMessageText);
await this.waitAndClick(e.chatCopy);
const copiedText = await this.getCopiedText(context);
const check = copiedText.includes(`${p.fullName}: ${e.frequentlyUsedEmoji}`);
2022-09-17 05:02:32 +08:00
await expect(check).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).toContainText(this.userPage.username);
const chatMessageCount = await this.modPage.getSelectorCount(e.chatUserMessageText);
await this.modPage.hasElement(e.hidePrivateChat);
await this.modPage.hasElement(e.closePrivateChat);
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);
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);
}
2022-09-17 04:26:47 +08:00
async emojiSaveChat(testInfo) {
const { emojiPickerEnabled } = getSettings();
test.fail(!emojiPickerEnabled, 'Emoji Picker is disabled');
await openPublicChat(this);
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.waitForSelector(e.chatUserMessageText);
await this.waitAndClick(e.chatOptions);
2023-02-16 02:41:21 +08:00
const chatSaveLocator = this.getLocator(e.chatSave);
const { content } = await this.handleDownload(chatSaveLocator, testInfo);
2022-09-17 04:26:47 +08:00
const dataToCheck = [
this.meetingId,
this.username,
e.frequentlyUsedEmoji,
];
await checkTextContent(content, dataToCheck);
}
2023-04-27 20:36:19 +08:00
async emojiSendPrivateChat() {
const { emojiPickerEnabled } = getSettings();
test.fail(!emojiPickerEnabled, 'Emoji Picker is disabled');
await openPrivateChat(this.modPage);
await this.modPage.waitForSelector(e.hidePrivateChat);
await sleep(500); // prevent a race condition when running on a deployed server
// modPage send message
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.waitForSelector(e.hidePrivateChat);
// check sent messages
await this.modPage.hasText(e.chatUserMessageText, e.frequentlyUsedEmoji);
await this.userPage.hasText(e.chatUserMessageText, e.frequentlyUsedEmoji);
// 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);
await this.userPage.hasText(e.privateChat, e.frequentlyUsedEmoji);
await this.modPage.waitAndClick(e.chatButton);
}
2022-09-17 04:26:47 +08:00
async autoConvertEmojiPublicChat() {
const { autoConvertEmojiEnabled } = getSettings();
test.fail(!autoConvertEmojiEnabled, 'Auto Convert Emoji is disabled');
2023-04-27 20:36:19 +08:00
try {
await this.modPage.hasElement(e.hidePrivateChat);
await this.modPage.waitAndClick(e.chatButton);
} catch {
2023-09-27 03:41:58 +08:00
await this.modPage.hasElement(e.hidePublicChat);
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);
2023-04-27 20:36:19 +08:00
await this.modPage.type(e.chatBox, e.autoConvertEmojiMessage);
await this.modPage.waitAndClick(e.sendButton);
await this.modPage.waitForSelector(e.chatUserMessageText);
await this.modPage.checkElementCount(e.chatUserMessageText, 2);
2022-09-17 04:26:47 +08:00
}
async autoConvertEmojiCopyChat(context) {
const { autoConvertEmojiEnabled } = getSettings();
test.fail(!autoConvertEmojiEnabled, 'Auto Convert Emoji is disabled');
await openPublicChat(this);
2022-09-17 04:26:47 +08:00
await this.type(e.chatBox, e.autoConvertEmojiMessage);
await this.waitAndClick(e.sendButton);
await this.waitAndClick(e.chatOptions);
await this.waitForSelector(e.chatUserMessageText);
await this.waitAndClick(e.chatCopy);
const copiedText = await this.getCopiedText(context);
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();
test.fail(!autoConvertEmojiEnabled, 'Auto Convert Emoji is disabled');
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);
await this.modPage.waitForSelector(e.chatUserMessageText);
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);
}
2022-12-01 19:19:03 +08:00
2023-04-27 20:36:19 +08:00
async autoConvertEmojiSendPrivateChat() {
const { autoConvertEmojiEnabled } = getSettings();
test.fail(!autoConvertEmojiEnabled, 'Auto Convert Emoji is disabled');
2022-12-01 19:19:03 +08:00
2023-04-27 20:36:19 +08:00
await openPrivateChat(this.modPage);
await this.modPage.waitForSelector(e.hidePrivateChat);
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);
await this.userPage.waitUntilHaveCountSelector(e.chatButton, 2);
//await openPrivateChat(this.userPage);
await this.userPage.waitAndClick(`${e.chatButton}>>nth=1`);
2023-04-27 20:36:19 +08:00
await this.userPage.waitForSelector(e.hidePrivateChat);
// check sent messages
await checkLastMessageSent(this.modPage, e.convertedEmojiMessage)
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).toHaveText(e.convertedEmojiMessage);
const lastMessageLocatorUser = await this.userPage.getLocator(e.chatUserMessageText).last()
await expect(lastMessageLocatorUser).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.waitForSelector(e.sendButton);
await this.userPage.waitAndClick(e.optionsButton);
await this.userPage.waitAndClick(e.logout);
await this.modPage.hasElement(e.partnerDisconnectedMessage, ELEMENT_WAIT_LONGER_TIME);
await this.modPage.wasRemoved(e.sendButton);
2023-04-27 20:36:19 +08:00
}
2022-01-20 03:50:59 +08:00
}
exports.Chat = Chat;