@@ -3,7 +3,7 @@ import { generateItem, Item } from './miscellaneous/items';
3
3
import { Misc } from './miscellaneous/misc' ;
4
4
import { Settings , DevSettings , DatasourceGet } from '../src/component/interfaces/index' ;
5
5
6
- const baseSettings : Settings = {
6
+ const baseSettings = {
7
7
startIndex : 1 ,
8
8
minIndex : 1 ,
9
9
maxIndex : 100 ,
@@ -14,12 +14,20 @@ const baseSettings: Settings = {
14
14
const configList : TestBedConfig [ ] = [ {
15
15
datasourceSettings : { ...baseSettings } ,
16
16
custom : {
17
- indexToReplace : 3 // visible replace
17
+ indexToReplace : baseSettings . minIndex + 1 ,
18
+ token : 'middle'
18
19
}
19
20
} , {
20
21
datasourceSettings : { ...baseSettings } ,
21
22
custom : {
22
- indexToReplace : 50 // invisible replace
23
+ indexToReplace : baseSettings . minIndex ,
24
+ token : 'first'
25
+ }
26
+ } , {
27
+ datasourceSettings : { ...baseSettings , startIndex : baseSettings . maxIndex } ,
28
+ custom : {
29
+ indexToReplace : baseSettings . maxIndex ,
30
+ token : 'last'
23
31
}
24
32
} ] ;
25
33
@@ -40,6 +48,7 @@ const getDatasourceClass = (settings: Settings) =>
40
48
}
41
49
42
50
this . settings = { ...settings } ;
51
+ // this.devSettings = { debug: true, logProcessRun: true };
43
52
44
53
this . get = ( index : number , count : number , success : Function ) => {
45
54
const data = [ ] ;
@@ -71,34 +80,45 @@ configList.forEach(config => config.datasourceClass = getDatasourceClass(config.
71
80
const shouldReplace = ( config : TestBedConfig ) => ( misc : Misc ) => async ( done : Function ) => {
72
81
await misc . relaxNext ( ) ;
73
82
const { adapter } = misc ;
74
- const { custom : { indexToReplace } , datasourceSettings : { minIndex, itemSize } } = config ;
83
+ const { custom : { indexToReplace, token } , datasourceSettings : { minIndex, itemSize } } = config ;
75
84
const replaceOne = ( misc . datasource as any ) . replaceOne . bind ( misc . datasource ) ;
76
- const scrollPosition = ( indexToReplace - 1 + minIndex - 1 ) * itemSize ;
85
+ const maxScrollPosition = misc . getMaxScrollPosition ( ) ;
86
+ const position = token === 'last' ? maxScrollPosition : ( indexToReplace - 1 + minIndex - 1 ) * itemSize ;
77
87
const newItem = generateItem ( indexToReplace ) ;
78
88
newItem . text += '*' ;
79
89
90
+ // replace at the Datasource level
80
91
replaceOne ( indexToReplace , newItem ) ;
81
92
93
+ // replace at the Viewport level (Adapter)
82
94
await adapter . replace ( {
83
95
predicate : ( { $index } ) => $index === indexToReplace ,
84
96
items : [ newItem ]
85
97
} ) ;
86
98
87
99
await misc . scrollMinMax ( ) ;
88
- adapter . fix ( { scrollPosition } ) ;
89
- await misc . relaxNext ( ) ;
90
100
91
- expect ( adapter . firstVisible . $index ) . toEqual ( indexToReplace ) ;
101
+ // scroll to replaced item
102
+ if ( misc . getScrollPosition ( ) !== position ) {
103
+ adapter . fix ( { scrollPosition : position } ) ;
104
+ await misc . relaxNext ( ) ;
105
+ }
106
+
107
+ if ( token === 'last' ) {
108
+ expect ( adapter . lastVisible . $index ) . toEqual ( indexToReplace ) ;
109
+ } else {
110
+ expect ( adapter . firstVisible . $index ) . toEqual ( indexToReplace ) ;
111
+ }
92
112
expect ( misc . getElementText ( indexToReplace ) ) . toEqual ( indexToReplace + ': ' + newItem . text ) ;
93
113
done ( ) ;
94
114
} ;
95
115
96
116
describe ( 'Adapter Replace Spec' , ( ) => {
97
117
98
- describe ( 'simple replacement' , ( ) =>
118
+ describe ( 'single replacement' , ( ) =>
99
119
configList . forEach ( config =>
100
120
makeTest ( {
101
- title : ' should work' ,
121
+ title : ` should work ( ${ config . custom . token } )` ,
102
122
config,
103
123
it : shouldReplace ( config )
104
124
} )
0 commit comments