@@ -24,7 +24,7 @@ import {CUSTOM_DRAG_TYPE} from '@react-aria/dnd/src/constants';
24
24
import { DataTransfer , DataTransferItem , DragEvent , FileSystemDirectoryEntry , FileSystemFileEntry } from '@react-aria/dnd/test/mocks' ;
25
25
import { DIRECTORY_DRAG_TYPE } from '@react-aria/dnd' ;
26
26
import { DragBetweenTablesComplex } from '../stories/TableDnDUtilExamples' ;
27
- import { DragBetweenTablesExample , DragBetweenTablesRootOnlyExample , DragExample , DragOntoRowExample , ReorderExample } from '../stories/TableDnDExamples' ;
27
+ import { DragBetweenTablesExample , DragBetweenTablesRootOnlyExample , DragExample , DragOntoRowExample , DragWithoutRowHeaderExample , ReorderExample } from '../stories/TableDnDExamples' ;
28
28
import { Droppable } from '@react-aria/dnd/test/examples' ;
29
29
import { Flex } from '@react-spectrum/layout' ;
30
30
import { globalDndState } from '@react-aria/dnd/src/utils' ;
@@ -114,6 +114,12 @@ describe('TableView', function () {
114
114
) ;
115
115
}
116
116
117
+ function DraggbleWithoutRowHeader ( props ) {
118
+ return (
119
+ < DragWithoutRowHeaderExample onDrop = { onDrop } onDragStart = { onDragStart } onDragEnd = { onDragEnd } { ...props } />
120
+ ) ;
121
+ }
122
+
117
123
function Reorderable ( props ) {
118
124
return (
119
125
< ReorderExample disabledKeys = { [ 'a' ] } onDrop = { onDrop } onDragStart = { onDragStart } onDragEnd = { onDragEnd } { ...props } />
@@ -197,6 +203,56 @@ describe('TableView', function () {
197
203
expect ( dataTransfer . _dragImage . y ) . toBe ( 5 ) ;
198
204
} ) ;
199
205
206
+ it ( 'should render a drag preview with highlight selection style' , function ( ) {
207
+ let { getByRole, getAllByText} = render (
208
+ < DraggbleWithoutRowHeader tableViewProps = { { selectedKeys : [ 'a' ] , selectionStyle : 'highlight' } } />
209
+ ) ;
210
+
211
+ let grid = getByRole ( 'grid' ) ;
212
+ let rowgroups = within ( grid ) . getAllByRole ( 'rowgroup' ) ;
213
+ let rows = within ( rowgroups [ 1 ] ) . getAllByRole ( 'row' ) ;
214
+ let row = rows [ 0 ] ;
215
+ let cell = within ( row ) . getAllByRole ( 'rowheader' ) [ 0 ] ;
216
+ let cellText = getAllByText ( cell . textContent ) ;
217
+ expect ( cellText ) . toHaveLength ( 1 ) ;
218
+
219
+ let dataTransfer = new DataTransfer ( ) ;
220
+
221
+ fireEvent . pointerDown ( cell , { pointerType : 'mouse' , button : 0 , pointerId : 1 , clientX : 5 , clientY : 5 } ) ;
222
+ fireEvent ( cell , new DragEvent ( 'dragstart' , { dataTransfer, clientX : 5 , clientY : 5 } ) ) ;
223
+ expect ( dataTransfer . _dragImage . node . tagName ) . toBe ( 'DIV' ) ;
224
+
225
+ // Verify that when no rowHeader is set, the drag preview displays the text of the first element of the row
226
+ expect ( dataTransfer . _dragImage . node . textContent ) . toBe ( 'Vin' ) ;
227
+ expect ( dataTransfer . _dragImage . x ) . toBe ( 5 ) ;
228
+ expect ( dataTransfer . _dragImage . y ) . toBe ( 5 ) ;
229
+ } ) ;
230
+
231
+ it ( 'should render a drag preview with checkbox selection style' , function ( ) {
232
+ let { getByRole, getAllByText} = render (
233
+ < DraggbleWithoutRowHeader tableViewProps = { { selectedKeys : [ 'a' ] , selectionStyle : 'checkbox' } } />
234
+ ) ;
235
+
236
+ let grid = getByRole ( 'grid' ) ;
237
+ let rowgroups = within ( grid ) . getAllByRole ( 'rowgroup' ) ;
238
+ let rows = within ( rowgroups [ 1 ] ) . getAllByRole ( 'row' ) ;
239
+ let row = rows [ 0 ] ;
240
+ let cell = within ( row ) . getAllByRole ( 'rowheader' ) [ 0 ] ;
241
+ let cellText = getAllByText ( cell . textContent ) ;
242
+ expect ( cellText ) . toHaveLength ( 1 ) ;
243
+
244
+ let dataTransfer = new DataTransfer ( ) ;
245
+
246
+ fireEvent . pointerDown ( cell , { pointerType : 'mouse' , button : 0 , pointerId : 1 , clientX : 5 , clientY : 5 } ) ;
247
+ fireEvent ( cell , new DragEvent ( 'dragstart' , { dataTransfer, clientX : 5 , clientY : 5 } ) ) ;
248
+
249
+ // Verify that when no rowHeader is set, the drag preview displays the text of the first element of the row
250
+ expect ( dataTransfer . _dragImage . node . tagName ) . toBe ( 'DIV' ) ;
251
+ expect ( dataTransfer . _dragImage . node . textContent ) . toBe ( 'Vin' ) ;
252
+ expect ( dataTransfer . _dragImage . x ) . toBe ( 5 ) ;
253
+ expect ( dataTransfer . _dragImage . y ) . toBe ( 5 ) ;
254
+ } ) ;
255
+
200
256
201
257
it ( 'should allow drag and drop of a single row' , async function ( ) {
202
258
let { getByRole, getByText} = render (
0 commit comments