Merge pull request #11695 from matrix-org/andybalaam/share-code-between-read-receipt-tests

Share code for room initialisation between read receipt tests
This commit is contained in:
Andy Balaam 2023-10-03 15:40:06 +01:00 committed by GitHub
commit f1d34adbbe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 90 additions and 229 deletions

View file

@ -18,7 +18,6 @@ limitations under the License.
/// <reference types="cypress" />
import type { MatrixClient } from "matrix-js-sdk/src/matrix";
import { HomeserverInstance } from "../../plugins/utils/homeserver";
import {
assertRead,
@ -32,22 +31,18 @@ import {
MessageContentSpec,
MessageFinder,
openThread,
ReadReceiptSetup,
saveAndReload,
sendMessageAsClient,
} from "./read-receipts-utils";
describe("Read receipts", () => {
const userName = "Mae";
const botName = "Other User";
const roomAlpha = "Room Alpha";
const roomBeta = "Room Beta";
let homeserver: HomeserverInstance;
let betaRoomId: string;
let alphaRoomId: string;
let bot: MatrixClient | undefined;
let messageFinder: MessageFinder;
let testSetup: ReadReceiptSetup;
function editOf(originalMessage: string, newMessage: string): MessageContentSpec {
return messageFinder.editOf(originalMessage, newMessage);
@ -81,36 +76,7 @@ describe("Read receipts", () => {
beforeEach(() => {
messageFinder = new MessageFinder();
// Create 2 rooms: Alpha & Beta. We join the bot to both of them
cy.initTestUser(homeserver, userName)
.then(() => {
cy.createRoom({ name: roomAlpha }).then((createdRoomId) => {
alphaRoomId = createdRoomId;
});
})
.then(() => {
cy.createRoom({ name: roomBeta }).then((createdRoomId) => {
betaRoomId = createdRoomId;
});
})
.then(() => {
cy.getBot(homeserver, { displayName: botName }).then((botClient) => {
bot = botClient;
});
})
.then(() => {
// Invite the bot to both rooms
cy.inviteUser(alphaRoomId, bot.getUserId());
cy.viewRoomById(alphaRoomId);
cy.get(".mx_LegacyRoomHeader").within(() => cy.findByTitle(roomAlpha).should("exist"));
cy.findByText(botName + " joined the room").should("exist");
cy.inviteUser(betaRoomId, bot.getUserId());
cy.viewRoomById(betaRoomId);
cy.get(".mx_LegacyRoomHeader").within(() => cy.findByTitle(roomBeta).should("exist"));
cy.findByText(botName + " joined the room").should("exist");
});
testSetup = new ReadReceiptSetup(homeserver, "Mae", "Other User", roomAlpha, roomBeta);
});
after(() => {
@ -123,7 +89,7 @@ describe("Read receipts", () => {
* @param messages - the list of messages to send, these can be strings or implementations of MessageSpec like `editOf`
*/
function receiveMessages(room: string, messages: Message[]) {
sendMessageAsClient(bot, room, messages);
sendMessageAsClient(testSetup.bot, room, messages);
}
const room1 = roomAlpha;

View file

@ -18,7 +18,6 @@ limitations under the License.
/// <reference types="cypress" />
import type { MatrixClient } from "matrix-js-sdk/src/matrix";
import { HomeserverInstance } from "../../plugins/utils/homeserver";
import {
assertMessageLoaded,
@ -40,22 +39,18 @@ import {
openThread,
openThreadList,
pageUp,
ReadReceiptSetup,
saveAndReload,
sendMessageAsClient,
} from "./read-receipts-utils";
describe("Read receipts", () => {
const userName = "Mae";
const botName = "Other User";
const roomAlpha = "Room Alpha";
const roomBeta = "Room Beta";
let homeserver: HomeserverInstance;
let betaRoomId: string;
let alphaRoomId: string;
let bot: MatrixClient | undefined;
let messageFinder: MessageFinder;
let testSetup: ReadReceiptSetup;
function threadedOff(rootMessage: string, newMessage: string): MessageContentSpec {
return messageFinder.threadedOff(rootMessage, newMessage);
@ -89,36 +84,7 @@ describe("Read receipts", () => {
beforeEach(() => {
messageFinder = new MessageFinder();
// Create 2 rooms: Alpha & Beta. We join the bot to both of them
cy.initTestUser(homeserver, userName)
.then(() => {
cy.createRoom({ name: roomAlpha }).then((createdRoomId) => {
alphaRoomId = createdRoomId;
});
})
.then(() => {
cy.createRoom({ name: roomBeta }).then((createdRoomId) => {
betaRoomId = createdRoomId;
});
})
.then(() => {
cy.getBot(homeserver, { displayName: botName }).then((botClient) => {
bot = botClient;
});
})
.then(() => {
// Invite the bot to both rooms
cy.inviteUser(alphaRoomId, bot.getUserId());
cy.viewRoomById(alphaRoomId);
cy.get(".mx_LegacyRoomHeader").within(() => cy.findByTitle(roomAlpha).should("exist"));
cy.findByText(botName + " joined the room").should("exist");
cy.inviteUser(betaRoomId, bot.getUserId());
cy.viewRoomById(betaRoomId);
cy.get(".mx_LegacyRoomHeader").within(() => cy.findByTitle(roomBeta).should("exist"));
cy.findByText(botName + " joined the room").should("exist");
});
testSetup = new ReadReceiptSetup(homeserver, "Mae", "Other User", roomAlpha, roomBeta);
});
after(() => {
@ -131,7 +97,7 @@ describe("Read receipts", () => {
* @param messages - the list of messages to send, these can be strings or implementations of MessageSpec like `editOf`
*/
function receiveMessages(room: string, messages: Message[]) {
sendMessageAsClient(bot, room, messages);
sendMessageAsClient(testSetup.bot, room, messages);
}
const room1 = roomAlpha;

View file

@ -18,22 +18,23 @@ limitations under the License.
/// <reference types="cypress" />
import type { MatrixClient } from "matrix-js-sdk/src/matrix";
import { HomeserverInstance } from "../../plugins/utils/homeserver";
import { goTo, Message, MessageContentSpec, MessageFinder, sendMessageAsClient } from "./read-receipts-utils";
import {
goTo,
Message,
MessageContentSpec,
MessageFinder,
ReadReceiptSetup,
sendMessageAsClient,
} from "./read-receipts-utils";
describe("Read receipts", () => {
const userName = "Mae";
const botName = "Other User";
const roomAlpha = "Room Alpha";
const roomBeta = "Room Beta";
let homeserver: HomeserverInstance;
let betaRoomId: string;
let alphaRoomId: string;
let bot: MatrixClient | undefined;
let messageFinder: MessageFinder;
let testSetup: ReadReceiptSetup;
function threadedOff(rootMessage: string, newMessage: string): MessageContentSpec {
return messageFinder.threadedOff(rootMessage, newMessage);
@ -59,36 +60,7 @@ describe("Read receipts", () => {
beforeEach(() => {
messageFinder = new MessageFinder();
// Create 2 rooms: Alpha & Beta. We join the bot to both of them
cy.initTestUser(homeserver, userName)
.then(() => {
cy.createRoom({ name: roomAlpha }).then((createdRoomId) => {
alphaRoomId = createdRoomId;
});
})
.then(() => {
cy.createRoom({ name: roomBeta }).then((createdRoomId) => {
betaRoomId = createdRoomId;
});
})
.then(() => {
cy.getBot(homeserver, { displayName: botName }).then((botClient) => {
bot = botClient;
});
})
.then(() => {
// Invite the bot to both rooms
cy.inviteUser(alphaRoomId, bot.getUserId());
cy.viewRoomById(alphaRoomId);
cy.get(".mx_LegacyRoomHeader").within(() => cy.findByTitle(roomAlpha).should("exist"));
cy.findByText(botName + " joined the room").should("exist");
cy.inviteUser(betaRoomId, bot.getUserId());
cy.viewRoomById(betaRoomId);
cy.get(".mx_LegacyRoomHeader").within(() => cy.findByTitle(roomBeta).should("exist"));
cy.findByText(botName + " joined the room").should("exist");
});
testSetup = new ReadReceiptSetup(homeserver, "Mae", "Other User", roomAlpha, roomBeta);
});
/**
@ -97,7 +69,7 @@ describe("Read receipts", () => {
* @param messages - the list of messages to send, these can be strings or implementations of MessageSpec like `editOf`
*/
function receiveMessages(room: string, messages: Message[]) {
sendMessageAsClient(bot, room, messages);
sendMessageAsClient(testSetup.bot, room, messages);
}
const room1 = roomAlpha;

View file

@ -18,7 +18,6 @@ limitations under the License.
/// <reference types="cypress" />
import type { MatrixClient } from "matrix-js-sdk/src/matrix";
import { HomeserverInstance } from "../../plugins/utils/homeserver";
import {
assertRead,
@ -27,6 +26,7 @@ import {
assertUnreadLessThan,
assertUnreadThread,
backToThreadsList,
ReadReceiptSetup,
goTo,
many,
markAsRead,
@ -39,17 +39,12 @@ import {
} from "./read-receipts-utils";
describe("Read receipts", () => {
const userName = "Mae";
const botName = "Other User";
const roomAlpha = "Room Alpha";
const roomBeta = "Room Beta";
let homeserver: HomeserverInstance;
let betaRoomId: string;
let alphaRoomId: string;
let bot: MatrixClient | undefined;
let messageFinder: MessageFinder;
let testSetup: ReadReceiptSetup;
function replyTo(targetMessage: string, newMessage: string): MessageContentSpec {
return messageFinder.replyTo(targetMessage, newMessage);
@ -87,36 +82,7 @@ describe("Read receipts", () => {
beforeEach(() => {
messageFinder = new MessageFinder();
// Create 2 rooms: Alpha & Beta. We join the bot to both of them
cy.initTestUser(homeserver, userName)
.then(() => {
cy.createRoom({ name: roomAlpha }).then((createdRoomId) => {
alphaRoomId = createdRoomId;
});
})
.then(() => {
cy.createRoom({ name: roomBeta }).then((createdRoomId) => {
betaRoomId = createdRoomId;
});
})
.then(() => {
cy.getBot(homeserver, { displayName: botName }).then((botClient) => {
bot = botClient;
});
})
.then(() => {
// Invite the bot to both rooms
cy.inviteUser(alphaRoomId, bot.getUserId());
cy.viewRoomById(alphaRoomId);
cy.get(".mx_LegacyRoomHeader").within(() => cy.findByTitle(roomAlpha).should("exist"));
cy.findByText(botName + " joined the room").should("exist");
cy.inviteUser(betaRoomId, bot.getUserId());
cy.viewRoomById(betaRoomId);
cy.get(".mx_LegacyRoomHeader").within(() => cy.findByTitle(roomBeta).should("exist"));
cy.findByText(botName + " joined the room").should("exist");
});
testSetup = new ReadReceiptSetup(homeserver, "Mae", "Other User", roomAlpha, roomBeta);
});
after(() => {
@ -129,7 +95,7 @@ describe("Read receipts", () => {
* @param messages - the list of messages to send, these can be strings or implementations of MessageSpec like `editOf`
*/
function receiveMessages(room: string, messages: Message[]) {
sendMessageAsClient(bot, room, messages);
sendMessageAsClient(testSetup.bot, room, messages);
}
/**

View file

@ -18,7 +18,6 @@ limitations under the License.
/// <reference types="cypress" />
import type { MatrixClient } from "matrix-js-sdk/src/matrix";
import { HomeserverInstance } from "../../plugins/utils/homeserver";
import {
assertRead,
@ -32,22 +31,18 @@ import {
MessageContentSpec,
MessageFinder,
openThread,
ReadReceiptSetup,
saveAndReload,
sendMessageAsClient,
} from "./read-receipts-utils";
describe("Read receipts", () => {
const userName = "Mae";
const botName = "Other User";
const roomAlpha = "Room Alpha";
const roomBeta = "Room Beta";
let homeserver: HomeserverInstance;
let betaRoomId: string;
let alphaRoomId: string;
let bot: MatrixClient | undefined;
let messageFinder: MessageFinder;
let testSetup: ReadReceiptSetup;
function threadedOff(rootMessage: string, newMessage: string): MessageContentSpec {
return messageFinder.threadedOff(rootMessage, newMessage);
@ -77,36 +72,7 @@ describe("Read receipts", () => {
beforeEach(() => {
messageFinder = new MessageFinder();
// Create 2 rooms: Alpha & Beta. We join the bot to both of them
cy.initTestUser(homeserver, userName)
.then(() => {
cy.createRoom({ name: roomAlpha }).then((createdRoomId) => {
alphaRoomId = createdRoomId;
});
})
.then(() => {
cy.createRoom({ name: roomBeta }).then((createdRoomId) => {
betaRoomId = createdRoomId;
});
})
.then(() => {
cy.getBot(homeserver, { displayName: botName }).then((botClient) => {
bot = botClient;
});
})
.then(() => {
// Invite the bot to both rooms
cy.inviteUser(alphaRoomId, bot.getUserId());
cy.viewRoomById(alphaRoomId);
cy.get(".mx_LegacyRoomHeader").within(() => cy.findByTitle(roomAlpha).should("exist"));
cy.findByText(botName + " joined the room").should("exist");
cy.inviteUser(betaRoomId, bot.getUserId());
cy.viewRoomById(betaRoomId);
cy.get(".mx_LegacyRoomHeader").within(() => cy.findByTitle(roomBeta).should("exist"));
cy.findByText(botName + " joined the room").should("exist");
});
testSetup = new ReadReceiptSetup(homeserver, "Mae", "Other User", roomAlpha, roomBeta);
});
after(() => {
@ -119,7 +85,7 @@ describe("Read receipts", () => {
* @param messages - the list of messages to send, these can be strings or implementations of MessageSpec like `editOf`
*/
function receiveMessages(room: string, messages: Message[]) {
sendMessageAsClient(bot, room, messages);
sendMessageAsClient(testSetup.bot, room, messages);
}
const room1 = roomAlpha;

View file

@ -15,8 +15,67 @@ limitations under the License.
*/
import type { MatrixClient, MatrixEvent, Room, IndexedDBStore } from "matrix-js-sdk/src/matrix";
import { HomeserverInstance } from "../../plugins/utils/homeserver";
import Chainable = Cypress.Chainable;
/**
* Set up for a read receipt test:
* - Create a user with the supplied name
* - As that user, create two rooms with the supplied names
* - Create a bot with the supplied name
* - Invite the bot to both rooms and ensure that it has joined
*/
export class ReadReceiptSetup {
roomAlpha: string;
roomBeta: string;
alphaRoomId: string;
betaRoomId: string;
bot: MatrixClient;
constructor(
homeserver: HomeserverInstance,
userName: string,
botName: string,
roomAlpha: string,
roomBeta: string,
) {
this.roomAlpha = roomAlpha;
this.roomBeta = roomBeta;
// Create a user
cy.initTestUser(homeserver, userName)
// Create 2 rooms
.then(() => {
cy.createRoom({ name: roomAlpha }).then((createdRoomId) => {
this.alphaRoomId = createdRoomId;
});
})
.then(() => {
cy.createRoom({ name: roomBeta }).then((createdRoomId) => {
this.betaRoomId = createdRoomId;
});
})
// Create a bot
.then(() => {
cy.getBot(homeserver, { displayName: botName }).then((botClient) => {
this.bot = botClient;
});
})
// Invite the bot to both rooms
.then(() => {
cy.inviteUser(this.alphaRoomId, this.bot.getUserId());
cy.viewRoomById(this.alphaRoomId);
cy.get(".mx_LegacyRoomHeader").within(() => cy.findByTitle(roomAlpha).should("exist"));
cy.findByText(botName + " joined the room").should("exist");
cy.inviteUser(this.betaRoomId, this.bot.getUserId());
cy.viewRoomById(this.betaRoomId);
cy.get(".mx_LegacyRoomHeader").within(() => cy.findByTitle(roomBeta).should("exist"));
cy.findByText(botName + " joined the room").should("exist");
});
}
}
/**
* A utility that is able to find messages based on their content, by looking
* inside the `timeline` objects in the object model.

View file

@ -18,7 +18,6 @@ limitations under the License.
/// <reference types="cypress" />
import type { MatrixClient } from "matrix-js-sdk/src/matrix";
import { HomeserverInstance } from "../../plugins/utils/homeserver";
import {
assertRead,
@ -35,22 +34,18 @@ import {
MessageContentSpec,
MessageFinder,
openThread,
ReadReceiptSetup,
saveAndReload,
sendMessageAsClient,
} from "./read-receipts-utils";
describe("Read receipts", () => {
const userName = "Mae";
const botName = "Other User";
const roomAlpha = "Room Alpha";
const roomBeta = "Room Beta";
let homeserver: HomeserverInstance;
let betaRoomId: string;
let alphaRoomId: string;
let bot: MatrixClient | undefined;
let messageFinder: MessageFinder;
let testSetup: ReadReceiptSetup;
function editOf(originalMessage: string, newMessage: string): MessageContentSpec {
return messageFinder.editOf(originalMessage, newMessage);
@ -92,36 +87,7 @@ describe("Read receipts", () => {
beforeEach(() => {
messageFinder = new MessageFinder();
// Create 2 rooms: Alpha & Beta. We join the bot to both of them
cy.initTestUser(homeserver, userName)
.then(() => {
cy.createRoom({ name: roomAlpha }).then((createdRoomId) => {
alphaRoomId = createdRoomId;
});
})
.then(() => {
cy.createRoom({ name: roomBeta }).then((createdRoomId) => {
betaRoomId = createdRoomId;
});
})
.then(() => {
cy.getBot(homeserver, { displayName: botName }).then((botClient) => {
bot = botClient;
});
})
.then(() => {
// Invite the bot to both rooms
cy.inviteUser(alphaRoomId, bot.getUserId());
cy.viewRoomById(alphaRoomId);
cy.get(".mx_LegacyRoomHeader").within(() => cy.findByTitle(roomAlpha).should("exist"));
cy.findByText(botName + " joined the room").should("exist");
cy.inviteUser(betaRoomId, bot.getUserId());
cy.viewRoomById(betaRoomId);
cy.get(".mx_LegacyRoomHeader").within(() => cy.findByTitle(roomBeta).should("exist"));
cy.findByText(botName + " joined the room").should("exist");
});
testSetup = new ReadReceiptSetup(homeserver, "Mae", "Other User", roomAlpha, roomBeta);
});
after(() => {
@ -134,7 +100,7 @@ describe("Read receipts", () => {
* @param messages - the list of messages to send, these can be strings or implementations of MessageSpec like `editOf`
*/
function receiveMessages(room: string, messages: Message[]) {
sendMessageAsClient(bot, room, messages);
sendMessageAsClient(testSetup.bot, room, messages);
}
const room1 = roomAlpha;