Only allow to start a DM with one email if encryption by default is enabled (#10253)
This commit is contained in:
parent
db6ee53535
commit
9b74b0f057
4 changed files with 241 additions and 23 deletions
|
@ -35,11 +35,37 @@ jest.mock("../../../../src/IdentityAuthClient", () =>
|
|||
})),
|
||||
);
|
||||
|
||||
const getSearchField = () => screen.getByTestId("invite-dialog-input");
|
||||
|
||||
const enterIntoSearchField = async (value: string) => {
|
||||
const searchField = getSearchField();
|
||||
await userEvent.clear(searchField);
|
||||
await userEvent.type(searchField, value + "{enter}");
|
||||
};
|
||||
|
||||
const pasteIntoSearchField = async (value: string) => {
|
||||
const searchField = getSearchField();
|
||||
await userEvent.clear(searchField);
|
||||
searchField.focus();
|
||||
await userEvent.paste(value);
|
||||
};
|
||||
|
||||
const expectPill = (value: string) => {
|
||||
expect(screen.getByText(value)).toBeInTheDocument();
|
||||
expect(getSearchField()).toHaveValue("");
|
||||
};
|
||||
|
||||
const expectNoPill = (value: string) => {
|
||||
expect(screen.queryByText(value)).not.toBeInTheDocument();
|
||||
expect(getSearchField()).toHaveValue(value);
|
||||
};
|
||||
|
||||
describe("InviteDialog", () => {
|
||||
const roomId = "!111111111111111111:example.org";
|
||||
const aliceId = "@alice:example.org";
|
||||
const aliceEmail = "foobar@email.com";
|
||||
const bobId = "@bob:example.org";
|
||||
const bobEmail = "bobbob@example.com"; // bob@example.com is already used as an example in the invite dialog
|
||||
const mockClient = getMockClientWithEventEmitter({
|
||||
getUserId: jest.fn().mockReturnValue(bobId),
|
||||
getSafeUserId: jest.fn().mockReturnValue(bobId),
|
||||
|
@ -64,6 +90,7 @@ describe("InviteDialog", () => {
|
|||
getTerms: jest.fn().mockResolvedValue({ policies: [] }),
|
||||
supportsThreads: jest.fn().mockReturnValue(false),
|
||||
isInitialSyncComplete: jest.fn().mockReturnValue(true),
|
||||
getClientWellKnown: jest.fn(),
|
||||
});
|
||||
let room: Room;
|
||||
|
||||
|
@ -72,6 +99,7 @@ describe("InviteDialog", () => {
|
|||
DMRoomMap.makeShared();
|
||||
jest.clearAllMocks();
|
||||
mockClient.getUserId.mockReturnValue(bobId);
|
||||
mockClient.getClientWellKnown.mockReturnValue({});
|
||||
|
||||
room = new Room(roomId, mockClient, mockClient.getSafeUserId());
|
||||
room.addLiveEvents([
|
||||
|
@ -208,4 +236,68 @@ describe("InviteDialog", () => {
|
|||
await screen.findByText(aliceEmail);
|
||||
expect(input).toHaveValue("");
|
||||
});
|
||||
|
||||
it("should allow to invite multiple emails to a room", async () => {
|
||||
render(<InviteDialog kind={InviteKind.Invite} roomId={roomId} onFinished={jest.fn()} />);
|
||||
|
||||
await enterIntoSearchField(aliceEmail);
|
||||
expectPill(aliceEmail);
|
||||
|
||||
await enterIntoSearchField(bobEmail);
|
||||
expectPill(bobEmail);
|
||||
});
|
||||
|
||||
describe("when encryption by default is disabled", () => {
|
||||
beforeEach(() => {
|
||||
mockClient.getClientWellKnown.mockReturnValue({
|
||||
"io.element.e2ee": {
|
||||
default: false,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("should allow to invite more than one email to a DM", async () => {
|
||||
render(<InviteDialog kind={InviteKind.Dm} onFinished={jest.fn()} />);
|
||||
|
||||
await enterIntoSearchField(aliceEmail);
|
||||
expectPill(aliceEmail);
|
||||
|
||||
await enterIntoSearchField(bobEmail);
|
||||
expectPill(bobEmail);
|
||||
});
|
||||
});
|
||||
|
||||
it("should not allow to invite more than one email to a DM", async () => {
|
||||
render(<InviteDialog kind={InviteKind.Dm} onFinished={jest.fn()} />);
|
||||
|
||||
// Start with an email → should convert to a pill
|
||||
await enterIntoSearchField(aliceEmail);
|
||||
expect(screen.getByText("Invites by email can only be sent one at a time")).toBeInTheDocument();
|
||||
expectPill(aliceEmail);
|
||||
|
||||
// Everything else from now on should not convert to a pill
|
||||
|
||||
await enterIntoSearchField(bobEmail);
|
||||
expectNoPill(bobEmail);
|
||||
|
||||
await enterIntoSearchField(aliceId);
|
||||
expectNoPill(aliceId);
|
||||
|
||||
await pasteIntoSearchField(bobEmail);
|
||||
expectNoPill(bobEmail);
|
||||
});
|
||||
|
||||
it("should not allow to invite a MXID and an email to a DM", async () => {
|
||||
render(<InviteDialog kind={InviteKind.Dm} onFinished={jest.fn()} />);
|
||||
|
||||
// Start with a MXID → should convert to a pill
|
||||
await enterIntoSearchField("@carol:example.com");
|
||||
expect(screen.queryByText("Invites by email can only be sent one at a time")).not.toBeInTheDocument();
|
||||
expectPill("@carol:example.com");
|
||||
|
||||
// Add an email → should not convert to a pill
|
||||
await enterIntoSearchField(bobEmail);
|
||||
expect(screen.getByText("Invites by email can only be sent one at a time")).toBeInTheDocument();
|
||||
expectNoPill(bobEmail);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue