Use doMaybeLocalRoomAction (#9038)
* Use doMaybeLocalRoomAction * Revert unnecessary changes
This commit is contained in:
parent
9b8b8763f7
commit
3be20cf434
12 changed files with 333 additions and 22 deletions
|
@ -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", () => {
|
||||
|
|
104
test/components/views/rooms/VoiceRecordComposerTile-test.tsx
Normal file
104
test/components/views/rooms/VoiceRecordComposerTile-test.tsx
Normal file
|
@ -0,0 +1,104 @@
|
|||
/*
|
||||
Copyright 2022 The Matrix.org Foundation C.I.C.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import React from "react";
|
||||
import { mount, ReactWrapper } from "enzyme";
|
||||
import { ISendEventResponse, MatrixClient, MsgType, Room } from "matrix-js-sdk/src/matrix";
|
||||
import { mocked } from "jest-mock";
|
||||
|
||||
import VoiceRecordComposerTile from "../../../../src/components/views/rooms/VoiceRecordComposerTile";
|
||||
import { IUpload, VoiceRecording } from "../../../../src/audio/VoiceRecording";
|
||||
import { doMaybeLocalRoomAction } from "../../../../src/utils/local-room";
|
||||
import { MatrixClientPeg } from "../../../../src/MatrixClientPeg";
|
||||
|
||||
jest.mock("../../../../src/utils/local-room", () => ({
|
||||
doMaybeLocalRoomAction: jest.fn(),
|
||||
}));
|
||||
|
||||
describe("<VoiceRecordComposerTile/>", () => {
|
||||
let voiceRecordComposerTile: ReactWrapper<VoiceRecordComposerTile>;
|
||||
let mockRecorder: VoiceRecording;
|
||||
let mockUpload: IUpload;
|
||||
let mockClient: MatrixClient;
|
||||
const roomId = "!room:example.com";
|
||||
|
||||
beforeEach(() => {
|
||||
mockClient = {
|
||||
sendMessage: jest.fn(),
|
||||
} as unknown as MatrixClient;
|
||||
MatrixClientPeg.get = () => mockClient;
|
||||
|
||||
const props = {
|
||||
room: {
|
||||
roomId,
|
||||
} as unknown as Room,
|
||||
};
|
||||
mockUpload = {
|
||||
mxc: "mxc://example.com/voice",
|
||||
};
|
||||
mockRecorder = {
|
||||
stop: jest.fn(),
|
||||
upload: () => Promise.resolve(mockUpload),
|
||||
durationSeconds: 1337,
|
||||
contentType: "audio/ogg",
|
||||
getPlayback: () => ({
|
||||
thumbnailWaveform: [],
|
||||
}),
|
||||
} as unknown as VoiceRecording;
|
||||
voiceRecordComposerTile = mount(<VoiceRecordComposerTile {...props} />);
|
||||
voiceRecordComposerTile.setState({
|
||||
recorder: mockRecorder,
|
||||
});
|
||||
|
||||
mocked(doMaybeLocalRoomAction).mockImplementation((
|
||||
roomId: string,
|
||||
fn: (actualRoomId: string) => Promise<ISendEventResponse>,
|
||||
_client?: MatrixClient,
|
||||
) => {
|
||||
return fn(roomId);
|
||||
});
|
||||
});
|
||||
|
||||
describe("send", () => {
|
||||
it("should send the voice recording", async () => {
|
||||
await (voiceRecordComposerTile.instance() as VoiceRecordComposerTile).send();
|
||||
expect(mockClient.sendMessage).toHaveBeenCalledWith(roomId, {
|
||||
"body": "Voice message",
|
||||
"file": undefined,
|
||||
"info": {
|
||||
"duration": 1337000,
|
||||
"mimetype": "audio/ogg",
|
||||
"size": undefined,
|
||||
},
|
||||
"msgtype": MsgType.Audio,
|
||||
"org.matrix.msc1767.audio": {
|
||||
"duration": 1337000,
|
||||
"waveform": [],
|
||||
},
|
||||
"org.matrix.msc1767.file": {
|
||||
"file": undefined,
|
||||
"mimetype": "audio/ogg",
|
||||
"name": "Voice message.ogg",
|
||||
"size": undefined,
|
||||
"url": "mxc://example.com/voice",
|
||||
},
|
||||
"org.matrix.msc1767.text": "Voice message",
|
||||
"org.matrix.msc3245.voice": {},
|
||||
"url": "mxc://example.com/voice",
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue