@@ -679,6 +679,124 @@ describe('<ResourceList />', () => {
679679 expect ( resourceList . find ( BulkActions ) . prop ( 'selectMode' ) ) . toBe ( true ) ;
680680 } ) ;
681681 } ) ;
682+
683+ describe ( 'multiselect' , ( ) => {
684+ it ( 'selects shift selected items if resolveItemId was provided' , ( ) => {
685+ function resolveItemId ( item : any ) {
686+ return item . id ;
687+ }
688+ const onSelectionChange = jest . fn ( ) ;
689+ const resourceList = mountWithAppProvider (
690+ < ResourceList
691+ items = { itemsWithID }
692+ selectedItems = { [ ] }
693+ promotedBulkActions = { promotedBulkActions }
694+ renderItem = { renderItem }
695+ onSelectionChange = { onSelectionChange }
696+ resolveItemId = { resolveItemId }
697+ /> ,
698+ ) ;
699+ const firstItem = resourceList . find ( Item ) . first ( ) ;
700+ findByTestID ( firstItem , 'LargerSelectionArea' ) . simulate ( 'click' ) ;
701+
702+ const lastItem = resourceList . find ( Item ) . last ( ) ;
703+ findByTestID ( lastItem , 'LargerSelectionArea' ) . simulate ( 'click' , {
704+ nativeEvent : { shiftKey : true } ,
705+ } ) ;
706+
707+ expect ( onSelectionChange ) . toBeCalledWith ( [ '5' , '6' , '7' ] ) ;
708+ } ) ;
709+
710+ it ( 'does not select shift selected items if resolveItemId was not provided' , ( ) => {
711+ const onSelectionChange = jest . fn ( ) ;
712+ const resourceList = mountWithAppProvider (
713+ < ResourceList
714+ items = { itemsWithID }
715+ selectedItems = { [ ] }
716+ promotedBulkActions = { promotedBulkActions }
717+ renderItem = { renderItem }
718+ onSelectionChange = { onSelectionChange }
719+ /> ,
720+ ) ;
721+ const firstItem = resourceList . find ( Item ) . first ( ) ;
722+ findByTestID ( firstItem , 'LargerSelectionArea' ) . simulate ( 'click' ) ;
723+
724+ const lastItem = resourceList . find ( Item ) . last ( ) ;
725+ findByTestID ( lastItem , 'LargerSelectionArea' ) . simulate ( 'click' , {
726+ nativeEvent : { shiftKey : true } ,
727+ } ) ;
728+
729+ expect ( onSelectionChange ) . toBeCalledWith ( [ '7' ] ) ;
730+ } ) ;
731+
732+ it ( 'does not select shift selected items if sortOrder is not provided' , ( ) => {
733+ function resolveItemId ( item : any ) {
734+ return item . id ;
735+ }
736+
737+ function renderItem ( item : any , id : any ) {
738+ return (
739+ < ResourceList . Item
740+ id = { id }
741+ url = { item . url }
742+ accessibilityLabel = { `View details for ${ item . title } ` }
743+ >
744+ < div > Item { id } </ div >
745+ < div > { item . title } </ div >
746+ </ ResourceList . Item >
747+ ) ;
748+ }
749+
750+ const onSelectionChange = jest . fn ( ) ;
751+ const resourceList = mountWithAppProvider (
752+ < ResourceList
753+ items = { itemsWithID }
754+ selectedItems = { [ ] }
755+ promotedBulkActions = { promotedBulkActions }
756+ renderItem = { renderItem }
757+ onSelectionChange = { onSelectionChange }
758+ resolveItemId = { resolveItemId }
759+ /> ,
760+ ) ;
761+ const firstItem = resourceList . find ( Item ) . first ( ) ;
762+ findByTestID ( firstItem , 'LargerSelectionArea' ) . simulate ( 'click' ) ;
763+
764+ const lastItem = resourceList . find ( Item ) . last ( ) ;
765+ findByTestID ( lastItem , 'LargerSelectionArea' ) . simulate ( 'click' , {
766+ nativeEvent : { shiftKey : true } ,
767+ } ) ;
768+
769+ expect ( onSelectionChange ) . toBeCalledWith ( [ '7' ] ) ;
770+ } ) ;
771+
772+ it ( 'deselects shift selected items if resolveItemId was provided' , ( ) => {
773+ const selectedItems = [ '6' , '7' ] ;
774+ function resolveItemId ( item : any ) {
775+ return item . id ;
776+ }
777+ const onSelectionChange = jest . fn ( ) ;
778+ const resourceList = mountWithAppProvider (
779+ < ResourceList
780+ items = { itemsWithID }
781+ selectedItems = { selectedItems }
782+ promotedBulkActions = { promotedBulkActions }
783+ renderItem = { renderItem }
784+ onSelectionChange = { onSelectionChange }
785+ resolveItemId = { resolveItemId }
786+ /> ,
787+ ) ;
788+ // Sets {lastSeleced: 0}
789+ const firstItem = resourceList . find ( Item ) . first ( ) ;
790+ findByTestID ( firstItem , 'LargerSelectionArea' ) . simulate ( 'click' ) ;
791+
792+ const lastItem = resourceList . find ( Item ) . last ( ) ;
793+ findByTestID ( lastItem , 'LargerSelectionArea' ) . simulate ( 'click' , {
794+ nativeEvent : { shiftKey : true } ,
795+ } ) ;
796+
797+ expect ( onSelectionChange ) . toBeCalledWith ( [ ] ) ;
798+ } ) ;
799+ } ) ;
682800} ) ;
683801
684802function idForItem ( item : any ) {
@@ -693,11 +811,12 @@ function renderCustomMarkup(item: any) {
693811 return < p > { item . title } </ p > ;
694812}
695813
696- function renderItem ( item : any , id : any ) {
814+ function renderItem ( item : any , id : any , index : number ) {
697815 return (
698816 < ResourceList . Item
699817 id = { id }
700818 url = { item . url }
819+ sortOrder = { index }
701820 accessibilityLabel = { `View details for ${ item . title } ` }
702821 >
703822 < div > Item { id } </ div >
0 commit comments