Add collaboration feature

Issue-ID: SDC-767
Change-Id: I14fb4c1f54086ed03a56a7ff7fab9ecd40381795
Signed-off-by: talig <talig@amdocs.com>
diff --git a/openecomp-ui/test/licenseModel/entitlementPools/test.js b/openecomp-ui/test/licenseModel/entitlementPools/test.js
index f541523..173384d 100644
--- a/openecomp-ui/test/licenseModel/entitlementPools/test.js
+++ b/openecomp-ui/test/licenseModel/entitlementPools/test.js
@@ -19,14 +19,18 @@
 import {storeCreator} from 'sdc-app/AppStore.js';
 import EntitlementPoolsActionHelper from 'sdc-app/onboarding/licenseModel/entitlementPools/EntitlementPoolsActionHelper.js';
 import {EntitlementPoolStoreFactory, EntitlementPoolPostFactory} from 'test-utils/factories/licenseModel/EntitlementPoolFactories.js';
-import VersionControllerUtilsFactory from 'test-utils/factories/softwareProduct/VersionControllerUtilsFactory.js';
+import VersionFactory from 'test-utils/factories/common/VersionFactory.js';
 import {LimitItemFactory, LimitPostFactory} from 'test-utils/factories/licenseModel/LimitFactories.js';
 import {getStrValue} from 'nfvo-utils/getValue.js';
