2022-07-13 05:56:36 +00:00
|
|
|
/*
|
2024-09-09 13:57:16 +00:00
|
|
|
Copyright 2024 New Vector Ltd.
|
2022-07-13 05:56:36 +00:00
|
|
|
Copyright 2022 The Matrix.org Foundation C.I.C.
|
|
|
|
|
2024-09-09 13:57:16 +00: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 05:56:36 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
import { mocked } from "jest-mock";
|
2023-08-23 09:04:25 +00:00
|
|
|
import {
|
|
|
|
ContentHelpers,
|
|
|
|
MatrixClient,
|
|
|
|
LegacyLocationEventContent,
|
|
|
|
MLocationEventContent,
|
|
|
|
} from "matrix-js-sdk/src/matrix";
|
2022-07-13 05:56:36 +00:00
|
|
|
|
|
|
|
import { doMaybeLocalRoomAction } from "../../../../src/utils/local-room";
|
|
|
|
import {
|
|
|
|
LocationShareType,
|
|
|
|
shareLocation,
|
|
|
|
ShareLocationFn,
|
|
|
|
} from "../../../../src/components/views/location/shareLocation";
|
|
|
|
|
|
|
|
jest.mock("../../../../src/utils/local-room", () => ({
|
|
|
|
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 15:00:17 +00:00
|
|
|
const makeLocationContent = jest.spyOn(ContentHelpers, "makeLocationContent");
|
2022-07-13 05:56:36 +00:00
|
|
|
client = {
|
|
|
|
sendMessage: jest.fn(),
|
|
|
|
} as unknown as MatrixClient;
|
|
|
|
|
|
|
|
mocked(makeLocationContent).mockReturnValue(content);
|
2022-12-12 11:24:14 +00:00
|
|
|
mocked(doMaybeLocalRoomAction).mockImplementation(
|
|
|
|
<T>(roomId: string, fn: (actualRoomId: string) => Promise<T>, client?: MatrixClient) => {
|
|
|
|
return fn(roomId);
|
|
|
|
},
|
|
|
|
);
|
2022-07-13 05:56:36 +00:00
|
|
|
|
2023-02-15 13:36:22 +00:00
|
|
|
shareLocationFn = shareLocation(client, roomId, shareType, undefined, () => {});
|
2022-07-13 05:56:36 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("should forward the call to doMaybeLocalRoomAction", () => {
|
|
|
|
shareLocationFn({ uri: "https://example.com/" });
|
|
|
|
expect(client.sendMessage).toHaveBeenCalledWith(roomId, null, content);
|
|
|
|
});
|
|
|
|
});
|