2023-04-27 20:36:19 +08:00
|
|
|
const { default: test, expect } = require('@playwright/test');
|
2021-11-18 04:07:14 +08:00
|
|
|
const e = require('../core/elements');
|
2022-03-29 21:53:07 +08:00
|
|
|
const { getSettings } = require('../core/settings');
|
2021-11-03 00:45:52 +08:00
|
|
|
|
2023-06-08 10:16:50 +08:00
|
|
|
async function openPublicChat(testPage) {
|
2022-03-29 21:53:07 +08:00
|
|
|
const { chatEnabled } = getSettings();
|
2023-11-01 20:26:35 +08:00
|
|
|
|
|
|
|
if(!chatEnabled) {
|
|
|
|
return await testPage.wasRemoved(e.chatButton);
|
|
|
|
}
|
2022-03-29 21:53:07 +08:00
|
|
|
|
|
|
|
await testPage.waitForSelector(e.chatBox);
|
|
|
|
await testPage.waitForSelector(e.chatMessages);
|
2023-06-08 10:16:50 +08:00
|
|
|
try {
|
|
|
|
await testPage.waitForSelector(e.chatWelcomeMessageText);
|
|
|
|
} catch {
|
|
|
|
await testPage.waitAndClick(e.chatMessages);
|
|
|
|
await testPage.down('Home');
|
|
|
|
await testPage.waitForSelector(e.chatWelcomeMessageText);
|
|
|
|
await testPage.down('End');
|
|
|
|
}
|
2022-03-29 21:53:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
async function openPrivateChat(testPage) {
|
|
|
|
const { chatEnabled } = getSettings();
|
|
|
|
test.fail(!chatEnabled, 'Chat is disabled');
|
|
|
|
|
|
|
|
await testPage.waitAndClick(e.userListItem);
|
|
|
|
await testPage.waitAndClick(e.startPrivateChat);
|
2021-11-03 00:45:52 +08:00
|
|
|
}
|
|
|
|
|
2023-04-27 20:36:19 +08:00
|
|
|
async function checkLastMessageSent(testPage, expectedMessage) {
|
|
|
|
const lastMessageSent = await testPage.getLocator(e.chatUserMessageText).last();
|
|
|
|
await expect(lastMessageSent).toHaveText(expectedMessage);
|
|
|
|
}
|
|
|
|
|
2023-06-08 10:16:50 +08:00
|
|
|
exports.openPublicChat = openPublicChat;
|
2022-03-29 21:53:07 +08:00
|
|
|
exports.openPrivateChat = openPrivateChat;
|
2023-04-27 20:36:19 +08:00
|
|
|
exports.checkLastMessageSent = checkLastMessageSent;
|