Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Chat to serial mode #17745

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
287 changes: 203 additions & 84 deletions bigbluebutton-tests/playwright/chat/chat.js
Original file line number Diff line number Diff line change
@@ -1,57 +1,86 @@
const { expect, default: test } = require('@playwright/test');
const Page = require('../core/page');
const { openChat } = require('./util');
const { openChat, openPrivateChat, checkLastMessageSent } = require('./util');
const p = require('../core/parameters');
const e = require('../core/elements');
const { checkTextContent } = require('../core/util');
const { getSettings } = require('../core/settings');
const { MultiUsers } = require('../user/multiusers');
const { sleep } = require('../core/helpers');
const { ELEMENT_WAIT_LONGER_TIME } = require('../core/constants');

class Chat extends Page {
constructor(browser, page) {
super(browser, page);
class Chat extends MultiUsers {
constructor(browser, context) {
super(browser, context);
}

async sendPublicMessage() {
await openChat(this);
await this.checkElementCount(e.chatUserMessageText, 0);
await openChat(this.modPage);
await this.modPage.checkElementCount(e.chatUserMessageText, 0);

await this.type(e.chatBox, e.message);
await this.waitAndClick(e.sendButton);
await this.checkElementCount(e.chatUserMessageText, 1);
await this.modPage.type(e.chatBox, e.message);
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);
await this.userPage.waitAndClick(e.sendButton);
// check sent messages
await this.modPage.hasText(e.privateChat, e.message2);
await this.userPage.hasText(e.privateChat, e.message2);

await this.modPage.waitAndClick(e.chatButton);
await this.userPage.waitAndClick(e.chatButton);
}

async clearChat() {
await openChat(this);
await openChat(this.modPage);

await this.type(e.chatBox, e.message);
await this.waitAndClick(e.sendButton);
await this.waitForSelector(e.chatUserMessageText);
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);

// 1 message
await this.checkElementCount(e.chatUserMessageText, 1);
await this.modPage.checkElementCount(e.chatUserMessageText, userMessageTextCount + 1);

// clear
await this.waitAndClick(e.chatOptions);
await this.waitAndClick(e.chatClear);
const clearMessage = this.getLocator(e.chatClearMessageText);
await this.modPage.waitAndClick(e.chatOptions);
await this.modPage.waitAndClick(e.chatClear);
const clearMessage = this.modPage.getLocator(e.chatClearMessageText);
await expect(clearMessage).toBeVisible();

}

async copyChat(context) {
const { publicChatOptionsEnabled } = getSettings();
test.fail(!publicChatOptionsEnabled, 'Public chat options (save and copy) are disabled');

await openChat(this);
await openChat(this.modPage);
// sending a message
await this.type(e.chatBox, e.message);
await this.waitAndClick(e.sendButton);
await this.modPage.type(e.chatBox, e.message);
await this.modPage.waitAndClick(e.sendButton);

await this.waitAndClick(e.chatOptions);
await this.modPage.waitAndClick(e.chatOptions);

await this.waitForSelector(e.chatUserMessageText);
await this.waitAndClick(e.chatCopy);
await this.modPage.waitForSelector(e.chatUserMessageText);
await this.modPage.waitAndClick(e.chatCopy);
// enable access to browser context clipboard
const copiedText = await this.getCopiedText(context);
const copiedText = await this.modPage.getCopiedText(context);
const check = copiedText.includes(`${p.fullName}: ${e.message}`);
await expect(check).toBeTruthy();
}
Expand All @@ -60,59 +89,76 @@ class Chat extends Page {
const { publicChatOptionsEnabled } = getSettings();
test.fail(!publicChatOptionsEnabled, 'Public chat options (save and copy) are disabled');

await openChat(this);
await this.type(e.chatBox, e.message);
await this.waitAndClick(e.sendButton);
await this.waitForSelector(e.chatUserMessageText);
await this.waitAndClick(e.chatOptions);
const chatSaveLocator = this.getLocator(e.chatSave);
const { content } = await this.handleDownload(chatSaveLocator, testInfo);
await openChat(this.modPage);
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);

const dataToCheck = [
this.meetingId,
this.username,
this.modPage.meetingId,
this.modPage.username,
e.message,
];
await checkTextContent(content, dataToCheck);
}

async characterLimit() {
await openChat(this);
await openChat(this.modPage);

const { maxMessageLength } = getSettings();
await this.page.fill(e.chatBox, e.uniqueCharacterMessage.repeat(maxMessageLength));
await this.waitAndClick(e.sendButton);
await this.waitForSelector(e.chatUserMessageText);
await this.checkElementCount(e.chatUserMessageText, 1);

await this.page.fill(e.chatBox, e.uniqueCharacterMessage.repeat(maxMessageLength + 1));
await this.waitForSelector(e.typingIndicator);
await this.waitAndClick(e.sendButton);
await this.waitForSelector(e.chatUserMessageText);
await this.checkElementCount(e.chatUserMessageText, 1);
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, 1);

