Use doMaybeLocalRoomAction (#9038)

* Use doMaybeLocalRoomAction

* Revert unnecessary changes
This commit is contained in:
Michael Weimann 2022-07-13 07:56:36 +02:00 committed by GitHub
parent 9b8b8763f7
commit 3be20cf434
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 333 additions and 22 deletions

View file

@ -17,8 +17,9 @@ limitations under the License.
import React from "react";
import { act } from "react-dom/test-utils";
import { sleep } from "matrix-js-sdk/src/utils";
import { MatrixClient } from "matrix-js-sdk/src/matrix";
import { ISendEventResponse, MatrixClient, MsgType } from "matrix-js-sdk/src/matrix";
import { mount } from 'enzyme';
import { mocked } from "jest-mock";
import SendMessageComposer, {
createMessageContent,
@ -37,6 +38,11 @@ import { Layout } from '../../../../src/settings/enums/Layout';
import { IRoomState } from "../../../../src/components/structures/RoomView";
import { RoomPermalinkCreator } from "../../../../src/utils/permalinks/Permalinks";
import { mockPlatformPeg } from "../../../test-utils/platform";
import { doMaybeLocalRoomAction } from "../../../../src/utils/local-room";
jest.mock("../../../../src/utils/local-room", () => ({
doMaybeLocalRoomAction: jest.fn(),
}));
const WrapWithProviders: React.FC<{
roomContext: IRoomState;
@ -306,6 +312,34 @@ describe('<SendMessageComposer/>', () => {
const key = instance.editorStateKey;
expect(key).toEqual('mx_cider_state_myfakeroom_myFakeThreadId');
});
it("correctly sends a message", () => {
mocked(doMaybeLocalRoomAction).mockImplementation((
roomId: string,
fn: (actualRoomId: string) => Promise<ISendEventResponse>,
_client?: MatrixClient,
) => {
return fn(roomId);
});
mockPlatformPeg({ overrideBrowserShortcuts: jest.fn().mockReturnValue(false) });
const wrapper = getComponent();
addTextToComposer(wrapper, "test message");
act(() => {
wrapper.find(".mx_SendMessageComposer").simulate("keydown", { key: "Enter" });
wrapper.update();
});
expect(mockClient.sendMessage).toHaveBeenCalledWith(
"myfakeroom",
null,
{
"body": "test message",
"msgtype": MsgType.Text,
},
);
});
});
describe("isQuickReaction", () => {