Fix start DM via right panel (#10278)
This commit is contained in:
parent
8d9fdc3b41
commit
6746ce2da3
2 changed files with 46 additions and 29 deletions
|
@ -43,6 +43,12 @@ import MultiInviter from "../../../../src/utils/MultiInviter";
|
|||
import * as mockVerification from "../../../../src/verification";
|
||||
import Modal from "../../../../src/Modal";
|
||||
import { E2EStatus } from "../../../../src/utils/ShieldUtils";
|
||||
import { DirectoryMember, startDmOnFirstMessage } from "../../../../src/utils/direct-messages";
|
||||
|
||||
jest.mock("../../../../src/utils/direct-messages", () => ({
|
||||
...jest.requireActual("../../../../src/utils/direct-messages"),
|
||||
startDmOnFirstMessage: jest.fn(),
|
||||
}));
|
||||
|
||||
jest.mock("../../../../src/dispatcher/dispatcher");
|
||||
|
||||
|
@ -121,7 +127,7 @@ const mockClient = mocked({
|
|||
setPowerLevel: jest.fn(),
|
||||
} as unknown as MatrixClient);
|
||||
|
||||
const defaultUserId = "@test:test";
|
||||
const defaultUserId = "@user:example.com";
|
||||
const defaultUser = new User(defaultUserId);
|
||||
|
||||
beforeEach(() => {
|
||||
|
@ -550,23 +556,6 @@ describe("<UserOptionsSection />", () => {
|
|||
});
|
||||
});
|
||||
|
||||
it("calling .invite with a null roomId still calls .invite and shows default error message", async () => {
|
||||
inviteSpy.mockRejectedValue({ this: "could be anything" });
|
||||
|
||||
// render the component and click the button
|
||||
renderComponent({ canInvite: true, member: { ...member, roomId: null } });
|
||||
const inviteButton = screen.getByRole("button", { name: /invite/i });
|
||||
expect(inviteButton).toBeInTheDocument();
|
||||
await userEvent.click(inviteButton);
|
||||
|
||||
expect(inviteSpy).toHaveBeenCalledTimes(1);
|
||||
|
||||
// check that the default test error message is displayed
|
||||
await waitFor(() => {
|
||||
expect(screen.getByText(/operation failed/i)).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
it("shows a modal before ignoring the user", async () => {
|
||||
const originalCreateDialog = Modal.createDialog;
|
||||
const modalSpy = (Modal.createDialog = jest.fn().mockReturnValue({
|
||||
|
@ -612,6 +601,24 @@ describe("<UserOptionsSection />", () => {
|
|||
await userEvent.click(screen.getByRole("button", { name: "Unignore" }));
|
||||
expect(mockClient.setIgnoredUsers).toHaveBeenCalledWith([]);
|
||||
});
|
||||
|
||||
it.each([
|
||||
["for a RoomMember", member, member.getMxcAvatarUrl()],
|
||||
["for a User", defaultUser, defaultUser.avatarUrl],
|
||||
])(
|
||||
"clicking »message« %s should start a DM",
|
||||
async (test: string, member: RoomMember | User, expectedAvatarUrl: string | undefined) => {
|
||||
renderComponent({ member });
|
||||
await userEvent.click(screen.getByText("Message"));
|
||||
expect(startDmOnFirstMessage).toHaveBeenCalledWith(mockClient, [
|
||||
new DirectoryMember({
|
||||
user_id: member.userId,
|
||||
display_name: member.rawDisplayName,
|
||||
avatar_url: expectedAvatarUrl,
|
||||
}),
|
||||
]);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
describe("<PowerLevelEditor />", () => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue