Add support for Module API 1.4 (#30185)

* Add support for Module API 1.3.0

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* Add missing import

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* Iterate

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* Iterate

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* Iterate

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* Fix import

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* Iterate

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* Bump module API

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* Update module API and remove jest stub

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* Fix test mocks

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* Improve coverage

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* types

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* Coverage

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* Coverage

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

---------

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
Michael Telatynski
2025-08-11 09:15:45 +01:00
committed by GitHub
parent bbb179b6d3
commit d5a9b3f4c0
18 changed files with 336 additions and 14 deletions

View File

@@ -53,6 +53,7 @@ import { ElementWidgetActions } from "../../../../src/stores/widgets/ElementWidg
jest.mock("../../../../src/stores/OwnProfileStore", () => ({
OwnProfileStore: {
instance: {
on: jest.fn(),
isProfileInfoFetched: true,
removeListener: jest.fn(),
getHttpAvatarUrl: jest.fn().mockReturnValue("http://avatar_url"),

View File

@@ -43,6 +43,7 @@ import { RoomPermalinkCreator } from "../../../../../src/utils/permalinks/Permal
jest.mock("../../../../../src/stores/OwnProfileStore", () => ({
OwnProfileStore: {
instance: {
on: jest.fn(),
isProfileInfoFetched: true,
removeListener: jest.fn(),
getHttpAvatarUrl: jest.fn().mockReturnValue("http://avatar_url"),

View File

@@ -48,6 +48,7 @@ jest.mock("../../../../../src/settings/SettingsStore", () => ({
jest.mock("../../../../../src/stores/OwnProfileStore", () => ({
OwnProfileStore: {
instance: {
on: jest.fn(),
displayName: "Ernie",
getHttpAvatarUrl: jest.fn().mockReturnValue("image.com/img"),
},

View File

@@ -16,6 +16,7 @@ import { MatrixClientPeg } from "../../../../../src/MatrixClientPeg";
import DMRoomMap from "../../../../../src/utils/DMRoomMap";
import RoomPreviewBar from "../../../../../src/components/views/rooms/RoomPreviewBar";
import defaultDispatcher from "../../../../../src/dispatcher/dispatcher";
import ModuleApi from "../../../../../src/modules/Api.ts";
jest.mock("../../../../../src/IdentityAuthClient", () => {
return jest.fn().mockImplementation(() => {
@@ -497,4 +498,12 @@ describe("<RoomPreviewBar />", () => {
expect(onCancelAskToJoin).toHaveBeenCalled();
});
});
it("should render Module roomPreviewBarRenderer if specified", () => {
jest.spyOn(ModuleApi.customComponents, "roomPreviewBarRenderer", "get").mockReturnValue(() => (
<>Test component</>
));
const { getByText } = render(<RoomPreviewBar />);
expect(getByText("Test component")).toBeTruthy();
});
});

View File

@@ -0,0 +1,30 @@
/*
Copyright 2025 New Vector Ltd.
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
Please see LICENSE files in the repository root for full details.
*/
import defaultDispatcher from "../../../src/dispatcher/dispatcher.ts";
import { overwriteAccountAuth } from "../../../src/modules/Auth.ts";
describe("overwriteAccountAuth", () => {
it("should call overwrite login with accountInfo", () => {
const spy = jest.spyOn(defaultDispatcher, "dispatch");
const accountInfo = {
userId: "@user:server.com",
deviceId: "DEVICEID",
accessToken: "TOKEN",
homeserverUrl: "https://server.com",
};
overwriteAccountAuth(accountInfo);
expect(spy).toHaveBeenCalledWith(
{
action: "overwrite_login",
credentials: expect.objectContaining(accountInfo),
},
true,
);
});
});

View File

@@ -0,0 +1,23 @@
/*
Copyright 2025 New Vector Ltd.
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
Please see LICENSE files in the repository root for full details.
*/
import React from "react";
import { screen } from "jest-matrix-react";
import { openDialog } from "../../../src/modules/Dialog.tsx";
describe("openDialog", () => {
it("should open a dialog with the expected title", async () => {
const Dialog = () => <>Dialog Content</>;
const title = "Test Dialog";
openDialog({ title }, Dialog, {});
await expect(screen.findByText("Test Dialog")).resolves.toBeInTheDocument();
expect(screen.getByText("Dialog Content")).toBeInTheDocument();
});
});

View File

@@ -0,0 +1,43 @@
/*
Copyright 2025 New Vector Ltd.
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
Please see LICENSE files in the repository root for full details.
*/
import { mocked } from "jest-mock";
import * as navigator from "../../../src/utils/permalinks/navigator";
import { NavigationApi } from "../../../src/modules/Navigation.ts";
import { stubClient } from "../../test-utils";
import defaultDispatcher from "../../../src/dispatcher/dispatcher.ts";
describe("NavigationApi", () => {
const api = new NavigationApi();
describe("toMatrixToLink", () => {
it("should call navigateToPermalink with the correct parameters", async () => {
const link = "https://matrix.to/#/!roomId:server.com";
const spy = jest.spyOn(navigator, "navigateToPermalink");
await api.toMatrixToLink(link);
expect(spy).toHaveBeenCalledWith(link);
});
it("should resolve the room alias to a room id when join=true", async () => {
const cli = stubClient();
mocked(cli.getRoomIdForAlias).mockResolvedValue({ room_id: "!roomId:server.com", servers: [] });
const link = "https://matrix.to/#/#alias:server.com";
const spy = jest.spyOn(defaultDispatcher, "dispatch");
await api.toMatrixToLink(link, true);
expect(spy).toHaveBeenCalledWith(
expect.objectContaining({
action: "join_room",
roomId: "!roomId:server.com",
}),
);
});
});
});