@@ -196,6 +196,53 @@ describe("data-editor", () => {
196196 expect ( spySelection ) . not . toHaveBeenCalled ( ) ;
197197 } ) ;
198198
199+ test ( "opens contextmenu at selected cell position when fired on canvas" , async ( ) => {
200+ const spy = vi . fn ( ) ;
201+
202+ vi . useFakeTimers ( ) ;
203+ render ( < DataEditor
204+ { ...basicProps }
205+ gridSelection = { {
206+ columns : CompactSelection . empty ( ) ,
207+ rows : CompactSelection . empty ( ) ,
208+ current : {
209+ cell : [ 1 , 1 ] ,
210+ range : { x : 1 , y : 1 , width : 1 , height : 1 } ,
211+ rangeStack : [ ] ,
212+ } ,
213+ } }
214+ onCellContextMenu = { spy }
215+ /> , { wrapper : Context } ) ;
216+
217+ prep ( ) ;
218+
219+ const canvas = screen . getByTestId ( "data-grid-canvas" ) ;
220+
221+ fireEvent . contextMenu ( canvas ) ;
222+
223+ expect ( spy ) . toHaveBeenCalledWith ( [ 1 , 1 ] , expect . anything ( ) ) ;
224+ } ) ;
225+
226+ test ( "does not open contextmenu when no cell selected" , async ( ) => {
227+ const spy = vi . fn ( ) ;
228+
229+ vi . useFakeTimers ( ) ;
230+ render ( < DataEditor
231+ { ...basicProps }
232+ gridSelection = { {
233+ columns : CompactSelection . empty ( ) ,
234+ rows : CompactSelection . empty ( ) ,
235+ } }
236+ onCellContextMenu = { spy }
237+ /> , { wrapper : Context } ) ;
238+
239+ prep ( ) ;
240+ const canvas = screen . getByTestId ( "data-grid-canvas" ) ;
241+ fireEvent . contextMenu ( canvas ) ;
242+
243+ expect ( spy ) . not . toHaveBeenCalled ( ) ;
244+ } ) ;
245+
199246 test ( "middle click does not change selection" , async ( ) => {
200247 const spySelection = vi . fn ( ) ;
201248
0 commit comments