@@ -4,7 +4,7 @@ import List from '../src';
4
4
import { spyElementPrototypes } from './utils/domHook' ;
5
5
6
6
function genData ( count ) {
7
- return new Array ( count ) . fill ( null ) . map ( ( _ , id ) => ( { id } ) ) ;
7
+ return new Array ( count ) . fill ( null ) . map ( ( _ , index ) => ( { id : String ( index ) } ) ) ;
8
8
}
9
9
10
10
describe ( 'List.Scroll' , ( ) => {
@@ -60,7 +60,7 @@ describe('List.Scroll', () => {
60
60
mockElement . mockRestore ( ) ;
61
61
} ) ;
62
62
63
- function testPlots ( type , props ) {
63
+ function testPlots ( type , scrollConfig , props ) {
64
64
describe ( `${ type } list` , ( ) => {
65
65
let listRef ;
66
66
let wrapper ;
@@ -81,11 +81,11 @@ describe('List.Scroll', () => {
81
81
} ) ;
82
82
83
83
it ( 'top' , ( ) => {
84
- listRef . current . scrollTo ( { index : 10 , align : 'top' } ) ;
84
+ listRef . current . scrollTo ( { ... scrollConfig , align : 'top' } ) ;
85
85
expect ( scrollTop ) . toEqual ( 200 ) ;
86
86
} ) ;
87
87
it ( 'bottom' , ( ) => {
88
- listRef . current . scrollTo ( { index : 10 , align : 'bottom' } ) ;
88
+ listRef . current . scrollTo ( { ... scrollConfig , align : 'bottom' } ) ;
89
89
expect ( scrollTop ) . toEqual ( 120 ) ;
90
90
} ) ;
91
91
describe ( 'auto' , ( ) => {
@@ -96,7 +96,7 @@ describe('List.Scroll', () => {
96
96
. last ( )
97
97
. simulate ( 'scroll' ) ;
98
98
expect ( onScroll ) . toHaveBeenCalled ( ) ;
99
- listRef . current . scrollTo ( { index : 10 , align : 'auto' } ) ;
99
+ listRef . current . scrollTo ( { ... scrollConfig , align : 'auto' } ) ;
100
100
expect ( scrollTop ) . toEqual ( 200 ) ;
101
101
} ) ;
102
102
it ( 'lower of' , ( ) => {
@@ -106,7 +106,7 @@ describe('List.Scroll', () => {
106
106
. last ( )
107
107
. simulate ( 'scroll' ) ;
108
108
expect ( onScroll ) . toHaveBeenCalled ( ) ;
109
- listRef . current . scrollTo ( { index : 10 , align : 'auto' } ) ;
109
+ listRef . current . scrollTo ( { ... scrollConfig , align : 'auto' } ) ;
110
110
expect ( scrollTop ) . toEqual ( 120 ) ;
111
111
} ) ;
112
112
it ( 'in range' , ( ) => {
@@ -116,14 +116,16 @@ describe('List.Scroll', () => {
116
116
. last ( )
117
117
. simulate ( 'scroll' ) ;
118
118
expect ( onScroll ) . toHaveBeenCalled ( ) ;
119
- listRef . current . scrollTo ( { index : 10 , align : 'auto' } ) ;
119
+ listRef . current . scrollTo ( { ... scrollConfig , align : 'auto' } ) ;
120
120
expect ( scrollTop ) . toEqual ( 150 ) ;
121
121
} ) ;
122
122
} ) ;
123
123
} ) ;
124
124
}
125
125
126
- testPlots ( 'virtual list' ) ;
127
- testPlots ( 'raw list' , { itemHeight : null } ) ;
126
+ testPlots ( 'virtual list' , { index : 10 } ) ;
127
+ testPlots ( 'raw list' , { index : 10 } , { itemHeight : null } ) ;
128
+ testPlots ( 'virtual list by key' , { key : '10' } ) ;
129
+ testPlots ( 'raw list by key' , { key : '10' } , { itemHeight : null } ) ;
128
130
} ) ;
129
131
} ) ;
0 commit comments