From 345a7d343ded1cd3b23ea76a79bed4fd456a91e4 Mon Sep 17 00:00:00 2001 From: Pedro Beschorner Marin Date: Wed, 21 Nov 2018 18:58:45 -0200 Subject: [PATCH] Refactored chat message test and included chat clear --- .../tests/puppeteer/chat.test.js | 33 +++++++++++++ .../tests/puppeteer/chat/clear.js | 28 +++++++++++ .../tests/puppeteer/chat/elements.js | 6 +++ .../tests/puppeteer/chat/send.js | 27 ++++++++++ .../tests/puppeteer/chat/util.js | 30 ++++++++++++ .../tests/puppeteer/elements.js | 5 -- .../tests/puppeteer/page-chat.js | 49 ------------------- .../tests/puppeteer/page-chat.test.js | 15 ------ 8 files changed, 124 insertions(+), 69 deletions(-) create mode 100644 bigbluebutton-html5/tests/puppeteer/chat.test.js create mode 100644 bigbluebutton-html5/tests/puppeteer/chat/clear.js create mode 100644 bigbluebutton-html5/tests/puppeteer/chat/elements.js create mode 100644 bigbluebutton-html5/tests/puppeteer/chat/send.js create mode 100644 bigbluebutton-html5/tests/puppeteer/chat/util.js delete mode 100644 bigbluebutton-html5/tests/puppeteer/page-chat.js delete mode 100644 bigbluebutton-html5/tests/puppeteer/page-chat.test.js diff --git a/bigbluebutton-html5/tests/puppeteer/chat.test.js b/bigbluebutton-html5/tests/puppeteer/chat.test.js new file mode 100644 index 0000000000..aff15f20b2 --- /dev/null +++ b/bigbluebutton-html5/tests/puppeteer/chat.test.js @@ -0,0 +1,33 @@ +const Page = require('./page'); +const Send = require('./chat/send'); +const Clear = require('./chat/clear'); + +describe('Chat tests', () => { + + test('Tests sending a message in chat', async () => { + const test = new Send(); + try { + await test.init(Page.getArgs()); + await test.test(); + await test.close(); + } catch (e) { + console.log(e); + await test.close(); + throw new Error('Test failed'); + } + }); + + test('Tests cleaning a message in chat', async () => { + const test = new Clear(); + try { + await test.init(Page.getArgs()); + await test.test(); + await test.close(); + } catch (e) { + console.log(e); + await test.close(); + throw new Error('Test failed'); + } + }); + +}); diff --git a/bigbluebutton-html5/tests/puppeteer/chat/clear.js b/bigbluebutton-html5/tests/puppeteer/chat/clear.js new file mode 100644 index 0000000000..f3ee17e823 --- /dev/null +++ b/bigbluebutton-html5/tests/puppeteer/chat/clear.js @@ -0,0 +1,28 @@ +// Test: Cleaning a chat message + +const Page = require('../page'); +const helper = require('../helper'); +const e = require('./elements'); +const util = require('./util'); + +class Clear extends Page { + async test() { + await util.openChat(this); + + const messages0 = await util.getTestElements(this); + + await this.click(e.chatOptions); + await this.click(e.chatClear, true); + await this.screenshot('clear-chat.png', true); + + // TODO: this must change + const messages1 = await util.getTestElements(this); + + console.log('\nChat messages before cleaning:'); + console.log(JSON.stringify(messages0, null, 2)); + console.log('\nChat messages after cleaning:'); + console.log(JSON.stringify(messages1, null, 2)); + } +} + +module.exports = exports = Clear; diff --git a/bigbluebutton-html5/tests/puppeteer/chat/elements.js b/bigbluebutton-html5/tests/puppeteer/chat/elements.js new file mode 100644 index 0000000000..9999f9ced6 --- /dev/null +++ b/bigbluebutton-html5/tests/puppeteer/chat/elements.js @@ -0,0 +1,6 @@ +exports.chatButton = 'div._imports_ui_components_user_list_chat_list_item__styles__chatName'; +exports.chatBox = '#message-input'; +exports.sendButton = '[aria-label="Send Message"]'; +exports.chatMessages = '#chat-messages'; +exports.chatOptions = '[aria-label="Chat Options"]'; +exports.chatClear = 'i._imports_ui_components_dropdown_list__styles__itemIcon.icon-bbb-delete'; diff --git a/bigbluebutton-html5/tests/puppeteer/chat/send.js b/bigbluebutton-html5/tests/puppeteer/chat/send.js new file mode 100644 index 0000000000..2f26713edd --- /dev/null +++ b/bigbluebutton-html5/tests/puppeteer/chat/send.js @@ -0,0 +1,27 @@ +// Test: Sending a chat message + +const Page = require('../page'); +const helper = require('../helper'); +const e = require('./elements'); +const util = require('./util'); + +class Send extends Page { + async test() { + await util.openChat(this); + + const messages0 = await util.getTestElements(this); + + await this.type(e.chatBox, 'Hello world!'); + await this.click(e.sendButton); + await this.screenshot('test-chat.png', true); + + const messages1 = await util.getTestElements(this); + + console.log('\nChat messages before posting:'); + console.log(JSON.stringify(messages0, null, 2)); + console.log('\nChat messages after posting:'); + console.log(JSON.stringify(messages1, null, 2)); + } +} + +module.exports = exports = Send; diff --git a/bigbluebutton-html5/tests/puppeteer/chat/util.js b/bigbluebutton-html5/tests/puppeteer/chat/util.js new file mode 100644 index 0000000000..9b7f9f69da --- /dev/null +++ b/bigbluebutton-html5/tests/puppeteer/chat/util.js @@ -0,0 +1,30 @@ +const e = require('./elements'); + +async function openChat(test) { + await test.createBBBMeeting(); + await test.joinWithoutAudio(); + await test.click(e.chatButton); + await test.page.waitFor(e.chatBox); + await test.page.waitFor(e.chatMessages); +} + +async function getTestElements(test) { + const messages = await test.page.evaluate((chat) => { + const messages = []; + const children = document.querySelector(chat).childNodes; + for (let i = 0; i < children.length; i++) { + let content = children[i].childNodes[0].childNodes[1]; + if (content) { + content = content.childNodes; + messages.push({ name: content[0].innerText, message: content[1].innerText }); + } + } + console.log(messages); + return messages; + }, e.chatMessages); + + return messages; +} + +exports.openChat = openChat; +exports.getTestElements = getTestElements; diff --git a/bigbluebutton-html5/tests/puppeteer/elements.js b/bigbluebutton-html5/tests/puppeteer/elements.js index 7fe848ad23..f78efacc10 100644 --- a/bigbluebutton-html5/tests/puppeteer/elements.js +++ b/bigbluebutton-html5/tests/puppeteer/elements.js @@ -17,11 +17,6 @@ exports.leaveAudio = 'button[aria-label="Leave Audio"]'; exports.videoMenu = 'button[aria-label="Open video menu dropdown"]'; exports.screenShare = 'button[aria-label="Share your screen"]'; -exports.chatButton = 'div._imports_ui_components_user_list_chat_list_item__styles__chatName'; -exports.chatBox = '#message-input'; -exports.sendButton = '[aria-label="Send Message"]'; -exports.chatMessages = '#chat-messages'; - exports.whiteboard = 'svg._imports_ui_components_presentation__styles__svgStyles'; exports.toolbox = '._imports_ui_components_whiteboard_whiteboard_toolbar__styles__toolbarContainer'; exports.tools = 'button[aria-label="Tools"]'; diff --git a/bigbluebutton-html5/tests/puppeteer/page-chat.js b/bigbluebutton-html5/tests/puppeteer/page-chat.js deleted file mode 100644 index 0edc6fae92..0000000000 --- a/bigbluebutton-html5/tests/puppeteer/page-chat.js +++ /dev/null @@ -1,49 +0,0 @@ -// Test: Sending a chat message - -const Page = require('./page'); -const helper = require('./helper'); -const e = require('./elements'); - -class ChatTestPage extends Page { - async test() { - await this.createBBBMeeting(); - await this.joinWithoutAudio(); - - await this.click(e.chatButton); - await this.page.waitFor(e.chatBox); - await this.page.waitFor(e.chatMessages); - - const messages0 = await this.getTestElements(); - - await this.type(e.chatBox, 'Hello world!'); - await this.click(e.sendButton); - await this.screenshot('test-chat.png', true); - - const messages1 = await this.getTestElements(); - - console.log('\nChat messages before posting:'); - console.log(JSON.stringify(messages0, null, 2)); - console.log('\nChat messages after posting:'); - console.log(JSON.stringify(messages1, null, 2)); - } - - async getTestElements() { - const messages = await this.page.evaluate((chat) => { - const messages = []; - const children = document.querySelector(chat).childNodes; - for (let i = 0; i < children.length; i++) { - let content = children[i].childNodes[0].childNodes[1]; - if (content) { - content = content.childNodes; - messages.push({ name: content[0].innerText, message: content[1].innerText }); - } - } - console.log(messages); - return messages; - }, e.chatMessages); - - return messages; - } -} - -module.exports = exports = ChatTestPage; diff --git a/bigbluebutton-html5/tests/puppeteer/page-chat.test.js b/bigbluebutton-html5/tests/puppeteer/page-chat.test.js deleted file mode 100644 index 51f863bee3..0000000000 --- a/bigbluebutton-html5/tests/puppeteer/page-chat.test.js +++ /dev/null @@ -1,15 +0,0 @@ -const Page = require('./page'); -const ChatTestPage = require('./page-chat'); - -test('Tests sending a message in chat', async () => { - const test = new ChatTestPage(); - try { - await test.init(Page.getArgs()); - await test.test(); - await test.close(); - } catch (e) { - console.log(e); - await test.close(); - throw new Error('Test failed'); - } -});