From 557db9c170a89447ec9cc14aa1af51e5fd11dd92 Mon Sep 17 00:00:00 2001 From: Mutasem Aldmour <4711238+mutdmour@users.noreply.github.com> Date: Mon, 23 Sep 2024 14:06:38 +0200 Subject: [PATCH] fix: Enable Assistant on other credential views (#10931) --- .../stores/__tests__/assistant.store.test.ts | 29 +++++++++++++++++-- .../editor-ui/src/stores/assistant.store.ts | 4 +++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/packages/editor-ui/src/stores/__tests__/assistant.store.test.ts b/packages/editor-ui/src/stores/__tests__/assistant.store.test.ts index 9cfc7e06dd8d8..bd83d16f1ca37 100644 --- a/packages/editor-ui/src/stores/__tests__/assistant.store.test.ts +++ b/packages/editor-ui/src/stores/__tests__/assistant.store.test.ts @@ -13,7 +13,7 @@ import { useSettingsStore } from '@/stores/settings.store'; import { defaultSettings } from '../../__tests__/defaults'; import { merge } from 'lodash-es'; import { DEFAULT_POSTHOG_SETTINGS } from './posthog.test'; -import { AI_ASSISTANT_EXPERIMENT } from '@/constants'; +import { AI_ASSISTANT_EXPERIMENT, VIEWS } from '@/constants'; import { reactive } from 'vue'; import * as chatAPI from '@/api/assistant'; import * as telemetryModule from '@/composables/useTelemetry'; @@ -41,12 +41,13 @@ const setAssistantEnabled = (enabled: boolean) => { ); }; +let currentRouteName = ENABLED_VIEWS[0]; vi.mock('vue-router', () => ({ useRoute: vi.fn(() => reactive({ path: '/', params: {}, - name: ENABLED_VIEWS[0], + name: currentRouteName, }), ), useRouter: vi.fn(), @@ -309,6 +310,30 @@ describe('AI Assistant store', () => { expect(assistantStore.canShowAssistantButtonsOnCanvas).toBe(true); }); + it('should not show assistant if on a settings page', () => { + currentRouteName = VIEWS.SSO_SETTINGS; + const assistantStore = useAssistantStore(); + + setAssistantEnabled(true); + mockPostHogVariant('variant'); + expect(assistantStore.isAssistantEnabled).toBe(true); + expect(assistantStore.canShowAssistant).toBe(false); + expect(assistantStore.canShowAssistantButtonsOnCanvas).toBe(false); + }); + + [VIEWS.PROJECTS_CREDENTIALS, VIEWS.TEMPLATE_SETUP, VIEWS.CREDENTIALS].forEach((view) => { + it(`should show assistant if on ${view} page`, () => { + currentRouteName = VIEWS.PROJECTS_CREDENTIALS; + const assistantStore = useAssistantStore(); + + setAssistantEnabled(true); + mockPostHogVariant('variant'); + expect(assistantStore.isAssistantEnabled).toBe(true); + expect(assistantStore.canShowAssistant).toBe(true); + expect(assistantStore.canShowAssistantButtonsOnCanvas).toBe(false); + }); + }); + it('should initialize assistant chat session on node error', async () => { const context: ChatRequest.ErrorContext = { error: { diff --git a/packages/editor-ui/src/stores/assistant.store.ts b/packages/editor-ui/src/stores/assistant.store.ts index cfa25e1141ec3..bb2838208830f 100644 --- a/packages/editor-ui/src/stores/assistant.store.ts +++ b/packages/editor-ui/src/stores/assistant.store.ts @@ -46,6 +46,10 @@ export const ENABLED_VIEWS = [ VIEWS.EXECUTION_PREVIEW, VIEWS.WORKFLOWS, VIEWS.CREDENTIALS, + VIEWS.PROJECTS_CREDENTIALS, + VIEWS.PROJECTS_WORKFLOWS, + VIEWS.PROJECT_SETTINGS, + VIEWS.TEMPLATE_SETUP, ]; const READABLE_TYPES = ['code-diff', 'text', 'block'];