@@ -1227,21 +1227,29 @@ sap.ui.define([
12271227 await FlexState . initialize ( {
12281228 reference : sReference
12291229 } ) ;
1230+ const oChangePersistence = ChangePersistenceFactory . getChangePersistenceForComponent ( sReference ) ;
12301231 // initial data
1231- FlexState . updateStorageResponse ( sReference , [
1232- { type : "add" , flexObject : FlexObjectFactory . createUIChange ( { id : "initialUIChange1" } ) . convertToFileContent ( ) } ,
1233- { type : "add" , flexObject : FlexObjectFactory . createUIChange ( { id : "initialUIChange2" , variantReference : "flVariant12" } ) . convertToFileContent ( ) } ,
1234- { type : "add" , flexObject : FlexObjectFactory . createUIChange ( { id : "initialUIChange3" , fileType : "ctrl_variant_change" } ) . convertToFileContent ( ) } ,
1235- { type : "add" , flexObject : FlexObjectFactory . createUIChange ( { id : "initialUIChange4" , fileType : "ctrl_variant_management_change" } ) . convertToFileContent ( ) } ,
1236- { type : "add" , flexObject : FlexObjectFactory . createFlVariant ( { id : "initialFlVariant1" } ) . convertToFileContent ( ) } ,
1237- { type : "add" , flexObject : FlexObjectFactory . createCompVariant ( { id : "initialCompVariant1" } ) . convertToFileContent ( ) } ,
1238- { type : "add" , flexObject : FlexObjectFactory . createUIChange ( {
1232+ const aInitialChanges = [
1233+ FlexObjectFactory . createUIChange ( { id : "initialUIChange1" } ) ,
1234+ FlexObjectFactory . createUIChange ( { id : "initialUIChange2" , variantReference : "flVariant12" } ) ,
1235+ FlexObjectFactory . createUIChange ( { id : "initialUIChange3" , fileType : "ctrl_variant_change" } ) ,
1236+ FlexObjectFactory . createUIChange ( { id : "initialUIChange4" , fileType : "ctrl_variant_management_change" } ) ,
1237+ FlexObjectFactory . createFlVariant ( { id : "initialFlVariant1" } ) ,
1238+ FlexObjectFactory . createCompVariant ( { id : "initialCompVariant1" } ) ,
1239+ FlexObjectFactory . createUIChange ( {
12391240 id : "initialUIChange5" ,
12401241 selector : {
12411242 persistencyKey : "foo"
12421243 }
1243- } ) . convertToFileContent ( ) }
1244- ] ) ;
1244+ } )
1245+ ] ;
1246+ aInitialChanges . forEach ( function ( oFlexObject ) {
1247+ oChangePersistence . addDirtyChange ( oFlexObject ) ;
1248+ } ) ;
1249+ FlexState . updateStorageResponse ( sReference , aInitialChanges . map ( ( flexObject ) => ( {
1250+ type : "add" ,
1251+ flexObject : flexObject . convertToFileContent ( )
1252+ } ) ) ) ;
12451253 FlexState . rebuildFilteredResponse ( sReference ) ;
12461254 this . oUIChange = FlexObjectFactory . createUIChange ( {
12471255 id : "uiChange1"
@@ -1277,16 +1285,26 @@ sap.ui.define([
12771285 }
12781286 } , function ( ) {
12791287 QUnit . test ( "with all operations at once" , async function ( assert ) {
1280- let aFlexObjects = FlexState . getFlexObjectsDataSelector ( ) . get ( { reference : sReference } ) ;
1288+ const oFlexObjectsDataSelector = FlexState . getFlexObjectsDataSelector ( ) ;
1289+ let aFlexObjects = oFlexObjectsDataSelector . get ( { reference : sReference } ) ;
12811290 assert . strictEqual ( aFlexObjects . length , 8 , "initially there are 8 flexObjects" ) ;
1291+ const aNewChanges = [
1292+ this . oUIChange ,
1293+ this . oVariantChange1 ,
1294+ this . oVariantChange2 ,
1295+ this . oVariantDepUIChange ,
1296+ this . oFlVariant ,
1297+ this . oCompVariant ,
1298+ this . oCompChange
1299+ ] ;
1300+ aNewChanges . forEach ( function ( oFlexObject ) {
1301+ FlexState . addDirtyFlexObject ( sReference , oFlexObject ) ;
1302+ } ) ;
12821303 FlexState . updateStorageResponse ( sReference , [
1283- { type : "add" , flexObject : this . oUIChange . convertToFileContent ( ) } ,
1284- { type : "add" , flexObject : this . oVariantChange1 . convertToFileContent ( ) } ,
1285- { type : "add" , flexObject : this . oVariantChange2 . convertToFileContent ( ) } ,
1286- { type : "add" , flexObject : this . oVariantDepUIChange . convertToFileContent ( ) } ,
1287- { type : "add" , flexObject : this . oFlVariant . convertToFileContent ( ) } ,
1288- { type : "add" , flexObject : this . oCompVariant . convertToFileContent ( ) } ,
1289- { type : "add" , flexObject : this . oCompChange . convertToFileContent ( ) } ,
1304+ ...aNewChanges . map ( ( flexObject ) => ( {
1305+ type : "add" ,
1306+ flexObject : flexObject . convertToFileContent ( )
1307+ } ) ) ,
12901308 { type : "ui2" , newData : "ui2" }
12911309 ] ) ;
12921310 const oStorageResponse = await FlexState . getStorageResponse ( sReference ) ;
@@ -1299,25 +1317,25 @@ sap.ui.define([
12991317 assert . strictEqual ( oStorageResponse . changes . variants . length , 2 , "fl variant was added" ) ;
13001318 assert . strictEqual ( oStorageResponse . changes . ui2personalization , "ui2" , "ui2 was set" ) ;
13011319
1302- FlexState . rebuildFilteredResponse ( sReference ) ;
1303- aFlexObjects = FlexState . getFlexObjectsDataSelector ( ) . get ( { reference : sReference } ) ;
1320+ aFlexObjects = oFlexObjectsDataSelector . get ( { reference : sReference } ) ;
13041321 assert . strictEqual ( aFlexObjects . length , 15 , "all flexObjects are part of the DataSelector" ) ;
13051322
13061323 this . oFlVariant . setFavorite ( true ) ;
13071324 this . oCompVariant . setFavorite ( true ) ;
13081325 this . oUIChange . setContent ( "foo" ) ;
13091326 this . oCompChange . setContent ( "bar" ) ;
13101327
1328+ const oUpdateSpy = sandbox . spy ( oFlexObjectsDataSelector , "checkUpdate" ) ;
1329+ const aUpdates = [ this . oUIChange , this . oFlVariant , this . oCompVariant , this . oCompChange ] ;
13111330 FlexState . updateStorageResponse ( sReference , [
1312- { type : "update" , flexObject : this . oUIChange . convertToFileContent ( ) } ,
1313- { type : "update" , flexObject : this . oFlVariant . convertToFileContent ( ) } ,
1314- { type : "update" , flexObject : this . oCompVariant . convertToFileContent ( ) } ,
1315- { type : "update" , flexObject : this . oCompChange . convertToFileContent ( ) } ,
1331+ ... aUpdates . map ( ( flexObject ) => ( {
1332+ type : "update" ,
1333+ flexObject : flexObject . convertToFileContent ( )
1334+ } ) ) ,
13161335 { type : "ui2" , newData : "newUi2" }
13171336 ] ) ;
13181337 assert . strictEqual ( oStorageResponse . changes . ui2personalization , "newUi2" , "ui2 was set" ) ;
1319- FlexState . rebuildFilteredResponse ( sReference ) ;
1320- aFlexObjects = FlexState . getFlexObjectsDataSelector ( ) . get ( { reference : sReference } ) ;
1338+ aFlexObjects = oFlexObjectsDataSelector . get ( { reference : sReference } ) ;
13211339 assert . strictEqual ( aFlexObjects . length , 15 , "all flexObjects are part of the DataSelector" ) ;
13221340 assert . strictEqual (
13231341 aFlexObjects . find ( ( oFlexObject ) => oFlexObject . getId ( ) === "uiChange1" ) . getContent ( ) ,
@@ -1336,14 +1354,12 @@ sap.ui.define([
13361354 "bar" , "the content was updated"
13371355 ) ;
13381356
1339- FlexState . updateStorageResponse ( sReference , [
1340- { type : "delete" , flexObject : this . oVariantDepUIChange . convertToFileContent ( ) } ,
1341- { type : "delete" , flexObject : this . oFlVariant . convertToFileContent ( ) } ,
1342- { type : "delete" , flexObject : this . oCompVariant . convertToFileContent ( ) } ,
1343- { type : "delete" , flexObject : this . oCompChange . convertToFileContent ( ) }
1344- ] ) ;
1345- FlexState . rebuildFilteredResponse ( sReference ) ;
1346- aFlexObjects = FlexState . getFlexObjectsDataSelector ( ) . get ( { reference : sReference } ) ;
1357+ const aDeletes = [ this . oVariantDepUIChange , this . oFlVariant , this . oCompVariant , this . oCompChange ] ;
1358+ FlexState . updateStorageResponse ( sReference , aDeletes . map ( ( flexObject ) => ( {
1359+ type : "delete" ,
1360+ flexObject : flexObject . convertToFileContent ( )
1361+ } ) ) ) ;
1362+ aFlexObjects = oFlexObjectsDataSelector . get ( { reference : sReference } ) ;
13471363 assert . strictEqual ( aFlexObjects . length , 11 , "all remaining flexObjects are part of the DataSelector" ) ;
13481364 assert . notOk (
13491365 aFlexObjects . find ( ( oFlexObject ) => oFlexObject . getId ( ) === this . oVariantDepUIChange . getId ( ) ) ,
@@ -1361,6 +1377,58 @@ sap.ui.define([
13611377 aFlexObjects . find ( ( oFlexObject ) => oFlexObject . getId ( ) === this . oCompChange . getId ( ) ) ,
13621378 "the flexObject was deleted"
13631379 ) ;
1380+ assert . ok (
1381+ oUpdateSpy . firstCall . args [ 1 ] . every ( ( oUpdateInfo , iIdx ) => {
1382+ return oUpdateInfo . type === "updateFlexObject" && oUpdateInfo . updatedObject === aUpdates [ iIdx ] ;
1383+ } ) ,
1384+ "the data selector was updated with the correct operation"
1385+ ) ;
1386+ assert . ok (
1387+ oUpdateSpy . secondCall . args [ 1 ] . every ( ( oUpdateInfo , iIdx ) => {
1388+ return oUpdateInfo . type === "removeFlexObject" && oUpdateInfo . updatedObject === aDeletes [ iIdx ] ;
1389+ } ) ,
1390+ "the data selector was updated with the correct operation"
1391+ ) ;
1392+ } ) ;
1393+
1394+ QUnit . test ( "when only ui2personalization is updated" , async function ( assert ) {
1395+ const oUpdateFlexObjectsSpy = sandbox . spy ( FlexState . getFlexObjectsDataSelector ( ) , "checkUpdate" ) ;
1396+ await FlexState . updateStorageResponse ( sReference , [
1397+ { type : "ui2" , newData : "ui2" }
1398+ ] ) ;
1399+ assert . strictEqual ( oUpdateFlexObjectsSpy . callCount , 0 , "then the flex objects data selector is not updated" ) ;
1400+ } ) ;
1401+
1402+ QUnit . test ( "when adding a flex object that is not part of the runtime pertsistence" , function ( assert ) {
1403+ assert . throws (
1404+ function ( ) {
1405+ FlexState . updateStorageResponse ( sReference , [
1406+ { type : "add" , flexObject : { id : "unknownObject" } }
1407+ ] ) ;
1408+ } ,
1409+ "then an error is thrown"
1410+ ) ;
1411+ } ) ;
1412+
1413+ QUnit . test ( "when updating the storage response" , function ( assert ) {
1414+ FlexState . addDirtyFlexObject ( sReference , this . oUIChange ) ;
1415+ FlexState . updateStorageResponse ( sReference , [
1416+ { type : "add" , flexObject : this . oUIChange . convertToFileContent ( ) }
1417+ ] ) ;
1418+ FlexState . updateStorageResponse ( sReference , [
1419+ {
1420+ type : "update" ,
1421+ flexObject : {
1422+ ...this . oUIChange . convertToFileContent ( ) ,
1423+ ...{ content : "bar" }
1424+ }
1425+ }
1426+ ] ) ;
1427+ assert . strictEqual (
1428+ this . oUIChange . getContent ( ) ,
1429+ "bar" ,
1430+ "then the content of the runtime persistence object is also updated"
1431+ ) ;
13641432 } ) ;
13651433 } ) ;
13661434
0 commit comments