From aecbde845e81905dd2144937ed5abc3bd53d26df Mon Sep 17 00:00:00 2001 From: John Stearns Date: Tue, 5 Nov 2024 16:55:57 -0800 Subject: [PATCH] Improving test coverage --- .../chat/__tests__/ChatView.test.tsx | 43 +++++++++++++------ 1 file changed, 31 insertions(+), 12 deletions(-) diff --git a/webview-ui/src/components/chat/__tests__/ChatView.test.tsx b/webview-ui/src/components/chat/__tests__/ChatView.test.tsx index 88d6fd1..bb97ddc 100644 --- a/webview-ui/src/components/chat/__tests__/ChatView.test.tsx +++ b/webview-ui/src/components/chat/__tests__/ChatView.test.tsx @@ -107,21 +107,31 @@ describe('ChatView', () => { } describe('Streaming State', () => { - it('should show cancel button while streaming', () => { + it('should show cancel button while streaming and trigger cancel on click', async () => { mockState.clineMessages = [ { - type: 'say', + type: 'say', + say: 'task', + ts: Date.now(), + }, + { + type: 'say', + say: 'text', partial: true, ts: Date.now(), } ] renderChatView() - const buttons = screen.queryAllByRole('button') - expect(buttons.length).toBeGreaterThan(0) + const cancelButton = screen.getByText('Cancel') + await userEvent.click(cancelButton) + + expect(vscode.postMessage).toHaveBeenCalledWith({ + type: 'cancelTask' + }) }) - it('should show terminate button when task is paused', () => { + it('should show terminate button when task is paused and trigger terminate on click', async () => { mockState.clineMessages = [ { type: 'ask', @@ -131,22 +141,31 @@ describe('ChatView', () => { ] renderChatView() - const buttons = screen.queryAllByRole('button') - expect(buttons.length).toBeGreaterThan(0) + const terminateButton = screen.getByText('Terminate') + await userEvent.click(terminateButton) + + expect(vscode.postMessage).toHaveBeenCalledWith({ + type: 'clearTask' + }) }) - it('should show retry button when API error occurs', () => { + it('should show retry button when API error occurs and trigger retry on click', async () => { mockState.clineMessages = [ { - type: 'say', - say: 'error', + type: 'ask', + ask: 'api_req_failed', ts: Date.now(), } ] renderChatView() - const buttons = screen.queryAllByRole('button') - expect(buttons.length).toBeGreaterThan(0) + const retryButton = screen.getByText('Retry') + await userEvent.click(retryButton) + + expect(vscode.postMessage).toHaveBeenCalledWith({ + type: 'askResponse', + askResponse: 'yesButtonClicked' + }) }) }) }) \ No newline at end of file