File tree Expand file tree Collapse file tree 2 files changed +44
-10
lines changed
app/code/Magento/Ui/view/base/web/js/dynamic-rows
dev/tests/js/jasmine/tests/app/code/Magento/Ui/base/js/dynamic-rows Expand file tree Collapse file tree 2 files changed +44
-10
lines changed Original file line number Diff line number Diff line change 1
1
/**
2
- * Copyright © Magento, Inc. All rights reserved.
3
- * See COPYING.txt for license details .
2
+ * Copyright 2016 Adobe
3
+ * All Rights Reserved .
4
4
*/
5
5
6
6
/**
@@ -689,14 +689,16 @@ define([
689
689
* @param {Number|String } prop - additional property to element
690
690
*/
691
691
processingAddChild : function ( ctx , index , prop ) {
692
+ var newTotal ,
693
+ newPages ;
694
+
692
695
this . bubble ( 'addChild' , false ) ;
693
696
694
- if ( this . relatedData . length && this . relatedData . length % this . pageSize === 0 ) {
695
- this . pages ( this . pages ( ) + 1 ) ;
696
- this . nextPage ( ) ;
697
- } else if ( ~ ~ this . currentPage ( ) !== this . pages ( ) ) {
698
- this . currentPage ( this . pages ( ) ) ;
699
- }
697
+ newTotal = this . relatedData . length + 1 ;
698
+ newPages = Math . ceil ( newTotal / this . pageSize ) ;
699
+
700
+ this . pages ( newPages ) ;
701
+ this . currentPage ( newPages ) ;
700
702
701
703
this . addChild ( ctx , index , prop ) ;
702
704
} ,
Original file line number Diff line number Diff line change 1
1
/**
2
- * Copyright © Magento, Inc. All rights reserved.
3
- * See COPYING.txt for license details .
2
+ * Copyright 2017 Adobe
3
+ * All Rights Reserved .
4
4
*/
5
5
6
6
/* eslint-disable max-nested-callbacks */
@@ -204,5 +204,37 @@ define([
204
204
expect ( model . pages ( ) ) . toEqual ( 2 ) ;
205
205
expect ( model . currentPage ( ) ) . toEqual ( 2 ) ;
206
206
} ) ;
207
+
208
+ it ( 'should process pages before addChild' , function ( ) {
209
+ var ctx = { } ,
210
+ index = 5 ,
211
+ prop = 'someProp' ;
212
+
213
+ model . pageSize = 2 ;
214
+ model . relatedData = [
215
+ {
216
+ name : 'first'
217
+ } ,
218
+ {
219
+ name : 'second'
220
+ } ,
221
+ {
222
+ name : 'third'
223
+ } ,
224
+ {
225
+ name : 'fourth'
226
+ } ,
227
+ {
228
+ name : 'fifth'
229
+ }
230
+ ] ;
231
+ model . bubble = jasmine . createSpy ( ) ;
232
+ model . addChild = jasmine . createSpy ( ) ;
233
+ model . processingAddChild ( ctx , index , prop ) ;
234
+ expect ( model . bubble ) . toHaveBeenCalledWith ( 'addChild' , false ) ;
235
+ expect ( model . pages ( ) ) . toEqual ( 3 ) ;
236
+ expect ( model . currentPage ( ) ) . toEqual ( 3 ) ;
237
+ expect ( model . addChild ) . toHaveBeenCalledWith ( ctx , index , prop ) ;
238
+ } ) ;
207
239
} ) ;
208
240
} ) ;
You can’t perform that action at this time.
0 commit comments