Await start DM in right panel (#10290)

This commit is contained in:
Michael Weimann 2023-03-06 16:09:56 +01:00 committed by GitHub
parent 667ec166d7
commit 394bffbae4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 2 deletions

View File

@ -131,7 +131,7 @@ async function openDmForUser(matrixClient: MatrixClient, user: Member): Promise<
display_name: user.rawDisplayName,
avatar_url: avatarUrl,
});
startDmOnFirstMessage(matrixClient, [startDmUser]);
await startDmOnFirstMessage(matrixClient, [startDmUser]);
}
type SetUpdating = (updating: boolean) => void;

View File

@ -15,13 +15,14 @@ limitations under the License.
*/
import React from "react";
import { fireEvent, render, screen, waitFor, cleanup } from "@testing-library/react";
import { fireEvent, render, screen, waitFor, cleanup, act } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { mocked } from "jest-mock";
import { Room, User, MatrixClient, RoomMember, MatrixEvent, EventType } from "matrix-js-sdk/src/matrix";
import { Phase, VerificationRequest } from "matrix-js-sdk/src/crypto/verification/request/VerificationRequest";
import { DeviceTrustLevel, UserTrustLevel } from "matrix-js-sdk/src/crypto/CrossSigning";
import { DeviceInfo } from "matrix-js-sdk/src/crypto/deviceinfo";
import { defer } from "matrix-js-sdk/src/utils";
import UserInfo, {
BanToggleButton,
@ -44,6 +45,7 @@ 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";
import { flushPromises } from "../../../test-utils";
jest.mock("../../../../src/utils/direct-messages", () => ({
...jest.requireActual("../../../../src/utils/direct-messages"),
@ -608,8 +610,15 @@ describe("<UserOptionsSection />", () => {
])(
"clicking »message« %s should start a DM",
async (test: string, member: RoomMember | User, expectedAvatarUrl: string | undefined) => {
const deferred = defer<string>();
mocked(startDmOnFirstMessage).mockReturnValue(deferred.promise);
renderComponent({ member });
await userEvent.click(screen.getByText("Message"));
// Checking the attribute, because the button is a DIV and toBeDisabled() does not work.
expect(screen.getByText("Message")).toHaveAttribute("disabled");
expect(startDmOnFirstMessage).toHaveBeenCalledWith(mockClient, [
new DirectoryMember({
user_id: member.userId,
@ -617,6 +626,14 @@ describe("<UserOptionsSection />", () => {
avatar_url: expectedAvatarUrl,
}),
]);
await act(async () => {
deferred.resolve("!dm:example.com");
await flushPromises();
});
// Checking the attribute, because the button is a DIV and toBeDisabled() does not work.
expect(screen.getByText("Message")).not.toHaveAttribute("disabled");
},
);
});