Add a test for custom modules.

This commit is contained in:
Half-Shot 2025-05-20 13:27:22 +01:00
parent 4d81b36270
commit afab6c29dc
4 changed files with 59 additions and 0 deletions

View File

@ -0,0 +1,36 @@
/*
Copyright 2025 New Vector Ltd.
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
Please see LICENSE files in the repository root for full details.
*/
import { test, expect } from "../../element-web-test";
test.describe("Custom Component Module", () => {
test.use({
displayName: "Manny",
config: {
modules: ["/modules/custom-component-module.js"],
},
page: async ({ page }, use) => {
await page.route("/modules/custom-component-module.js", async (route) => {
await route.fulfill({ path: "playwright/sample-files/custom-component-module.js" });
});
await use(page);
},
room: async ({ page, app, user, bot }, use) => {
const roomId = await app.client.createRoom({ name: 'TestRoom' });
await use({ roomId });
},
});
test("should replace the render method of a textual event", { tag: "@screenshot" }, async ({ page, room, app }) => {
await app.viewRoomById(room.roomId);
await app.client.sendMessage(room.roomId, 'Simple message');
await expect(await page.getByText("Simple message")).toMatchScreenshot("custom-component-tile.png");
});
test("should render the original content of a textual event conditionally", { tag: "@screenshot" }, async ({ page, room, app }) => {
await app.viewRoomById(room.roomId);
await app.client.sendMessage(room.roomId, 'Do not replace me');
await expect(await page.getByText("Do not replace me")).toMatchScreenshot("custom-component-tile-original.png");
});
});

View File

@ -0,0 +1,23 @@
/*
Copyright 2025 New Vector Ltd.
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
Please see LICENSE files in the repository root for full details.
*/
export default class CustomComponentModule {
static moduleApiVersion = "^1.0.0";
constructor(api) {
this.api = api;
this.api.customComponents.register("TextualBody", (props, originalComponent) => {
const body = props.mxEvent.getContent().body;
if (body === "Do not replace me") {
return originalComponent();
}
return `Custom text for ${body}`;
})
}
async load() {
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB