Skip to content

Commit ca87eaa

Browse files
committed
Merge remote-tracking branch 'adobe-commerce-tier-4/ACP2E-2909' into Tier4-Kings-PR-07-16-2024
2 parents b21e5d9 + 91f2321 commit ca87eaa

File tree

4 files changed

+68
-7
lines changed

4 files changed

+68
-7
lines changed

app/code/Magento/Bundle/view/adminhtml/web/js/components/bundle-dynamic-rows-grid.js

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -141,18 +141,13 @@ define([
141141
* @returns {Object} Chainable.
142142
*/
143143
initElements: function (data) {
144-
var newData = this.getNewData(data),
145-
recordIndex;
144+
var newData = this.getNewData(data);
146145

147146
this.parsePagesData(data);
148147

149148
if (newData.length) {
150149
if (this.insertData().length) {
151-
recordIndex = data.length - newData.length - 1;
152-
153-
_.each(newData, function (newRecord) {
154-
this.processingAddChild(newRecord, ++recordIndex, newRecord[this.identificationProperty]);
155-
}, this);
150+
this.parseProcessingAddChild(data, newData);
156151
}
157152
}
158153

@@ -181,6 +176,23 @@ define([
181176
this.reload();
182177
}
183178
}, this);
179+
},
180+
181+
/**
182+
* Parse and processing the add child method to update the latest records if the record index is not a number.
183+
*
184+
* @param {Array} data
185+
* @param {Array} newData
186+
*/
187+
parseProcessingAddChild: function (data, newData) {
188+
let recordIndex;
189+
190+
recordIndex = data.length - newData.length - 1;
191+
if (!isNaN(recordIndex)) {
192+
_.each(newData, function (newRecord) {
193+
this.processingAddChild(newRecord, ++recordIndex, newRecord[this.identificationProperty]);
194+
}, this);
195+
}
184196
}
185197
});
186198
});

app/code/Magento/Bundle/view/adminhtml/web/js/components/bundle-dynamic-rows.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ define([
7474
let bundleSelections = registry.get(this.name + '.' + index + '.' + this.bundleSelectionsName);
7575

7676
bundleSelections.destroyChildren();
77+
bundleSelections._elems.clear();
7778
},
7879

7980
/**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/************************************************************************
2+
*
3+
* Copyright 2024 Adobe
4+
* All Rights Reserved.
5+
*
6+
* ************************************************************************
7+
*/
8+
/*eslint max-nested-callbacks: 0*/
9+
define(['Magento_Bundle/js/components/bundle-dynamic-rows-grid'],
10+
function (BundleDynamicRowsGrid) {
11+
'use strict';
12+
13+
describe('Magento_Bundle/js/components/bundle-dynamic-rows-grid', function () {
14+
let dynamicRowsGrid;
15+
16+
beforeEach(function () {
17+
dynamicRowsGrid = new BundleDynamicRowsGrid();
18+
});
19+
20+
describe('test parseProcessingAddChild method', function () {
21+
it('Check the processingAddChild method should call when recordIndex is a valid number', function () {
22+
let data = [4], newData = [4];
23+
24+
spyOn(dynamicRowsGrid, 'processingAddChild').and.callThrough();
25+
26+
dynamicRowsGrid.parseProcessingAddChild(data, newData);
27+
28+
expect(dynamicRowsGrid.processingAddChild).toHaveBeenCalled();
29+
});
30+
31+
it('Check the processingAddChild method should not call when recordIndex is inValid number',
32+
function () {
33+
let data = NaN, newData = [2];
34+
35+
spyOn(dynamicRowsGrid, 'processingAddChild').and.callThrough();
36+
37+
dynamicRowsGrid.parseProcessingAddChild(data, newData);
38+
39+
expect(dynamicRowsGrid.processingAddChild).not.toHaveBeenCalled();
40+
});
41+
});
42+
});
43+
});

dev/tests/js/jasmine/tests/app/code/Magento/Bundle/adminhtml/js/components/bundle-dynamic-rows.test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ define(['Magento_Bundle/js/components/bundle-dynamic-rows', 'uiRegistry', 'uiCol
3131
it('Check if bundle items are removed from option', function () {
3232
let bundleSelections = new uiCollection;
3333

34+
bundleSelections._elems = {
35+
clear: jasmine.createSpy('clear')
36+
};
37+
3438
spyOn(bundleSelections, 'destroyChildren').and.callThrough();
3539
spyOn(registry, 'get').and.returnValue(bundleSelections);
3640
spyOn(unit, 'removeBundleItemsFromOption').and.callThrough();
@@ -39,6 +43,7 @@ define(['Magento_Bundle/js/components/bundle-dynamic-rows', 'uiRegistry', 'uiCol
3943

4044
expect(registry.get).toHaveBeenCalledWith('dynamic.1.bundle_selections');
4145
expect(bundleSelections.destroyChildren).toHaveBeenCalled();
46+
expect(bundleSelections._elems.clear).toHaveBeenCalled();
4247
});
4348
});
4449
});

0 commit comments

Comments
 (0)