ui unit tests fix

This commit is contained in:
Ishaan Jaffer
2025-11-22 14:05:59 -08:00
parent b43b68a072
commit c6b8f19adc
4 changed files with 20 additions and 12 deletions
@@ -57,15 +57,16 @@ vi.mock("@/app/(dashboard)/hooks/useTeams", () => ({
}));
describe("ModelsAndEndpointsView", () => {
it("should render the models and endpoints view", () => {
it("should render the models and endpoints view", async () => {
// JSDOM polyfill for libraries expecting ResizeObserver (e.g., recharts)
// Note: ResizeObserver is now globally mocked in setupTests.ts, but keeping this for backwards compatibility
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(global as any).ResizeObserver = class {
observe() {}
unobserve() {}
disconnect() {}
};
const { getByText } = render(
const { findByText } = render(
<ModelsAndEndpointsView
accessToken="123"
token="123"
@@ -78,6 +79,6 @@ describe("ModelsAndEndpointsView", () => {
teams={[]}
/>,
);
expect(getByText("Model Management")).toBeInTheDocument();
expect(await findByText("Model Management", {}, { timeout: 10000 })).toBeInTheDocument();
});
});
@@ -219,7 +219,7 @@ describe("SSOModals", () => {
);
};
const { getByLabelText, getByText, queryByText, container } = render(<TestWrapper />);
const { getByLabelText, getByText, queryByText, container, findByText } = render(<TestWrapper />);
// Find and interact with the SSO provider select
const ssoProviderSelect = container.querySelector("#sso_provider");
@@ -244,10 +244,9 @@ describe("SSOModals", () => {
const saveButton = getByText("Save");
fireEvent.click(saveButton);
// Check that only the URL format error appears
await waitFor(() => {
expect(getByText("URL must start with http:// or https://")).toBeInTheDocument();
});
// Check that only the URL format error appears (use findByText for async rendering)
const errorMessage = await findByText("URL must start with http:// or https://", {}, { timeout: 3000 });
expect(errorMessage).toBeInTheDocument();
// Verify the trailing slash error does NOT appear
expect(queryByText("URL must not end with a trailing slash")).not.toBeInTheDocument();
@@ -32,7 +32,7 @@ vi.mock("../networking", async () => {
});
describe("Add Model Tab", () => {
it("should render", () => {
it("should render", async () => {
// Create a form instance using renderHook
const { result } = renderHook(() => Form.useForm());
const [form] = result.current;
@@ -85,7 +85,7 @@ describe("Add Model Tab", () => {
const userRole = "Admin";
const premiumUser = true;
const { getByRole } = render(
const { findByRole } = render(
<AddModelTab
form={form}
handleOk={handleOk}
@@ -104,7 +104,7 @@ describe("Add Model Tab", () => {
premiumUser={premiumUser}
/>,
);
// Check for the heading specifically
expect(getByRole("heading", { name: "Add Model" })).toBeInTheDocument();
// Check for the heading specifically (use findByRole for async rendering)
expect(await findByRole("heading", { name: "Add Model" }, { timeout: 10000 })).toBeInTheDocument();
});
});
+8
View File
@@ -72,3 +72,11 @@ Object.defineProperty(HTMLAnchorElement.prototype, "click", {
if (!document.getAnimations) {
document.getAnimations = () => [];
}
// Mock ResizeObserver for components that use it (e.g., Tremor UI components)
// This prevents "ResizeObserver is not defined" errors in JSDOM
global.ResizeObserver = class ResizeObserver {
observe() {}
unobserve() {}
disconnect() {}
};