@@ -29,6 +29,7 @@ import {Link} from '@react-spectrum/link';
29
29
import { Provider } from '@react-spectrum/provider' ;
30
30
import React from 'react' ;
31
31
import { Switch } from '@react-spectrum/switch' ;
32
+ import { TableWithBreadcrumbs } from '../stories/Table.stories' ;
32
33
import { TextField } from '@react-spectrum/textfield' ;
33
34
import { theme } from '@react-spectrum/theme-default' ;
34
35
import { typeText } from '@react-spectrum/test-utils' ;
@@ -2280,6 +2281,85 @@ describe('TableView', function () {
2280
2281
} ) ;
2281
2282
} ) ;
2282
2283
2284
+ it ( 'can announce deselect even when items are swapped out completely' , ( ) => {
2285
+ let tree = render ( < TableWithBreadcrumbs /> ) ;
2286
+
2287
+ let row = tree . getAllByRole ( 'row' ) [ 2 ] ;
2288
+ triggerPress ( row ) ;
2289
+ expect ( announce ) . toHaveBeenLastCalledWith ( 'File B selected.' ) ;
2290
+
2291
+ let link = tree . getAllByRole ( 'link' ) [ 1 ] ;
2292
+ triggerPress ( link ) ;
2293
+
2294
+ expect ( announce ) . toHaveBeenLastCalledWith ( 'No items selected.' ) ;
2295
+ expect ( announce ) . toHaveBeenCalledTimes ( 2 ) ;
2296
+ } ) ;
2297
+
2298
+ it ( 'will not announce deselect caused by breadcrumb navigation' , ( ) => {
2299
+ let tree = render ( < TableWithBreadcrumbs /> ) ;
2300
+
2301
+ let link = tree . getAllByRole ( 'link' ) [ 1 ] ;
2302
+ triggerPress ( link ) ;
2303
+
2304
+ act ( ( ) => {
2305
+ // TableWithBreadcrumbs has a setTimeout to load the results of the link navigation on Folder A
2306
+ jest . runAllTimers ( ) ;
2307
+ } ) ;
2308
+ let row = tree . getAllByRole ( 'row' ) [ 1 ] ;
2309
+ triggerPress ( row ) ;
2310
+ expect ( announce ) . toHaveBeenLastCalledWith ( 'File C selected.' ) ;
2311
+ expect ( announce ) . toHaveBeenCalledTimes ( 2 ) ;
2312
+
2313
+ // breadcrumb root
2314
+ link = tree . getAllByRole ( 'link' ) [ 0 ] ;
2315
+ triggerPress ( link ) ;
2316
+
2317
+ // focus isn't on the table, so we don't announce that it has been deselected
2318
+ expect ( announce ) . toHaveBeenCalledTimes ( 2 ) ;
2319
+ } ) ;
2320
+
2321
+ it ( 'updates even if not focused' , ( ) => {
2322
+ let tree = render ( < TableWithBreadcrumbs /> ) ;
2323
+
2324
+ let link = tree . getAllByRole ( 'link' ) [ 1 ] ;
2325
+ triggerPress ( link ) ;
2326
+
2327
+ act ( ( ) => {
2328
+ // TableWithBreadcrumbs has a setTimeout to load the results of the link navigation on Folder A
2329
+ jest . runAllTimers ( ) ;
2330
+ } ) ;
2331
+ let row = tree . getAllByRole ( 'row' ) [ 1 ] ;
2332
+ triggerPress ( row ) ;
2333
+ expect ( announce ) . toHaveBeenLastCalledWith ( 'File C selected.' ) ;
2334
+ expect ( announce ) . toHaveBeenCalledTimes ( 2 ) ;
2335
+ let button = tree . getAllByRole ( 'button' ) [ 0 ] ;
2336
+ triggerPress ( button ) ;
2337
+ expect ( announce ) . toHaveBeenCalledTimes ( 2 ) ;
2338
+
2339
+ // breadcrumb root
2340
+ link = tree . getAllByRole ( 'menuitemradio' ) [ 0 ] ;
2341
+ triggerPress ( link ) ;
2342
+
2343
+ act ( ( ) => {
2344
+ // TableWithBreadcrumbs has a setTimeout to load the results of the link navigation on Folder A
2345
+ jest . runAllTimers ( ) ;
2346
+ } ) ;
2347
+
2348
+ // focus isn't on the table, so we don't announce that it has been deselected
2349
+ expect ( announce ) . toHaveBeenCalledTimes ( 2 ) ;
2350
+
2351
+ link = tree . getAllByRole ( 'link' ) [ 1 ] ;
2352
+ triggerPress ( link ) ;
2353
+
2354
+ act ( ( ) => {
2355
+ // TableWithBreadcrumbs has a setTimeout to load the results of the link navigation on Folder A
2356
+ jest . runAllTimers ( ) ;
2357
+ } ) ;
2358
+
2359
+ expect ( announce ) . toHaveBeenCalledTimes ( 3 ) ;
2360
+ expect ( announce ) . toHaveBeenLastCalledWith ( 'No items selected.' ) ;
2361
+ } ) ;
2362
+
2283
2363
describe ( 'selectionStyle highlight' , function ( ) {
2284
2364
installPointerEvent ( ) ;
2285
2365
@@ -2747,7 +2827,7 @@ describe('TableView', function () {
2747
2827
} ) ;
2748
2828
2749
2829
describe ( 'press/hover interactions and selection mode' , function ( ) {
2750
- let TableExample = ( props ) => (
2830
+ let TableWithBreadcrumbs = ( props ) => (
2751
2831
< TableView aria-label = "Table" { ...props } >
2752
2832
< TableHeader columns = { columns } >
2753
2833
{ column => < Column > { column . name } </ Column > }
@@ -2763,15 +2843,15 @@ describe('TableView', function () {
2763
2843
) ;
2764
2844
2765
2845
it ( 'displays pressed/hover styles when row is pressed/hovered and selection mode is not "none"' , function ( ) {
2766
- let tree = render ( < TableExample selectionMode = "multiple" /> ) ;
2846
+ let tree = render ( < TableWithBreadcrumbs selectionMode = "multiple" /> ) ;
2767
2847
2768
2848
let row = tree . getAllByRole ( 'row' ) [ 1 ] ;
2769
2849
fireEvent . mouseDown ( row , { detail : 1 } ) ;
2770
2850
expect ( row . className . includes ( 'is-active' ) ) . toBeTruthy ( ) ;
2771
2851
fireEvent . mouseEnter ( row ) ;
2772
2852
expect ( row . className . includes ( 'is-hovered' ) ) . toBeTruthy ( ) ;
2773
2853
2774
- rerender ( tree , < TableExample selectionMode = "single" /> ) ;
2854
+ rerender ( tree , < TableWithBreadcrumbs selectionMode = "single" /> ) ;
2775
2855
row = tree . getAllByRole ( 'row' ) [ 1 ] ;
2776
2856
fireEvent . mouseDown ( row , { detail : 1 } ) ;
2777
2857
expect ( row . className . includes ( 'is-active' ) ) . toBeTruthy ( ) ;
@@ -2780,7 +2860,7 @@ describe('TableView', function () {
2780
2860
} ) ;
2781
2861
2782
2862
it ( 'doesn\'t show pressed/hover styles when row is pressed/hovered and selection mode is "none"' , function ( ) {
2783
- let tree = render ( < TableExample selectionMode = "none" /> ) ;
2863
+ let tree = render ( < TableWithBreadcrumbs selectionMode = "none" /> ) ;
2784
2864
2785
2865
let row = tree . getAllByRole ( 'row' ) [ 1 ] ;
2786
2866
fireEvent . mouseDown ( row , { detail : 1 } ) ;
@@ -3084,7 +3164,7 @@ describe('TableView', function () {
3084
3164
} ) ;
3085
3165
3086
3166
describe ( 'with dialog trigger' , function ( ) {
3087
- let TableExample = ( props ) => (
3167
+ let TableWithBreadcrumbs = ( props ) => (
3088
3168
< TableView aria-label = "TableView with static contents" selectionMode = "multiple" width = { 300 } height = { 200 } { ...props } >
3089
3169
< TableHeader >
3090
3170
< Column key = "foo" > Foo</ Column >
@@ -3119,7 +3199,7 @@ describe('TableView', function () {
3119
3199
) ;
3120
3200
3121
3201
it ( 'arrow keys interactions don\'t move the focus away from the textfield in the dialog' , function ( ) {
3122
- let tree = render ( < TableExample /> ) ;
3202
+ let tree = render ( < TableWithBreadcrumbs /> ) ;
3123
3203
let table = tree . getByRole ( 'grid' ) ;
3124
3204
let rows = within ( table ) . getAllByRole ( 'row' ) ;
3125
3205
expect ( rows ) . toHaveLength ( 2 ) ;
0 commit comments