+import {SyncStates} from 'sdc-app/common/merge/MergeEditorConstants.js';
+import CurrentScreenFactory from 'test-utils/factories/common/CurrentScreenFactory.js';
 
 describe('Entitlement Pools Module Tests', function () {
 
 	const LICENSE_MODEL_ID = '555';
-	const version = VersionControllerUtilsFactory.build().version;
+	const version = VersionFactory.build();
+	const itemPermissionAndProps = CurrentScreenFactory.build({}, {version});
+	const returnedVersionFields = {baseId: version.baseId, description: version.description, id: version.id, name: version.name, status: version.status};
 
 	it('Load Entitlement Pools List', () => {
 
@@ -54,6 +58,7 @@
 		const entitlementPoolsList = buildListFromFactory(EntitlementPoolStoreFactory,1);
 		deepFreeze(entitlementPoolsList);
 		const store = storeCreator({
+			currentScreen: {...itemPermissionAndProps},
 			licenseModel: {
 				entitlementPool: {
 					entitlementPoolsList
@@ -62,7 +67,16 @@
 		});
 		deepFreeze(store.getState());
 
-		const expectedStore = cloneAndSet(store.getState(), 'licenseModel.entitlementPool.entitlementPoolsList', []);
+		const expectedCurrentScreenProps = {
+			...itemPermissionAndProps,
+			itemPermission: {
+				...itemPermissionAndProps.itemPermission,
+				isDirty: true
+			}
+		};
+
+		let expectedStore = cloneAndSet(store.getState(), 'licenseModel.entitlementPool.entitlementPoolsList', []);
+		expectedStore = cloneAndSet(expectedStore, 'currentScreen.itemPermission', expectedCurrentScreenProps.itemPermission);
 
 		mockRest.addHandler('destroy', ({data, options, baseUrl}) => {
 			expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools/${entitlementPoolsList[0].id}`);
@@ -75,6 +89,13 @@
 			};
 		});
 
+		mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
+			expect(baseUrl).toEqual(`/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}/versions/${version.id}`);
+			expect(data).toEqual(undefined);
+			expect(options).toEqual(undefined);
+			return {...returnedVersionFields, state: {synchronizationState: SyncStates.UP_TO_DATE, dirty: true}};
+		});
+
 		return EntitlementPoolsActionHelper.deleteEntitlementPool(store.dispatch, {
 			licenseModelId: LICENSE_MODEL_ID,
 			version,
@@ -86,7 +107,9 @@
 
 	it('Add Entitlement Pool', () => {
 
-		const store = storeCreator();
+		const store = storeCreator({
+			currentScreen: {...itemPermissionAndProps}
+		});
 		deepFreeze(store.getState());
 
 		const EntitlementPoolPostRequest = EntitlementPoolPostFactory.build();
@@ -97,7 +120,16 @@
 		const entitlementPoolAfterAdd = EntitlementPoolStoreFactory.build({id: entitlementPoolIdFromResponse});
 		deepFreeze(entitlementPoolAfterAdd);
 
-		const expectedStore = cloneAndSet(store.getState(), 'licenseModel.entitlementPool.entitlementPoolsList', [entitlementPoolAfterAdd]);
+		const expectedCurrentScreenProps = {
+			...itemPermissionAndProps,
+			itemPermission: {
+				...itemPermissionAndProps.itemPermission,
+				isDirty: true
+			}
+		};
+
+		let expectedStore = cloneAndSet(store.getState(), 'licenseModel.entitlementPool.entitlementPoolsList', [entitlementPoolAfterAdd]);
+		expectedStore = cloneAndSet(expectedStore, 'currentScreen.itemPermission', expectedCurrentScreenProps.itemPermission);
 
 		mockRest.addHandler('post', ({data, options, baseUrl}) => {
 			expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools`);
@@ -109,6 +141,13 @@
 			};
 		});
 
+		mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
+			expect(baseUrl).toEqual(`/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}/versions/${version.id}`);
+			expect(data).toEqual(undefined);
+			expect(options).toEqual(undefined);
+			return {...returnedVersionFields, state: {synchronizationState: SyncStates.UP_TO_DATE, dirty: true}};
+		});
+
 		return EntitlementPoolsActionHelper.saveEntitlementPool(store.dispatch,
 			{
 				licenseModelId: LICENSE_MODEL_ID,
@@ -127,6 +166,7 @@
 		deepFreeze(entitlementPoolsList);
 
 		const store = storeCreator({
+			currentScreen: {...itemPermissionAndProps},
 			licenseModel: {
 				entitlementPool: {
 					entitlementPoolsList
@@ -144,7 +184,16 @@
 		const entitlementPoolPutRequest = EntitlementPoolPostFactory.build({name: 'ep1_UPDATED', description: 'string_UPDATED'});
 		deepFreeze(entitlementPoolPutRequest);
 
-		const expectedStore = cloneAndSet(store.getState(), 'licenseModel.entitlementPool.entitlementPoolsList', [entitlementPoolUpdateData]);
+		const expectedCurrentScreenProps = {
+			...itemPermissionAndProps,
+			itemPermission: {
+				...itemPermissionAndProps.itemPermission,
+				isDirty: true
+			}
+		};
+
+		let expectedStore = cloneAndSet(store.getState(), 'licenseModel.entitlementPool.entitlementPoolsList', [entitlementPoolUpdateData]);
+		expectedStore = cloneAndSet(expectedStore, 'currentScreen.itemPermission', expectedCurrentScreenProps.itemPermission);
 
 
 		mockRest.addHandler('put', ({data, options, baseUrl}) => {
@@ -154,6 +203,13 @@
 			return {returnCode: 'OK'};
 		});
 
+		mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
+			expect(baseUrl).toEqual(`/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}/versions/${version.id}`);
+			expect(data).toEqual(undefined);
+			expect(options).toEqual(undefined);
+			return {...returnedVersionFields, state: {synchronizationState: SyncStates.UP_TO_DATE, dirty: true}};
+		});
+
 		return EntitlementPoolsActionHelper.saveEntitlementPool(store.dispatch, {
 			licenseModelId: LICENSE_MODEL_ID,
 			version,
@@ -187,7 +243,9 @@
 
 	it('Add Limit', () => {
 
-		const store = storeCreator();
+		const store = storeCreator({
+			currentScreen: {...itemPermissionAndProps}
+		});
 		deepFreeze(store.getState());
 
 		const limitToAdd = LimitPostFactory.build();
@@ -203,7 +261,16 @@
 		deepFreeze(limitAddedItem);
 		const entitlementPool = EntitlementPoolStoreFactory.build();
 
-		const expectedStore = cloneAndSet(store.getState(), 'licenseModel.entitlementPool.entitlementPoolEditor.limitsList', [limitAddedItem]);
+		const expectedCurrentScreenProps = {
+			...itemPermissionAndProps,
+			itemPermission: {
+				...itemPermissionAndProps.itemPermission,
+				isDirty: true
+			}
+		};
+
+		let expectedStore = cloneAndSet(store.getState(), 'licenseModel.entitlementPool.entitlementPoolEditor.limitsList', [limitAddedItem]);
+		expectedStore = cloneAndSet(expectedStore, 'currentScreen.itemPermission', expectedCurrentScreenProps.itemPermission);
 
 		mockRest.addHandler('post', ({data, options, baseUrl}) => {
 			expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools/${entitlementPool.id}/limits`);
@@ -222,6 +289,13 @@
 			return {results: [limitAddedItem]};
 		 });
 
+		mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
+			expect(baseUrl).toEqual(`/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}/versions/${version.id}`);
+			expect(data).toEqual(undefined);
+			expect(options).toEqual(undefined);
+			return {...returnedVersionFields, state: {synchronizationState: SyncStates.UP_TO_DATE, dirty: true}};
+		});
+
 		return EntitlementPoolsActionHelper.submitLimit(store.dispatch,
 			{
 				licenseModelId: LICENSE_MODEL_ID,
@@ -241,6 +315,7 @@
 		deepFreeze(limitsList);
 
 		const store = storeCreator({
+			currentScreen: {...itemPermissionAndProps},
 			licenseModel: {
 				entitlementPool: {
 					entitlementPoolEditor: {
@@ -252,7 +327,17 @@
 		deepFreeze(store.getState());
 
 		const entitlementPool = EntitlementPoolStoreFactory.build();
-		const expectedStore = cloneAndSet(store.getState(), 'licenseModel.entitlementPool.entitlementPoolEditor.limitsList', []);
+
+		const expectedCurrentScreenProps = {
+			...itemPermissionAndProps,
+			itemPermission: {
+				...itemPermissionAndProps.itemPermission,
+				isDirty: true
+			}
+		};
+
+		let expectedStore = cloneAndSet(store.getState(), 'licenseModel.entitlementPool.entitlementPoolEditor.limitsList', []);
+		expectedStore = cloneAndSet(expectedStore, 'currentScreen.itemPermission', expectedCurrentScreenProps.itemPermission);
 
 		mockRest.addHandler('destroy', ({data, options, baseUrl}) => {
 			expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools/${entitlementPool.id}/limits/${limitsList[0].id}`);
@@ -272,6 +357,13 @@
 			return {results: []};
 		 });
 
+		mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
+			expect(baseUrl).toEqual(`/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}/versions/${version.id}`);
+			expect(data).toEqual(undefined);
+			expect(options).toEqual(undefined);
+			return {...returnedVersionFields, state: {synchronizationState: SyncStates.UP_TO_DATE, dirty: true}};
+		});
+
 		return EntitlementPoolsActionHelper.deleteLimit(store.dispatch, {
 			licenseModelId: LICENSE_MODEL_ID,
 			version,
@@ -288,6 +380,7 @@
 		deepFreeze(limitsList);
 		const entitlementPool = EntitlementPoolStoreFactory.build();
 		const store = storeCreator({
+			currentScreen: {...itemPermissionAndProps},
 			licenseModel: {
 				entitlementPool: {
 					entitlementPoolEditor: {
@@ -312,7 +405,16 @@
 		updatedLimit.unit = {choice: updatedLimit.unit, other: ''};
 		deepFreeze(updatedLimit);
 
-		const expectedStore = cloneAndSet(store.getState(), 'licenseModel.entitlementPool.entitlementPoolEditor.limitsList', [updatedLimitForPut]);
+		const expectedCurrentScreenProps = {
+			...itemPermissionAndProps,
+			itemPermission: {
+				...itemPermissionAndProps.itemPermission,
+				isDirty: true
+			}
+		};
+
+		let expectedStore = cloneAndSet(store.getState(), 'licenseModel.entitlementPool.entitlementPoolEditor.limitsList', [updatedLimitForPut]);
+		expectedStore = cloneAndSet(expectedStore, 'currentScreen.itemPermission', expectedCurrentScreenProps.itemPermission);
 
 
 		mockRest.addHandler('put', ({data, options, baseUrl}) => {
@@ -329,6 +431,13 @@
 			return {results: [updatedLimitForPut]};
 		 });
 
+		mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
+			expect(baseUrl).toEqual(`/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}/versions/${version.id}`);
+			expect(data).toEqual(undefined);
+			expect(options).toEqual(undefined);
+			return {...returnedVersionFields, state: {synchronizationState: SyncStates.UP_TO_DATE, dirty: true}};
+		});
+
 		return EntitlementPoolsActionHelper.submitLimit(store.dispatch,
 			{
 				licenseModelId: LICENSE_MODEL_ID,