11/**
22 * @vitest -environment jsdom
33 */
4- import { act , type ReactNode } from 'react'
4+ import { act , type ButtonHTMLAttributes , type ReactNode } from 'react'
55import { createRoot , type Root } from 'react-dom/client'
66import { afterEach , beforeEach , describe , expect , it , vi } from 'vitest'
77import type { ColumnDefinition } from '@/lib/table'
88
99vi . mock ( '@sim/emcn' , ( ) => ( {
10+ Button : ( { children, ...props } : ButtonHTMLAttributes < HTMLButtonElement > ) => (
11+ < button { ...props } > { children } </ button >
12+ ) ,
1013 cn : ( ...values : Array < string | false | null | undefined > ) => values . filter ( Boolean ) . join ( ' ' ) ,
14+ FloatingTooltip : ( ) => null ,
15+ isTextClipped : ( ) => false ,
16+ useFloatingTooltip : ( ) => ( { state : { } , handlers : { } } ) ,
1117 DropdownMenu : ( { children, open } : { children : ReactNode ; open : boolean } ) =>
1218 open ? < > { children } </ > : null ,
1319 DropdownMenuContent : ( { children } : { children : ReactNode } ) => < div > { children } </ div > ,
@@ -28,6 +34,7 @@ vi.mock('@sim/emcn/icons', () => ({
2834 ArrowLeft : ( ) => null ,
2935 ArrowRight : ( ) => null ,
3036 ArrowUp : ( ) => null ,
37+ ChevronDown : ( ) => null ,
3138 Eye : ( ) => null ,
3239 EyeOff : ( ) => null ,
3340 Fingerprint : ( ) => null ,
@@ -39,10 +46,12 @@ vi.mock('@sim/emcn/icons', () => ({
3946 SquareArrowUpRight : ( ) => null ,
4047 Trash : ( ) => null ,
4148 Workflow : ( ) => null ,
49+ WorkflowX : ( ) => null ,
4250 X : ( ) => null ,
4351} ) )
4452
4553vi . mock ( '@/lib/table/column-types' , ( ) => ( {
54+ columnTypeById : ( ) => ( { icon : ( ) => null } ) ,
4655 columnTypeOf : ( column : ColumnDefinition ) => ( {
4756 icon : ( ) => null ,
4857 label : column . type === 'reference' ? 'Reference' : 'Text' ,
@@ -55,6 +64,7 @@ vi.mock('@/app/workspace/[workspaceId]/tables/[tableId]/components/column-config
5564
5665vi . mock ( '@/enrichments/registry' , ( ) => ( { getEnrichment : ( ) => undefined } ) )
5766
67+ import { ColumnHeaderMenu } from '@/app/workspace/[workspaceId]/tables/[tableId]/components/table-grid/headers/column-header-menu'
5868import { ColumnOptionsMenu } from '@/app/workspace/[workspaceId]/tables/[tableId]/components/table-grid/headers/workflow-group-meta-cell'
5969
6070let container : HTMLDivElement
@@ -134,3 +144,55 @@ describe('ColumnOptionsMenu Reference navigation', () => {
134144 expect ( findButton ( 'Go to Reference Table' ) ) . toBeUndefined ( )
135145 } )
136146} )
147+
148+ describe ( 'ColumnHeaderMenu read-only Reference navigation' , ( ) => {
149+ it ( 'keeps a direct navigation action available without exposing the options menu' , ( ) => {
150+ const onGoToReferenceTable = vi . fn ( )
151+
152+ act ( ( ) => {
153+ root . render (
154+ < ColumnHeaderMenu
155+ column = { {
156+ id : 'col-account' ,
157+ key : 'col-account' ,
158+ name : 'Account' ,
159+ type : 'reference' ,
160+ referenceTableId : 'table-accounts' ,
161+ groupSize : 1 ,
162+ groupStartColIndex : 0 ,
163+ headerLabel : 'Account' ,
164+ isGroupStart : true ,
165+ } }
166+ colIndex = { 0 }
167+ readOnly
168+ isRenaming = { false }
169+ isColumnSelected = { false }
170+ renameValue = ''
171+ onRenameValueChange = { vi . fn ( ) }
172+ onRenameSubmit = { vi . fn ( ) }
173+ onRenameCancel = { vi . fn ( ) }
174+ onColumnSelect = { vi . fn ( ) }
175+ onInsertLeft = { vi . fn ( ) }
176+ onInsertRight = { vi . fn ( ) }
177+ onGoToReferenceTable = { onGoToReferenceTable }
178+ onDeleteColumn = { vi . fn ( ) }
179+ onResizeStart = { vi . fn ( ) }
180+ onResize = { vi . fn ( ) }
181+ onResizeEnd = { vi . fn ( ) }
182+ onAutoResize = { vi . fn ( ) }
183+ onOpenConfig = { vi . fn ( ) }
184+ />
185+ )
186+ } )
187+
188+ const navigationButton = container . querySelector < HTMLButtonElement > (
189+ 'button[aria-label="Go to Reference Table"]'
190+ )
191+ expect ( navigationButton ) . not . toBeNull ( )
192+
193+ act ( ( ) => navigationButton ?. click ( ) )
194+
195+ expect ( onGoToReferenceTable ) . toHaveBeenCalledWith ( 'table-accounts' )
196+ expect ( container . querySelector ( 'button[aria-label="Column options"]' ) ) . toBeNull ( )
197+ } )
198+ } )
0 commit comments