Skip to content

Commit ff1057f

Browse files
committed
Share code for room initialisation between read receipt tests
1 parent 966d8bd commit ff1057f

File tree

7 files changed

+90
-229
lines changed

7 files changed

+90
-229
lines changed

cypress/e2e/read-receipts/editing-messages.spec.ts

Lines changed: 4 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ limitations under the License.
1818

1919
/// <reference types="cypress" />
2020

21-
import type { MatrixClient } from "matrix-js-sdk/src/matrix";
2221
import { HomeserverInstance } from "../../plugins/utils/homeserver";
2322
import {
2423
assertRead,
@@ -32,22 +31,18 @@ import {
3231
MessageContentSpec,
3332
MessageFinder,
3433
openThread,
34+
ReadReceiptSetup,
3535
saveAndReload,
3636
sendMessageAsClient,
3737
} from "./read-receipts-utils";
3838

3939
describe("Read receipts", () => {
40-
const userName = "Mae";
41-
const botName = "Other User";
4240
const roomAlpha = "Room Alpha";
4341
const roomBeta = "Room Beta";
4442

4543
let homeserver: HomeserverInstance;
46-
let betaRoomId: string;
47-
let alphaRoomId: string;
48-
let bot: MatrixClient | undefined;
49-
5044
let messageFinder: MessageFinder;
45+
let testSetup: ReadReceiptSetup;
5146

5247
function editOf(originalMessage: string, newMessage: string): MessageContentSpec {
5348
return messageFinder.editOf(originalMessage, newMessage);
@@ -81,36 +76,7 @@ describe("Read receipts", () => {
8176

8277
beforeEach(() => {
8378
messageFinder = new MessageFinder();
84-
85-
// Create 2 rooms: Alpha & Beta. We join the bot to both of them
86-
cy.initTestUser(homeserver, userName)
87-
.then(() => {
88-
cy.createRoom({ name: roomAlpha }).then((createdRoomId) => {
89-
alphaRoomId = createdRoomId;
90-
});
91-
})
92-
.then(() => {
93-
cy.createRoom({ name: roomBeta }).then((createdRoomId) => {
94-
betaRoomId = createdRoomId;
95-
});
96-
})
97-
.then(() => {
98-
cy.getBot(homeserver, { displayName: botName }).then((botClient) => {
99-
bot = botClient;
100-
});
101-
})
102-
.then(() => {
103-
// Invite the bot to both rooms
104-
cy.inviteUser(alphaRoomId, bot.getUserId());
105-
cy.viewRoomById(alphaRoomId);
106-
cy.get(".mx_LegacyRoomHeader").within(() => cy.findByTitle(roomAlpha).should("exist"));
107-
cy.findByText(botName + " joined the room").should("exist");
108-
109-
cy.inviteUser(betaRoomId, bot.getUserId());
110-
cy.viewRoomById(betaRoomId);
111-
cy.get(".mx_LegacyRoomHeader").within(() => cy.findByTitle(roomBeta).should("exist"));
112-
cy.findByText(botName + " joined the room").should("exist");
113-
});
79+
testSetup = new ReadReceiptSetup(homeserver, "Mae", "Other User", roomAlpha, roomBeta);
11480
});
11581

11682
after(() => {
@@ -123,7 +89,7 @@ describe("Read receipts", () => {
12389
* @param messages - the list of messages to send, these can be strings or implementations of MessageSpec like `editOf`
12490
*/
12591
function receiveMessages(room: string, messages: Message[]) {
126-
sendMessageAsClient(bot, room, messages);
92+
sendMessageAsClient(testSetup.bot, room, messages);
12793
}
12894

12995
const room1 = roomAlpha;

cypress/e2e/read-receipts/high-level.spec.ts

Lines changed: 4 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ limitations under the License.
1818

1919
/// <reference types="cypress" />
2020

21-
import type { MatrixClient } from "matrix-js-sdk/src/matrix";
2221
import { HomeserverInstance } from "../../plugins/utils/homeserver";
2322
import {
2423
assertMessageLoaded,
@@ -40,22 +39,18 @@ import {
4039
openThread,
4140
openThreadList,
4241
pageUp,
42+
ReadReceiptSetup,
4343
saveAndReload,
4444
sendMessageAsClient,
4545
} from "./read-receipts-utils";
4646

4747
describe("Read receipts", () => {
48-
const userName = "Mae";
49-
const botName = "Other User";
5048
const roomAlpha = "Room Alpha";
5149
const roomBeta = "Room Beta";
5250

5351
let homeserver: HomeserverInstance;
54-
let betaRoomId: string;
55-
let alphaRoomId: string;
56-
let bot: MatrixClient | undefined;
57-
5852
let messageFinder: MessageFinder;
53+
let testSetup: ReadReceiptSetup;
5954

6055
function threadedOff(rootMessage: string, newMessage: string): MessageContentSpec {
6156
return messageFinder.threadedOff(rootMessage, newMessage);
@@ -89,36 +84,7 @@ describe("Read receipts", () => {
8984

9085
beforeEach(() => {
9186
messageFinder = new MessageFinder();
92-
93-
// Create 2 rooms: Alpha & Beta. We join the bot to both of them
94-
cy.initTestUser(homeserver, userName)
95-
.then(() => {
96-
cy.createRoom({ name: roomAlpha }).then((createdRoomId) => {
97-
alphaRoomId = createdRoomId;
98-
});
99-
})
100-
.then(() => {
101-
cy.createRoom({ name: roomBeta }).then((createdRoomId) => {
102-
betaRoomId = createdRoomId;
103-
});
104-
})
105-
.then(() => {
106-
cy.getBot(homeserver, { displayName: botName }).then((botClient) => {
107-
bot = botClient;
108-
});
109-
})
110-
.then(() => {
111-
// Invite the bot to both rooms
112-
cy.inviteUser(alphaRoomId, bot.getUserId());
113-
cy.viewRoomById(alphaRoomId);
114-
cy.get(".mx_LegacyRoomHeader").within(() => cy.findByTitle(roomAlpha).should("exist"));
115-
cy.findByText(botName + " joined the room").should("exist");
116-
117-
cy.inviteUser(betaRoomId, bot.getUserId());
118-
cy.viewRoomById(betaRoomId);
119-
cy.get(".mx_LegacyRoomHeader").within(() => cy.findByTitle(roomBeta).should("exist"));
120-
cy.findByText(botName + " joined the room").should("exist");
121-
});
87+
testSetup = new ReadReceiptSetup(homeserver, "Mae", "Other User", roomAlpha, roomBeta);
12288
});
12389

12490
after(() => {
@@ -131,7 +97,7 @@ describe("Read receipts", () => {
13197
* @param messages - the list of messages to send, these can be strings or implementations of MessageSpec like `editOf`
13298
*/
13399
function receiveMessages(room: string, messages: Message[]) {
134-
sendMessageAsClient(bot, room, messages);
100+
sendMessageAsClient(testSetup.bot, room, messages);
135101
}
136102

137103
const room1 = roomAlpha;

cypress/e2e/read-receipts/missing-referents.spec.ts

Lines changed: 11 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,23 @@ limitations under the License.
1818

1919
/// <reference types="cypress" />
2020

21-
import type { MatrixClient } from "matrix-js-sdk/src/matrix";
2221
import { HomeserverInstance } from "../../plugins/utils/homeserver";
23-
import { goTo, Message, MessageContentSpec, MessageFinder, sendMessageAsClient } from "./read-receipts-utils";
22+
import {
23+
goTo,
24+
Message,
25+
MessageContentSpec,
26+
MessageFinder,
27+
ReadReceiptSetup,
28+
sendMessageAsClient,
29+
} from "./read-receipts-utils";
2430

2531
describe("Read receipts", () => {
26-
const userName = "Mae";
27-
const botName = "Other User";
2832
const roomAlpha = "Room Alpha";
2933
const roomBeta = "Room Beta";
3034

3135
let homeserver: HomeserverInstance;
32-
let betaRoomId: string;
33-
let alphaRoomId: string;
34-
let bot: MatrixClient | undefined;
35-
3636
let messageFinder: MessageFinder;
37+
let testSetup: ReadReceiptSetup;
3738

3839
function threadedOff(rootMessage: string, newMessage: string): MessageContentSpec {
3940
return messageFinder.threadedOff(rootMessage, newMessage);
@@ -59,36 +60,7 @@ describe("Read receipts", () => {
5960

6061
beforeEach(() => {
6162
messageFinder = new MessageFinder();
62-
63-
// Create 2 rooms: Alpha & Beta. We join the bot to both of them
64-
cy.initTestUser(homeserver, userName)
65-
.then(() => {
66-
cy.createRoom({ name: roomAlpha }).then((createdRoomId) => {
67-
alphaRoomId = createdRoomId;
68-
});
69-
})
70-
.then(() => {
71-
cy.createRoom({ name: roomBeta }).then((createdRoomId) => {
72-
betaRoomId = createdRoomId;
73-
});
74-
})
75-
.then(() => {
76-
cy.getBot(homeserver, { displayName: botName }).then((botClient) => {
77-
bot = botClient;
78-
});
79-
})
80-
.then(() => {
81-
// Invite the bot to both rooms
82-
cy.inviteUser(alphaRoomId, bot.getUserId());
83-
cy.viewRoomById(alphaRoomId);
84-
cy.get(".mx_LegacyRoomHeader").within(() => cy.findByTitle(roomAlpha).should("exist"));
85-
cy.findByText(botName + " joined the room").should("exist");
86-
87-
cy.inviteUser(betaRoomId, bot.getUserId());
88-
cy.viewRoomById(betaRoomId);
89-
cy.get(".mx_LegacyRoomHeader").within(() => cy.findByTitle(roomBeta).should("exist"));
90-
cy.findByText(botName + " joined the room").should("exist");
91-
});
63+
testSetup = new ReadReceiptSetup(homeserver, "Mae", "Other User", roomAlpha, roomBeta);
9264
});
9365

9466
/**
@@ -97,7 +69,7 @@ describe("Read receipts", () => {
9769
* @param messages - the list of messages to send, these can be strings or implementations of MessageSpec like `editOf`
9870
*/
9971
function receiveMessages(room: string, messages: Message[]) {
100-
sendMessageAsClient(bot, room, messages);
72+
sendMessageAsClient(testSetup.bot, room, messages);
10173
}
10274

10375
const room1 = roomAlpha;

cypress/e2e/read-receipts/new-messages.spec.ts

Lines changed: 4 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ limitations under the License.
1818

1919
/// <reference types="cypress" />
2020

21-
import type { MatrixClient } from "matrix-js-sdk/src/matrix";
2221
import { HomeserverInstance } from "../../plugins/utils/homeserver";
2322
import {
2423
assertRead,
@@ -27,6 +26,7 @@ import {
2726
assertUnreadLessThan,
2827
assertUnreadThread,
2928
backToThreadsList,
29+
ReadReceiptSetup,
3030
goTo,
3131
many,
3232
markAsRead,
@@ -39,17 +39,12 @@ import {
3939
} from "./read-receipts-utils";
4040

4141
describe("Read receipts", () => {
42-
const userName = "Mae";
43-
const botName = "Other User";
4442
const roomAlpha = "Room Alpha";
4543
const roomBeta = "Room Beta";
4644

4745
let homeserver: HomeserverInstance;
48-
let betaRoomId: string;
49-
let alphaRoomId: string;
50-
let bot: MatrixClient | undefined;
51-
5246
let messageFinder: MessageFinder;
47+
let testSetup: ReadReceiptSetup;
5348

5449
function replyTo(targetMessage: string, newMessage: string): MessageContentSpec {
5550
return messageFinder.replyTo(targetMessage, newMessage);
@@ -87,36 +82,7 @@ describe("Read receipts", () => {
8782

8883
beforeEach(() => {
8984
messageFinder = new MessageFinder();
90-
91-
// Create 2 rooms: Alpha & Beta. We join the bot to both of them
92-
cy.initTestUser(homeserver, userName)
93-
.then(() => {
94-
cy.createRoom({ name: roomAlpha }).then((createdRoomId) => {
95-
alphaRoomId = createdRoomId;
96-
});
97-
})
98-
.then(() => {
99-
cy.createRoom({ name: roomBeta }).then((createdRoomId) => {
100-
betaRoomId = createdRoomId;
101-
});
102-
})
103-
.then(() => {
104-
cy.getBot(homeserver, { displayName: botName }).then((botClient) => {
105-
bot = botClient;
106-
});
107-
})
108-
.then(() => {
109-
// Invite the bot to both rooms
110-
cy.inviteUser(alphaRoomId, bot.getUserId());
111-
cy.viewRoomById(alphaRoomId);
112-
cy.get(".mx_LegacyRoomHeader").within(() => cy.findByTitle(roomAlpha).should("exist"));
113-
cy.findByText(botName + " joined the room").should("exist");
114-
115-
cy.inviteUser(betaRoomId, bot.getUserId());
116-
cy.viewRoomById(betaRoomId);
117-
cy.get(".mx_LegacyRoomHeader").within(() => cy.findByTitle(roomBeta).should("exist"));
118-
cy.findByText(botName + " joined the room").should("exist");
119-
});
85+
testSetup = new ReadReceiptSetup(homeserver, "Mae", "Other User", roomAlpha, roomBeta);
12086
});
12187

12288
after(() => {
@@ -129,7 +95,7 @@ describe("Read receipts", () => {
12995
* @param messages - the list of messages to send, these can be strings or implementations of MessageSpec like `editOf`
13096
*/
13197
function receiveMessages(room: string, messages: Message[]) {
132-
sendMessageAsClient(bot, room, messages);
98+
sendMessageAsClient(testSetup.bot, room, messages);
13399
}
134100

135101
/**

0 commit comments

Comments
 (0)