Make apps/web/playwright comply with strict mode (#34403)
* Make apps/web/playwright comply with strict mode Otherwise it sometimes fails to compile matrix-js-sdk as strict mode & noImplicitAny both impact how overloads are asserted * Iterate
This commit is contained in:
@@ -8,7 +8,7 @@ Please see LICENSE files in the repository root for full details.
|
||||
|
||||
/* See readme.md for tips on writing these tests. */
|
||||
|
||||
import { customEvent, many, test } from ".";
|
||||
import { many, test } from ".";
|
||||
import { isDendrite } from "../../plugins/homeserver/dendrite";
|
||||
|
||||
test.describe("Read receipts", { tag: "@mergequeue" }, () => {
|
||||
@@ -20,6 +20,7 @@ test.describe("Read receipts", { tag: "@mergequeue" }, () => {
|
||||
roomAlpha: room1,
|
||||
roomBeta: room2,
|
||||
util,
|
||||
msg,
|
||||
}) => {
|
||||
await util.goTo(room1);
|
||||
await util.assertRead(room2);
|
||||
@@ -29,13 +30,14 @@ test.describe("Read receipts", { tag: "@mergequeue" }, () => {
|
||||
await util.markAsRead(room2);
|
||||
await util.assertRead(room2);
|
||||
|
||||
await util.receiveMessages(room2, [customEvent("org.custom.event", { body: "foobar" })]);
|
||||
await util.receiveMessages(room2, [msg.customEvent("org.custom.event", { body: "foobar" })]);
|
||||
await util.assertRead(room2);
|
||||
});
|
||||
test("Sending an important event after unimportant ones makes the room unread", async ({
|
||||
roomAlpha: room1,
|
||||
roomBeta: room2,
|
||||
util,
|
||||
msg,
|
||||
}) => {
|
||||
// Given We have read the important messages
|
||||
await util.goTo(room1);
|
||||
@@ -47,7 +49,7 @@ test.describe("Read receipts", { tag: "@mergequeue" }, () => {
|
||||
await util.goTo(room1);
|
||||
|
||||
// When we receive unimportant messages
|
||||
await util.receiveMessages(room2, [customEvent("org.custom.event", { body: "foobar" })]);
|
||||
await util.receiveMessages(room2, [msg.customEvent("org.custom.event", { body: "foobar" })]);
|
||||
|
||||
// Then the room is still read
|
||||
await util.assertStillRead(room2);
|
||||
@@ -62,6 +64,7 @@ test.describe("Read receipts", { tag: "@mergequeue" }, () => {
|
||||
roomAlpha: room1,
|
||||
roomBeta: room2,
|
||||
util,
|
||||
msg,
|
||||
}) => {
|
||||
// Display room 1
|
||||
await util.goTo(room1);
|
||||
@@ -71,9 +74,9 @@ test.describe("Read receipts", { tag: "@mergequeue" }, () => {
|
||||
|
||||
// We received 3 unimportant messages to room2
|
||||
await util.receiveMessages(room2, [
|
||||
customEvent("org.custom.event", { body: "foobar1" }),
|
||||
customEvent("org.custom.event", { body: "foobar2" }),
|
||||
customEvent("org.custom.event", { body: "foobar3" }),
|
||||
msg.customEvent("org.custom.event", { body: "foobar1" }),
|
||||
msg.customEvent("org.custom.event", { body: "foobar2" }),
|
||||
msg.customEvent("org.custom.event", { body: "foobar3" }),
|
||||
]);
|
||||
|
||||
// The room 2 is still read
|
||||
|
||||
@@ -23,9 +23,9 @@ type RoomRef = { name: string; roomId: string };
|
||||
* - Invite the bot to both rooms and ensure that it has joined
|
||||
*/
|
||||
export const test = base.extend<{
|
||||
roomAlphaName?: string;
|
||||
roomAlphaName: string;
|
||||
roomAlpha: RoomRef;
|
||||
roomBetaName?: string;
|
||||
roomBetaName: string;
|
||||
roomBeta: RoomRef;
|
||||
msg: MessageBuilder;
|
||||
util: Helpers;
|
||||
@@ -35,13 +35,13 @@ export const test = base.extend<{
|
||||
|
||||
roomAlphaName: "Room Alpha",
|
||||
roomAlpha: async ({ roomAlphaName: name, app, user, bot }, use) => {
|
||||
const roomId = await app.client.createRoom({ name, invite: [bot.credentials.userId] });
|
||||
const roomId = await app.client.createRoom({ name, invite: [bot.credentials!.userId] });
|
||||
await bot.awaitRoomMembership(roomId);
|
||||
await use({ name, roomId });
|
||||
},
|
||||
roomBetaName: "Room Beta",
|
||||
roomBeta: async ({ roomBetaName: name, app, user, bot }, use) => {
|
||||
const roomId = await app.client.createRoom({ name, invite: [bot.credentials.userId] });
|
||||
const roomId = await app.client.createRoom({ name, invite: [bot.credentials!.userId] });
|
||||
await bot.awaitRoomMembership(roomId);
|
||||
await use({ name, roomId });
|
||||
},
|
||||
@@ -159,7 +159,7 @@ export class MessageBuilder {
|
||||
ev.getRelation()?.rel_type === "m.thread"
|
||||
? {
|
||||
rel_type: "m.thread",
|
||||
event_id: ev.getRelation().event_id,
|
||||
event_id: ev.getRelation()!.event_id,
|
||||
}
|
||||
: {};
|
||||
|
||||
@@ -222,11 +222,11 @@ export class MessageBuilder {
|
||||
public async performAction(bot: Bot, room: JSHandle<Room>): Promise<void> {
|
||||
const ev = await this.messageFinder.getMessage(room, targetMessage, true);
|
||||
const { id, threadId } = await ev.evaluate((ev) => ({
|
||||
id: ev.getId(),
|
||||
id: ev.getId()!,
|
||||
threadId: !ev.isThreadRoot ? ev.threadRootId : undefined,
|
||||
}));
|
||||
const roomId = await room.evaluate((room) => room.roomId);
|
||||
await bot.reactToMessage(roomId, threadId, id, reaction);
|
||||
await bot.reactToMessage(roomId, threadId ?? null, id, reaction);
|
||||
}
|
||||
})(this);
|
||||
}
|
||||
@@ -240,11 +240,11 @@ export class MessageBuilder {
|
||||
public async performAction(bot: Bot, room: JSHandle<Room>): Promise<void> {
|
||||
const ev = await this.messageFinder.getMessage(room, targetMessage, true);
|
||||
const { id, threadId } = await ev.evaluate((ev) => ({
|
||||
id: ev.getId(),
|
||||
id: ev.getId()!,
|
||||
threadId: !ev.isThreadRoot ? ev.threadRootId : undefined,
|
||||
}));
|
||||
const roomId = await room.evaluate((room) => room.roomId);
|
||||
await bot.redactEvent(roomId, threadId, id);
|
||||
await bot.redactEvent(roomId, threadId!, id);
|
||||
}
|
||||
})(this);
|
||||
}
|
||||
@@ -286,6 +286,20 @@ export class MessageBuilder {
|
||||
{ event },
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* BotActionSpec to send a custom event
|
||||
* @param eventType - the type of the event to send
|
||||
* @param content - the event content to send
|
||||
*/
|
||||
customEvent(eventType: string, content: Record<string, any>): BotActionSpec {
|
||||
return new (class extends BotActionSpec {
|
||||
public async performAction(cli: Client, room: JSHandle<Room>): Promise<void> {
|
||||
const roomId = await room.evaluate((room) => room.roomId);
|
||||
await cli.sendEvent(roomId, null, eventType, content);
|
||||
}
|
||||
})(this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -295,11 +309,7 @@ export class MessageBuilder {
|
||||
* MessageBuilder.replyTo} which creates a reply based on a previous message.
|
||||
*/
|
||||
export abstract class MessageContentSpec {
|
||||
messageFinder: MessageBuilder | null;
|
||||
|
||||
constructor(messageFinder: MessageBuilder = null) {
|
||||
this.messageFinder = messageFinder;
|
||||
}
|
||||
constructor(public readonly messageFinder: MessageBuilder) {}
|
||||
|
||||
public abstract getContent(room: JSHandle<Room>): Promise<Record<string, unknown>>;
|
||||
}
|
||||
@@ -312,11 +322,7 @@ export abstract class MessageContentSpec {
|
||||
* MessageBuilder.redactionOf} which redacts the message we are referring to.
|
||||
*/
|
||||
export abstract class BotActionSpec {
|
||||
messageFinder: MessageBuilder | null;
|
||||
|
||||
constructor(messageFinder: MessageBuilder = null) {
|
||||
this.messageFinder = messageFinder;
|
||||
}
|
||||
constructor(public readonly messageFinder: MessageBuilder) {}
|
||||
|
||||
public abstract performAction(client: Client, room: JSHandle<Room>): Promise<void>;
|
||||
}
|
||||
@@ -542,7 +548,7 @@ class Helpers {
|
||||
|
||||
async findRoomById(roomId: string): Promise<JSHandle<Room>> {
|
||||
return this.app.client.evaluateHandle((cli, roomId) => {
|
||||
return cli.getRooms().find((r) => r.roomId === roomId);
|
||||
return cli.getRooms().find((r) => r.roomId === roomId)!;
|
||||
}, roomId);
|
||||
}
|
||||
|
||||
@@ -614,20 +620,6 @@ class Helpers {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* BotActionSpec to send a custom event
|
||||
* @param eventType - the type of the event to send
|
||||
* @param content - the event content to send
|
||||
*/
|
||||
export function customEvent(eventType: string, content: Record<string, any>): BotActionSpec {
|
||||
return new (class extends BotActionSpec {
|
||||
public async performAction(cli: Client, room: JSHandle<Room>): Promise<void> {
|
||||
const roomId = await room.evaluate((room) => room.roomId);
|
||||
await cli.sendEvent(roomId, null, eventType, content);
|
||||
}
|
||||
})();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate strings with the supplied prefix, suffixed with numbers.
|
||||
*
|
||||
|
||||
@@ -64,7 +64,7 @@ test.describe("Read receipts", { tag: "@mergequeue" }, () => {
|
||||
const sendThreadedReadReceipt = async (
|
||||
app: ElementAppPage,
|
||||
eventResponse: ISendEventResponse,
|
||||
threadRootEventResponse: ISendEventResponse = undefined,
|
||||
threadRootEventResponse?: ISendEventResponse,
|
||||
) => {
|
||||
await app.client.sendReadReceipt(
|
||||
await fakeEventFromSent(app, eventResponse, threadRootEventResponse?.event_id),
|
||||
@@ -93,10 +93,10 @@ test.describe("Read receipts", { tag: "@mergequeue" }, () => {
|
||||
*/
|
||||
selectedRoomId = await app.client.createRoom({ name: selectedRoomName });
|
||||
// Invite the bot to Other room
|
||||
otherRoomId = await app.client.createRoom({ name: otherRoomName, invite: [bot.credentials.userId] });
|
||||
otherRoomId = await app.client.createRoom({ name: otherRoomName, invite: [bot.credentials!.userId] });
|
||||
|
||||
await page.goto(`/#/room/${otherRoomId}`);
|
||||
await expect(page.getByText(`${bot.credentials.displayName} joined the room`)).toBeVisible();
|
||||
await expect(page.getByText(`${bot.credentials!.displayName} joined the room`)).toBeVisible();
|
||||
|
||||
// Then go into Selected room
|
||||
await page.goto(`/#/room/${selectedRoomId}`);
|
||||
@@ -287,7 +287,7 @@ test.describe("Read receipts", { tag: "@mergequeue" }, () => {
|
||||
sendMessageResponses.push(await sendMessage(bot, i));
|
||||
}
|
||||
|
||||
const lastMessageId = sendMessageResponses.at(-1).event_id;
|
||||
const lastMessageId = sendMessageResponses.at(-1)!.event_id;
|
||||
const uriEncodedLastMessageId = encodeURIComponent(lastMessageId);
|
||||
|
||||
// wait until all messages have been received
|
||||
@@ -330,7 +330,7 @@ test.describe("Read receipts", { tag: "@mergequeue" }, () => {
|
||||
|
||||
const readMarkersRequest2 = await readMarkersRequestPromise2;
|
||||
expect(readMarkersRequest2.postDataJSON()).toEqual({
|
||||
["m.fully_read"]: sendMessageResponses.at(-1).event_id,
|
||||
["m.fully_read"]: sendMessageResponses.at(-1)!.event_id,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -22,7 +22,7 @@ test.describe("Read receipts", { tag: "@mergequeue" }, () => {
|
||||
bot,
|
||||
}) => {
|
||||
// Create a third room to navigate to
|
||||
const room3Id = await app.client.createRoom({ name: "Room Gamma", invite: [bot.credentials.userId] });
|
||||
const room3Id = await app.client.createRoom({ name: "Room Gamma", invite: [bot.credentials!.userId] });
|
||||
await bot.awaitRoomMembership(room3Id);
|
||||
const room3 = { name: "Room Gamma", roomId: room3Id };
|
||||
|
||||
@@ -51,7 +51,7 @@ test.describe("Read receipts", { tag: "@mergequeue" }, () => {
|
||||
bot,
|
||||
}) => {
|
||||
// Create a third room to navigate to
|
||||
const room3Id = await app.client.createRoom({ name: "Room Gamma", invite: [bot.credentials.userId] });
|
||||
const room3Id = await app.client.createRoom({ name: "Room Gamma", invite: [bot.credentials!.userId] });
|
||||
await bot.awaitRoomMembership(room3Id);
|
||||
const room3 = { name: "Room Gamma", roomId: room3Id };
|
||||
|
||||
|
||||
Reference in New Issue
Block a user