split up scenarios in multiple files as lazy-loading scenarios grow

This commit is contained in:
Bruno Windels 2018-09-13 10:31:15 +02:00
parent 5ec8f6f9b4
commit 1725e7524b
7 changed files with 164 additions and 95 deletions

View File

@ -15,23 +15,12 @@ limitations under the License.
*/
const {delay, range} = require('./util');
const {acceptDialogMaybe} = require('./usecases/dialog');
const {range} = require('./util');
const signup = require('./usecases/signup');
const join = require('./usecases/join');
const sendMessage = require('./usecases/send-message');
const acceptInvite = require('./usecases/accept-invite');
const invite = require('./usecases/invite');
const {
receiveMessage,
checkTimelineContains,
scrollToTimelineTop
} = require('./usecases/timeline');
const createRoom = require('./usecases/create-room');
const changeRoomSettings = require('./usecases/room-settings');
const acceptServerNoticesInviteAndConsent = require('./usecases/server-notices-consent');
const {enableLazyLoading, getE2EDeviceFromSettings} = require('./usecases/settings');
const verifyDeviceForUser = require("./usecases/verify-device");
const roomDirectoryScenarios = require('./scenarios/directory');
const lazyLoadingScenarios = require('./scenarios/lazy-loading');
const e2eEncryptionScenarios = require('./scenarios/e2e-encryption');
module.exports = async function scenario(createSession, restCreator) {
async function createUser(username) {
@ -45,9 +34,9 @@ module.exports = async function scenario(createSession, restCreator) {
const bob = await createUser("bob");
const charlies = await createRestUsers(restCreator);
await createDirectoryRoomAndTalk(alice, bob);
await createE2ERoomAndTalk(alice, bob);
await aLazyLoadingTest(alice, bob, charlies);
await roomDirectoryScenarios(alice, bob);
await e2eEncryptionScenarios(alice, bob);
await lazyLoadingScenarios(alice, bob, charlies);
}
async function createRestUsers(restCreator) {
@ -56,79 +45,3 @@ async function createRestUsers(restCreator) {
await charlies.setDisplayName((s) => `Charly #${s.userName().split('-')[1]}`);
return charlies;
}
async function createDirectoryRoomAndTalk(alice, bob) {
console.log(" creating a public room and join through directory:");
const room = 'test';
await createRoom(alice, room);
await changeRoomSettings(alice, {directory: true, visibility: "public_no_guests"});
await join(bob, room);
const bobMessage = "hi Alice!";
await sendMessage(bob, bobMessage);
await receiveMessage(alice, {sender: "bob", body: bobMessage});
const aliceMessage = "hi Bob, welcome!"
await sendMessage(alice, aliceMessage);
await receiveMessage(bob, {sender: "alice", body: aliceMessage});
}
async function createE2ERoomAndTalk(alice, bob) {
console.log(" creating an e2e encrypted room and join through invite:");
const room = "secrets";
await createRoom(bob, room);
await changeRoomSettings(bob, {encryption: true});
await invite(bob, "@alice:localhost");
await acceptInvite(alice, room);
const bobDevice = await getE2EDeviceFromSettings(bob);
// wait some time for the encryption warning dialog
// to appear after closing the settings
await delay(1000);
await acceptDialogMaybe(bob, "encryption");
const aliceDevice = await getE2EDeviceFromSettings(alice);
// wait some time for the encryption warning dialog
// to appear after closing the settings
await delay(1000);
await acceptDialogMaybe(alice, "encryption");
await verifyDeviceForUser(bob, "alice", aliceDevice);
await verifyDeviceForUser(alice, "bob", bobDevice);
const aliceMessage = "Guess what I just heard?!"
await sendMessage(alice, aliceMessage);
await receiveMessage(bob, {sender: "alice", body: aliceMessage, encrypted: true});
const bobMessage = "You've got to tell me!";
await sendMessage(bob, bobMessage);
await receiveMessage(alice, {sender: "bob", body: bobMessage, encrypted: true});
}
async function aLazyLoadingTest(alice, bob, charlies) {
console.log(" creating a room for lazy loading member scenarios:");
await enableLazyLoading(alice);
const room = "Lazy Loading Test";
const alias = "#lltest:localhost";
const charlyMsg1 = "hi bob!";
const charlyMsg2 = "how's it going??";
await createRoom(bob, room);
await changeRoomSettings(bob, {directory: true, visibility: "public_no_guests", alias});
// wait for alias to be set by server after clicking "save"
// so the charlies can join it.
await bob.delay(500);
const charlyMembers = await charlies.join(alias);
await charlyMembers.talk(charlyMsg1);
await charlyMembers.talk(charlyMsg2);
bob.log.step("sends 20 messages").mute();
for(let i = 20; i >= 1; --i) {
await sendMessage(bob, `I will only say this ${i} time(s)!`);
}
bob.log.unmute().done();
await join(alice, alias);
await scrollToTimelineTop(alice);
//alice should see 2 messages from every charly with
//the correct display name
const expectedMessages = [charlyMsg1, charlyMsg2].reduce((messages, msgText) => {
return charlies.sessions.reduce((messages, charly) => {
return messages.concat({
sender: charly.displayName(),
body: msgText,
});
}, messages);
}, []);
await checkTimelineContains(alice, expectedMessages, "Charly #1-10");
}

1
src/scenarios/README.md Normal file
View File

@ -0,0 +1 @@
scenarios contains the high-level playbook for the test suite

View File

@ -0,0 +1,36 @@
/*
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 join = require('../usecases/join');
const sendMessage = require('../usecases/send-message');
const {receiveMessage} = require('../usecases/timeline');
const createRoom = require('../usecases/create-room');
const changeRoomSettings = require('../usecases/room-settings');
module.exports = async function roomDirectoryScenarios(alice, bob) {
console.log(" creating a public room and join through directory:");
const room = 'test';
await createRoom(alice, room);
await changeRoomSettings(alice, {directory: true, visibility: "public_no_guests"});
await join(bob, room); //looks up room in directory
const bobMessage = "hi Alice!";
await sendMessage(bob, bobMessage);
await receiveMessage(alice, {sender: "bob", body: bobMessage});
const aliceMessage = "hi Bob, welcome!"
await sendMessage(alice, aliceMessage);
await receiveMessage(bob, {sender: "alice", body: aliceMessage});
}

View File

@ -0,0 +1,55 @@
/*
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 {delay} = require('../util');
const {acceptDialogMaybe} = require('../usecases/dialog');
const join = require('../usecases/join');
const sendMessage = require('../usecases/send-message');
const acceptInvite = require('../usecases/accept-invite');
const invite = require('../usecases/invite');
const {receiveMessage} = require('../usecases/timeline');
const createRoom = require('../usecases/create-room');
const changeRoomSettings = require('../usecases/room-settings');
const {getE2EDeviceFromSettings} = require('../usecases/settings');
const verifyDeviceForUser = require('../usecases/verify-device');
module.exports = async function e2eEncryptionScenarios(alice, bob) {
console.log(" creating an e2e encrypted room and join through invite:");
const room = "secrets";
await createRoom(bob, room);
await changeRoomSettings(bob, {encryption: true});
await invite(bob, "@alice:localhost");
await acceptInvite(alice, room);
const bobDevice = await getE2EDeviceFromSettings(bob);
// wait some time for the encryption warning dialog
// to appear after closing the settings
await delay(1000);
await acceptDialogMaybe(bob, "encryption");
const aliceDevice = await getE2EDeviceFromSettings(alice);
// wait some time for the encryption warning dialog
// to appear after closing the settings
await delay(1000);
await acceptDialogMaybe(alice, "encryption");
await verifyDeviceForUser(bob, "alice", aliceDevice);
await verifyDeviceForUser(alice, "bob", bobDevice);
const aliceMessage = "Guess what I just heard?!"
await sendMessage(alice, aliceMessage);
await receiveMessage(bob, {sender: "alice", body: aliceMessage, encrypted: true});
const bobMessage = "You've got to tell me!";
await sendMessage(bob, bobMessage);
await receiveMessage(alice, {sender: "bob", body: bobMessage, encrypted: true});
}

View File

@ -0,0 +1,62 @@
/*
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 {delay} = require('../util');
const join = require('../usecases/join');
const sendMessage = require('../usecases/send-message');
const {
checkTimelineContains,
scrollToTimelineTop
} = require('../usecases/timeline');
const createRoom = require('../usecases/create-room');
const changeRoomSettings = require('../usecases/room-settings');
const {enableLazyLoading} = require('../usecases/settings');
module.exports = async function lazyLoadingScenarios(alice, bob, charlies) {
console.log(" creating a room for lazy loading member scenarios:");
await enableLazyLoading(alice);
const room = "Lazy Loading Test";
const alias = "#lltest:localhost";
const charlyMsg1 = "hi bob!";
const charlyMsg2 = "how's it going??";
await createRoom(bob, room);
await changeRoomSettings(bob, {directory: true, visibility: "public_no_guests", alias});
// wait for alias to be set by server after clicking "save"
// so the charlies can join it.
await bob.delay(500);
const charlyMembers = await charlies.join(alias);
await charlyMembers.talk(charlyMsg1);
await charlyMembers.talk(charlyMsg2);
bob.log.step("sends 20 messages").mute();
for(let i = 20; i >= 1; --i) {
await sendMessage(bob, `I will only say this ${i} time(s)!`);
}
bob.log.unmute().done();
await join(alice, alias);
await scrollToTimelineTop(alice);
//alice should see 2 messages from every charly with
//the correct display name
const expectedMessages = [charlyMsg1, charlyMsg2].reduce((messages, msgText) => {
return charlies.sessions.reduce((messages, charly) => {
return messages.concat({
sender: charly.displayName(),
body: msgText,
});
}, messages);
}, []);
await checkTimelineContains(alice, expectedMessages, "Charly #1-10");
}

View File

@ -124,7 +124,7 @@ module.exports = class RiotSession {
return await this.queryAll(selector);
}
waitForReload(timeout = 5000) {
waitForReload(timeout = 10000) {
return new Promise((resolve, reject) => {
const timeoutHandle = setTimeout(() => {
this.browser.removeEventListener('domcontentloaded', callback);

2
src/usecases/README.md Normal file
View File

@ -0,0 +1,2 @@
use cases contains the detailed DOM interactions to perform a given use case, may also do some assertions.
use cases are often used in multiple scenarios.