1
1
import { makeTest , TestBedConfig } from './scaffolding/runner' ;
2
2
import { Misc } from './miscellaneous/misc' ;
3
3
import { testItemsCounter , ItemsCounter } from './miscellaneous/itemsCounter' ;
4
+ import { ClipOptions } from 'src/component/interfaces' ;
4
5
5
6
const configList : TestBedConfig [ ] = [ {
6
- datasourceSettings : { startIndex : 100 , bufferSize : 4 , padding : 0.22 , itemSize : 20 } ,
7
- templateSettings : { viewportHeight : 71 , itemHeight : 20 }
8
- } , {
9
7
datasourceSettings : { startIndex : 1 , bufferSize : 5 , padding : 0.2 , itemSize : 20 } ,
10
8
templateSettings : { viewportHeight : 100 }
11
9
} , {
12
- datasourceSettings : { startIndex : - 15 , bufferSize : 12 , padding : 0.98 , itemSize : 20 } ,
13
- templateSettings : { viewportHeight : 66 , itemHeight : 20 }
10
+ datasourceSettings : { startIndex : - 158 , bufferSize : 11 , padding : 0.68 , itemSize : 20 } ,
11
+ templateSettings : { viewportHeight : 77 , itemHeight : 20 }
14
12
} , {
15
13
datasourceSettings : { startIndex : 1 , bufferSize : 5 , padding : 1 , horizontal : true , itemSize : 90 } ,
16
14
templateSettings : { viewportWidth : 450 , itemWidth : 90 , horizontal : true }
17
15
} , {
18
- datasourceSettings : { startIndex : - 74 , bufferSize : 4 , padding : 0.72 , horizontal : true , itemSize : 75 } ,
19
- templateSettings : { viewportWidth : 300 , itemWidth : 75 , horizontal : true }
16
+ datasourceSettings : { startIndex : - 274 , bufferSize : 3 , padding : 1.22 , horizontal : true , itemSize : 75 } ,
17
+ templateSettings : { viewportWidth : 320 , itemWidth : 75 , horizontal : true }
20
18
} ] ;
21
19
20
+ const configByDirectionList = configList . map ( ( config : TestBedConfig , index : number ) => ( {
21
+ ...config ,
22
+ custom : { forward : index % 2 === 0 , backward : index % 2 !== 0 }
23
+ } ) ) ;
24
+
22
25
configList . forEach ( config => config . datasourceSettings . adapter = true ) ;
23
26
24
27
export const getItemsCounter = (
25
- settings : TestBedConfig , misc : Misc , itemSize : number , firstIndex : number , lastIndex : number
28
+ settings : TestBedConfig , misc : Misc , itemSize : number , firstIndex : number , lastIndex : number , clipOptions : ClipOptions
26
29
) : ItemsCounter => {
27
30
const { startIndex, padding } = misc . scroller . settings ;
28
31
const viewportSize = misc . getViewportSize ( settings ) ;
@@ -40,7 +43,16 @@ export const getItemsCounter = (
40
43
41
44
itemsCounter . backward . padding = ( backward . index - firstIndex ) * itemSize ;
42
45
itemsCounter . forward . padding = ( lastIndex - forward . index ) * itemSize ;
43
-
46
+
47
+ if ( clipOptions ) {
48
+ if ( clipOptions . forwardOnly ) {
49
+ backward . padding = 0 ;
50
+ backward . index = firstIndex ;
51
+ } else {
52
+ forward . padding = 0 ;
53
+ forward . index = lastIndex ;
54
+ }
55
+ }
44
56
return itemsCounter ;
45
57
} ;
46
58
@@ -49,6 +61,7 @@ const shouldClipAfterAppend = (config: TestBedConfig) => (misc: Misc) => (done:
49
61
const NEW_ITEMS_COUNT = 50 ;
50
62
const { itemSize } = config . datasourceSettings ;
51
63
let firstIndex : number , lastIndex : number ;
64
+ const clipSettings = getClipArgument ( config ) ;
52
65
53
66
spyOn ( misc . workflow , 'finalize' ) . and . callFake ( ( ) => {
54
67
const cycles = misc . workflow . cyclesDone ;
@@ -64,18 +77,45 @@ const shouldClipAfterAppend = (config: TestBedConfig) => (misc: Misc) => (done:
64
77
lastIndex = < number > misc . scroller . buffer . lastIndex ;
65
78
expect ( lastIndex ) . toEqual ( indexToAppend + NEW_ITEMS_COUNT - 1 ) ;
66
79
expect ( misc . padding . backward . getSize ( ) ) . toEqual ( 0 ) ;
67
- misc . datasource . adapter . clip ( ) ;
80
+ misc . datasource . adapter . clip ( clipSettings ) ;
68
81
} else {
69
82
// user clip requires additional reflow to remove DOM elements
70
83
setTimeout ( ( ) => {
71
- const itemsCounter = getItemsCounter ( config , misc , itemSize , firstIndex , lastIndex ) ;
84
+ const itemsCounter = getItemsCounter ( config , misc , itemSize , firstIndex , lastIndex , clipSettings ) ;
72
85
testItemsCounter ( config , misc , itemsCounter ) ;
73
86
done ( ) ;
74
87
} ) ;
75
88
}
76
89
} ) ;
77
90
} ;
78
91
92
+ const getClipArgument = ( { custom } : TestBedConfig ) : any => {
93
+ let argument ;
94
+ if ( custom && custom . forward ) {
95
+ argument = { forwardOnly : true } ;
96
+ }
97
+ if ( custom && custom . backward ) {
98
+ argument = { backwardOnly : true } ;
99
+ }
100
+ return argument ;
101
+ } ;
102
+
103
+ const getClipDirection = ( config : TestBedConfig ) : string => {
104
+ if ( ! config . custom ) {
105
+ return '' ;
106
+ }
107
+ if ( config . custom . forward && config . custom . backward ) {
108
+ return 'forward and backward' ;
109
+ }
110
+ if ( config . custom . forward ) {
111
+ return 'forward' ;
112
+ }
113
+ if ( config . custom . backward ) {
114
+ return 'backward' ;
115
+ }
116
+ return '' ;
117
+ }
118
+
79
119
describe ( 'Adapter Clip Spec' , ( ) => {
80
120
81
121
configList . forEach ( config =>
@@ -86,5 +126,13 @@ describe('Adapter Clip Spec', () => {
86
126
} )
87
127
) ;
88
128
129
+ configByDirectionList . forEach ( config =>
130
+ makeTest ( {
131
+ config,
132
+ title : `should clip ${ getClipDirection ( config ) } after append many` ,
133
+ it : shouldClipAfterAppend ( config )
134
+ } )
135
+ ) ;
136
+
89
137
} ) ;
90
138
0 commit comments