-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Adding a terminate task button to quit and restart #6
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 all commits
Commits
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
Binary file not shown.
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
171 changes: 171 additions & 0 deletions
171
webview-ui/src/components/chat/__tests__/ChatView.test.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,171 @@ | ||
| import { render, screen, act } from '@testing-library/react' | ||
| import userEvent from '@testing-library/user-event' | ||
| import { ExtensionStateContextType } from '../../../context/ExtensionStateContext' | ||
| import ChatView from '../ChatView' | ||
| import { vscode } from '../../../utils/vscode' | ||
| import * as ExtensionStateContext from '../../../context/ExtensionStateContext' | ||
|
|
||
| // Mock vscode | ||
| jest.mock('../../../utils/vscode', () => ({ | ||
| vscode: { | ||
| postMessage: jest.fn() | ||
| } | ||
| })) | ||
|
|
||
| // Mock all components that use problematic dependencies | ||
| jest.mock('../../common/CodeBlock', () => ({ | ||
| __esModule: true, | ||
| default: () => <div data-testid="mock-code-block" /> | ||
| })) | ||
|
|
||
| jest.mock('../../common/MarkdownBlock', () => ({ | ||
| __esModule: true, | ||
| default: () => <div data-testid="mock-markdown-block" /> | ||
| })) | ||
|
|
||
| jest.mock('../BrowserSessionRow', () => ({ | ||
| __esModule: true, | ||
| default: () => <div data-testid="mock-browser-session-row" /> | ||
| })) | ||
|
|
||
| // Update ChatRow mock to capture props | ||
| let chatRowProps = null | ||
| jest.mock('../ChatRow', () => ({ | ||
| __esModule: true, | ||
| default: (props: any) => { | ||
| chatRowProps = props | ||
| return <div data-testid="mock-chat-row" /> | ||
| } | ||
| })) | ||
|
|
||
|
|
||
| // Mock Virtuoso component | ||
| jest.mock('react-virtuoso', () => ({ | ||
| Virtuoso: ({ children }: any) => ( | ||
| <div data-testid="mock-virtuoso">{children}</div> | ||
| ) | ||
| })) | ||
|
|
||
| // Mock VS Code components | ||
| jest.mock('@vscode/webview-ui-toolkit/react', () => ({ | ||
| VSCodeButton: ({ children, onClick }: any) => ( | ||
| <button onClick={onClick}>{children}</button> | ||
| ), | ||
| VSCodeProgressRing: () => <div data-testid="progress-ring" /> | ||
| })) | ||
|
|
||
| describe('ChatView', () => { | ||
| const mockShowHistoryView = jest.fn() | ||
| const mockHideAnnouncement = jest.fn() | ||
|
|
||
| let mockState: ExtensionStateContextType | ||
|
|
||
| beforeEach(() => { | ||
| jest.clearAllMocks() | ||
|
|
||
| mockState = { | ||
| clineMessages: [], | ||
| apiConfiguration: { | ||
| apiProvider: 'anthropic', | ||
| apiModelId: 'claude-3-sonnet' | ||
| }, | ||
| version: '1.0.0', | ||
| customInstructions: '', | ||
| alwaysAllowReadOnly: true, | ||
| alwaysAllowWrite: true, | ||
| alwaysAllowExecute: true, | ||
| openRouterModels: {}, | ||
| didHydrateState: true, | ||
| showWelcome: false, | ||
| theme: 'dark', | ||
| filePaths: [], | ||
| taskHistory: [], | ||
| shouldShowAnnouncement: false, | ||
| uriScheme: 'vscode', | ||
|
|
||
| setAlwaysAllowReadOnly: jest.fn(), | ||
| setAlwaysAllowWrite: jest.fn(), | ||
| setCustomInstructions: jest.fn(), | ||
| setAlwaysAllowExecute: jest.fn(), | ||
| setApiConfiguration: jest.fn(), | ||
| setShowAnnouncement: jest.fn() | ||
| } | ||
|
|
||
| // Mock the useExtensionState hook | ||
| jest.spyOn(ExtensionStateContext, 'useExtensionState').mockReturnValue(mockState) | ||
| }) | ||
|
|
||
| const renderChatView = () => { | ||
| return render( | ||
| <ChatView | ||
| isHidden={false} | ||
| showAnnouncement={false} | ||
| hideAnnouncement={mockHideAnnouncement} | ||
| showHistoryView={mockShowHistoryView} | ||
| /> | ||
| ) | ||
| } | ||
|
|
||
| describe('Streaming State', () => { | ||
| it('should show cancel button while streaming and trigger cancel on click', async () => { | ||
| mockState.clineMessages = [ | ||
| { | ||
| type: 'say', | ||
| say: 'task', | ||
| ts: Date.now(), | ||
| }, | ||
| { | ||
| type: 'say', | ||
| say: 'text', | ||
| partial: true, | ||
| ts: Date.now(), | ||
| } | ||
| ] | ||
| renderChatView() | ||
|
|
||
| const cancelButton = screen.getByText('Cancel') | ||
stea9499 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| await userEvent.click(cancelButton) | ||
|
|
||
| expect(vscode.postMessage).toHaveBeenCalledWith({ | ||
| type: 'cancelTask' | ||
| }) | ||
| }) | ||
|
|
||
| it('should show terminate button when task is paused and trigger terminate on click', async () => { | ||
| mockState.clineMessages = [ | ||
| { | ||
| type: 'ask', | ||
| ask: 'resume_task', | ||
| ts: Date.now(), | ||
| } | ||
| ] | ||
| renderChatView() | ||
|
|
||
| const terminateButton = screen.getByText('Terminate') | ||
| await userEvent.click(terminateButton) | ||
|
|
||
| expect(vscode.postMessage).toHaveBeenCalledWith({ | ||
| type: 'clearTask' | ||
| }) | ||
| }) | ||
|
|
||
| it('should show retry button when API error occurs and trigger retry on click', async () => { | ||
| mockState.clineMessages = [ | ||
| { | ||
| type: 'ask', | ||
| ask: 'api_req_failed', | ||
| ts: Date.now(), | ||
| } | ||
| ] | ||
| renderChatView() | ||
|
|
||
| const retryButton = screen.getByText('Retry') | ||
| await userEvent.click(retryButton) | ||
|
|
||
| expect(vscode.postMessage).toHaveBeenCalledWith({ | ||
| type: 'askResponse', | ||
| askResponse: 'yesButtonClicked' | ||
| }) | ||
| }) | ||
| }) | ||
| }) | ||
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.