Share code for room initialisation between read receipt tests

This commit is contained in:
Andy Balaam 2023-10-02 16:14:56 +01:00
parent 966d8bd695
commit ff1057fb0a
7 changed files with 90 additions and 229 deletions

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;