Skip to content

Commit

Permalink
fix: Enable Assistant on other credential views (#10931)
Browse files Browse the repository at this point in the history
  • Loading branch information
mutdmour authored Sep 23, 2024
1 parent eae4e30 commit 557db9c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
29 changes: 27 additions & 2 deletions packages/editor-ui/src/stores/__tests__/assistant.store.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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: {
Expand Down
4 changes: 4 additions & 0 deletions packages/editor-ui/src/stores/assistant.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'];

Expand Down

0 comments on commit 557db9c

Please sign in to comment.