@@ -8,9 +8,28 @@ import type { DisplayColumn } from '@/app/workspace/[workspaceId]/tables/[tableI
88
99vi . mock ( '@sim/emcn' , ( ) => ( {
1010 Badge : ( { children } : { children : React . ReactNode } ) => < span > { children } </ span > ,
11+ Button : ( {
12+ children,
13+ size,
14+ variant,
15+ ...props
16+ } : React . ButtonHTMLAttributes < HTMLButtonElement > & {
17+ size ?: string
18+ variant ?: string
19+ } ) => (
20+ < button data-size = { size } data-variant = { variant } { ...props } >
21+ { children }
22+ </ button >
23+ ) ,
1124 Checkbox : ( ) => null ,
12- Chip : ( { children, ...props } : React . ButtonHTMLAttributes < HTMLButtonElement > ) => (
13- < button { ...props } > { children } </ button >
25+ ChipTag : ( {
26+ children,
27+ variant,
28+ ...props
29+ } : React . HTMLAttributes < HTMLSpanElement > & { variant ?: string } ) => (
30+ < span data-chip-tag-variant = { variant } { ...props } >
31+ { children }
32+ </ span >
1433 ) ,
1534 cn : ( ...values : Array < string | false | null | undefined > ) => values . filter ( Boolean ) . join ( ' ' ) ,
1635 Tooltip : {
@@ -45,6 +64,7 @@ const REFERENCE_COLUMN: DisplayColumn = {
4564 name : 'Account' ,
4665 type : 'reference' ,
4766 referenceTableId : 'table-accounts' ,
67+ referenceTableName : 'Accounts' ,
4868 groupSize : 1 ,
4969 groupStartColIndex : 0 ,
5070 headerLabel : 'Account' ,
@@ -69,15 +89,15 @@ afterEach(() => {
6989} )
7090
7191describe ( 'reference cell rendering' , ( ) => {
72- it ( 'resolves a stored row ID to a chip labeled with the reference column name' , ( ) => {
92+ it ( 'resolves a stored row ID to a chip labeled with the referenced table name' , ( ) => {
7393 expect (
7494 resolveCellRender ( {
7595 value : 'row-account-1' ,
7696 exec : undefined ,
7797 column : REFERENCE_COLUMN ,
7898 waitingOnLabels : undefined ,
7999 } )
80- ) . toMatchObject ( { kind : 'column-chip' , label : 'Account ' } )
100+ ) . toEqual ( { kind : 'column-chip' , label : 'Accounts ' } )
81101 } )
82102
83103 it ( 'keeps an empty reference cell empty' , ( ) => {
@@ -91,6 +111,17 @@ describe('reference cell rendering', () => {
91111 ) . toEqual ( { kind : 'empty' } )
92112 } )
93113
114+ it ( 'uses a neutral label while the referenced table name is unavailable' , ( ) => {
115+ expect (
116+ resolveCellRender ( {
117+ value : 'row-account-1' ,
118+ exec : undefined ,
119+ column : { ...REFERENCE_COLUMN , referenceTableName : undefined } ,
120+ waitingOnLabels : undefined ,
121+ } )
122+ ) . toEqual ( { kind : 'column-chip' , label : 'Referenced table' } )
123+ } )
124+
94125 it ( 'opens the referenced row from the chip without exposing its stored row ID' , ( ) => {
95126 const onReferenceClick = vi . fn ( )
96127
@@ -110,11 +141,44 @@ describe('reference cell rendering', () => {
110141 } )
111142
112143 const chip = container . querySelector ( 'button' )
113- expect ( chip ?. textContent ) . toBe ( 'Account' )
144+ expect ( chip ?. textContent ) . toBe ( 'Accounts' )
145+ expect ( chip ?. dataset . variant ) . toBe ( 'ghost' )
146+ expect ( chip ?. dataset . size ) . toBe ( 'sm' )
147+ expect ( chip ?. className ) . toContain ( 'max-w-full' )
148+ expect ( chip ?. className ) . toContain ( 'p-0' )
149+ expect ( chip ?. querySelector ( 'svg' ) ) . toBeNull ( )
150+ const tag = chip ?. querySelector ( '[data-chip-tag-variant="field"]' )
151+ expect ( tag ?. textContent ) . toBe ( 'Accounts' )
152+ expect ( tag ?. className ) . toContain ( 'min-w-0' )
153+ expect ( tag ?. className ) . toContain ( 'max-w-full' )
114154
115155 act ( ( ) => chip ?. click ( ) )
116156
117157 expect ( onReferenceClick ) . toHaveBeenCalledOnce ( )
118158 expect ( container . textContent ) . not . toContain ( 'row-account-1' )
119159 } )
160+
161+ it ( 'keeps a chip double-click from reaching the reference cell' , ( ) => {
162+ const onCellDoubleClick = vi . fn ( )
163+
164+ act ( ( ) => {
165+ root . render (
166+ < div onDoubleClick = { onCellDoubleClick } >
167+ < CellRender
168+ kind = { { kind : 'column-chip' , label : 'Accounts' } }
169+ isEditing = { false }
170+ referenceAction = { { expanded : false , onClick : vi . fn ( ) } }
171+ />
172+ </ div >
173+ )
174+ } )
175+
176+ act ( ( ) => {
177+ container
178+ . querySelector ( 'button' )
179+ ?. dispatchEvent ( new MouseEvent ( 'dblclick' , { bubbles : true } ) )
180+ } )
181+
182+ expect ( onCellDoubleClick ) . not . toHaveBeenCalled ( )
183+ } )
120184} )
0 commit comments