@@ -679,6 +679,125 @@ 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+
773+ it ( 'deselects shift selected items if resolveItemId was provided' , ( ) => {
774+ const selectedItems = [ '6' , '7' ] ;
775+ function resolveItemId ( item : any ) {
776+ return item . id ;
777+ }
778+ const onSelectionChange = jest . fn ( ) ;
779+ const resourceList = mountWithAppProvider (
780+ < ResourceList
781+ items = { itemsWithID }
782+ selectedItems = { selectedItems }
783+ promotedBulkActions = { promotedBulkActions }
784+ renderItem = { renderItem }
785+ onSelectionChange = { onSelectionChange }
786+ resolveItemId = { resolveItemId }
787+ /> ,
788+ ) ;
789+ // Sets {lastSeleced: 0}
790+ const firstItem = resourceList . find ( Item ) . first ( ) ;
791+ findByTestID ( firstItem , 'LargerSelectionArea' ) . simulate ( 'click' ) ;
792+
793+ const lastItem = resourceList . find ( Item ) . last ( ) ;
794+ findByTestID ( lastItem , 'LargerSelectionArea' ) . simulate ( 'click' , {
795+ nativeEvent : { shiftKey : true } ,
796+ } ) ;
797+
798+ expect ( onSelectionChange ) . toBeCalledWith ( [ ] ) ;
799+ } ) ;
800+ } ) ;
682801} ) ;
683802
684803function idForItem ( item : any ) {
@@ -693,11 +812,12 @@ function renderCustomMarkup(item: any) {
693812 return < p > { item . title } </ p > ;
694813}
695814
696- function renderItem ( item : any , id : any ) {
815+ function renderItem ( item : any , id : any , index : number ) {
697816 return (
698817 < ResourceList . Item
699818 id = { id }
700819 url = { item . url }
820+ sortOrder = { index }
701821 accessibilityLabel = { `View details for ${ item . title } ` }
702822 >
703823 < div > Item { id } </ div >
0 commit comments