mirror of
https://github.com/vector-im/element-web.git
synced 2026-05-14 17:06:18 +02:00
Add a test for custom modules.
This commit is contained in:
parent
4d81b36270
commit
afab6c29dc
36
playwright/e2e/modules/custom-component.spec.ts
Normal file
36
playwright/e2e/modules/custom-component.spec.ts
Normal 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");
|
||||
});
|
||||
});
|
||||
23
playwright/sample-files/custom-component-module.js
Normal file
23
playwright/sample-files/custom-component-module.js
Normal 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 |
Loading…
x
Reference in New Issue
Block a user