Skip to content

test(ui): preserve global Button/Tooltip mocks in per-file @tremor/react vi.mock#27958

Merged
yuneng-berri merged 2 commits into
litellm_internal_stagingfrom
litellm_/funny-williams-dab711
May 15, 2026
Merged

test(ui): preserve global Button/Tooltip mocks in per-file @tremor/react vi.mock#27958
yuneng-berri merged 2 commits into
litellm_internal_stagingfrom
litellm_/funny-williams-dab711

Conversation

@yuneng-berri

Copy link
Copy Markdown
Collaborator

Summary

Fixes the flaky ReferenceError: window is not defined that surfaces against src/components/user_edit_view.test.tsx (and other UI tests) in CI.

Per-file vi.mock("@tremor/react", ...) factories fully replace the setup-level mock from tests/setupTests.ts, so the global Button/Tooltip overrides are lost in any file that re-mocks @tremor/react. Without them, the real Tremor <Button> leaks through and its internal useTooltip(300) schedules a native 300ms setTimeout on pointer events. When the test environment is torn down before the timer fires, the trailing setState calls getCurrentEventPriority, which reads window.event against a destroyed jsdom — producing the unhandled error.

This PR re-supplies the Button (bare <button>) and Tooltip (Fragment) overrides in each of the 7 leaky test files. It also drops a dead afterEach workaround in user_edit_view.test.tsx (the vi.useFakeTimers() + vi.runAllTimers() dance could not drain the real timer scheduled before the swap) and corrects a misleading comment in MakeMCPPublicForm.test.tsx.

Files touched (all are test files):

  • ui/litellm-dashboard/src/components/user_edit_view.test.tsx
  • ui/litellm-dashboard/src/components/AIHub/forms/MakeMCPPublicForm.test.tsx
  • ui/litellm-dashboard/src/app/(dashboard)/models-and-endpoints/components/ModelRetrySettingsTab.test.tsx
  • ui/litellm-dashboard/src/app/(dashboard)/teams/components/TeamsTable/ModelsCell.test.tsx
  • ui/litellm-dashboard/src/components/molecules/models/columns.test.tsx
  • ui/litellm-dashboard/src/components/GuardrailsMonitor/ScoreChart.test.tsx
  • ui/litellm-dashboard/src/components/policies/impact_popover.test.tsx

Test plan

  • All 7 patched files green: npx vitest run ... — 107/107 tests pass
  • Full UI suite green under CI-equivalent flags: CI=true npx vitest run --pool forks --poolOptions.forks.maxForks=8 — 3844/3844 tests pass across 383 files, run 3× consecutively with zero Unhandled Errors and zero window is not defined
  • tsc --noEmit produces no new type errors in any patched file

…act vi.mock

Per-file `vi.mock("@tremor/react", ...)` factories fully replace the
setup-level mock from `tests/setupTests.ts`, so the global Button/Tooltip
overrides are lost in any file that re-mocks `@tremor/react`. Without
them, the real Tremor `<Button>` leaks through and its internal
`useTooltip(300)` schedules a native 300ms `setTimeout` on pointer
events. When the test environment is torn down before the timer fires,
the trailing `setState` calls `getCurrentEventPriority`, which reads
`window.event` against a destroyed jsdom -> "window is not defined"
flake observed on CI.

Patches the 7 leaky test files to re-supply `Button` (bare `<button>`)
and `Tooltip` (Fragment) overrides matching `setupTests.ts`. Also drops
a dead `afterEach` workaround in `user_edit_view.test.tsx` (the
fake-timer dance it ran could not drain a real timer scheduled before
the swap) and corrects a misleading comment in `MakeMCPPublicForm.test.tsx`.
@greptile-apps

greptile-apps Bot commented May 14, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a flaky ReferenceError: window is not defined in CI by re-supplying the Button and Tooltip stubs in every test file that overrides @tremor/react with a per-file vi.mock. In Vitest, a file-level factory completely replaces the setup-level mock from setupTests.ts, so the real Tremor Button was leaking through and scheduling a 300ms setTimeout via useTooltip that fired against an already-torn-down jsdom.

  • Adds identical Button (React.forwardRef → native <button>) and Tooltip (Fragment passthrough) overrides to 7 test files that already had their own @tremor/react mock factories.
  • Removes the dead vi.useFakeTimers() / vi.runAllTimers() / vi.useRealTimers() block in user_edit_view.test.tsx that could not drain timers scheduled before the mock swap, and corrects a misleading comment in MakeMCPPublicForm.test.tsx.

