|
| 1 | +/* |
| 2 | +Copyright 2025 New Vector Ltd. |
| 3 | +
|
| 4 | +SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial |
| 5 | +Please see LICENSE files in the repository root for full details. |
| 6 | +*/ |
| 7 | + |
| 8 | +import { createNewInstance } from "@element-hq/element-web-playwright-common"; |
| 9 | + |
| 10 | +import { expect, test } from "../../element-web-test"; |
| 11 | +import { ElementAppPage } from "../../pages/ElementAppPage"; |
| 12 | +import { createRoom, sendMessageInCurrentRoom } from "./utils"; |
| 13 | + |
| 14 | +test.use({ |
| 15 | + displayName: "Alice", |
| 16 | + labsFlags: ["feature_share_history_on_invite"], |
| 17 | +}); |
| 18 | + |
| 19 | +/** Tests for MSC4268: encrypted history sharing */ |
| 20 | +test.describe("History sharing", function () { |
| 21 | + test( |
| 22 | + "We should share history when sending invites", |
| 23 | + { tag: "@screenshot" }, |
| 24 | + async ( |
| 25 | + { labsFlags, browser, page: alicePage, user: aliceCredentials, app: aliceElementApp, homeserver }, |
| 26 | + testInfo, |
| 27 | + ) => { |
| 28 | + // In this test, Alice creates an encrypted room and sends an event; |
| 29 | + // we then invite Bob, and ensure Bob can see the content. |
| 30 | + |
| 31 | + await aliceElementApp.client.bootstrapCrossSigning(aliceCredentials); |
| 32 | + |
| 33 | + // Register a second user, and open it in a second instance of the app |
| 34 | + const bobCredentials = await homeserver.registerUser(`user_${testInfo.testId}_bob`, "password", "Bob"); |
| 35 | + const bobPage = await createNewInstance(browser, bobCredentials, {}, labsFlags); |
| 36 | + const bobElementApp = new ElementAppPage(bobPage); |
| 37 | + await bobElementApp.client.bootstrapCrossSigning(bobCredentials); |
| 38 | + |
| 39 | + // Create the room and send a message |
| 40 | + await createRoom(alicePage, "TestRoom", true); |
| 41 | + await sendMessageInCurrentRoom(alicePage, "A message from Alice"); |
| 42 | + |
| 43 | + // Send the invite to Bob |
| 44 | + await aliceElementApp.inviteUserToCurrentRoom(bobCredentials.userId); |
| 45 | + |
| 46 | + // Bob accepts the invite |
| 47 | + await bobPage.getByRole("option", { name: "TestRoom" }).click(); |
| 48 | + await bobPage.getByRole("button", { name: "Accept" }).click(); |
| 49 | + |
| 50 | + // Bob should now be able to decrypt the event |
| 51 | + await expect(bobPage.getByText("A message from Alice")).toBeVisible(); |
| 52 | + |
| 53 | + const mask = [bobPage.locator(".mx_MessageTimestamp")]; |
| 54 | + await expect(bobPage.locator(".mx_RoomView_body")).toMatchScreenshot("shared-history-invite-accepted.png", { |
| 55 | + mask, |
| 56 | + }); |
| 57 | + }, |
| 58 | + ); |
| 59 | +}); |
0 commit comments