diff --git a/src-ui/src/app/components/chat/chat/chat.component.html b/src-ui/src/app/components/chat/chat/chat.component.html index e41d13511..78a1626f7 100644 --- a/src-ui/src/app/components/chat/chat/chat.component.html +++ b/src-ui/src/app/components/chat/chat/chat.component.html @@ -3,63 +3,84 @@ -
diff --git a/src-ui/src/app/components/chat/chat/chat.component.spec.ts b/src-ui/src/app/components/chat/chat/chat.component.spec.ts index f792d6c86..90052cce0 100644 --- a/src-ui/src/app/components/chat/chat/chat.component.spec.ts +++ b/src-ui/src/app/components/chat/chat/chat.component.spec.ts @@ -206,7 +206,7 @@ describe('ChatComponent', () => { component.sendMessage() fixture.detectChanges() const stopButton = fixture.nativeElement.querySelector('.chat-input button') - expect(stopButton.textContent).toContain('Stop') + expect(stopButton.getAttribute('aria-label')).toBe('Stop') mockStream$.next('Hi there') jest.advanceTimersByTime(20) @@ -232,6 +232,27 @@ describe('ChatComponent', () => { expect(component.messages()).toHaveLength(1) }) + it('should clear the conversation', () => { + component.input.set('Hello') + component.sendMessage() + mockStream$.next('Hi there') + fixture.detectChanges() + + fixture.nativeElement.querySelector('button[title="Clear chat"]').click() + expect(component.messages()).toHaveLength(0) + expect(component.loading()).toBe(false) + expect(mockStream$.observed).toBe(false) + + fixture.detectChanges() + jest.advanceTimersByTime(10) + expect(document.activeElement).toBe( + fixture.nativeElement.querySelector('#chatInput') + ) + expect(fixture.nativeElement.textContent).toContain( + 'Answers come from your documents' + ) + }) + it('should enqueue typewriter chunks correctly', () => { const message = { content: '', role: 'assistant', isStreaming: true } component.enqueueTypewriter(null, message as any) // coverage for null diff --git a/src-ui/src/app/components/chat/chat/chat.component.ts b/src-ui/src/app/components/chat/chat/chat.component.ts index d40e2bd2e..a69a735c4 100644 --- a/src-ui/src/app/components/chat/chat/chat.component.ts +++ b/src-ui/src/app/components/chat/chat/chat.component.ts @@ -150,6 +150,12 @@ export class ChatComponent implements OnInit { this.finishStreaming(message) } + clearChat(): void { + this.stopStreaming() + this.messages.set([]) + setTimeout(() => this.chatInput?.nativeElement.focus()) + } + private finishStreaming(message: ChatMessage): void { this.clearSlowResponse() this.streamFinished = false diff --git a/src-ui/src/main.ts b/src-ui/src/main.ts index 83990a3f9..ebb72bf49 100644 --- a/src-ui/src/main.ts +++ b/src-ui/src/main.ts @@ -32,6 +32,7 @@ import { arrowDownUp, arrowLeft, arrowRepeat, + arrowReturnLeft, arrowRight, arrowRightShort, arrowUpRight, @@ -283,6 +284,7 @@ const icons = { arrowDownUp, arrowLeft, arrowRepeat, + arrowReturnLeft, arrowRight, arrowRightShort, arrowUpRight,