create session object to scope a user, move helper methods there

This commit is contained in:
Bruno Windels 2018-08-07 16:45:34 +02:00
parent 97fa7e03d1
commit 7c91ecab7e
8 changed files with 203 additions and 216 deletions

27
src/tests/consent.js Normal file
View file

@ -0,0 +1,27 @@
/*
Copyright 2018 New Vector Ltd
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
const assert = require('assert');
module.exports = async function acceptTerms(session) {
const reviewTermsButton = await session.waitAndQuerySelector('.mx_QuestionDialog button.mx_Dialog_primary', 5000);
const termsPagePromise = session.waitForNewPage();
await reviewTermsButton.click();
const termsPage = await termsPagePromise;
const acceptButton = await termsPage.$('input[type=submit]');
await acceptButton.click();
await session.delay(500); //TODO yuck, timers
}

31
src/tests/create-room.js Normal file
View file

@ -0,0 +1,31 @@
/*
Copyright 2018 New Vector Ltd
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
const assert = require('assert');
module.exports = async function createRoom(session, roomName) {
//TODO: brittle selector
const createRoomButton = await session.waitAndQuerySelector('.mx_RoleButton[aria-label="Create new room"]');
await createRoomButton.click();
const roomNameInput = await session.waitAndQuerySelector('.mx_CreateRoomDialog_input');
await session.replaceInputText(roomNameInput, roomName);
const createButton = await session.waitAndQuerySelector('.mx_Dialog_primary');
await createButton.click();
await session.waitForSelector('.mx_MessageComposer');
}

34
src/tests/join.js Normal file
View file

@ -0,0 +1,34 @@
/*
Copyright 2018 New Vector Ltd
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
const assert = require('assert');
module.exports = async function join(session, roomName) {
//TODO: brittle selector
const directoryButton = await session.waitAndQuerySelector('.mx_RoleButton[aria-label="Room directory"]');
await directoryButton.click();
const roomInput = await session.waitAndQuerySelector('.mx_DirectorySearchBox_input');
await session.replaceInputText(roomInput, roomName);
const firstRoomLabel = await session.waitAndQuerySelector('.mx_RoomDirectory_table .mx_RoomDirectory_name:first-child');
await firstRoomLabel.click();
const joinLink = await session.waitAndQuerySelector('.mx_RoomPreviewBar_join_text a');
await joinLink.click();
await session.waitForSelector('.mx_MessageComposer');
}

View file

@ -0,0 +1,43 @@
/*
Copyright 2018 New Vector Ltd
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
const assert = require('assert');
module.exports = async function acceptServerNoticesInviteAndConsent(session, name) {
//TODO: brittle selector
const invitesHandles = await session.waitAndQueryAll('.mx_RoomTile_name.mx_RoomTile_invite');
const invitesWithText = await Promise.all(invitesHandles.map(async (inviteHandle) => {
const text = await session.innerText(inviteHandle);
return {inviteHandle, text};
}));
const inviteHandle = invitesWithText.find(({inviteHandle, text}) => {
return text.trim() === name;
}).inviteHandle;
await inviteHandle.click();
const acceptInvitationLink = await session.waitAndQuerySelector(".mx_RoomPreviewBar_join_text a:first-child");
await acceptInvitationLink.click();
const consentLink = await session.waitAndQuerySelector(".mx_EventTile_body a", 1000);
const termsPagePromise = session.waitForNewPage();
await consentLink.click();
const termsPage = await termsPagePromise;
const acceptButton = await termsPage.$('input[type=submit]');
await acceptButton.click();
await session.delay(500); //TODO yuck, timers
}

67
src/tests/signup.js Normal file
View file

@ -0,0 +1,67 @@
/*
Copyright 2018 New Vector Ltd
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
const acceptTerms = require('./consent');
const assert = require('assert');
module.exports = async function signup(session, username, password, homeserver) {
await session.goto(session.riotUrl('/#/register'));
//click 'Custom server' radio button
if (homeserver) {
const advancedRadioButton = await session.waitAndQuerySelector('#advanced');
await advancedRadioButton.click();
}
// wait until register button is visible
await session.waitForSelector('.mx_Login_submit[value=Register]', {visible: true, timeout: 500});
//fill out form
const loginFields = await session.page.$$('.mx_Login_field');
assert.strictEqual(loginFields.length, 7);
const usernameField = loginFields[2];
const passwordField = loginFields[3];
const passwordRepeatField = loginFields[4];
const hsurlField = loginFields[5];
await session.replaceInputText(usernameField, username);
await session.replaceInputText(passwordField, password);
await session.replaceInputText(passwordRepeatField, password);
if (homeserver) {
await session.waitForSelector('.mx_ServerConfig', {visible: true, timeout: 500});
await session.replaceInputText(hsurlField, homeserver);
}
//wait over a second because Registration/ServerConfig have a 1000ms
//delay to internally set the homeserver url
//see Registration::render and ServerConfig::props::delayTimeMs
await session.delay(1200);
/// focus on the button to make sure error validation
/// has happened before checking the form is good to go
const registerButton = await session.page.$('.mx_Login_submit');
await registerButton.focus();
//check no errors
const error_text = await session.tryGetInnertext('.mx_Login_error');
assert.strictEqual(!!error_text, false);
//submit form
//await page.screenshot({path: "beforesubmit.png", fullPage: true});
await registerButton.click();
//confirm dialog saying you cant log back in without e-mail
const continueButton = await session.waitAndQuerySelector('.mx_QuestionDialog button.mx_Dialog_primary');
await continueButton.click();
//wait for registration to finish so the hash gets set
//onhashchange better?
await session.delay(2000);
const url = session.page.url();
assert.strictEqual(url, session.riotUrl('/#/home'));
}