Fix warnings in LoginPage test

Change-Id: I844bb190e1d3ea172395035224bab497f3950912
This commit is contained in:
Manuel Stahl 2024-04-24 20:37:42 +02:00
parent b112689b8c
commit 03fcd8126a
1 changed files with 26 additions and 18 deletions

View File

@ -1,26 +1,32 @@
import React from "react"; import React from "react";
import { render, screen } from "@testing-library/react"; import { render, screen } from "@testing-library/react";
import { AdminContext } from "react-admin"; import { AdminContext } from "react-admin";
import polyglotI18nProvider from "ra-i18n-polyglot";
import LoginPage from "./LoginPage"; import LoginPage from "./LoginPage";
import { AppContext } from "../AppContext"; import { AppContext } from "../AppContext";
import englishMessages from "../i18n/en";
const i18nProvider = polyglotI18nProvider(() => englishMessages, "en", [
{ locale: "en", name: "English" },
]);
describe("LoginForm", () => { describe("LoginForm", () => {
it("renders with no restriction to homeserver", () => { it("renders with no restriction to homeserver", () => {
render( render(
<AdminContext> <AdminContext i18nProvider={i18nProvider}>
<LoginPage /> <LoginPage />
</AdminContext> </AdminContext>
); );
screen.getByText("synapseadmin.auth.welcome"); screen.getByText(englishMessages.synapseadmin.auth.welcome);
screen.getByRole("combobox", { name: "" }); screen.getByRole("combobox", { name: "" });
screen.getByRole("textbox", { name: "ra.auth.username" }); screen.getByRole("textbox", { name: englishMessages.ra.auth.username });
screen.getByText("ra.auth.password"); screen.getByText(englishMessages.ra.auth.password);
const baseUrlInput = screen.getByRole("textbox", { const baseUrlInput = screen.getByRole("textbox", {
name: "synapseadmin.auth.base_url", name: englishMessages.synapseadmin.auth.base_url,
}); });
expect(baseUrlInput.className.split(" ")).not.toContain("Mui-readOnly"); expect(baseUrlInput.className.split(" ")).not.toContain("Mui-readOnly");
screen.getByRole("button", { name: "ra.auth.sign_in" }); screen.getByRole("button", { name: englishMessages.ra.auth.sign_in });
}); });
it("renders with single restricted homeserver", () => { it("renders with single restricted homeserver", () => {
@ -28,21 +34,21 @@ describe("LoginForm", () => {
<AppContext.Provider <AppContext.Provider
value={{ restrictBaseUrl: "https://matrix.example.com" }} value={{ restrictBaseUrl: "https://matrix.example.com" }}
> >
<AdminContext> <AdminContext i18nProvider={i18nProvider}>
<LoginPage /> <LoginPage />
</AdminContext> </AdminContext>
</AppContext.Provider> </AppContext.Provider>
); );
screen.getByText("synapseadmin.auth.welcome"); screen.getByText(englishMessages.synapseadmin.auth.welcome);
screen.getByRole("combobox", { name: "" }); screen.getByRole("combobox", { name: "" });
screen.getByRole("textbox", { name: "ra.auth.username" }); screen.getByRole("textbox", { name: englishMessages.ra.auth.username });
screen.getByText("ra.auth.password"); screen.getByText(englishMessages.ra.auth.password);
const baseUrlInput = screen.getByRole("textbox", { const baseUrlInput = screen.getByRole("textbox", {
name: "synapseadmin.auth.base_url", name: englishMessages.synapseadmin.auth.base_url,
}); });
expect(baseUrlInput.className.split(" ")).toContain("Mui-readOnly"); expect(baseUrlInput.className.split(" ")).toContain("Mui-readOnly");
screen.getByRole("button", { name: "ra.auth.sign_in" }); screen.getByRole("button", { name: englishMessages.ra.auth.sign_in });
}); });
it("renders with multiple restricted homeservers", async () => { it("renders with multiple restricted homeservers", async () => {
@ -55,17 +61,19 @@ describe("LoginForm", () => {
], ],
}} }}
> >
<AdminContext> <AdminContext i18nProvider={i18nProvider}>
<LoginPage /> <LoginPage />
</AdminContext> </AdminContext>
</AppContext.Provider> </AppContext.Provider>
); );
screen.getByText("synapseadmin.auth.welcome"); screen.getByText(englishMessages.synapseadmin.auth.welcome);
screen.getByRole("combobox", { name: "" }); screen.getByRole("combobox", { name: "" });
screen.getByRole("textbox", { name: "ra.auth.username" }); screen.getByRole("textbox", { name: englishMessages.ra.auth.username });
screen.getByText("ra.auth.password"); screen.getByText(englishMessages.ra.auth.password);
screen.getByRole("combobox", { name: "synapseadmin.auth.base_url" }); screen.getByRole("combobox", {
screen.getByRole("button", { name: "ra.auth.sign_in" }); name: englishMessages.synapseadmin.auth.base_url,
});
screen.getByRole("button", { name: englishMessages.ra.auth.sign_in });
}); });
}); });