11/** @vitest -environment jsdom */
22
33import { act , type ComponentProps , type ReactNode } from 'react'
4+ import { toast } from '@sim/emcn'
45import { authClientMock , authClientMockFns } from '@sim/testing/mocks/auth-client.mock'
56import {
67 createMockDeploymentShape ,
@@ -9,7 +10,6 @@ import {
910} from '@sim/testing/mocks/deployment-shape.mock'
1011import { integrationMatcherMock } from '@sim/testing/mocks/integration-matcher.mock'
1112import { kbConnectorsQueriesMock } from '@sim/testing/mocks/kb-connectors-queries.mock'
12- import { nextNavigationMock } from '@sim/testing/mocks/next-navigation.mock'
1313import {
1414 organizationProviderMock ,
1515 organizationProviderMockFns ,
@@ -24,6 +24,7 @@ import { useOrganizationChatModeStore } from '@/stores/organization-chat-mode/st
2424
2525const mocks = vi . hoisted ( ( ) => ( {
2626 plan : false ,
27+ projects : true ,
2728 resourcePanel : vi . fn ( ) ,
2829 chat : vi . fn ( ) ,
2930 composer : vi . fn ( ) ,
@@ -40,11 +41,15 @@ const mocks = vi.hoisted(() => ({
4041 activeResource : null as string | null ,
4142} ) )
4243vi . mock ( '@/app/workspace/[workspaceId]/providers/feature-flags-provider' , ( ) => ( {
43- useFeatureFlag : ( name : string ) => ( name === 'mothership-plan-mode' ? mocks . plan : false ) ,
44+ useFeatureFlag : ( name : string ) =>
45+ name === 'mothership-plan-mode' ? mocks . plan : name === 'projects' ? mocks . projects : false ,
4446} ) )
4547vi . mock ( '@/lib/core/config/deployment-shape' , ( ) => deploymentShapeMock )
4648vi . mock ( '@/blocks/integration-matcher' , ( ) => integrationMatcherMock )
47- vi . mock ( 'next/navigation' , ( ) => nextNavigationMock )
49+ vi . mock (
50+ 'next/navigation' ,
51+ async ( ) => ( await import ( '@sim/testing/mocks/next-navigation.mock' ) ) . nextNavigationMock
52+ )
4853vi . mock ( '@tanstack/react-query' , ( ) => reactQueryMock )
4954vi . mock ( '@/app/workspace/[workspaceId]/home/hooks/use-resource-panel' , ( ) => ( {
5055 useResourcePanelController : ( ) => ( {
@@ -103,6 +108,7 @@ let root: Root
103108let container : HTMLDivElement
104109beforeEach ( ( ) => {
105110 useMothershipDraftsStore . setState ( { drafts : { } } )
111+ mocks . projects = true
106112 mocks . plan = false
107113 mocks . activeResource = null
108114 mockSession . mockReturnValue ( { data : { user : { id : 'reader' } } } )
@@ -224,3 +230,28 @@ it('isolates saved drafts by user, organization, and conversation', async () =>
224230 await act ( async ( ) => renderHome ( < OrganizationHome chatId = 'chat-a' requestMode = 'assistant' /> ) )
225231 expect ( composerProps ( ) . value ) . toBe ( '' )
226232} )
233+
234+ it . each ( [ false ] ) ( 'does not look up saved Project references with projects=%s' , async ( projects ) => {
235+ mocks . projects = projects
236+ vi . spyOn ( toast , 'error' ) . mockReturnValue ( 'lookup-error' )
237+ const requests : unknown [ ] = [ ]
238+ const resources : unknown [ ] = [ ]
239+ vi . stubGlobal ( 'fetch' , async ( input : unknown ) => {
240+ requests . push ( input )
241+ throw new Error ( 'Project lookup is disabled' )
242+ } )
243+ mocks . addResource . mockImplementation ( ( resource : unknown ) => resources . push ( resource ) )
244+ await act ( async ( ) => renderHome ( < OrganizationHome chatId = 'chat-a' /> ) )
245+ const selectResource = mocks . renderer . mock . lastCall ?. [ 0 ] . onWorkspaceResourceSelect
246+ if ( ! selectResource ) throw new Error ( 'Chat resource selection is unavailable' )
247+ await act ( async ( ) =>
248+ selectResource ( {
249+ type : 'file' ,
250+ id : 'file-a' ,
251+ title : 'Saved Project file' ,
252+ owner : { entityType : 'project' , entityId : 'project-a' } ,
253+ } )
254+ )
255+ expect ( requests ) . toEqual ( [ ] )
256+ expect ( resources ) . toEqual ( [ ] )
257+ } )
0 commit comments