-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Fixed auto question timer unmount #5368
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
aeea95b
fixed bug
liwilliam2021 78f92b7
expanded tests and made better mock
liwilliam2021 04b7b35
code review: refactor & race conditions
liwilliam2021 e269841
code review, some refactor and reset timer on task switch
liwilliam2021 6e1233a
Merge branch 'main' into will/auto-question-timer-unmount
liwilliam2021 2d49c16
rename to onCancelAutoApproval
liwilliam2021 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
200 changes: 200 additions & 0 deletions
200
webview-ui/src/components/chat/__tests__/FollowUpSuggest.spec.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,200 @@ | ||
| import { render, screen } from "@testing-library/react" | ||
| import { describe, it, expect, vi, beforeEach, afterEach } from "vitest" | ||
| import { FollowUpSuggest } from "../FollowUpSuggest" | ||
| import { ExtensionStateContext, ExtensionStateContextType } from "@src/context/ExtensionStateContext" | ||
| import { TooltipProvider } from "@radix-ui/react-tooltip" | ||
|
|
||
| // Mock the translation hook | ||
| vi.mock("@src/i18n/TranslationContext", () => ({ | ||
| TranslationProvider: ({ children }: { children: React.ReactNode }) => children, | ||
| useAppTranslation: () => ({ | ||
| t: (key: string, options?: any) => { | ||
| if (key === "chat:followUpSuggest.countdownDisplay" && options?.count !== undefined) { | ||
| return `${options.count}s` | ||
| } | ||
| if (key === "chat:followUpSuggest.autoSelectCountdown" && options?.count !== undefined) { | ||
| return `Auto-selecting in ${options.count} seconds` | ||
| } | ||
| if (key === "chat:followUpSuggest.copyToInput") { | ||
| return "Copy to input" | ||
| } | ||
| return key | ||
| }, | ||
| }), | ||
| })) | ||
|
|
||
| // Mock the extension state | ||
| const createMockExtensionState = (overrides?: Partial<ExtensionStateContextType>): ExtensionStateContextType => | ||
liwilliam2021 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ({ | ||
| version: "1.0.0", | ||
| clineMessages: [], | ||
| taskHistory: [], | ||
| shouldShowAnnouncement: false, | ||
| allowedCommands: [], | ||
| soundEnabled: false, | ||
| soundVolume: 0.5, | ||
| ttsEnabled: false, | ||
| ttsSpeed: 1.0, | ||
| diffEnabled: false, | ||
| enableCheckpoints: true, | ||
| fuzzyMatchThreshold: 1.0, | ||
| language: "en", | ||
| writeDelayMs: 1000, | ||
| browserViewportSize: "900x600", | ||
| screenshotQuality: 75, | ||
| terminalOutputLineLimit: 500, | ||
| terminalShellIntegrationTimeout: 4000, | ||
| mcpEnabled: true, | ||
| enableMcpServerCreation: false, | ||
| alwaysApproveResubmit: false, | ||
| requestDelaySeconds: 5, | ||
| currentApiConfigName: "default", | ||
| listApiConfigMeta: [], | ||
| mode: "code", | ||
| customModePrompts: {}, | ||
| customSupportPrompts: {}, | ||
| experiments: {}, | ||
| enhancementApiConfigId: "", | ||
| condensingApiConfigId: "", | ||
| customCondensingPrompt: "", | ||
| hasOpenedModeSelector: false, | ||
| autoApprovalEnabled: true, | ||
| alwaysAllowFollowupQuestions: true, | ||
| followupAutoApproveTimeoutMs: 3000, // 3 seconds for testing | ||
| customModes: [], | ||
| maxOpenTabsContext: 20, | ||
| maxWorkspaceFiles: 200, | ||
| cwd: "", | ||
| browserToolEnabled: true, | ||
| telemetrySetting: "unset", | ||
| showRooIgnoredFiles: true, | ||
| renderContext: "sidebar", | ||
| maxReadFileLine: -1, | ||
| pinnedApiConfigs: {}, | ||
| didHydrateState: true, | ||
| showWelcome: false, | ||
| theme: {}, | ||
| mcpServers: [], | ||
| filePaths: [], | ||
| openedTabs: [], | ||
| organizationAllowList: { type: "all" }, | ||
| cloudIsAuthenticated: false, | ||
| sharingEnabled: false, | ||
| mdmCompliant: true, | ||
| autoCondenseContext: false, | ||
| autoCondenseContextPercent: 50, | ||
| setHasOpenedModeSelector: vi.fn(), | ||
| setAlwaysAllowFollowupQuestions: vi.fn(), | ||
| setFollowupAutoApproveTimeoutMs: vi.fn(), | ||
| setCondensingApiConfigId: vi.fn(), | ||
| setCustomCondensingPrompt: vi.fn(), | ||
| setPinnedApiConfigs: vi.fn(), | ||
| togglePinnedApiConfig: vi.fn(), | ||
| setTerminalCompressProgressBar: vi.fn(), | ||
| setHistoryPreviewCollapsed: vi.fn(), | ||
| setAutoCondenseContext: vi.fn(), | ||
| setAutoCondenseContextPercent: vi.fn(), | ||
| ...overrides, | ||
| }) as ExtensionStateContextType | ||
|
|
||
| const renderWithProviders = (component: React.ReactElement, stateOverrides?: Partial<ExtensionStateContextType>) => { | ||
| const mockState = createMockExtensionState(stateOverrides) | ||
|
|
||
| return render( | ||
| <ExtensionStateContext.Provider value={mockState}> | ||
| <TooltipProvider>{component}</TooltipProvider> | ||
| </ExtensionStateContext.Provider>, | ||
| ) | ||
| } | ||
|
|
||
| describe("FollowUpSuggest", () => { | ||
| const mockSuggestions = [{ answer: "First suggestion" }, { answer: "Second suggestion" }] | ||
|
|
||
| const mockOnSuggestionClick = vi.fn() | ||
| const mockOnUnmount = vi.fn() | ||
|
|
||
| beforeEach(() => { | ||
| vi.clearAllMocks() | ||
| vi.useFakeTimers() | ||
| }) | ||
|
|
||
| afterEach(() => { | ||
| vi.useRealTimers() | ||
| }) | ||
|
|
||
| it("should display countdown timer when auto-approval is enabled", () => { | ||
| renderWithProviders( | ||
| <FollowUpSuggest | ||
| suggestions={mockSuggestions} | ||
| onSuggestionClick={mockOnSuggestionClick} | ||
| ts={123} | ||
| onUnmount={mockOnUnmount} | ||
| />, | ||
| ) | ||
|
|
||
| // Should show initial countdown (3 seconds) | ||
| expect(screen.getByText(/3s/)).toBeInTheDocument() | ||
| }) | ||
|
|
||
| it("should not display countdown timer when isAnswered is true", () => { | ||
liwilliam2021 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| renderWithProviders( | ||
| <FollowUpSuggest | ||
| suggestions={mockSuggestions} | ||
| onSuggestionClick={mockOnSuggestionClick} | ||
| ts={123} | ||
| onUnmount={mockOnUnmount} | ||
| isAnswered={true} | ||
| />, | ||
| ) | ||
|
|
||
| // Should not show countdown | ||
| expect(screen.queryByText(/\d+s/)).not.toBeInTheDocument() | ||
| }) | ||
|
|
||
| it("should clear interval and call onUnmount when component unmounts", () => { | ||
| const { unmount } = renderWithProviders( | ||
| <FollowUpSuggest | ||
| suggestions={mockSuggestions} | ||
| onSuggestionClick={mockOnSuggestionClick} | ||
| ts={123} | ||
| onUnmount={mockOnUnmount} | ||
| />, | ||
| ) | ||
|
|
||
| // Unmount the component | ||
| unmount() | ||
|
|
||
| // onUnmount should have been called | ||
| expect(mockOnUnmount).toHaveBeenCalled() | ||
| }) | ||
|
|
||
| it("should not show countdown when auto-approval is disabled", () => { | ||
| renderWithProviders( | ||
| <FollowUpSuggest | ||
| suggestions={mockSuggestions} | ||
| onSuggestionClick={mockOnSuggestionClick} | ||
| ts={123} | ||
| onUnmount={mockOnUnmount} | ||
| />, | ||
| { autoApprovalEnabled: false }, | ||
| ) | ||
|
|
||
| // Should not show countdown | ||
| expect(screen.queryByText(/\d+s/)).not.toBeInTheDocument() | ||
| }) | ||
|
|
||
| it("should not show countdown when alwaysAllowFollowupQuestions is false", () => { | ||
| renderWithProviders( | ||
| <FollowUpSuggest | ||
| suggestions={mockSuggestions} | ||
| onSuggestionClick={mockOnSuggestionClick} | ||
| ts={123} | ||
| onUnmount={mockOnUnmount} | ||
| />, | ||
| { alwaysAllowFollowupQuestions: false }, | ||
| ) | ||
|
|
||
| // Should not show countdown | ||
| expect(screen.queryByText(/\d+s/)).not.toBeInTheDocument() | ||
| }) | ||
| }) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.