From 7699240073122cdef31cf109fd37fa66961f588a Mon Sep 17 00:00:00 2001 From: Charlie Kolb Date: Fri, 25 Oct 2024 15:35:46 +0200 Subject: [PATCH] fix(editor): Add Retry button for AI Assistant errors (#11345) --- .../AskAssistantChat/AskAssistantChat.vue | 17 + .../__tests__/AskAssistantChat.spec.ts | 54 +++ .../AskAssistantChat.spec.ts.snap | 343 ++++++++++++++++++ packages/design-system/src/types/assistant.ts | 1 + .../stores/__tests__/assistant.store.test.ts | 71 ++++ .../editor-ui/src/stores/assistant.store.ts | 29 +- 6 files changed, 507 insertions(+), 8 deletions(-) diff --git a/packages/design-system/src/components/AskAssistantChat/AskAssistantChat.vue b/packages/design-system/src/components/AskAssistantChat/AskAssistantChat.vue index 1acffa82fa..78b4ccbf51 100644 --- a/packages/design-system/src/components/AskAssistantChat/AskAssistantChat.vue +++ b/packages/design-system/src/components/AskAssistantChat/AskAssistantChat.vue @@ -226,6 +226,16 @@ async function onCopyButtonClick(content: string, e: MouseEvent) { data-test-id="chat-message-system" > ⚠️ {{ message.content }} + + {{ t('generic.retry') }} +
{ }); expect(container).toMatchSnapshot(); }); + + it('renders error message correctly with retry button', () => { + const wrapper = render(AskAssistantChat, { + global: { + directives: { + n8nHtml, + }, + stubs, + }, + props: { + user: { firstName: 'Kobi', lastName: 'Dog' }, + messages: [ + { + id: '1', + role: 'assistant', + type: 'error', + content: 'This is an error message.', + read: false, + // Button is not shown without a retry function + retry: async () => {}, + }, + ], + }, + }); + expect(wrapper.container).toMatchSnapshot(); + expect(wrapper.getByTestId('error-retry-button')).toBeInTheDocument(); + }); + + it('does not render retry button if no error is present', () => { + const wrapper = render(AskAssistantChat, { + global: { + directives: { + n8nHtml, + }, + stubs, + }, + props: { + user: { firstName: 'Kobi', lastName: 'Dog' }, + messages: [ + { + id: '1', + type: 'text', + role: 'assistant', + content: + 'Hi Max! Here is my top solution to fix the error in your **Transform data** node👇', + read: false, + }, + ], + }, + }); + + expect(wrapper.container).toMatchSnapshot(); + expect(wrapper.queryByTestId('error-retry-button')).not.toBeInTheDocument(); + }); }); diff --git a/packages/design-system/src/components/AskAssistantChat/__tests__/__snapshots__/AskAssistantChat.spec.ts.snap b/packages/design-system/src/components/AskAssistantChat/__tests__/__snapshots__/AskAssistantChat.spec.ts.snap index 891c10abf6..c26913e405 100644 --- a/packages/design-system/src/components/AskAssistantChat/__tests__/__snapshots__/AskAssistantChat.spec.ts.snap +++ b/packages/design-system/src/components/AskAssistantChat/__tests__/__snapshots__/AskAssistantChat.spec.ts.snap @@ -1,5 +1,179 @@ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html +exports[`AskAssistantChat > does not render retry button if no error is present 1`] = ` +
+
+
+
+
+ + + + + + + + + + + + AI Assistant + +
+
+ beta +
+
+
+ +
+
+
+
+ +
+
+
+ + + + + + + + + + +
+ + Assistant + +
+
+
+

+ Hi Max! Here is my top solution to fix the error in your + + Transform data + + node👇 +

+ + +
+ + +
+ +
+ +
+ +
+
+