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:
committed by
GitHub
parent
bbb179b6d3
commit
d5a9b3f4c0
30
test/unit-tests/modules/Auth-test.ts
Normal file
30
test/unit-tests/modules/Auth-test.ts
Normal 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,
|
||||
);
|
||||
});
|
||||
});
|
||||
23
test/unit-tests/modules/Dialog-test.tsx
Normal file
23
test/unit-tests/modules/Dialog-test.tsx
Normal 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();
|
||||
});
|
||||
});
|
||||
43
test/unit-tests/modules/Navigation-test.ts
Normal file
43
test/unit-tests/modules/Navigation-test.ts
Normal 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",
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user