Confidence Score: 4/5

Safe to merge — all changes are confined to test files and directly address a documented, reproducible CI flakiness root cause.

The fix is correct and well-scoped: it re-applies the two Tremor overrides that prevent the post-teardown timer error in every affected file. The one gap is that setupTests.ts also stubs Switch as a native checkbox, and that stub is silently dropped in all 7 per-file mocks (pre-existing before this PR). Tests that interact with a Switch inside these components will exercise the real Tremor Switch rather than the lightweight test double, which could affect interaction-based assertions.

All 7 patched test files are missing the Switch re-override; user_edit_view.test.tsx is most likely to be affected given its breadth of user-interaction tests.

Important Files Changed

Filename Overview
ui/litellm-dashboard/src/components/user_edit_view.test.tsx Adds Button/Tooltip overrides to the per-file tremor mock and removes the dead vi.useFakeTimers workaround; Switch mock is not re-applied (pre-existing gap)
ui/litellm-dashboard/src/components/AIHub/forms/MakeMCPPublicForm.test.tsx Corrects a misleading comment and adds Button/Tooltip overrides with a dynamic React import needed for React.forwardRef inside the async factory
ui/litellm-dashboard/src/app/(dashboard)/models-and-endpoints/components/ModelRetrySettingsTab.test.tsx Adds Button/Tooltip overrides to the existing per-file tremor mock; change is minimal and correct
ui/litellm-dashboard/src/app/(dashboard)/teams/components/TeamsTable/ModelsCell.test.tsx Adds Button/Tooltip overrides to the existing per-file tremor mock; change is minimal and correct
ui/litellm-dashboard/src/components/GuardrailsMonitor/ScoreChart.test.tsx Adds Button/Tooltip overrides to the existing per-file tremor mock; change is minimal and correct
ui/litellm-dashboard/src/components/molecules/models/columns.test.tsx Adds Button/Tooltip overrides as named locals before the return object; consistent style with surrounding code
ui/litellm-dashboard/src/components/policies/impact_popover.test.tsx Adds Button/Tooltip overrides to the existing per-file tremor mock; change is minimal and correct

Reviews (1): Last reviewed commit: "Merge remote-tracking branch 'origin/lit..." | Re-trigger Greptile

Comment on lines 85 to +100
return React.createElement("option", { value, title }, childText || title || value);
};
SelectItem.displayName = "SelectItem";
// Re-apply the global Button/Tooltip overrides from tests/setupTests.ts.
// A file-level vi.mock fully replaces the setup-level mock, so without this
// the real Tremor Button leaks through and its useTooltip(300) schedules a
// native setTimeout that fires post-teardown -> "window is not defined".
const Button = React.forwardRef<HTMLButtonElement, any>(({ children, ...props }, ref) =>
React.createElement("button", { ...props, ref }, children),
);
const TremorTooltip = ({ children }: any) => React.createElement(React.Fragment, null, children);
return {
...actual,
SelectItem,
Button,
Tooltip: TremorTooltip,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Switch mock not re-applied alongside Button/Tooltip

setupTests.ts overrides three Tremor exports: Button, Tooltip, and Switch (renders as a native <input type="checkbox" role="switch">). Each per-file vi.mock fully replaces the setup-level factory, so every file that re-mocks @tremor/react silently restores the real Tremor Switch via ...actual. This PR re-applies Button and Tooltip but leaves Switch as the real Tremor implementation in all 7 patched files. Any test that interacts with a Switch in these files — toggling it, asserting its checked state — will be exercising the real Tremor component instead of the lightweight native checkbox the setup mock was designed to provide. This is a pre-existing gap that this PR misses an opportunity to close.

@codecov

codecov Bot commented May 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@yuneng-berri yuneng-berri enabled auto-merge May 15, 2026 03:45
@yuneng-berri yuneng-berri merged commit bcbae93 into litellm_internal_staging May 15, 2026
115 checks passed
@yuneng-berri yuneng-berri deleted the litellm_/funny-williams-dab711 branch May 15, 2026 03:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants