Implement customisations & login component Module API 1.11.0 (#32687)
* Update to Module API v1.11.0 Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Remove stale state field to make CQL happy Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Bump npm dep Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Improve coverage Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Improve coverage Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Update comment Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --------- Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
@@ -20,6 +20,7 @@ import Login from "../../../../../src/components/structures/auth/Login";
|
||||
import type BasePlatform from "../../../../../src/BasePlatform";
|
||||
import * as registerClientUtils from "../../../../../src/utils/oidc/registerClient";
|
||||
import { makeDelegatedAuthConfig } from "../../../../test-utils/oidc";
|
||||
import { ModuleApi } from "../../../../../src/modules/Api.ts";
|
||||
|
||||
jest.useRealTimers();
|
||||
|
||||
@@ -100,6 +101,35 @@ describe("Login", function () {
|
||||
expect(container.querySelector(".mx_ServerPicker_change")).toBeTruthy();
|
||||
});
|
||||
|
||||
it("should show register button", async () => {
|
||||
const onRegisterClick = jest.fn();
|
||||
const { getByText } = render(
|
||||
<Login
|
||||
serverConfig={mkServerConfig("https://matrix.org", "https://vector.im")}
|
||||
onLoggedIn={() => {}}
|
||||
onRegisterClick={onRegisterClick}
|
||||
onServerConfigChange={() => {}}
|
||||
/>,
|
||||
);
|
||||
await waitForElementToBeRemoved(() => screen.queryAllByLabelText("Loading…"));
|
||||
|
||||
fireEvent.click(getByText("Create an account"));
|
||||
expect(onRegisterClick).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("should hide register button", async () => {
|
||||
const { queryByText } = render(
|
||||
<Login
|
||||
serverConfig={mkServerConfig("https://matrix.org", "https://vector.im")}
|
||||
onLoggedIn={() => {}}
|
||||
onServerConfigChange={() => {}}
|
||||
/>,
|
||||
);
|
||||
await waitForElementToBeRemoved(() => screen.queryAllByLabelText("Loading…"));
|
||||
|
||||
expect(queryByText("Create an account")).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("should show form without change server link when custom URLs disabled", async () => {
|
||||
const { container } = getComponent();
|
||||
await waitForElementToBeRemoved(() => screen.queryAllByLabelText("Loading…"));
|
||||
@@ -417,4 +447,16 @@ describe("Login", function () {
|
||||
expect(screen.getByText("Continue")).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
describe("Module API", () => {
|
||||
afterEach(() => {
|
||||
ModuleApi.instance.customComponents.registerLoginComponent(undefined as any);
|
||||
});
|
||||
|
||||
it("should use registered module renderer", async () => {
|
||||
ModuleApi.instance.customComponents.registerLoginComponent(() => <>Test component</>);
|
||||
const { getByText } = getComponent();
|
||||
expect(getByText("Test component")).toBeTruthy();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
Copyright 2026 Element Creations 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 { CustomisationsApi } from "../../../src/modules/customisationsApi";
|
||||
import { UIComponent } from "../../../src/settings/UIFeature.ts";
|
||||
|
||||
describe("CustomisationsApi", () => {
|
||||
let api: CustomisationsApi;
|
||||
|
||||
beforeEach(() => {
|
||||
api = new CustomisationsApi();
|
||||
});
|
||||
|
||||
it("should register a shouldShowComponent callback", () => {
|
||||
const shouldShowComponent = jest.fn().mockReturnValue(true);
|
||||
api.registerShouldShowComponent(shouldShowComponent);
|
||||
expect(api.shouldShowComponent(UIComponent.CreateRooms)).toBe(true);
|
||||
expect(shouldShowComponent).toHaveBeenCalledWith("UIComponent.roomCreation");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user