Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

🔨 chore: stabilize Claude quota focus tests (#19808)

YuTengjingc354bf47b7e6
diff --git a/src/features/ChatInput/ControlBar/HeteroControlBar/QuotaMenu/QuotaMenu.test.tsx b/src/features/ChatInput/ControlBar/HeteroControlBar/QuotaMenu/QuotaMenu.test.tsx
index 434536df165..b4dd18ea773 100644
--- a/src/features/ChatInput/ControlBar/HeteroControlBar/QuotaMenu/QuotaMenu.test.tsx
+++ b/src/features/ChatInput/ControlBar/HeteroControlBar/QuotaMenu/QuotaMenu.test.tsx
@@ -264,6 +264,15 @@ const liveSessionReading = (capturedAt: number) => ({
utilization: 8,
});
+/** Persisted quota can render before the initial load finishes; focus is ignored while loading. */
+const waitForQuotaIdle = async () => {
+ await waitFor(() => expect(screen.getByTestId('refresh').hasAttribute('disabled')).toBe(false));
+ // Let the focus listener's effect observe loading=false before dispatching focus.
+ await act(async () => {
+ await Promise.resolve();
+ });
+};
+
const codexSnapshot = (
overrides: Partial<ElectronClientIpcModule.CodexQuotaSnapshot> = {},
): ElectronClientIpcModule.CodexQuotaSnapshot => ({
@@ -1005,6 +1014,7 @@ describe('ClaudeCodeQuotaMenu', () => {
// Fresh persisted data: nothing hits the live API on mount…
expect(await screen.findByText('92%')).toBeTruthy();
+ await waitForQuotaIdle();
expect(mockService.getClaudeCodeQuota).not.toHaveBeenCalled();
// …but regaining focus revalidates (the main-process cache rate-limits it).
@@ -1107,6 +1117,7 @@ describe('ClaudeCodeQuotaMenu', () => {
render(<ClaudeCodeQuotaMenu />);
expect(await screen.findByText('92%')).toBeTruthy();
+ await waitForQuotaIdle();
await act(async () => {
window.dispatchEvent(new Event('focus'));
@@ -1128,6 +1139,7 @@ describe('ClaudeCodeQuotaMenu', () => {
render(<ClaudeCodeQuotaMenu />);
expect(await screen.findByText('92%')).toBeTruthy();
+ await waitForQuotaIdle();
await act(async () => {
window.dispatchEvent(new Event('focus'));
@@ -1150,6 +1162,7 @@ describe('ClaudeCodeQuotaMenu', () => {
render(<ClaudeCodeQuotaMenu />);
expect(await screen.findByText('92%')).toBeTruthy();
+ await waitForQuotaIdle();
await act(async () => {
window.dispatchEvent(new Event('focus'));