2022-07-13 13:56:36 +08:00
|
|
|
/*
|
2024-09-09 21:57:16 +08:00
|
|
|
Copyright 2024 New Vector Ltd.
|
2022-07-13 13:56:36 +08:00
|
|
|
Copyright 2022 The Matrix.org Foundation C.I.C.
|
|
|
|
|
2024-09-09 21:57:16 +08:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
|
|
|
|
Please see LICENSE files in the repository root for full details.
|
2022-07-13 13:56:36 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
import { mocked } from "jest-mock";
|
2023-08-23 17:04:25 +08:00
|
|
|
import {
|
|
|
|
ContentHelpers,
|
|
|
|
MatrixClient,
|
|
|
|
LegacyLocationEventContent,
|
|
|
|
MLocationEventContent,
|
|
|
|
} from "matrix-js-sdk/src/matrix";
|
2022-07-13 13:56:36 +08:00
|
|
|
|
2024-10-15 21:57:26 +08:00
|
|
|
import { doMaybeLocalRoomAction } from "../../../../../src/utils/local-room";
|
2022-07-13 13:56:36 +08:00
|
|
|
import {
|
|
|
|
LocationShareType,
|
|
|
|
shareLocation,
|
|
|
|
ShareLocationFn,
|
2024-10-15 21:57:26 +08:00
|
|
|
} from "../../../../../src/components/views/location/shareLocation";
|
2022-07-13 13:56:36 +08:00
|
|
|
|
2024-10-15 21:57:26 +08:00
|
|
|
jest.mock("../../../../../src/utils/local-room", () => ({
|
2022-07-13 13:56:36 +08:00
|
|
|
doMaybeLocalRoomAction: jest.fn(),
|
|
|
|
}));
|
|
|
|
|
|
|
|
describe("shareLocation", () => {
|
|
|
|
const roomId = "!room:example.com";
|
|
|
|
const shareType = LocationShareType.Pin;
|
|
|
|
const content = { test: "location content" } as unknown as LegacyLocationEventContent & MLocationEventContent;
|
|
|
|
let client: MatrixClient;
|
|
|
|
let shareLocationFn: ShareLocationFn;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2023-08-15 23:00:17 +08:00
|
|
|
const makeLocationContent = jest.spyOn(ContentHelpers, "makeLocationContent");
|
2022-07-13 13:56:36 +08:00
|
|
|
client = {
|
|
|
|
sendMessage: jest.fn(),
|
|
|
|
} as unknown as MatrixClient;
|
|
|
|
|
|
|
|
mocked(makeLocationContent).mockReturnValue(content);
|
2022-11-04 18:48:08 +08:00
|
|
|
mocked(doMaybeLocalRoomAction).mockImplementation(
|
|
|
|
<T>(roomId: string, fn: (actualRoomId: string) => Promise<T>, client?: MatrixClient) => {
|
2022-07-13 13:56:36 +08:00
|
|
|
return fn(roomId);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
2023-02-15 21:36:22 +08:00
|
|
|
shareLocationFn = shareLocation(client, roomId, shareType, undefined, () => {});
|
2022-07-13 13:56:36 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it("should forward the call to doMaybeLocalRoomAction", () => {
|
|
|
|
shareLocationFn({ uri: "https://example.com/" });
|
|
|
|
expect(client.sendMessage).toHaveBeenCalledWith(roomId, null, content);
|
|
|
|
});
|
|
|
|
});
|