From a78c095cf657978e442113cc6e56cf80e60bbfb7 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Wed, 8 Aug 2018 11:39:17 +0200 Subject: [PATCH] add support for changing the room settings --- src/scenario.js | 4 ++- src/session.js | 39 +++++++++++++++-------- src/tests/join.js | 4 +-- src/tests/room-settings.js | 48 ++++++++++++++++++++++++++++- src/tests/server-notices-consent.js | 1 + start.js | 8 ++--- 6 files changed, 83 insertions(+), 21 deletions(-) diff --git a/src/scenario.js b/src/scenario.js index ee049a14f9..9aa0ed2ec0 100644 --- a/src/scenario.js +++ b/src/scenario.js @@ -18,6 +18,7 @@ limitations under the License. const signup = require('./tests/signup'); const join = require('./tests/join'); const createRoom = require('./tests/create-room'); +const changeRoomSettings = require('./tests/room-settings'); const acceptServerNoticesInviteAndConsent = require('./tests/server-notices-consent'); module.exports = async function scenario(createSession) { @@ -33,5 +34,6 @@ module.exports = async function scenario(createSession) { const bob = await createUser("bob"); const room = 'test'; await createRoom(alice, room); - // await join(bob, room); + await changeRoomSettings(alice, {directory: true, visibility: "public_no_guests"}); + await join(bob, room); } diff --git a/src/session.js b/src/session.js index e5e16400b8..4f6e04584f 100644 --- a/src/session.js +++ b/src/session.js @@ -33,15 +33,27 @@ class LogBuffer { class Logger { constructor(username) { + this.indent = 0; this.username = username; } - step(description) { - process.stdout.write(` * ${this.username} ${description} ... `); + startGroup(description) { + const indent = " ".repeat(this.indent * 2); + console.log(`${indent} * ${this.username} ${description}:`); + this.indent += 1; } - done() { - process.stdout.write("done\n"); + endGroup() { + this.indent -= 1; + } + + step(description) { + const indent = " ".repeat(this.indent * 2); + process.stdout.write(`${indent} * ${this.username} ${description} ... `); + } + + done(status = "done") { + process.stdout.write(status + "\n"); } } @@ -79,9 +91,17 @@ module.exports = class RiotSession { return null; } - async innerText(field) { - const text_handle = await field.getProperty('innerText'); - return await text_handle.jsonValue(); + async getElementProperty(handle, property) { + const propHandle = await handle.getProperty(property); + return await propHandle.jsonValue(); + } + + innerText(field) { + return this.getElementProperty(field, 'innerText'); + } + + getOuterHTML(element_handle) { + return this.getElementProperty(field, 'outerHTML'); } consoleLogs() { @@ -111,11 +131,6 @@ module.exports = class RiotSession { } } - async getOuterHTML(element_handle) { - const html_handle = await element_handle.getProperty('outerHTML'); - return await html_handle.jsonValue(); - } - async printElements(label, elements) { console.log(label, await Promise.all(elements.map(getOuterHTML))); } diff --git a/src/tests/join.js b/src/tests/join.js index 0577b7a8b6..3c76ad2c67 100644 --- a/src/tests/join.js +++ b/src/tests/join.js @@ -25,12 +25,12 @@ module.exports = async function join(session, roomName) { const roomInput = await session.waitAndQuery('.mx_DirectorySearchBox_input'); await session.replaceInputText(roomInput, roomName); - const firstRoomLabel = await session.waitAndQuery('.mx_RoomDirectory_table .mx_RoomDirectory_name:first-child'); + const firstRoomLabel = await session.waitAndQuery('.mx_RoomDirectory_table .mx_RoomDirectory_name:first-child', 1000); await firstRoomLabel.click(); const joinLink = await session.waitAndQuery('.mx_RoomPreviewBar_join_text a'); await joinLink.click(); - await session.waitForSelector('.mx_MessageComposer'); + await session.waitAndQuery('.mx_MessageComposer'); session.log.done(); } \ No newline at end of file diff --git a/src/tests/room-settings.js b/src/tests/room-settings.js index 70d84de10f..d7bbad3451 100644 --- a/src/tests/room-settings.js +++ b/src/tests/room-settings.js @@ -17,5 +17,51 @@ limitations under the License. const assert = require('assert'); module.exports = async function changeRoomSettings(session, settings) { - session.waitFor + session.log.startGroup(`changes the room settings`); + /// XXX delay is needed here, possible because the header is being rerendered + /// click doesn't do anything otherwise + await session.delay(500); + const settingsButton = await session.query(".mx_RoomHeader .mx_AccessibleButton[title=Settings]"); + await settingsButton.click(); + const checks = await session.waitAndQueryAll(".mx_RoomSettings_settings input[type=checkbox]"); + assert.equal(checks.length, 3); + const e2eEncryptionCheck = checks[0]; + const sendToUnverifiedDevices = checks[1]; + const isDirectory = checks[2]; + + if (typeof settings.directory === "boolean") { + session.log.step(`sets directory listing to ${settings.directory}`); + const checked = await session.getElementProperty(isDirectory, "checked"); + assert(typeof checked, "boolean"); + if (checked !== settings.directory) { + await isDirectory.click(); + session.log.done(); + } else { + session.log.done("already set"); + } + } + + if (settings.visibility) { + session.log.step(`sets visibility to ${settings.visibility}`); + const radios = await session.waitAndQueryAll(".mx_RoomSettings_settings input[type=radio]"); + assert.equal(radios.length, 7); + const inviteOnly = radios[0]; + const publicNoGuests = radios[1]; + const publicWithGuests = radios[2]; + + if (settings.visibility === "invite_only") { + await inviteOnly.click(); + } else if (settings.visibility === "public_no_guests") { + await publicNoGuests.click(); + } else if (settings.visibility === "public_with_guests") { + await publicWithGuests.click(); + } else { + throw new Error(`unrecognized room visibility setting: ${settings.visibility}`); + } + session.log.done(); + } + + const saveButton = await session.query(".mx_RoomHeader_wrapper .mx_RoomHeader_textButton"); + await saveButton.click(); + session.log.endGroup(); } \ No newline at end of file diff --git a/src/tests/server-notices-consent.js b/src/tests/server-notices-consent.js index d52588f962..def21d04c3 100644 --- a/src/tests/server-notices-consent.js +++ b/src/tests/server-notices-consent.js @@ -41,5 +41,6 @@ module.exports = async function acceptServerNoticesInviteAndConsent(session, not const acceptButton = await termsPage.$('input[type=submit]'); await acceptButton.click(); await session.delay(500); //TODO yuck, timers + await termsPage.close(); session.log.done(); } \ No newline at end of file diff --git a/start.js b/start.js index 5e235dd1ef..11dbe8d2fa 100644 --- a/start.js +++ b/start.js @@ -25,6 +25,7 @@ async function runTests() { console.log("running tests ..."); const options = {}; + // options.headless = false; if (process.env.CHROME_PATH) { const path = process.env.CHROME_PATH; console.log(`(using external chrome/chromium at ${path}, make sure it's compatible with puppeteer)`); @@ -41,6 +42,7 @@ async function runTests() { try { await scenario(createSession); } catch(err) { + failure = true; console.log('failure: ', err); for(let i = 0; i < sessions.length; ++i) { const session = sessions[i]; @@ -54,13 +56,9 @@ async function runTests() { console.log(documentHtml); console.log(`---------------- END OF ${session.username} LOGS ----------------`); } - failure = true; } - for(let i = 0; i < sessions.length; ++i) { - const session = sessions[i]; - await session.close(); - } + await Promise.all(sessions.map((session) => session.close())); if (failure) { process.exit(-1);