await this.modPage.page.fill(e.chatBox, e.uniqueCharacterMessage.repeat(maxMessageLength + 1));
await this.modPage.waitForSelector(e.typingIndicator);
await this.modPage.waitAndClick(e.sendButton);
await this.modPage.waitForSelector(e.chatUserMessageText);
await this.modPage.checkElementCount(e.chatUserMessageText, 1);
}

async emptyMessage() {
await openChat(this);
await openChat(this.modPage);

await this.waitAndClick(e.sendButton);
await this.checkElementCount(e.chatUserMessageText, 0);
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.waitAndClick(e.sendButton);

await this.modPage.hasText(e.secondChatUserMessageText, /test/);
}

// Emojis
async sendEmoji() {
const { emojiPickerEnabled } = getSettings();
test.fail(!emojiPickerEnabled, 'Emoji Picker is disabled');

await openChat(this);
const message = this.getLocator(e.chatUserMessageText);
await openChat(this.modPage);
const message = this.modPage.getLocator(e.chatUserMessageText);
await expect(message).toHaveCount(0);

await this.waitAndClick(e.emojiPickerButton);
await this.waitAndClick(e.emojiSent);
await this.waitAndClick(e.sendButton);
await this.modPage.waitAndClick(e.emojiPickerButton);
await this.modPage.waitAndClick(e.emojiSent);
await this.modPage.waitAndClick(e.sendButton);

await this.waitForSelector(e.chatUserMessageText);
await this.modPage.waitForSelector(e.chatUserMessageText);
await expect(message).toHaveCount(1);
}

Expand All @@ -135,6 +181,28 @@ class Chat extends Page {
await expect(check).toBeTruthy();
}

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);
}

async emojiSaveChat(testInfo) {
const { emojiPickerEnabled } = getSettings();
test.fail(!emojiPickerEnabled, 'Emoji Picker is disabled');
Expand All @@ -156,18 +224,52 @@ class Chat extends Page {
await checkTextContent(content, dataToCheck);
}

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);
}

async autoConvertEmojiPublicChat() {
const { autoConvertEmojiEnabled } = getSettings();
test.fail(!autoConvertEmojiEnabled, 'Auto Convert Emoji is disabled');

await openChat(this);
const message = this.getLocator(e.chatUserMessageText);
await expect(message).toHaveCount(0);
try {
await this.modPage.hasElement(e.hidePrivateChat);
await this.modPage.waitAndClick(e.chatButton);
} catch {
await this.modPage.hasElement(e.publicChat);
}

await this.type(e.chatBox, e.autoConvertEmojiMessage);
await this.waitAndClick(e.sendButton);
await this.waitForSelector(e.chatUserMessageText);
await expect(message).toHaveCount(1);
const message = await this.modPage.getSelectorCount(e.chatUserMessageText);
await this.modPage.checkElementCount(e.chatUserMessageText, message);

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, message + 1);
}

async autoConvertEmojiCopyChat(context) {
Expand All @@ -192,37 +294,54 @@ class Chat extends Page {
const { autoConvertEmojiEnabled } = getSettings();
test.fail(!autoConvertEmojiEnabled, 'Auto Convert Emoji is disabled');

await openChat(this);
await this.type(e.chatBox, e.autoConvertEmojiMessage);
await this.waitAndClick(e.sendButton);
await this.waitForSelector(e.chatUserMessageText);
await this.waitAndClick(e.chatOptions);
const chatSaveLocator = this.getLocator(e.chatSave);
const { content } = await this.handleDownload(chatSaveLocator, testInfo);
await openChat(this.modPage);
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);

const dataToCheck = [
this.meetingId,
this.username,
this.modPage.meetingId,
this.modPage.username,
e.convertedEmojiMessage,
];
await checkTextContent(content, dataToCheck);
}

async copyPastePublicMessage() {
await this.type(e.chatBox, 'test');
await this.waitAndClick(e.sendButton);
await this.hasText(e.chatUserMessageText, /test/);

const text = await this.getLocator(e.chatUserMessageText).boundingBox();

await this.mouseDoubleClick(text.x, text.y);
await this.press('Control+KeyC');
await this.getLocator(e.chatBox).focus();
await this.press('Control+KeyV');
await this.waitAndClick(e.sendButton);
async autoConvertEmojiSendPrivateChat() {
const { autoConvertEmojiEnabled } = getSettings();
test.fail(!autoConvertEmojiEnabled, 'Auto Convert Emoji is disabled');

await this.hasText(e.secondChatUserMessageText, /test/);
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.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
await this.modPage.hasText(e.privateChat, e.convertedEmojiMessage);
await this.userPage.hasText(e.privateChat, e.convertedEmojiMessage);
}

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.hasElementDisabled(e.chatBox);
await this.modPage.hasElementDisabled(e.sendButton);
}
}

exports.Chat = Chat;