Skip to content

Commit

Permalink
[INTERNAL] m.p13n flex: add null check for current state
Browse files Browse the repository at this point in the history
SNOW: CS20240007660056
Change-Id: Ic1c37a61a20752a73495c9f7a3d9814dbd415db2
  • Loading branch information
martinhaeuser committed May 22, 2024
1 parent 4d61790 commit 3467747
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 11 deletions.
10 changes: 6 additions & 4 deletions src/sap.m/src/sap/m/p13n/handler/xConfigHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,12 @@ sap.ui.define([

if (!oPriorAggregationConfig) {
const aCurrentState = await xConfigAPI.getCurrentItemState(oControl, {propertyBag: mPropertyBag, changeType: oChange.getChangeType()}, oPriorAggregationConfig, sAffectedAggregation);
const oStateItem = aCurrentState.find((oItem, iIndex) => {
return oItem.key === oChange.getContent().key;
});
oRevertData.index = aCurrentState.indexOf(oStateItem);
if (aCurrentState) {
const oStateItem = aCurrentState?.find((oItem, iIndex) => {
return oItem.key === oChange.getContent().key;
});
oRevertData.index = aCurrentState.indexOf(oStateItem);
}
}

oRevertData.targetAggregation = oChange.getContent().targetAggregation;
Expand Down
59 changes: 52 additions & 7 deletions src/sap.m/test/sap/m/qunit/p13n/handler/xConfigHandler.qunit.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ sap.ui.define([
"sap/m/p13n/handler/xConfigHandler",
"sap/ui/fl/apply/_internal/flexObjects/FlexObjectFactory",
"sap/ui/core/util/reflection/JsControlTreeModifier",
"sap/m/p13n/modules/xConfigAPI"
], function (MDCControl, Table, xConfigHandler, FlexObjectFactory, JsControlTreeModifier, xConfigAPI) {
"sap/m/p13n/modules/xConfigAPI",
"sap/ui/core/CustomData"
], function (MDCControl, Table, xConfigHandler, FlexObjectFactory, JsControlTreeModifier, xConfigAPI, CustomData) {
"use strict";

this.oControl = null;
Expand All @@ -15,13 +16,9 @@ sap.ui.define([

QUnit.module("API Tests", {
createChangeObject: function(mChangeConfig) {
mChangeConfig = mChangeConfig || {};
const oChangeProperties = {
...mChangeConfig,
"content": {
// "key": "P5",
// "value": false,
// "targetAggregation": "items"
},
"variantReference": "__management0",
"developerMode": false,
"layer": "USER",
Expand Down Expand Up @@ -191,4 +188,52 @@ sap.ui.define([
});
});

QUnit.test("Check correct revert object creation (no existing state, item based change)", function (assert) {

const oHandler = xConfigHandler.createHandler({
aggregationBased: true,
property: "visible",
operation: "add"
});

this.createChangeObject({
changeType: "addItem",
content: {
key: "string"
}
});

return oHandler.changeHandler.applyChange(this.oUIChange, this.oControl, this.oPropertyBag)
.then((result) => {
const oRevertData = this.oUIChange.getRevertData();

assert.equal(oRevertData.key, "string", "The revert data key was created correctly");
assert.equal(oRevertData.index, -1, "The revert data index was created correctly");
});
});

QUnit.test("Check correct revert object creation (no existing state, non item related change)", function (assert) {

const oHandler = xConfigHandler.createHandler({
aggregationBased: true,
property: "visible",
operation: "add"
});

this.createChangeObject({
changeType: "unknownChangeType",
content: {
key: "string"
}
});

return oHandler.changeHandler.applyChange(this.oUIChange, this.oControl, this.oPropertyBag)
.then((result) => {
const oRevertData = this.oUIChange.getRevertData();

assert.equal(oRevertData.key, "string", "The revert data key was created correctly");
assert.equal(oRevertData.index, undefined, "The revert data index was created correctly");
});
});

});

0 comments on commit 3467747

Please sign in to comment.