diff --git a/openecomp-ui/test/licenseModel/entitlementPools/test.js b/openecomp-ui/test/licenseModel/entitlementPools/test.js
index dc56b11..63eab1f 100644
--- a/openecomp-ui/test/licenseModel/entitlementPools/test.js
+++ b/openecomp-ui/test/licenseModel/entitlementPools/test.js
@@ -1,455 +1,706 @@
-/*!
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+/*
+ * Copyright © 2016-2018 European Support Limited
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
- * or implied. See the License for the specific language governing
- * permissions and limitations under the License.
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
  */
 import deepFreeze from 'deep-freeze';
 import mockRest from 'test-utils/MockRest.js';
-import {cloneAndSet, buildListFromFactory} from 'test-utils/Util.js';
-import {storeCreator} from 'sdc-app/AppStore.js';
+import { cloneAndSet, buildListFromFactory } from 'test-utils/Util.js';
+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 {
+    EntitlementPoolStoreFactory,
+    EntitlementPoolPostFactory
+} from 'test-utils/factories/licenseModel/EntitlementPoolFactories.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 {
+    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 () {
+describe('Entitlement Pools Module Tests', function() {
+    const LICENSE_MODEL_ID = '555';
+    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
+    };
 
-	const LICENSE_MODEL_ID = '555';
-	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', () => {
+        const entitlementPoolsList = buildListFromFactory(
+            EntitlementPoolStoreFactory
+        );
+        deepFreeze(entitlementPoolsList);
+        const store = storeCreator();
+        deepFreeze(store.getState());
 
-	it('Load Entitlement Pools List', () => {
+        const expectedStore = cloneAndSet(
+            store.getState(),
+            'licenseModel.entitlementPool.entitlementPoolsList',
+            entitlementPoolsList
+        );
 
-		const entitlementPoolsList = buildListFromFactory(EntitlementPoolStoreFactory);
-		deepFreeze(entitlementPoolsList);
-		const store = storeCreator();
-		deepFreeze(store.getState());
+        mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
+            expect(baseUrl).toEqual(
+                `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
+                    version.id
+                }/entitlement-pools`
+            );
+            expect(data).toEqual(undefined);
+            expect(options).toEqual(undefined);
+            return { results: entitlementPoolsList };
+        });
 
-		const expectedStore = cloneAndSet(store.getState(), 'licenseModel.entitlementPool.entitlementPoolsList', entitlementPoolsList);
+        return EntitlementPoolsActionHelper.fetchEntitlementPoolsList(
+            store.dispatch,
+            { licenseModelId: LICENSE_MODEL_ID, version }
+        ).then(() => {
+            expect(store.getState()).toEqual(expectedStore);
+        });
+    });
 
-		mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
-			expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools`);
-			expect(data).toEqual(undefined);
-			expect(options).toEqual(undefined);
-			return {results: entitlementPoolsList};
-		});
+    it('Delete Entitlement Pool', () => {
+        const entitlementPoolsList = buildListFromFactory(
+            EntitlementPoolStoreFactory,
+            1
+        );
+        deepFreeze(entitlementPoolsList);
+        const store = storeCreator({
+            currentScreen: { ...itemPermissionAndProps },
+            licenseModel: {
+                entitlementPool: {
+                    entitlementPoolsList
+                }
+            }
+        });
+        deepFreeze(store.getState());
 
-		return EntitlementPoolsActionHelper.fetchEntitlementPoolsList(store.dispatch, {licenseModelId: LICENSE_MODEL_ID, version}).then(() => {
-			expect(store.getState()).toEqual(expectedStore);
-		});
-	});
+        const expectedCurrentScreenProps = {
+            ...itemPermissionAndProps,
+            itemPermission: {
+                ...itemPermissionAndProps.itemPermission,
+                isDirty: true
+            }
+        };
 
-	it('Delete Entitlement Pool', () => {
+        let expectedStore = cloneAndSet(
+            store.getState(),
+            'licenseModel.entitlementPool.entitlementPoolsList',
+            []
+        );
+        expectedStore = cloneAndSet(
+            expectedStore,
+            'currentScreen.itemPermission',
+            expectedCurrentScreenProps.itemPermission
+        );
 
-		const entitlementPoolsList = buildListFromFactory(EntitlementPoolStoreFactory,1);
-		deepFreeze(entitlementPoolsList);
-		const store = storeCreator({
-			currentScreen: {...itemPermissionAndProps},
-			licenseModel: {
-				entitlementPool: {
-					entitlementPoolsList
-				}
-			}
-		});
-		deepFreeze(store.getState());
+        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}`
+            );
+            expect(data).toEqual(undefined);
+            expect(options).toEqual(undefined);
+            return {
+                results: {
+                    returnCode: 'OK'
+                }
+            };
+        });
 
-		const expectedCurrentScreenProps = {
-			...itemPermissionAndProps,
-			itemPermission: {
-				...itemPermissionAndProps.itemPermission,
-				isDirty: true
-			}
-		};
+        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
+                }
+            };
+        });
 
-		let expectedStore = cloneAndSet(store.getState(), 'licenseModel.entitlementPool.entitlementPoolsList', []);
-		expectedStore = cloneAndSet(expectedStore, 'currentScreen.itemPermission', expectedCurrentScreenProps.itemPermission);
+        mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
+            expect(baseUrl).toEqual(
+                `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}`
+            );
+            expect(data).toEqual(undefined);
+            expect(options).toEqual(undefined);
+            return {
+                ...returnedVersionFields
+            };
+        });
 
-		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}`);
-			expect(data).toEqual(undefined);
-			expect(options).toEqual(undefined);
-			return {
-				results: {
-					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.deleteEntitlementPool(store.dispatch, {
-			licenseModelId: LICENSE_MODEL_ID,
-			version,
-			entitlementPoolId: entitlementPoolsList[0].id
-		}).then(() => {
-			expect(store.getState()).toEqual(expectedStore);
-		});
-	});
+        return EntitlementPoolsActionHelper.deleteEntitlementPool(
+            store.dispatch,
+            {
+                licenseModelId: LICENSE_MODEL_ID,
+                version,
+                entitlementPoolId: entitlementPoolsList[0].id
+            }
+        ).then(() => {
+            expect(store.getState()).toEqual(expectedStore);
+        });
+    });
 
-	it('Add Entitlement Pool', () => {
+    it('Add Entitlement Pool', () => {
+        const store = storeCreator({
+            currentScreen: { ...itemPermissionAndProps }
+        });
+        deepFreeze(store.getState());
 
-		const store = storeCreator({
-			currentScreen: {...itemPermissionAndProps}
-		});
-		deepFreeze(store.getState());
+        const EntitlementPoolPostRequest = EntitlementPoolPostFactory.build();
 
-		const EntitlementPoolPostRequest = EntitlementPoolPostFactory.build();
+        deepFreeze(EntitlementPoolPostRequest);
 
-		deepFreeze(EntitlementPoolPostRequest);
+        const entitlementPoolIdFromResponse = 'ADDED_ID';
+        const entitlementPoolAfterAdd = EntitlementPoolStoreFactory.build({
+            id: entitlementPoolIdFromResponse
+        });
+        deepFreeze(entitlementPoolAfterAdd);
 
-		const entitlementPoolIdFromResponse = 'ADDED_ID';
-		const entitlementPoolAfterAdd = EntitlementPoolStoreFactory.build({id: entitlementPoolIdFromResponse});
-		deepFreeze(entitlementPoolAfterAdd);
+        const expectedCurrentScreenProps = {
+            ...itemPermissionAndProps,
+            itemPermission: {
+                ...itemPermissionAndProps.itemPermission,
+                isDirty: true
+            }
+        };
 
-		const expectedCurrentScreenProps = {
-			...itemPermissionAndProps,
-			itemPermission: {
-				...itemPermissionAndProps.itemPermission,
-				isDirty: true
-			}
-		};
+        let expectedStore = cloneAndSet(
+            store.getState(),
+            'licenseModel.entitlementPool.entitlementPoolsList',
+            [entitlementPoolAfterAdd]
+        );
+        expectedStore = cloneAndSet(
+            expectedStore,
+            'currentScreen.itemPermission',
+            expectedCurrentScreenProps.itemPermission
+        );
 
-		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`
+            );
+            expect(data).toEqual(EntitlementPoolPostRequest);
+            expect(options).toEqual(undefined);
+            return {
+                returnCode: 'OK',
+                value: entitlementPoolIdFromResponse
+            };
+        });
 
-		mockRest.addHandler('post', ({data, options, baseUrl}) => {
-			expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools`);
-			expect(data).toEqual(EntitlementPoolPostRequest);
-			expect(options).toEqual(undefined);
-			return {
-				returnCode: 'OK',
-				value: entitlementPoolIdFromResponse
-			};
-		});
+        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
+                }
+            };
+        });
 
-		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}};
-		});
+        mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
+            expect(baseUrl).toEqual(
+                `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}`
+            );
+            expect(data).toEqual(undefined);
+            expect(options).toEqual(undefined);
+            return {
+                ...returnedVersionFields
+            };
+        });
 
-		
+        return EntitlementPoolsActionHelper.saveEntitlementPool(
+            store.dispatch,
+            {
+                licenseModelId: LICENSE_MODEL_ID,
+                version,
+                previousEntitlementPool: null,
+                entitlementPool: EntitlementPoolPostRequest
+            }
+        ).then(() => {
+            expect(store.getState()).toEqual(expectedStore);
+        });
+    });
 
-		return EntitlementPoolsActionHelper.saveEntitlementPool(store.dispatch,
-			{
-				licenseModelId: LICENSE_MODEL_ID,
-				version,
-				previousEntitlementPool: null,
-				entitlementPool: EntitlementPoolPostRequest
-			}
-		).then(() => {
-			expect(store.getState()).toEqual(expectedStore);
-		});
-	});
+    it('Update Entitlement Pool', () => {
+        const entitlementPoolsList = buildListFromFactory(
+            EntitlementPoolStoreFactory,
+            1
+        );
+        deepFreeze(entitlementPoolsList);
 
-	it('Update Entitlement Pool', () => {
+        const store = storeCreator({
+            currentScreen: { ...itemPermissionAndProps },
+            licenseModel: {
+                entitlementPool: {
+                    entitlementPoolsList
+                }
+            }
+        });
 
-		const entitlementPoolsList = buildListFromFactory(EntitlementPoolStoreFactory, 1);
-		deepFreeze(entitlementPoolsList);
+        deepFreeze(store.getState());
 
-		const store = storeCreator({
-			currentScreen: {...itemPermissionAndProps},
-			licenseModel: {
-				entitlementPool: {
-					entitlementPoolsList
-				}
-			}
-		});
+        const toBeUpdatedEntitlementPoolId = entitlementPoolsList[0].id;
+        const previousEntitlementPoolData = entitlementPoolsList[0];
+        const entitlementPoolUpdateData = EntitlementPoolStoreFactory.build({
+            name: 'ep1_UPDATED',
+            description: 'string_UPDATED',
+            id: toBeUpdatedEntitlementPoolId
+        });
+        deepFreeze(entitlementPoolUpdateData);
 
-		deepFreeze(store.getState());
+        const entitlementPoolPutRequest = EntitlementPoolPostFactory.build({
+            name: 'ep1_UPDATED',
+            description: 'string_UPDATED'
+        });
+        deepFreeze(entitlementPoolPutRequest);
 
-		const toBeUpdatedEntitlementPoolId = entitlementPoolsList[0].id;
-		const previousEntitlementPoolData = entitlementPoolsList[0];
-		const entitlementPoolUpdateData = EntitlementPoolStoreFactory.build({name: 'ep1_UPDATED', description: 'string_UPDATED', id: toBeUpdatedEntitlementPoolId});
-		deepFreeze(entitlementPoolUpdateData);
+        const expectedCurrentScreenProps = {
+            ...itemPermissionAndProps,
+            itemPermission: {
+                ...itemPermissionAndProps.itemPermission,
+                isDirty: true
+            }
+        };
 
-		const entitlementPoolPutRequest = EntitlementPoolPostFactory.build({name: 'ep1_UPDATED', description: 'string_UPDATED'});
-		deepFreeze(entitlementPoolPutRequest);
+        let expectedStore = cloneAndSet(
+            store.getState(),
+            'licenseModel.entitlementPool.entitlementPoolsList',
+            [entitlementPoolUpdateData]
+        );
+        expectedStore = cloneAndSet(
+            expectedStore,
+            'currentScreen.itemPermission',
+            expectedCurrentScreenProps.itemPermission
+        );
 
-		const expectedCurrentScreenProps = {
-			...itemPermissionAndProps,
-			itemPermission: {
-				...itemPermissionAndProps.itemPermission,
-				isDirty: true
-			}
-		};
+        mockRest.addHandler('put', ({ data, options, baseUrl }) => {
+            expect(baseUrl).toEqual(
+                `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
+                    version.id
+                }/entitlement-pools/${toBeUpdatedEntitlementPoolId}`
+            );
+            expect(data).toEqual(entitlementPoolPutRequest);
+            expect(options).toEqual(undefined);
+            return { returnCode: 'OK' };
+        });
 
-		let expectedStore = cloneAndSet(store.getState(), 'licenseModel.entitlementPool.entitlementPoolsList', [entitlementPoolUpdateData]);
-		expectedStore = cloneAndSet(expectedStore, 'currentScreen.itemPermission', expectedCurrentScreenProps.itemPermission);
+        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
+                }
+            };
+        });
 
+        mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
+            expect(baseUrl).toEqual(
+                `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}`
+            );
+            expect(data).toEqual(undefined);
+            expect(options).toEqual(undefined);
+            return {
+                ...returnedVersionFields
+            };
+        });
 
-		mockRest.addHandler('put', ({data, options, baseUrl}) => {
-			expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools/${toBeUpdatedEntitlementPoolId}`);
-			expect(data).toEqual(entitlementPoolPutRequest);
-			expect(options).toEqual(undefined);
-			return {returnCode: 'OK'};
-		});
+        return EntitlementPoolsActionHelper.saveEntitlementPool(
+            store.dispatch,
+            {
+                licenseModelId: LICENSE_MODEL_ID,
+                version,
+                previousEntitlementPool: previousEntitlementPoolData,
+                entitlementPool: entitlementPoolUpdateData
+            }
+        ).then(() => {
+            expect(store.getState()).toEqual(expectedStore);
+        });
+    });
 
-		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}};
-		});
+    it('Load Limits List', () => {
+        const limitsList = LimitItemFactory.buildList(3);
+        deepFreeze(limitsList);
+        const store = storeCreator();
+        deepFreeze(store.getState());
 
-		return EntitlementPoolsActionHelper.saveEntitlementPool(store.dispatch, {
-			licenseModelId: LICENSE_MODEL_ID,
-			version,
-			previousEntitlementPool: previousEntitlementPoolData,
-			entitlementPool: entitlementPoolUpdateData
-		}).then(() => {
-			expect(store.getState()).toEqual(expectedStore);
-		});
-	});
+        const expectedStore = cloneAndSet(
+            store.getState(),
+            'licenseModel.entitlementPool.entitlementPoolEditor.limitsList',
+            limitsList
+        );
+        const entitlementPool = EntitlementPoolStoreFactory.build();
+        mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
+            expect(baseUrl).toEqual(
+                `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
+                    version.id
+                }/entitlement-pools/${entitlementPool.id}/limits`
+            );
+            expect(data).toEqual(undefined);
+            expect(options).toEqual(undefined);
+            return { results: limitsList };
+        });
 
-	it('Load Limits List', () => {
-
-		const limitsList = LimitItemFactory.buildList(3);
-		deepFreeze(limitsList);
-		const store = storeCreator();
-		deepFreeze(store.getState());
-
-		const expectedStore = cloneAndSet(store.getState(), 'licenseModel.entitlementPool.entitlementPoolEditor.limitsList', limitsList);
-		const entitlementPool = EntitlementPoolStoreFactory.build();
-		mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
-			expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools/${entitlementPool.id}/limits`);
-			expect(data).toEqual(undefined);
-			expect(options).toEqual(undefined);
-			return {results: limitsList};
-		 });
-
-		return EntitlementPoolsActionHelper.fetchLimits(store.dispatch, {licenseModelId: LICENSE_MODEL_ID, version, entitlementPool}).then(() => {
-			expect(store.getState()).toEqual(expectedStore);
-		 });
-	});
-
-	it('Add Limit', () => {
-
-		const store = storeCreator({
-			currentScreen: {...itemPermissionAndProps}
-		});
-		deepFreeze(store.getState());
-
-		const limitToAdd = LimitPostFactory.build();
-		let limitFromBE = {...limitToAdd};
-		limitFromBE.metric = getStrValue(limitFromBE.metric);
-		limitFromBE.unit = getStrValue(limitFromBE.unit);
-
-		deepFreeze(limitToAdd);
-		deepFreeze(limitFromBE);
+        return EntitlementPoolsActionHelper.fetchLimits(store.dispatch, {
+            licenseModelId: LICENSE_MODEL_ID,
+            version,
+            entitlementPool
+        }).then(() => {
+            expect(store.getState()).toEqual(expectedStore);
+        });
+    });
 
-		const LimitIdFromResponse = 'ADDED_ID';
-		const limitAddedItem = {...limitToAdd, id: LimitIdFromResponse};
-		deepFreeze(limitAddedItem);
-		const entitlementPool = EntitlementPoolStoreFactory.build();
+    it('Add Limit', () => {
+        const store = storeCreator({
+            currentScreen: { ...itemPermissionAndProps }
+        });
+        deepFreeze(store.getState());
 
-		const expectedCurrentScreenProps = {
-			...itemPermissionAndProps,
-			itemPermission: {
-				...itemPermissionAndProps.itemPermission,
-				isDirty: true
-			}
-		};
+        const limitToAdd = LimitPostFactory.build();
+        let limitFromBE = { ...limitToAdd };
+        limitFromBE.metric = getStrValue(limitFromBE.metric);
+        limitFromBE.unit = getStrValue(limitFromBE.unit);
 
-		let expectedStore = cloneAndSet(store.getState(), 'licenseModel.entitlementPool.entitlementPoolEditor.limitsList', [limitAddedItem]);
-		expectedStore = cloneAndSet(expectedStore, 'currentScreen.itemPermission', expectedCurrentScreenProps.itemPermission);
+        deepFreeze(limitToAdd);
+        deepFreeze(limitFromBE);
 
-		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`);
-			expect(data).toEqual(limitFromBE);
-			expect(options).toEqual(undefined);
-			return {
-				returnCode: 'OK',
-				value: LimitIdFromResponse
-			};
-		});
+        const LimitIdFromResponse = 'ADDED_ID';
+        const limitAddedItem = { ...limitToAdd, id: LimitIdFromResponse };
+        deepFreeze(limitAddedItem);
+        const entitlementPool = EntitlementPoolStoreFactory.build();
 
-		mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
-			expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools/${entitlementPool.id}/limits`);
-			expect(data).toEqual(undefined);
-			expect(options).toEqual(undefined);
-			return {results: [limitAddedItem]};
-		 });
+        const expectedCurrentScreenProps = {
+            ...itemPermissionAndProps,
+            itemPermission: {
+                ...itemPermissionAndProps.itemPermission,
+                isDirty: true
+            }
+        };
 
-		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}};
-		});
+        let expectedStore = cloneAndSet(
+            store.getState(),
+            'licenseModel.entitlementPool.entitlementPoolEditor.limitsList',
+            [limitAddedItem]
+        );
+        expectedStore = cloneAndSet(
+            expectedStore,
+            'currentScreen.itemPermission',
+            expectedCurrentScreenProps.itemPermission
+        );
 
-		return EntitlementPoolsActionHelper.submitLimit(store.dispatch,
-			{
-				licenseModelId: LICENSE_MODEL_ID,
-				version,
-				entitlementPool,
-				limit: limitToAdd
-			}
-		).then(() => {
-			expect(store.getState()).toEqual(expectedStore);
-		});
-	});
+        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`
+            );
+            expect(data).toEqual(limitFromBE);
+            expect(options).toEqual(undefined);
+            return {
+                returnCode: 'OK',
+                value: LimitIdFromResponse
+            };
+        });
 
+        mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
+            expect(baseUrl).toEqual(
+                `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
+                    version.id
+                }/entitlement-pools/${entitlementPool.id}/limits`
+            );
+            expect(data).toEqual(undefined);
+            expect(options).toEqual(undefined);
+            return { results: [limitAddedItem] };
+        });
 
-	it('Delete Limit', () => {
+        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
+                }
+            };
+        });
 
-		const limitsList = LimitItemFactory.buildList(1);
-		deepFreeze(limitsList);
+        mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
+            expect(baseUrl).toEqual(
+                `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}`
+            );
+            expect(data).toEqual(undefined);
+            expect(options).toEqual(undefined);
+            return {
+                ...returnedVersionFields
+            };
+        });
 
-		const store = storeCreator({
-			currentScreen: {...itemPermissionAndProps},
-			licenseModel: {
-				entitlementPool: {
-					entitlementPoolEditor: {
-						limitsList
-					}
-				}
-			}
-		});
-		deepFreeze(store.getState());
+        return EntitlementPoolsActionHelper.submitLimit(store.dispatch, {
+            licenseModelId: LICENSE_MODEL_ID,
+            version,
+            entitlementPool,
+            limit: limitToAdd
+        }).then(() => {
+            expect(store.getState()).toEqual(expectedStore);
+        });
+    });
 
-		const entitlementPool = EntitlementPoolStoreFactory.build();
+    it('Delete Limit', () => {
+        const limitsList = LimitItemFactory.buildList(1);
+        deepFreeze(limitsList);
 
-		const expectedCurrentScreenProps = {
-			...itemPermissionAndProps,
-			itemPermission: {
-				...itemPermissionAndProps.itemPermission,
-				isDirty: true
-			}
-		};
+        const store = storeCreator({
+            currentScreen: { ...itemPermissionAndProps },
+            licenseModel: {
+                entitlementPool: {
+                    entitlementPoolEditor: {
+                        limitsList
+                    }
+                }
+            }
+        });
+        deepFreeze(store.getState());
 
-		let expectedStore = cloneAndSet(store.getState(), 'licenseModel.entitlementPool.entitlementPoolEditor.limitsList', []);
-		expectedStore = cloneAndSet(expectedStore, 'currentScreen.itemPermission', expectedCurrentScreenProps.itemPermission);
+        const entitlementPool = EntitlementPoolStoreFactory.build();
 
-		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}`);
-			expect(data).toEqual(undefined);
-			expect(options).toEqual(undefined);
-			return {
-				results: {
-					returnCode: 'OK'
-				}
-			};
-		});
+        const expectedCurrentScreenProps = {
+            ...itemPermissionAndProps,
+            itemPermission: {
+                ...itemPermissionAndProps.itemPermission,
+                isDirty: true
+            }
+        };
 
-		mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
-			expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools/${entitlementPool.id}/limits`);
-			expect(data).toEqual(undefined);
-			expect(options).toEqual(undefined);
-			return {results: []};
-		 });
+        let expectedStore = cloneAndSet(
+            store.getState(),
+            'licenseModel.entitlementPool.entitlementPoolEditor.limitsList',
+            []
+        );
+        expectedStore = cloneAndSet(
+            expectedStore,
+            'currentScreen.itemPermission',
+            expectedCurrentScreenProps.itemPermission
+        );
 
-		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}};
-		});
+        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
+                }`
+            );
+            expect(data).toEqual(undefined);
+            expect(options).toEqual(undefined);
+            return {
+                results: {
+                    returnCode: 'OK'
+                }
+            };
+        });
 
-		return EntitlementPoolsActionHelper.deleteLimit(store.dispatch, {
-			licenseModelId: LICENSE_MODEL_ID,
-			version,
-			entitlementPool,
-			limit: limitsList[0]
-		}).then(() => {
-			expect(store.getState()).toEqual(expectedStore);
-		});
-	});
+        mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
+            expect(baseUrl).toEqual(
+                `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
+                    version.id
+                }/entitlement-pools/${entitlementPool.id}/limits`
+            );
+            expect(data).toEqual(undefined);
+            expect(options).toEqual(undefined);
+            return { results: [] };
+        });
 
-	it('Update Limit', () => {
+        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
+                }
+            };
+        });
 
-		const limitsList = LimitItemFactory.buildList(1);
-		deepFreeze(limitsList);
-		const entitlementPool = EntitlementPoolStoreFactory.build();
-		const store = storeCreator({
-			currentScreen: {...itemPermissionAndProps},
-			licenseModel: {
-				entitlementPool: {
-					entitlementPoolEditor: {
-						limitsList
-					}
-				}
-			}
-		});
+        mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
+            expect(baseUrl).toEqual(
+                `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}`
+            );
+            expect(data).toEqual(undefined);
+            expect(options).toEqual(undefined);
+            return {
+                ...returnedVersionFields
+            };
+        });
 
-		deepFreeze(store.getState());
+        return EntitlementPoolsActionHelper.deleteLimit(store.dispatch, {
+            licenseModelId: LICENSE_MODEL_ID,
+            version,
+            entitlementPool,
+            limit: limitsList[0]
+        }).then(() => {
+            expect(store.getState()).toEqual(expectedStore);
+        });
+    });
 
+    it('Update Limit', () => {
+        const limitsList = LimitItemFactory.buildList(1);
+        deepFreeze(limitsList);
+        const entitlementPool = EntitlementPoolStoreFactory.build();
+        const store = storeCreator({
+            currentScreen: { ...itemPermissionAndProps },
+            licenseModel: {
+                entitlementPool: {
+                    entitlementPoolEditor: {
+                        limitsList
+                    }
+                }
+            }
+        });
 
-		const previousData = limitsList[0];
+        deepFreeze(store.getState());
 
-		deepFreeze(previousData);
-		const limitId = limitsList[0].id;
+        const previousData = limitsList[0];
 
-		let updatedLimit = {...previousData, name: 'updatedLimit'};
+        deepFreeze(previousData);
+        const limitId = limitsList[0].id;
 
-		const updatedLimitForPut = {...updatedLimit, id: undefined};
-		updatedLimit.metric = {choice: updatedLimit.metric, other: ''};
-		updatedLimit.unit = {choice: updatedLimit.unit, other: ''};
-		deepFreeze(updatedLimit);
+        let updatedLimit = { ...previousData, name: 'updatedLimit' };
 
-		const expectedCurrentScreenProps = {
-			...itemPermissionAndProps,
-			itemPermission: {
-				...itemPermissionAndProps.itemPermission,
-				isDirty: true
-			}
-		};
+        const updatedLimitForPut = { ...updatedLimit, id: undefined };
+        updatedLimit.metric = { choice: updatedLimit.metric, other: '' };
+        updatedLimit.unit = { choice: updatedLimit.unit, other: '' };
+        deepFreeze(updatedLimit);
 
-		let expectedStore = cloneAndSet(store.getState(), 'licenseModel.entitlementPool.entitlementPoolEditor.limitsList', [updatedLimitForPut]);
-		expectedStore = cloneAndSet(expectedStore, 'currentScreen.itemPermission', expectedCurrentScreenProps.itemPermission);
+        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}) => {
-			expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools/${entitlementPool.id}/limits/${limitId}`);
-			expect(data).toEqual(updatedLimitForPut);
-			expect(options).toEqual(undefined);
-			return {returnCode: 'OK'};
-		});
+        mockRest.addHandler('put', ({ data, options, baseUrl }) => {
+            expect(baseUrl).toEqual(
+                `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
+                    version.id
+                }/entitlement-pools/${entitlementPool.id}/limits/${limitId}`
+            );
+            expect(data).toEqual(updatedLimitForPut);
+            expect(options).toEqual(undefined);
+            return { returnCode: 'OK' };
+        });
 
-		mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
-			expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools/${entitlementPool.id}/limits`);
-			expect(data).toEqual(undefined);
-			expect(options).toEqual(undefined);
-			return {results: [updatedLimitForPut]};
-		 });
+        mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
+            expect(baseUrl).toEqual(
+                `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
+                    version.id
+                }/entitlement-pools/${entitlementPool.id}/limits`
+            );
+            expect(data).toEqual(undefined);
+            expect(options).toEqual(undefined);
+            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}};
-		});
+        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,
-				version,
-				entitlementPool,
-				limit: updatedLimit
-			}
-		).then(() => {
-			expect(store.getState()).toEqual(expectedStore);
-		});
-	});
+        mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
+            expect(baseUrl).toEqual(
+                `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}`
+            );
+            expect(data).toEqual(undefined);
+            expect(options).toEqual(undefined);
+            return {
+                ...returnedVersionFields
+            };
+        });
 
+        return EntitlementPoolsActionHelper.submitLimit(store.dispatch, {
+            licenseModelId: LICENSE_MODEL_ID,
+            version,
+            entitlementPool,
+            limit: updatedLimit
+        }).then(() => {
+            expect(store.getState()).toEqual(expectedStore);
+        });
+    });
 });
diff --git a/openecomp-ui/test/licenseModel/featureGroups/test.js b/openecomp-ui/test/licenseModel/featureGroups/test.js
index eb947b8..63c876c 100644
--- a/openecomp-ui/test/licenseModel/featureGroups/test.js
+++ b/openecomp-ui/test/licenseModel/featureGroups/test.js
@@ -1,306 +1,456 @@
-/*!
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+/*
+ * Copyright © 2016-2018 European Support Limited
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
- * or implied. See the License for the specific language governing
- * permissions and limitations under the License.
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
  */
 import deepFreeze from 'deep-freeze';
 import mockRest from 'test-utils/MockRest.js';
-import {cloneAndSet, buildListFromFactory} from 'test-utils/Util.js';
-import {storeCreator} from 'sdc-app/AppStore.js';
+import { cloneAndSet, buildListFromFactory } from 'test-utils/Util.js';
+import { storeCreator } from 'sdc-app/AppStore.js';
 import FeatureGroupsActionHelper from 'sdc-app/onboarding/licenseModel/featureGroups/FeatureGroupsActionHelper.js';
-import { FeatureGroupStoreFactory, FeatureGroupPostFactory, FeatureGroupDispatchFactory, FeatureGroupPutFactory } from 'test-utils/factories/licenseModel/FeatureGroupFactories.js';
+import {
+    FeatureGroupStoreFactory,
+    FeatureGroupPostFactory,
+    FeatureGroupDispatchFactory,
+    FeatureGroupPutFactory
+} from 'test-utils/factories/licenseModel/FeatureGroupFactories.js';
 import VersionFactory from 'test-utils/factories/common/VersionFactory.js';
 import CurrentScreenFactory from 'test-utils/factories/common/CurrentScreenFactory.js';
-import {SyncStates} from 'sdc-app/common/merge/MergeEditorConstants.js';
+import { SyncStates } from 'sdc-app/common/merge/MergeEditorConstants.js';
 
+describe('Feature Groups Module Tests', function() {
+    const LICENSE_MODEL_ID = '555';
+    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
+    };
 
-describe('Feature Groups Module Tests', function () {
+    it('Load Feature Groups List', () => {
+        const featureGroupsList = buildListFromFactory(
+            FeatureGroupStoreFactory
+        );
+        deepFreeze(featureGroupsList);
 
-	const LICENSE_MODEL_ID = '555';
-	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};
+        const store = storeCreator();
+        deepFreeze(store.getState());
 
-	it('Load Feature Groups List', () => {
+        const expectedStore = cloneAndSet(
+            store.getState(),
+            'licenseModel.featureGroup.featureGroupsList',
+            featureGroupsList
+        );
 
-		const featureGroupsList = buildListFromFactory(FeatureGroupStoreFactory);
-		deepFreeze(featureGroupsList);
+        mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
+            expect(baseUrl).toEqual(
+                `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
+                    version.id
+                }/feature-groups`
+            );
+            expect(data).toEqual(undefined);
+            expect(options).toEqual(undefined);
+            return { results: featureGroupsList };
+        });
 
-		const store = storeCreator();
-		deepFreeze(store.getState());
+        return FeatureGroupsActionHelper.fetchFeatureGroupsList(
+            store.dispatch,
+            { licenseModelId: LICENSE_MODEL_ID, version }
+        ).then(() => {
+            expect(store.getState()).toEqual(expectedStore);
+        });
+    });
 
-		const expectedStore = cloneAndSet(store.getState(), 'licenseModel.featureGroup.featureGroupsList', featureGroupsList);
+    it('Delete Feature Group', () => {
+        const featureGroupsList = buildListFromFactory(
+            FeatureGroupStoreFactory,
+            1
+        );
+        deepFreeze(featureGroupsList);
+        const store = storeCreator({
+            currentScreen: { ...itemPermissionAndProps },
+            licenseModel: {
+                featureGroup: {
+                    featureGroupsList
+                }
+            }
+        });
+        deepFreeze(store.getState());
 
-		mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
-			expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/feature-groups`);
-			expect(data).toEqual(undefined);
-			expect(options).toEqual(undefined);
-			return {results: featureGroupsList};
-		});
+        const expectedCurrentScreenProps = {
+            ...itemPermissionAndProps,
+            itemPermission: {
+                ...itemPermissionAndProps.itemPermission,
+                isDirty: true
+            }
+        };
 
-		return FeatureGroupsActionHelper.fetchFeatureGroupsList(store.dispatch, {licenseModelId: LICENSE_MODEL_ID, version}).then(() => {
-			expect(store.getState()).toEqual(expectedStore);
-		});
-	});
+        let expectedStore = cloneAndSet(
+            store.getState(),
+            'licenseModel.featureGroup.featureGroupsList',
+            []
+        );
+        expectedStore = cloneAndSet(
+            expectedStore,
+            'currentScreen.itemPermission',
+            expectedCurrentScreenProps.itemPermission
+        );
 
-	it('Delete Feature Group', () => {
-		const featureGroupsList = buildListFromFactory(FeatureGroupStoreFactory, 1);
-		deepFreeze(featureGroupsList);
-		const store = storeCreator({
-			currentScreen: {...itemPermissionAndProps},
-			licenseModel: {
-				featureGroup: {
-					featureGroupsList
-				}
-			}
-		});
-		deepFreeze(store.getState());
+        const idToDelete = featureGroupsList[0].id;
 
-		const expectedCurrentScreenProps = {
-			...itemPermissionAndProps,
-			itemPermission: {
-				...itemPermissionAndProps.itemPermission,
-				isDirty: true
-			}
-		};
+        mockRest.addHandler('destroy', ({ data, options, baseUrl }) => {
+            expect(baseUrl).toEqual(
+                `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
+                    version.id
+                }/feature-groups/${idToDelete}`
+            );
+            expect(data).toEqual(undefined);
+            expect(options).toEqual(undefined);
+            return {
+                results: {
+                    returnCode: 'OK'
+                }
+            };
+        });
 
-		let expectedStore = cloneAndSet(store.getState(), 'licenseModel.featureGroup.featureGroupsList', []);
-		expectedStore = cloneAndSet(expectedStore, 'currentScreen.itemPermission', expectedCurrentScreenProps.itemPermission);
+        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
+                }
+            };
+        });
 
-		const idToDelete = featureGroupsList[0].id;
+        mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
+            expect(baseUrl).toEqual(
+                `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}`
+            );
+            expect(data).toEqual(undefined);
+            expect(options).toEqual(undefined);
+            return {
+                ...returnedVersionFields
+            };
+        });
 
-		mockRest.addHandler('destroy', ({data, options, baseUrl}) => {
-			expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/feature-groups/${idToDelete}`);
-			expect(data).toEqual(undefined);
-			expect(options).toEqual(undefined);
-			return {
-				results: {
-					returnCode: 'OK'
-				}
-			};
-		});
+        return FeatureGroupsActionHelper.deleteFeatureGroup(store.dispatch, {
+            licenseModelId: LICENSE_MODEL_ID,
+            version,
+            featureGroupId: idToDelete
+        }).then(() => {
+            expect(store.getState()).toEqual(expectedStore);
+        });
+    });
 
-		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}};
-		});
+    it('Add Feature Group', () => {
+        const store = storeCreator({
+            currentScreen: { ...itemPermissionAndProps },
+            licenseModel: {
+                featureGroup: {
+                    featureGroupsList: []
+                }
+            }
+        });
+        deepFreeze(store.getState());
 
-		return FeatureGroupsActionHelper.deleteFeatureGroup(store.dispatch, {
-			licenseModelId: LICENSE_MODEL_ID,
-			version,
-			featureGroupId: idToDelete
-		}).then(() => {
-			expect(store.getState()).toEqual(expectedStore);
-		});
-	});
+        const FeatureGroupPostRequest = FeatureGroupPostFactory.build({
+            addedLicenseKeyGroupsIds: [1],
+            addedEntitlementPoolsIds: [1]
+        });
+        const featureGroupToAdd = FeatureGroupDispatchFactory.build({
+            licenseKeyGroupsIds: [1],
+            entitlementPoolsIds: [1]
+        });
 
-	it('Add Feature Group', () => {
+        const featureGroupIdFromResponse = 'ADDED_ID';
+        const featureGroupAfterAdd = FeatureGroupStoreFactory.build({
+            ...featureGroupToAdd,
+            id: featureGroupIdFromResponse
+        });
 
-		const store = storeCreator({
-			currentScreen: {...itemPermissionAndProps},
-			licenseModel: {
-				featureGroup: {
-					featureGroupsList: []
-				}
-			}
-		});
-		deepFreeze(store.getState());
+        const expectedCurrentScreenProps = {
+            ...itemPermissionAndProps,
+            itemPermission: {
+                ...itemPermissionAndProps.itemPermission,
+                isDirty: true
+            }
+        };
 
-		const FeatureGroupPostRequest = FeatureGroupPostFactory.build({
-			addedLicenseKeyGroupsIds: [1],
-			addedEntitlementPoolsIds: [1]
-		});
-		const featureGroupToAdd = FeatureGroupDispatchFactory.build({
-			licenseKeyGroupsIds: [1],
-			entitlementPoolsIds: [1]
-		});
+        let expectedStore = cloneAndSet(
+            store.getState(),
+            'licenseModel.featureGroup.featureGroupsList',
+            [featureGroupAfterAdd]
+        );
+        expectedStore = cloneAndSet(
+            expectedStore,
+            'currentScreen.itemPermission',
+            expectedCurrentScreenProps.itemPermission
+        );
 
-		const featureGroupIdFromResponse = 'ADDED_ID';
-		const featureGroupAfterAdd = FeatureGroupStoreFactory.build({
-			...featureGroupToAdd,
-			id: featureGroupIdFromResponse
-		});
+        mockRest.addHandler('post', ({ data, options, baseUrl }) => {
+            expect(baseUrl).toEqual(
+                `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
+                    version.id
+                }/feature-groups`
+            );
+            expect(data).toEqual(FeatureGroupPostRequest);
+            expect(options).toEqual(undefined);
+            return {
+                returnCode: 'OK',
+                value: featureGroupIdFromResponse
+            };
+        });
 
-		const expectedCurrentScreenProps = {
-			...itemPermissionAndProps,
-			itemPermission: {
-				...itemPermissionAndProps.itemPermission,
-				isDirty: true
-			}
-		};
+        mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
+            expect(baseUrl).toEqual(
+                `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
+                    version.id
+                }/entitlement-pools`
+            );
+            expect(data).toEqual(undefined);
+            expect(options).toEqual(undefined);
+            return { results: [] };
+        });
 
-		let expectedStore = cloneAndSet(store.getState(), 'licenseModel.featureGroup.featureGroupsList', [featureGroupAfterAdd]);
-		expectedStore = cloneAndSet(expectedStore, 'currentScreen.itemPermission', expectedCurrentScreenProps.itemPermission);
+        mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
+            expect(baseUrl).toEqual(
+                `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
+                    version.id
+                }/license-key-groups`
+            );
+            expect(data).toEqual(undefined);
+            expect(options).toEqual(undefined);
+            return { results: [] };
+        });
 
-		mockRest.addHandler('post', ({data, options, baseUrl}) => {
-			expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/feature-groups`);
-			expect(data).toEqual(FeatureGroupPostRequest);
-			expect(options).toEqual(undefined);
-			return {
-				returnCode: 'OK',
-				value: featureGroupIdFromResponse
-			};
-		});
+        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
+                }
+            };
+        });
 
-		mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
-			expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools`);
-			expect(data).toEqual(undefined);
-			expect(options).toEqual(undefined);
-			return {results: []};
-		});
+        mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
+            expect(baseUrl).toEqual(
+                `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}`
+            );
+            expect(data).toEqual(undefined);
+            expect(options).toEqual(undefined);
+            return {
+                ...returnedVersionFields
+            };
+        });
 
-		mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
-			expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups`);
-			expect(data).toEqual(undefined);
-			expect(options).toEqual(undefined);
-			return {results: []};
-		});
+        return FeatureGroupsActionHelper.saveFeatureGroup(store.dispatch, {
+            licenseModelId: LICENSE_MODEL_ID,
+            version,
+            featureGroup: featureGroupToAdd
+        }).then(() => {
+            expect(store.getState()).toEqual(expectedStore);
+        });
+    });
 
-		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}};
-		});
+    it('Update Feature Group', () => {
+        const featureGroupsList = buildListFromFactory(
+            FeatureGroupStoreFactory,
+            1,
+            {
+                licenseKeyGroupsIds: [1],
+                entitlementPoolsIds: [1]
+            }
+        );
+        deepFreeze(featureGroupsList);
 
+        const store = storeCreator({
+            currentScreen: { ...itemPermissionAndProps },
+            licenseModel: {
+                featureGroup: {
+                    featureGroupsList
+                }
+            }
+        });
+        deepFreeze(store.getState());
 
-		return FeatureGroupsActionHelper.saveFeatureGroup(store.dispatch, {
-			licenseModelId: LICENSE_MODEL_ID,
-			version,
-			featureGroup: featureGroupToAdd
-		}).then(() => {
-			expect(store.getState()).toEqual(expectedStore);
-		});
-	});
+        const toBeUpdatedFeatureGroupId = featureGroupsList[0].id;
+        const previousFeatureGroupData = featureGroupsList[0];
 
-	it('Update Feature Group', () => {
-		const featureGroupsList = buildListFromFactory(FeatureGroupStoreFactory, 1, {
-			licenseKeyGroupsIds: [1],
-			entitlementPoolsIds: [1]
-		});
-		deepFreeze(featureGroupsList);
+        const featureGroupUpdateData = FeatureGroupStoreFactory.build({
+            ...previousFeatureGroupData,
+            licenseKeyGroupsIds: [7],
+            entitlementPoolsIds: [7]
+        });
+        deepFreeze(featureGroupUpdateData);
 
-		const store = storeCreator({
-			currentScreen: {...itemPermissionAndProps},
-			licenseModel: {
-				featureGroup: {
-					featureGroupsList
-				}
-			}
-		});
-		deepFreeze(store.getState());
+        const FeatureGroupPutFactoryRequest = FeatureGroupPutFactory.build({
+            name: featureGroupUpdateData.name,
+            description: featureGroupUpdateData.description,
+            partNumber: featureGroupUpdateData.partNumber,
+            addedLicenseKeyGroupsIds: [7],
+            addedEntitlementPoolsIds: [7],
+            removedLicenseKeyGroupsIds: [1],
+            removedEntitlementPoolsIds: [1]
+        });
+        deepFreeze(FeatureGroupPutFactoryRequest);
 
-		const toBeUpdatedFeatureGroupId = featureGroupsList[0].id;
-		const previousFeatureGroupData = featureGroupsList[0];
+        const expectedCurrentScreenProps = {
+            ...itemPermissionAndProps,
+            itemPermission: {
+                ...itemPermissionAndProps.itemPermission,
+                isDirty: true
+            }
+        };
 
-		const featureGroupUpdateData = FeatureGroupStoreFactory.build({
-			...previousFeatureGroupData,
-			licenseKeyGroupsIds: [7],
-			entitlementPoolsIds: [7]
-		});
-		deepFreeze(featureGroupUpdateData);
+        let expectedStore = cloneAndSet(
+            store.getState(),
+            'licenseModel.featureGroup.featureGroupsList',
+            [featureGroupUpdateData]
+        );
+        expectedStore = cloneAndSet(
+            expectedStore,
+            'currentScreen.itemPermission',
+            expectedCurrentScreenProps.itemPermission
+        );
 
-		const FeatureGroupPutFactoryRequest = FeatureGroupPutFactory.build({
-			name: featureGroupUpdateData.name,
-			description: featureGroupUpdateData.description,
-			partNumber: featureGroupUpdateData.partNumber,
-			addedLicenseKeyGroupsIds: [7],
-			addedEntitlementPoolsIds: [7],
-			removedLicenseKeyGroupsIds: [1],
-			removedEntitlementPoolsIds: [1]
-		});
-		deepFreeze(FeatureGroupPutFactoryRequest);
+        mockRest.addHandler('put', ({ data, options, baseUrl }) => {
+            expect(baseUrl).toEqual(
+                `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
+                    version.id
+                }/feature-groups/${toBeUpdatedFeatureGroupId}`
+            );
+            expect(data).toEqual(FeatureGroupPutFactoryRequest);
+            expect(options).toEqual(undefined);
+            return { returnCode: 'OK' };
+        });
 
-		const expectedCurrentScreenProps = {
-			...itemPermissionAndProps,
-			itemPermission: {
-				...itemPermissionAndProps.itemPermission,
-				isDirty: true
-			}
-		};
+        mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
+            expect(baseUrl).toEqual(
+                `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
+                    version.id
+                }/entitlement-pools`
+            );
+            expect(data).toEqual(undefined);
+            expect(options).toEqual(undefined);
+            return { results: [] };
+        });
 
-		let expectedStore = cloneAndSet(store.getState(), 'licenseModel.featureGroup.featureGroupsList', [featureGroupUpdateData]);
-		expectedStore = cloneAndSet(expectedStore, 'currentScreen.itemPermission', expectedCurrentScreenProps.itemPermission);
+        mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
+            expect(baseUrl).toEqual(
+                `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
+                    version.id
+                }/license-key-groups`
+            );
+            expect(data).toEqual(undefined);
+            expect(options).toEqual(undefined);
+            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
+                }
+            };
+        });
 
-		mockRest.addHandler('put', ({data, options, baseUrl}) => {
-			expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/feature-groups/${toBeUpdatedFeatureGroupId}`);
-			expect(data).toEqual(FeatureGroupPutFactoryRequest);
-			expect(options).toEqual(undefined);
-			return {returnCode: 'OK'};
-		});
+        mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
+            expect(baseUrl).toEqual(
+                `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}`
+            );
+            expect(data).toEqual(undefined);
+            expect(options).toEqual(undefined);
+            return {
+                ...returnedVersionFields
+            };
+        });
 
-		mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
-			expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools`);
-			expect(data).toEqual(undefined);
-			expect(options).toEqual(undefined);
-			return {results: []};
-		});
+        return FeatureGroupsActionHelper.saveFeatureGroup(store.dispatch, {
+            licenseModelId: LICENSE_MODEL_ID,
+            version,
+            previousFeatureGroup: previousFeatureGroupData,
+            featureGroup: featureGroupUpdateData
+        }).then(() => {
+            expect(store.getState()).toEqual(expectedStore);
+        });
+    });
 
-		mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
-			expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups`);
-			expect(data).toEqual(undefined);
-			expect(options).toEqual(undefined);
-			return {results: []};
-		});
+    it('Open Editor', () => {
+        const store = storeCreator();
+        deepFreeze(store.getState());
 
-		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}};
-		});
+        const editorData = FeatureGroupStoreFactory.build();
+        deepFreeze(editorData);
+        const LICENSE_MODEL_ID = '123';
 
-		return FeatureGroupsActionHelper.saveFeatureGroup(store.dispatch, {
-			licenseModelId: LICENSE_MODEL_ID,
-			version,
-			previousFeatureGroup: previousFeatureGroupData,
-			featureGroup: featureGroupUpdateData
-		}).then(() => {
-			expect(store.getState()).toEqual(expectedStore);
-		});
+        mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
+            expect(baseUrl).toEqual(
+                `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
+                    version.id
+                }/entitlement-pools`
+            );
+            expect(data).toEqual(undefined);
+            expect(options).toEqual(undefined);
+            return { results: [] };
+        });
 
-	});
+        mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
+            expect(baseUrl).toEqual(
+                `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
+                    version.id
+                }/license-key-groups`
+            );
+            expect(data).toEqual(undefined);
+            expect(options).toEqual(undefined);
+            return { results: [] };
+        });
 
-	it('Open Editor', () => {
-
-		const store = storeCreator();
-		deepFreeze(store.getState());
-
-		const editorData = FeatureGroupStoreFactory.build();
-		deepFreeze(editorData);
-		const LICENSE_MODEL_ID = '123';
-
-		mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
-			expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools`);
-			expect(data).toEqual(undefined);
-			expect(options).toEqual(undefined);
-			return {results: []};
-		});
-
-		mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
-			expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups`);
-			expect(data).toEqual(undefined);
-			expect(options).toEqual(undefined);
-			return {results: []};
-		});
-
-
-		return FeatureGroupsActionHelper.openFeatureGroupsEditor(store.dispatch, {featureGroup: editorData, licenseModelId: '123', version}).then(() => {
-			expect(store.getState().licenseModel.featureGroup.featureGroupEditor.data).toEqual(editorData);
-		});
-	});
-
+        return FeatureGroupsActionHelper.openFeatureGroupsEditor(
+            store.dispatch,
+            { featureGroup: editorData, licenseModelId: '123', version }
+        ).then(() => {
+            expect(
+                store.getState().licenseModel.featureGroup.featureGroupEditor
+                    .data
+            ).toEqual(editorData);
+        });
+    });
 });
diff --git a/openecomp-ui/test/licenseModel/licenseAgreement/test.js b/openecomp-ui/test/licenseModel/licenseAgreement/test.js
index 5a3dd17..17cad4f 100644
--- a/openecomp-ui/test/licenseModel/licenseAgreement/test.js
+++ b/openecomp-ui/test/licenseModel/licenseAgreement/test.js
@@ -16,225 +16,386 @@
 import deepFreeze from 'deep-freeze';
 import pickBy from 'lodash/pickBy';
 import mockRest from 'test-utils/MockRest.js';
-import {cloneAndSet, buildListFromFactory} from 'test-utils/Util.js';
-import {storeCreator} from 'sdc-app/AppStore.js';
+import { cloneAndSet, buildListFromFactory } from 'test-utils/Util.js';
+import { storeCreator } from 'sdc-app/AppStore.js';
 import LicenseAgreementActionHelper from 'sdc-app/onboarding/licenseModel/licenseAgreement/LicenseAgreementActionHelper.js';
 
-import { LicenseAgreementStoreFactory, LicenseAgreementDispatchFactory, LicenseAgreementPostFactory, LicenseAgreementPutFactory } from 'test-utils/factories/licenseModel/LicenseAgreementFactories.js';
+import {
+    LicenseAgreementStoreFactory,
+    LicenseAgreementDispatchFactory,
+    LicenseAgreementPostFactory,
+    LicenseAgreementPutFactory
+} from 'test-utils/factories/licenseModel/LicenseAgreementFactories.js';
 import VersionFactory from 'test-utils/factories/common/VersionFactory.js';
-import {SyncStates} from 'sdc-app/common/merge/MergeEditorConstants.js';
+import { SyncStates } from 'sdc-app/common/merge/MergeEditorConstants.js';
 import CurrentScreenFactory from 'test-utils/factories/common/CurrentScreenFactory.js';
 
 describe('License Agreement Module Tests', () => {
+    const LICENSE_MODEL_ID = '777';
+    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
+    };
 
-	const LICENSE_MODEL_ID = '777';
-	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 License Agreement List', () => {
+        const licenseAgreementList = buildListFromFactory(
+            LicenseAgreementStoreFactory
+        );
 
-	it('Load License Agreement List', () => {
-		const licenseAgreementList = buildListFromFactory(LicenseAgreementStoreFactory);
+        const store = storeCreator();
+        deepFreeze(store.getState());
 
-		const store = storeCreator();
-		deepFreeze(store.getState());
+        const expectedStore = cloneAndSet(
+            store.getState(),
+            'licenseModel.licenseAgreement.licenseAgreementList',
+            licenseAgreementList
+        );
 
-		const expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseAgreement.licenseAgreementList', licenseAgreementList);
+        mockRest.addHandler('fetch', ({ options, data, baseUrl }) => {
+            expect(baseUrl).toEqual(
+                `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
+                    version.id
+                }/license-agreements`
+            );
+            expect(data).toEqual(undefined);
+            expect(options).toEqual(undefined);
+            return { results: licenseAgreementList };
+        });
+        return LicenseAgreementActionHelper.fetchLicenseAgreementList(
+            store.dispatch,
+            { licenseModelId: LICENSE_MODEL_ID, version }
+        ).then(() => {
+            expect(store.getState()).toEqual(expectedStore);
+        });
+    });
 
-		mockRest.addHandler('fetch', ({options, data, baseUrl}) => {
-			expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-agreements`);
-			expect(data).toEqual(undefined);
-			expect(options).toEqual(undefined);
-			return {results: licenseAgreementList};
-		});
-		return LicenseAgreementActionHelper.fetchLicenseAgreementList(store.dispatch, {licenseModelId: LICENSE_MODEL_ID, version}).then(() => {
-			expect(store.getState()).toEqual(expectedStore);
-		});
-	});
+    it('Delete License Agreement', () => {
+        const licenseAgreementList = buildListFromFactory(
+            LicenseAgreementStoreFactory,
+            1
+        );
+        const store = storeCreator({
+            currentScreen: { ...itemPermissionAndProps },
+            licenseModel: {
+                licenseAgreement: {
+                    licenseAgreementList
+                }
+            }
+        });
+        deepFreeze(store.getState());
+        const expectedCurrentScreenProps = {
+            ...itemPermissionAndProps,
+            itemPermission: {
+                ...itemPermissionAndProps.itemPermission,
+                isDirty: true
+            }
+        };
+        const toBeDeletedLicenseAgreementId = licenseAgreementList[0].id;
+        let expectedStore = cloneAndSet(
+            store.getState(),
+            'licenseModel.licenseAgreement.licenseAgreementList',
+            []
+        );
+        expectedStore = cloneAndSet(
+            expectedStore,
+            'currentScreen.itemPermission',
+            expectedCurrentScreenProps.itemPermission
+        );
 
-	it('Delete License Agreement', () => {
-		const licenseAgreementList = buildListFromFactory(LicenseAgreementStoreFactory, 1);
-		const store = storeCreator({
-			currentScreen: {...itemPermissionAndProps},
-			licenseModel: {
-				licenseAgreement: {
-					licenseAgreementList
-				}
-			}
-		});
-		deepFreeze(store.getState());
-		const expectedCurrentScreenProps = {
-			...itemPermissionAndProps,
-			itemPermission: {
-				...itemPermissionAndProps.itemPermission,
-				isDirty: true
-			}
-		};
-		const toBeDeletedLicenseAgreementId = licenseAgreementList[0].id;
-		let  expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseAgreement.licenseAgreementList', []);
-		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
+                }/license-agreements/${toBeDeletedLicenseAgreementId}`
+            );
+            expect(data).toEqual(undefined);
+            expect(options).toEqual(undefined);
+        });
+        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
+                }
+            };
+        });
 
-		mockRest.addHandler('destroy', ({data, options, baseUrl}) => {
-			expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-agreements/${toBeDeletedLicenseAgreementId}`);
-			expect(data).toEqual(undefined);
-			expect(options).toEqual(undefined);
-		});
-		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}};
-		});
+        mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
+            expect(baseUrl).toEqual(
+                `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}`
+            );
+            expect(data).toEqual(undefined);
+            expect(options).toEqual(undefined);
+            return {
+                ...returnedVersionFields
+            };
+        });
 
-		return LicenseAgreementActionHelper.deleteLicenseAgreement(store.dispatch, {
-			licenseAgreementId: toBeDeletedLicenseAgreementId,
-			licenseModelId: LICENSE_MODEL_ID,
-			version
-		}).then(() => {
-			expect(store.getState()).toEqual(expectedStore);
-		});
-	});
+        return LicenseAgreementActionHelper.deleteLicenseAgreement(
+            store.dispatch,
+            {
+                licenseAgreementId: toBeDeletedLicenseAgreementId,
+                licenseModelId: LICENSE_MODEL_ID,
+                version
+            }
+        ).then(() => {
+            expect(store.getState()).toEqual(expectedStore);
+        });
+    });
 
-	it('Add License Agreement', () => {
-		const store = storeCreator({
-			currentScreen: {...itemPermissionAndProps}
-		});
-		deepFreeze(store.getState());
+    it('Add License Agreement', () => {
+        const store = storeCreator({
+            currentScreen: { ...itemPermissionAndProps }
+        });
+        deepFreeze(store.getState());
 
-		const licenseAgreementToAdd = LicenseAgreementDispatchFactory.build();
+        const licenseAgreementToAdd = LicenseAgreementDispatchFactory.build();
 
-		const LicenseAgreementPostRequest = LicenseAgreementPostFactory.build(
-			pickBy(licenseAgreementToAdd, (val, key) => key !== 'featureGroupsIds')
-		);
+        const LicenseAgreementPostRequest = LicenseAgreementPostFactory.build(
+            pickBy(
+                licenseAgreementToAdd,
+                (val, key) => key !== 'featureGroupsIds'
+            )
+        );
 
-		deepFreeze(LicenseAgreementPostRequest);
+        deepFreeze(LicenseAgreementPostRequest);
 
-		const licenseAgreementIdFromResponse = 'ADDED_ID';
-		const licenseAgreementAfterAdd = LicenseAgreementStoreFactory.build({
-			...licenseAgreementToAdd,
-			id: licenseAgreementIdFromResponse
-		});
-		deepFreeze(licenseAgreementAfterAdd);
-		const licenseAgreementList = [licenseAgreementAfterAdd];
-		const expectedCurrentScreenProps = {
-			...itemPermissionAndProps,
-			itemPermission: {
-				...itemPermissionAndProps.itemPermission,
-				isDirty: true
-			}
-		};
-		const featureGroupsList = licenseAgreementList[0].featureGroupsIds;
-		let expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseAgreement.licenseAgreementList', [licenseAgreementAfterAdd]);
-		expectedStore = cloneAndSet(expectedStore, 'currentScreen.itemPermission', expectedCurrentScreenProps.itemPermission);
+        const licenseAgreementIdFromResponse = 'ADDED_ID';
+        const licenseAgreementAfterAdd = LicenseAgreementStoreFactory.build({
+            ...licenseAgreementToAdd,
+            id: licenseAgreementIdFromResponse
+        });
+        deepFreeze(licenseAgreementAfterAdd);
+        const licenseAgreementList = [licenseAgreementAfterAdd];
+        const expectedCurrentScreenProps = {
+            ...itemPermissionAndProps,
+            itemPermission: {
+                ...itemPermissionAndProps.itemPermission,
+                isDirty: true
+            }
+        };
+        const featureGroupsList = licenseAgreementList[0].featureGroupsIds;
+        let expectedStore = cloneAndSet(
+            store.getState(),
+            'licenseModel.licenseAgreement.licenseAgreementList',
+            [licenseAgreementAfterAdd]
+        );
+        expectedStore = cloneAndSet(
+            expectedStore,
+            'currentScreen.itemPermission',
+            expectedCurrentScreenProps.itemPermission
+        );
 
-		mockRest.addHandler('post', ({options, data, baseUrl}) => {
-			expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-agreements`);
-			expect(data).toEqual(LicenseAgreementPostRequest);
-			expect(options).toEqual(undefined);
-			return {
-				value: licenseAgreementIdFromResponse
-			};
-		});
-		mockRest.addHandler('fetch', ({options, data, baseUrl}) => {
-			expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-agreements`);
-			expect(data).toEqual(undefined);
-			expect(options).toEqual(undefined);
-			return {results: licenseAgreementList};
-		});
-		mockRest.addHandler('fetch', ({options, data, baseUrl}) => {
-			expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/feature-groups`);
-			expect(data).toEqual(undefined);
-			expect(options).toEqual(undefined);
-			return {results: featureGroupsList};
-		});
-		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}};
+        mockRest.addHandler('post', ({ options, data, baseUrl }) => {
+            expect(baseUrl).toEqual(
+                `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
+                    version.id
+                }/license-agreements`
+            );
+            expect(data).toEqual(LicenseAgreementPostRequest);
+            expect(options).toEqual(undefined);
+            return {
+                value: licenseAgreementIdFromResponse
+            };
+        });
+        mockRest.addHandler('fetch', ({ options, data, baseUrl }) => {
+            expect(baseUrl).toEqual(
+                `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
+                    version.id
+                }/license-agreements`
+            );
+            expect(data).toEqual(undefined);
+            expect(options).toEqual(undefined);
+            return { results: licenseAgreementList };
+        });
+        mockRest.addHandler('fetch', ({ options, data, baseUrl }) => {
+            expect(baseUrl).toEqual(
+                `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
+                    version.id
+                }/feature-groups`
+            );
+            expect(data).toEqual(undefined);
+            expect(options).toEqual(undefined);
+            return { results: featureGroupsList };
+        });
+        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 LicenseAgreementActionHelper.saveLicenseAgreement(store.dispatch, {
-			licenseAgreement: licenseAgreementToAdd,
-			licenseModelId: LICENSE_MODEL_ID,
-			version
-		}).then(() => {
-			expect(store.getState()).toEqual(expectedStore);
-		});
-	});
+        mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
+            expect(baseUrl).toEqual(
+                `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}`
+            );
+            expect(data).toEqual(undefined);
+            expect(options).toEqual(undefined);
+            return {
+                ...returnedVersionFields
+            };
+        });
 
-	it('Update License Agreement', () => {
-		const licenseAgreementList = buildListFromFactory(LicenseAgreementStoreFactory, 1, {featureGroupsIds: ['77']});
-		const store = storeCreator({
-			currentScreen: {...itemPermissionAndProps},
-			licenseModel: {
-				licenseAgreement: {
-					licenseAgreementList
-				}
-			}
-		});
-		deepFreeze(store.getState());
+        return LicenseAgreementActionHelper.saveLicenseAgreement(
+            store.dispatch,
+            {
+                licenseAgreement: licenseAgreementToAdd,
+                licenseModelId: LICENSE_MODEL_ID,
+                version
+            }
+        ).then(() => {
+            expect(store.getState()).toEqual(expectedStore);
+        });
+    });
 
-		const previousLicenseAgreementData = licenseAgreementList[0];
-		const toBeUpdatedLicenseAgreementId = previousLicenseAgreementData.id;
-		const oldFeatureGroupIds = previousLicenseAgreementData.featureGroupsIds;
+    it('Update License Agreement', () => {
+        const licenseAgreementList = buildListFromFactory(
+            LicenseAgreementStoreFactory,
+            1,
+            { featureGroupsIds: ['77'] }
+        );
+        const store = storeCreator({
+            currentScreen: { ...itemPermissionAndProps },
+            licenseModel: {
+                licenseAgreement: {
+                    licenseAgreementList
+                }
+            }
+        });
+        deepFreeze(store.getState());
 
-		const newFeatureGroupsIds = ['update_id_1', 'update_id_2'];
+        const previousLicenseAgreementData = licenseAgreementList[0];
+        const toBeUpdatedLicenseAgreementId = previousLicenseAgreementData.id;
+        const oldFeatureGroupIds =
+            previousLicenseAgreementData.featureGroupsIds;
 
-		const licenseAgreementUpdateData = LicenseAgreementStoreFactory.build({
-			id: toBeUpdatedLicenseAgreementId,
-			featureGroupsIds: newFeatureGroupsIds
-		});
-		deepFreeze(licenseAgreementUpdateData);
+        const newFeatureGroupsIds = ['update_id_1', 'update_id_2'];
 
-		const LicenseAgreementPutFactoryRequest = LicenseAgreementPutFactory.build({
-			addedFeatureGroupsIds: newFeatureGroupsIds,
-			removedFeatureGroupsIds: oldFeatureGroupIds
-		});
+        const licenseAgreementUpdateData = LicenseAgreementStoreFactory.build({
+            id: toBeUpdatedLicenseAgreementId,
+            featureGroupsIds: newFeatureGroupsIds
+        });
+        deepFreeze(licenseAgreementUpdateData);
 
-		deepFreeze(LicenseAgreementPutFactoryRequest);
+        const LicenseAgreementPutFactoryRequest = LicenseAgreementPutFactory.build(
+            {
+                addedFeatureGroupsIds: newFeatureGroupsIds,
+                removedFeatureGroupsIds: oldFeatureGroupIds
+            }
+        );
 
-		const expectedCurrentScreenProps = {
-			...itemPermissionAndProps,
-			itemPermission: {
-				...itemPermissionAndProps.itemPermission,
-				isDirty: true
-			}
-		};
-		let expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseAgreement.licenseAgreementList', [licenseAgreementUpdateData]);
-		expectedStore = cloneAndSet(expectedStore, 'currentScreen.itemPermission', expectedCurrentScreenProps.itemPermission);
+        deepFreeze(LicenseAgreementPutFactoryRequest);
 
-		mockRest.addHandler('put', ({data, options, baseUrl}) => {
-			expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-agreements/${toBeUpdatedLicenseAgreementId}`);
-			expect(data).toEqual(LicenseAgreementPutFactoryRequest);
-			expect(options).toEqual(undefined);
-		});
-		mockRest.addHandler('fetch', ({options, data, baseUrl}) => {
-			expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-agreements`);
-			expect(data).toEqual(undefined);
-			expect(options).toEqual(undefined);
-			return {results: [licenseAgreementUpdateData]};
-		});
-		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}};
-		});
-		mockRest.addHandler('fetch', ({options, data, baseUrl}) => {
-			expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/feature-groups`);
-			expect(data).toEqual(undefined);
-			expect(options).toEqual(undefined);
-			return {results: newFeatureGroupsIds};
-		});
+        const expectedCurrentScreenProps = {
+            ...itemPermissionAndProps,
+            itemPermission: {
+                ...itemPermissionAndProps.itemPermission,
+                isDirty: true
+            }
+        };
+        let expectedStore = cloneAndSet(
+            store.getState(),
+            'licenseModel.licenseAgreement.licenseAgreementList',
+            [licenseAgreementUpdateData]
+        );
+        expectedStore = cloneAndSet(
+            expectedStore,
+            'currentScreen.itemPermission',
+            expectedCurrentScreenProps.itemPermission
+        );
 
-		return LicenseAgreementActionHelper.saveLicenseAgreement(store.dispatch, {
-			licenseModelId: LICENSE_MODEL_ID,
-			version,
-			previousLicenseAgreement: previousLicenseAgreementData,
-			licenseAgreement: licenseAgreementUpdateData
-		}).then(() => {
-			expect(store.getState()).toEqual(expectedStore);
-		});
-	});
+        mockRest.addHandler('put', ({ data, options, baseUrl }) => {
+            expect(baseUrl).toEqual(
+                `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
+                    version.id
+                }/license-agreements/${toBeUpdatedLicenseAgreementId}`
+            );
+            expect(data).toEqual(LicenseAgreementPutFactoryRequest);
+            expect(options).toEqual(undefined);
+        });
+        mockRest.addHandler('fetch', ({ options, data, baseUrl }) => {
+            expect(baseUrl).toEqual(
+                `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
+                    version.id
+                }/license-agreements`
+            );
+            expect(data).toEqual(undefined);
+            expect(options).toEqual(undefined);
+            return { results: [licenseAgreementUpdateData] };
+        });
 
+        mockRest.addHandler('fetch', ({ options, data, baseUrl }) => {
+            expect(baseUrl).toEqual(
+                `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
+                    version.id
+                }/feature-groups`
+            );
+            expect(data).toEqual(undefined);
+            expect(options).toEqual(undefined);
+            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
+                }
+            };
+        });
+
+        mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
+            expect(baseUrl).toEqual(
+                `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}`
+            );
+            expect(data).toEqual(undefined);
+            expect(options).toEqual(undefined);
+            return {
+                ...returnedVersionFields
+            };
+        });
+
+        return LicenseAgreementActionHelper.saveLicenseAgreement(
+            store.dispatch,
+            {
+                licenseModelId: LICENSE_MODEL_ID,
+                version,
+                previousLicenseAgreement: previousLicenseAgreementData,
+                licenseAgreement: licenseAgreementUpdateData
+            }
+        ).then(() => {
+            expect(store.getState()).toEqual(expectedStore);
+        });
+    });
 });
diff --git a/openecomp-ui/test/licenseModel/licenseKeyGroups/test.js b/openecomp-ui/test/licenseModel/licenseKeyGroups/test.js
index 09a2c6f..1326025 100644
--- a/openecomp-ui/test/licenseModel/licenseKeyGroups/test.js
+++ b/openecomp-ui/test/licenseModel/licenseKeyGroups/test.js
@@ -1,5 +1,5 @@
 /*!
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2016-2018 European Support Limited
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -15,432 +15,681 @@
  */
 import deepFreeze from 'deep-freeze';
 import mockRest from 'test-utils/MockRest.js';
-import {cloneAndSet, buildListFromFactory} from 'test-utils/Util.js';
-import {storeCreator} from 'sdc-app/AppStore.js';
-import {LicenseKeyGroupStoreFactory, LicenseKeyGroupPostFactory} from 'test-utils/factories/licenseModel/LicenseKeyGroupFactories.js';
+import { cloneAndSet, buildListFromFactory } from 'test-utils/Util.js';
+import { storeCreator } from 'sdc-app/AppStore.js';
+import {
+    LicenseKeyGroupStoreFactory,
+    LicenseKeyGroupPostFactory
+} from 'test-utils/factories/licenseModel/LicenseKeyGroupFactories.js';
 
 import LicenseKeyGroupsActionHelper from 'sdc-app/onboarding/licenseModel/licenseKeyGroups/LicenseKeyGroupsActionHelper.js';
 import VersionFactory from 'test-utils/factories/common/VersionFactory.js';
 import CurrentScreenFactory from 'test-utils/factories/common/CurrentScreenFactory.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 {
+    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';
 
-describe('License Key Groups Module Tests', function () {
+describe('License Key Groups Module Tests', function() {
+    const LICENSE_MODEL_ID = '555';
+    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
+    };
 
-	const LICENSE_MODEL_ID = '555';
-	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 License Key Group', () => {
+        const licenseKeyGroupsList = buildListFromFactory(
+            LicenseKeyGroupStoreFactory
+        );
 
-	it('Load License Key Group', () => {
+        deepFreeze(licenseKeyGroupsList);
+        const store = storeCreator();
+        deepFreeze(store.getState());
 
-		const licenseKeyGroupsList = buildListFromFactory(LicenseKeyGroupStoreFactory);
+        const expectedStore = cloneAndSet(
+            store.getState(),
+            'licenseModel.licenseKeyGroup.licenseKeyGroupsList',
+            licenseKeyGroupsList
+        );
 
-		deepFreeze(licenseKeyGroupsList);
-		const store = storeCreator();
-		deepFreeze(store.getState());
+        mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
+            expect(baseUrl).toEqual(
+                `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
+                    version.id
+                }/license-key-groups`
+            );
+            expect(data).toEqual(undefined);
+            expect(options).toEqual(undefined);
+            return { results: licenseKeyGroupsList };
+        });
 
-		const expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsList', licenseKeyGroupsList);
+        return LicenseKeyGroupsActionHelper.fetchLicenseKeyGroupsList(
+            store.dispatch,
+            { licenseModelId: LICENSE_MODEL_ID, version }
+        ).then(() => {
+            expect(store.getState()).toEqual(expectedStore);
+        });
+    });
 
-		mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
-			expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups`);
-			expect(data).toEqual(undefined);
-			expect(options).toEqual(undefined);
-			return {results: licenseKeyGroupsList};
-		});
+    it('Delete License Key Group', () => {
+        const licenseKeyGroupsList = buildListFromFactory(
+            LicenseKeyGroupStoreFactory,
+            1
+        );
 
-		return LicenseKeyGroupsActionHelper.fetchLicenseKeyGroupsList(store.dispatch, {licenseModelId: LICENSE_MODEL_ID, version}).then(() => {
-			expect(store.getState()).toEqual(expectedStore);
-		});
-	});
+        deepFreeze(licenseKeyGroupsList);
+        const store = storeCreator({
+            currentScreen: { ...itemPermissionAndProps },
+            licenseModel: {
+                licenseKeyGroup: {
+                    licenseKeyGroupsList
+                }
+            }
+        });
+        deepFreeze(store.getState());
+        const toBeDeletedLicenseKeyGroupId = licenseKeyGroupsList[0].id;
 
-	it('Delete License Key Group', () => {
+        const expectedCurrentScreenProps = {
+            ...itemPermissionAndProps,
+            itemPermission: {
+                ...itemPermissionAndProps.itemPermission,
+                isDirty: true
+            }
+        };
 
-		const licenseKeyGroupsList = buildListFromFactory(LicenseKeyGroupStoreFactory, 1);
+        let expectedStore = cloneAndSet(
+            store.getState(),
+            'licenseModel.licenseKeyGroup.licenseKeyGroupsList',
+            []
+        );
+        expectedStore = cloneAndSet(
+            expectedStore,
+            'currentScreen.itemPermission',
+            expectedCurrentScreenProps.itemPermission
+        );
 
-		deepFreeze(licenseKeyGroupsList);
-		const store = storeCreator({
-			currentScreen: {...itemPermissionAndProps},
-			licenseModel: {
-				licenseKeyGroup: {
-					licenseKeyGroupsList
-				}
-			}
-		});
-		deepFreeze(store.getState());
-		const toBeDeletedLicenseKeyGroupId = licenseKeyGroupsList[0].id;
+        mockRest.addHandler('destroy', ({ data, options, baseUrl }) => {
+            expect(baseUrl).toEqual(
+                `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
+                    version.id
+                }/license-key-groups/${toBeDeletedLicenseKeyGroupId}`
+            );
+            expect(data).toEqual(undefined);
+            expect(options).toEqual(undefined);
+        });
 
-		const expectedCurrentScreenProps = {
-			...itemPermissionAndProps,
-			itemPermission: {
-				...itemPermissionAndProps.itemPermission,
-				isDirty: true
-			}
-		};
+        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
+                }
+            };
+        });
 
-		let expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsList', []);
-		expectedStore = cloneAndSet(expectedStore, 'currentScreen.itemPermission', expectedCurrentScreenProps.itemPermission);
+        mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
+            expect(baseUrl).toEqual(
+                `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}`
+            );
+            expect(data).toEqual(undefined);
+            expect(options).toEqual(undefined);
+            return {
+                ...returnedVersionFields
+            };
+        });
 
-		mockRest.addHandler('destroy', ({data, options, baseUrl}) => {
-			expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups/${toBeDeletedLicenseKeyGroupId}`);
-			expect(data).toEqual(undefined);
-			expect(options).toEqual(undefined);
-		});
+        return LicenseKeyGroupsActionHelper.deleteLicenseKeyGroup(
+            store.dispatch,
+            {
+                licenseKeyGroupId: toBeDeletedLicenseKeyGroupId,
+                licenseModelId: LICENSE_MODEL_ID,
+                version
+            }
+        ).then(() => {
+            expect(store.getState()).toEqual(expectedStore);
+        });
+    });
 
-		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}};
-		});
+    it('Add License Key Group', () => {
+        const store = storeCreator({
+            currentScreen: { ...itemPermissionAndProps }
+        });
+        deepFreeze(store.getState());
 
-		return LicenseKeyGroupsActionHelper.deleteLicenseKeyGroup(store.dispatch, {
-			licenseKeyGroupId: toBeDeletedLicenseKeyGroupId,
-			licenseModelId: LICENSE_MODEL_ID,
-			version
-		}).then(() => {
-			expect(store.getState()).toEqual(expectedStore);
-		});
-	});
+        const LicenseKeyGroupPost = LicenseKeyGroupPostFactory.build();
+        deepFreeze(LicenseKeyGroupPost);
 
-	it('Add License Key Group', () => {
+        const LicenseKeyGroupStore = LicenseKeyGroupStoreFactory.build();
+        deepFreeze(LicenseKeyGroupStore);
 
-		const store = storeCreator({
-			currentScreen: {...itemPermissionAndProps}
-		});
-		deepFreeze(store.getState());
+        const expectedCurrentScreenProps = {
+            ...itemPermissionAndProps,
+            itemPermission: {
+                ...itemPermissionAndProps.itemPermission,
+                isDirty: true
+            }
+        };
 
-		const LicenseKeyGroupPost = LicenseKeyGroupPostFactory.build();
-		deepFreeze(LicenseKeyGroupPost);
+        let expectedStore = cloneAndSet(
+            store.getState(),
+            'licenseModel.licenseKeyGroup.licenseKeyGroupsList',
+            [LicenseKeyGroupStore]
+        );
+        expectedStore = cloneAndSet(
+            expectedStore,
+            'currentScreen.itemPermission',
+            expectedCurrentScreenProps.itemPermission
+        );
 
-		const LicenseKeyGroupStore = LicenseKeyGroupStoreFactory.build();
-		deepFreeze(LicenseKeyGroupStore);
+        mockRest.addHandler('post', ({ options, data, baseUrl }) => {
+            expect(baseUrl).toEqual(
+                `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
+                    version.id
+                }/license-key-groups`
+            );
+            expect(data).toEqual(LicenseKeyGroupPost);
+            expect(options).toEqual(undefined);
+            return {
+                value: LicenseKeyGroupStore.id
+            };
+        });
 
-		const expectedCurrentScreenProps = {
-			...itemPermissionAndProps,
-			itemPermission: {
-				...itemPermissionAndProps.itemPermission,
-				isDirty: true
-			}
-		};
+        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
+                }
+            };
+        });
 
-		let expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsList', [LicenseKeyGroupStore]);
-		expectedStore = cloneAndSet(expectedStore, 'currentScreen.itemPermission', expectedCurrentScreenProps.itemPermission);
+        mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
+            expect(baseUrl).toEqual(
+                `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}`
+            );
+            expect(data).toEqual(undefined);
+            expect(options).toEqual(undefined);
+            return {
+                ...returnedVersionFields
+            };
+        });
 
-		mockRest.addHandler('post', ({options, data, baseUrl}) => {
-			expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups`);
-			expect(data).toEqual(LicenseKeyGroupPost);
-			expect(options).toEqual(undefined);
-			return {
-				value: LicenseKeyGroupStore.id
-			};
-		});
+        return LicenseKeyGroupsActionHelper.saveLicenseKeyGroup(
+            store.dispatch,
+            {
+                licenseKeyGroup: LicenseKeyGroupPost,
+                licenseModelId: LICENSE_MODEL_ID,
+                version
+            }
+        ).then(() => {
+            expect(store.getState()).toEqual(expectedStore);
+        });
+    });
 
-		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}};
-		});
+    it('Update License Key Group', () => {
+        const licenseKeyGroupsList = buildListFromFactory(
+            LicenseKeyGroupStoreFactory,
+            1
+        );
+        deepFreeze(licenseKeyGroupsList);
+        const store = storeCreator({
+            currentScreen: { ...itemPermissionAndProps },
+            licenseModel: {
+                licenseKeyGroup: {
+                    licenseKeyGroupsList
+                }
+            }
+        });
 
-		return LicenseKeyGroupsActionHelper.saveLicenseKeyGroup(store.dispatch, {
-			licenseKeyGroup: LicenseKeyGroupPost,
-			licenseModelId: LICENSE_MODEL_ID,
-			version
-		}).then(() => {
-			expect(store.getState()).toEqual(expectedStore);
-		});
-	});
+        const toBeUpdatedLicenseKeyGroupId = licenseKeyGroupsList[0].id;
+        const previousLicenseKeyGroupData = licenseKeyGroupsList[0];
 
-	it('Update License Key Group', () => {
-		const licenseKeyGroupsList = buildListFromFactory(LicenseKeyGroupStoreFactory, 1);
-		deepFreeze(licenseKeyGroupsList);
-		const store = storeCreator({
-			currentScreen: {...itemPermissionAndProps},
-			licenseModel: {
-				licenseKeyGroup: {
-					licenseKeyGroupsList
-				}
-			}
-		});
+        const licenseKeyGroupUpdatedData = LicenseKeyGroupPostFactory.build({
+            name: 'lsk1_UPDATE',
+            description: 'string_UPDATE',
+            id: toBeUpdatedLicenseKeyGroupId
+        });
+        deepFreeze(licenseKeyGroupUpdatedData);
 
-		const toBeUpdatedLicenseKeyGroupId = licenseKeyGroupsList[0].id;
-		const previousLicenseKeyGroupData = licenseKeyGroupsList[0];
+        const licenseKeyGroupPutRequest = LicenseKeyGroupPostFactory.build({
+            name: 'lsk1_UPDATE',
+            description: 'string_UPDATE'
+        });
 
-		const licenseKeyGroupUpdatedData = LicenseKeyGroupPostFactory.build({
-			name: 'lsk1_UPDATE',
-			description: 'string_UPDATE',
-			id: toBeUpdatedLicenseKeyGroupId
-		});
-		deepFreeze(licenseKeyGroupUpdatedData);
+        deepFreeze(licenseKeyGroupPutRequest);
 
-		const licenseKeyGroupPutRequest = LicenseKeyGroupPostFactory.build({
-			name: 'lsk1_UPDATE',
-			description: 'string_UPDATE'
-		});
+        const expectedCurrentScreenProps = {
+            ...itemPermissionAndProps,
+            itemPermission: {
+                ...itemPermissionAndProps.itemPermission,
+                isDirty: true
+            }
+        };
 
-		deepFreeze(licenseKeyGroupPutRequest);
+        let expectedStore = cloneAndSet(
+            store.getState(),
+            'licenseModel.licenseKeyGroup.licenseKeyGroupsList',
+            [licenseKeyGroupUpdatedData]
+        );
+        expectedStore = cloneAndSet(
+            expectedStore,
+            'currentScreen.itemPermission',
+            expectedCurrentScreenProps.itemPermission
+        );
 
-		const expectedCurrentScreenProps = {
-			...itemPermissionAndProps,
-			itemPermission: {
-				...itemPermissionAndProps.itemPermission,
-				isDirty: true
-			}
-		};
+        mockRest.addHandler('put', ({ data, options, baseUrl }) => {
+            expect(baseUrl).toEqual(
+                `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
+                    version.id
+                }/license-key-groups/${toBeUpdatedLicenseKeyGroupId}`
+            );
+            expect(data).toEqual(licenseKeyGroupPutRequest);
+            expect(options).toEqual(undefined);
+        });
 
-		let expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsList', [licenseKeyGroupUpdatedData]);
-		expectedStore = cloneAndSet(expectedStore, 'currentScreen.itemPermission', expectedCurrentScreenProps.itemPermission);
+        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
+                }
+            };
+        });
 
-		mockRest.addHandler('put', ({data, options, baseUrl}) => {
-			expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups/${toBeUpdatedLicenseKeyGroupId}`);
-			expect(data).toEqual(licenseKeyGroupPutRequest);
-			expect(options).toEqual(undefined);
-		});
+        mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
+            expect(baseUrl).toEqual(
+                `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}`
+            );
+            expect(data).toEqual(undefined);
+            expect(options).toEqual(undefined);
+            return {
+                ...returnedVersionFields
+            };
+        });
 
-		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 LicenseKeyGroupsActionHelper.saveLicenseKeyGroup(
+            store.dispatch,
+            {
+                previousLicenseKeyGroup: previousLicenseKeyGroupData,
+                licenseKeyGroup: licenseKeyGroupUpdatedData,
+                licenseModelId: LICENSE_MODEL_ID,
+                version
+            }
+        ).then(() => {
+            expect(store.getState()).toEqual(expectedStore);
+        });
+    });
 
-		return LicenseKeyGroupsActionHelper.saveLicenseKeyGroup(store.dispatch, {
-			previousLicenseKeyGroup: previousLicenseKeyGroupData,
-			licenseKeyGroup: licenseKeyGroupUpdatedData,
-			licenseModelId: LICENSE_MODEL_ID,
-			version
-		}).then(() => {
-			expect(store.getState()).toEqual(expectedStore);
-		});
-	});
+    it('Load Limits List', () => {
+        const limitsList = LimitItemFactory.buildList(3);
+        deepFreeze(limitsList);
+        const store = storeCreator();
+        deepFreeze(store.getState());
 
-	it('Load Limits List', () => {
+        const expectedStore = cloneAndSet(
+            store.getState(),
+            'licenseModel.licenseKeyGroup.licenseKeyGroupsEditor.limitsList',
+            limitsList
+        );
+        const licenseKeyGroup = LicenseKeyGroupStoreFactory.build();
+        mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
+            expect(baseUrl).toEqual(
+                `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
+                    version.id
+                }/license-key-groups/${licenseKeyGroup.id}/limits`
+            );
+            expect(data).toEqual(undefined);
+            expect(options).toEqual(undefined);
+            return { results: limitsList };
+        });
 
-		const limitsList = LimitItemFactory.buildList(3);
-		deepFreeze(limitsList);
-		const store = storeCreator();
-		deepFreeze(store.getState());
-
-		const expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsEditor.limitsList', limitsList);
-		const licenseKeyGroup = LicenseKeyGroupStoreFactory.build();
-		mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
-			expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups/${licenseKeyGroup.id}/limits`);
-			expect(data).toEqual(undefined);
-			expect(options).toEqual(undefined);
-			return {results: limitsList};
-		 });
-
-		return LicenseKeyGroupsActionHelper.fetchLimits(store.dispatch, {licenseModelId: LICENSE_MODEL_ID, version, licenseKeyGroup}).then(() => {
-			expect(store.getState()).toEqual(expectedStore);
-		 });
-	});
-
-	it('Add Limit', () => {
-
-		const store = storeCreator({
-			currentScreen: {...itemPermissionAndProps}
-		});
-		deepFreeze(store.getState());
-
-		const limitToAdd = LimitPostFactory.build();
-		let limitFromBE = {...limitToAdd};
-		limitFromBE.metric = getStrValue(limitFromBE.metric);
-		limitFromBE.unit = getStrValue(limitFromBE.unit);
+        return LicenseKeyGroupsActionHelper.fetchLimits(store.dispatch, {
+            licenseModelId: LICENSE_MODEL_ID,
+            version,
+            licenseKeyGroup
+        }).then(() => {
+            expect(store.getState()).toEqual(expectedStore);
+        });
+    });
 
-		deepFreeze(limitToAdd);
-		deepFreeze(limitFromBE);
+    it('Add Limit', () => {
+        const store = storeCreator({
+            currentScreen: { ...itemPermissionAndProps }
+        });
+        deepFreeze(store.getState());
 
-		const LimitIdFromResponse = 'ADDED_ID';
-		const limitAddedItem = {...limitToAdd, id: LimitIdFromResponse};
-		deepFreeze(limitAddedItem);
-		const licenseKeyGroup = LicenseKeyGroupStoreFactory.build();
+        const limitToAdd = LimitPostFactory.build();
+        let limitFromBE = { ...limitToAdd };
+        limitFromBE.metric = getStrValue(limitFromBE.metric);
+        limitFromBE.unit = getStrValue(limitFromBE.unit);
 
-		const expectedCurrentScreenProps = {
-			...itemPermissionAndProps,
-			itemPermission: {
-				...itemPermissionAndProps.itemPermission,
-				isDirty: true
-			}
-		};
+        deepFreeze(limitToAdd);
+        deepFreeze(limitFromBE);
 
-		let expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsEditor.limitsList', [limitAddedItem]);
-		expectedStore = cloneAndSet(expectedStore, 'currentScreen.itemPermission', expectedCurrentScreenProps.itemPermission);
+        const LimitIdFromResponse = 'ADDED_ID';
+        const limitAddedItem = { ...limitToAdd, id: LimitIdFromResponse };
+        deepFreeze(limitAddedItem);
+        const licenseKeyGroup = LicenseKeyGroupStoreFactory.build();
 
-		mockRest.addHandler('post', ({data, options, baseUrl}) => {
-			expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups/${licenseKeyGroup.id}/limits`);
-			expect(data).toEqual(limitFromBE);
-			expect(options).toEqual(undefined);
-			return {
-				returnCode: 'OK',
-				value: LimitIdFromResponse
-			};
-		});
+        const expectedCurrentScreenProps = {
+            ...itemPermissionAndProps,
+            itemPermission: {
+                ...itemPermissionAndProps.itemPermission,
+                isDirty: true
+            }
+        };
 
-		mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
-			expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups/${licenseKeyGroup.id}/limits`);
-			expect(data).toEqual(undefined);
-			expect(options).toEqual(undefined);
-			return {results: [limitAddedItem]};
-		 });
+        let expectedStore = cloneAndSet(
+            store.getState(),
+            'licenseModel.licenseKeyGroup.licenseKeyGroupsEditor.limitsList',
+            [limitAddedItem]
+        );
+        expectedStore = cloneAndSet(
+            expectedStore,
+            'currentScreen.itemPermission',
+            expectedCurrentScreenProps.itemPermission
+        );
 
-		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}};
-		});
+        mockRest.addHandler('post', ({ data, options, baseUrl }) => {
+            expect(baseUrl).toEqual(
+                `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
+                    version.id
+                }/license-key-groups/${licenseKeyGroup.id}/limits`
+            );
+            expect(data).toEqual(limitFromBE);
+            expect(options).toEqual(undefined);
+            return {
+                returnCode: 'OK',
+                value: LimitIdFromResponse
+            };
+        });
 
-		return LicenseKeyGroupsActionHelper.submitLimit(store.dispatch,
-			{
-				licenseModelId: LICENSE_MODEL_ID,
-				version,
-				licenseKeyGroup,
-				limit: limitToAdd
-			}
-		).then(() => {
-			expect(store.getState()).toEqual(expectedStore);
-		});
-	});
+        mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
+            expect(baseUrl).toEqual(
+                `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
+                    version.id
+                }/license-key-groups/${licenseKeyGroup.id}/limits`
+            );
+            expect(data).toEqual(undefined);
+            expect(options).toEqual(undefined);
+            return { results: [limitAddedItem] };
+        });
 
-	it('Delete Limit', () => {
+        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
+                }
+            };
+        });
 
-		const limitsList = LimitItemFactory.buildList(1);
-		deepFreeze(limitsList);
+        mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
+            expect(baseUrl).toEqual(
+                `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}`
+            );
+            expect(data).toEqual(undefined);
+            expect(options).toEqual(undefined);
+            return {
+                ...returnedVersionFields
+            };
+        });
 
-		const store = storeCreator({
-			currentScreen: {...itemPermissionAndProps},
-			licenseModel: {
-				entitlementPool: {
-					entitlementPoolEditor: {
-						limitsList
-					}
-				}
-			}
-		});
-		deepFreeze(store.getState());
+        return LicenseKeyGroupsActionHelper.submitLimit(store.dispatch, {
+            licenseModelId: LICENSE_MODEL_ID,
+            version,
+            licenseKeyGroup,
+            limit: limitToAdd
+        }).then(() => {
+            expect(store.getState()).toEqual(expectedStore);
+        });
+    });
 
-		const licenseKeyGroup = LicenseKeyGroupStoreFactory.build();
+    it('Delete Limit', () => {
+        const limitsList = LimitItemFactory.buildList(1);
+        deepFreeze(limitsList);
 
-		const expectedCurrentScreenProps = {
-			...itemPermissionAndProps,
-			itemPermission: {
-				...itemPermissionAndProps.itemPermission,
-				isDirty: true
-			}
-		};
+        const store = storeCreator({
+            currentScreen: { ...itemPermissionAndProps },
+            licenseModel: {
+                entitlementPool: {
+                    entitlementPoolEditor: {
+                        limitsList
+                    }
+                }
+            }
+        });
+        deepFreeze(store.getState());
 
-		let expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsEditor.limitsList', []);
-		expectedStore = cloneAndSet(expectedStore, 'currentScreen.itemPermission', expectedCurrentScreenProps.itemPermission);
+        const licenseKeyGroup = LicenseKeyGroupStoreFactory.build();
 
-		mockRest.addHandler('destroy', ({data, options, baseUrl}) => {
-			expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups/${licenseKeyGroup.id}/limits/${limitsList[0].id}`);
-			expect(data).toEqual(undefined);
-			expect(options).toEqual(undefined);
-			return {
-				results: {
-					returnCode: 'OK'
-				}
-			};
-		});
+        const expectedCurrentScreenProps = {
+            ...itemPermissionAndProps,
+            itemPermission: {
+                ...itemPermissionAndProps.itemPermission,
+                isDirty: true
+            }
+        };
 
-		mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
-			expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups/${licenseKeyGroup.id}/limits`);
-			expect(data).toEqual(undefined);
-			expect(options).toEqual(undefined);
-			return {results: []};
-		 });
+        let expectedStore = cloneAndSet(
+            store.getState(),
+            'licenseModel.licenseKeyGroup.licenseKeyGroupsEditor.limitsList',
+            []
+        );
+        expectedStore = cloneAndSet(
+            expectedStore,
+            'currentScreen.itemPermission',
+            expectedCurrentScreenProps.itemPermission
+        );
 
-		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}};
-		});
+        mockRest.addHandler('destroy', ({ data, options, baseUrl }) => {
+            expect(baseUrl).toEqual(
+                `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
+                    version.id
+                }/license-key-groups/${licenseKeyGroup.id}/limits/${
+                    limitsList[0].id
+                }`
+            );
+            expect(data).toEqual(undefined);
+            expect(options).toEqual(undefined);
+            return {
+                results: {
+                    returnCode: 'OK'
+                }
+            };
+        });
 
-		return LicenseKeyGroupsActionHelper.deleteLimit(store.dispatch, {
-			licenseModelId: LICENSE_MODEL_ID,
-			version,
-			licenseKeyGroup,
-			limit: limitsList[0]
-		}).then(() => {
-			expect(store.getState()).toEqual(expectedStore);
-		});
-	});
+        mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
+            expect(baseUrl).toEqual(
+                `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
+                    version.id
+                }/license-key-groups/${licenseKeyGroup.id}/limits`
+            );
+            expect(data).toEqual(undefined);
+            expect(options).toEqual(undefined);
+            return { results: [] };
+        });
 
-	it('Update Limit', () => {
+        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
+                }
+            };
+        });
 
-		const limitsList = LimitItemFactory.buildList(1);
-		deepFreeze(limitsList);
-		const licenseKeyGroup = LicenseKeyGroupStoreFactory.build();
-		const store = storeCreator({
-			currentScreen: {...itemPermissionAndProps},
-			licenseModel: {
-				licenseKeyGroup: {
-					licenseKeyGroupsEditor: {
-						limitsList
-					}
-				}
-			}
-		});
+        mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
+            expect(baseUrl).toEqual(
+                `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}`
+            );
+            expect(data).toEqual(undefined);
+            expect(options).toEqual(undefined);
+            return {
+                ...returnedVersionFields
+            };
+        });
 
-		deepFreeze(store.getState());
+        return LicenseKeyGroupsActionHelper.deleteLimit(store.dispatch, {
+            licenseModelId: LICENSE_MODEL_ID,
+            version,
+            licenseKeyGroup,
+            limit: limitsList[0]
+        }).then(() => {
+            expect(store.getState()).toEqual(expectedStore);
+        });
+    });
 
+    it('Update Limit', () => {
+        const limitsList = LimitItemFactory.buildList(1);
+        deepFreeze(limitsList);
+        const licenseKeyGroup = LicenseKeyGroupStoreFactory.build();
+        const store = storeCreator({
+            currentScreen: { ...itemPermissionAndProps },
+            licenseModel: {
+                licenseKeyGroup: {
+                    licenseKeyGroupsEditor: {
+                        limitsList
+                    }
+                }
+            }
+        });
 
-		const previousData = limitsList[0];
-		deepFreeze(previousData);
-		const limitId = limitsList[0].id;
+        deepFreeze(store.getState());
 
-		let updatedLimit = {...previousData, name: 'updatedLimit'};
-		const updatedLimitForPut = {...updatedLimit, id: undefined};
-		updatedLimit.metric = {choice: updatedLimit.metric, other: ''};
-		updatedLimit.unit = {choice: updatedLimit.unit, other: ''};
-		deepFreeze(updatedLimit);
+        const previousData = limitsList[0];
+        deepFreeze(previousData);
+        const limitId = limitsList[0].id;
 
-		const expectedCurrentScreenProps = {
-			...itemPermissionAndProps,
-			itemPermission: {
-				...itemPermissionAndProps.itemPermission,
-				isDirty: true
-			}
-		};
+        let updatedLimit = { ...previousData, name: 'updatedLimit' };
+        const updatedLimitForPut = { ...updatedLimit, id: undefined };
+        updatedLimit.metric = { choice: updatedLimit.metric, other: '' };
+        updatedLimit.unit = { choice: updatedLimit.unit, other: '' };
+        deepFreeze(updatedLimit);
 
-		let expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsEditor.limitsList', [updatedLimitForPut]);
-		expectedStore = cloneAndSet(expectedStore, 'currentScreen.itemPermission', expectedCurrentScreenProps.itemPermission);
+        const expectedCurrentScreenProps = {
+            ...itemPermissionAndProps,
+            itemPermission: {
+                ...itemPermissionAndProps.itemPermission,
+                isDirty: true
+            }
+        };
 
+        let expectedStore = cloneAndSet(
+            store.getState(),
+            'licenseModel.licenseKeyGroup.licenseKeyGroupsEditor.limitsList',
+            [updatedLimitForPut]
+        );
+        expectedStore = cloneAndSet(
+            expectedStore,
+            'currentScreen.itemPermission',
+            expectedCurrentScreenProps.itemPermission
+        );
 
-		mockRest.addHandler('put', ({data, options, baseUrl}) => {
-			expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups/${licenseKeyGroup.id}/limits/${limitId}`);
-			expect(data).toEqual(updatedLimitForPut);
-			expect(options).toEqual(undefined);
-			return {returnCode: 'OK'};
-		});
+        mockRest.addHandler('put', ({ data, options, baseUrl }) => {
+            expect(baseUrl).toEqual(
+                `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
+                    version.id
+                }/license-key-groups/${licenseKeyGroup.id}/limits/${limitId}`
+            );
+            expect(data).toEqual(updatedLimitForPut);
+            expect(options).toEqual(undefined);
+            return { returnCode: 'OK' };
+        });
 
-		mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
-			expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups/${licenseKeyGroup.id}/limits`);
-			expect(data).toEqual(undefined);
-			expect(options).toEqual(undefined);
-			return {results: [updatedLimitForPut]};
-		 });
+        mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
+            expect(baseUrl).toEqual(
+                `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
+                    version.id
+                }/license-key-groups/${licenseKeyGroup.id}/limits`
+            );
+            expect(data).toEqual(undefined);
+            expect(options).toEqual(undefined);
+            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}};
-		});
+        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 LicenseKeyGroupsActionHelper.submitLimit(store.dispatch,
-			{
-				licenseModelId: LICENSE_MODEL_ID,
-				version,
-				licenseKeyGroup,
-				limit: updatedLimit
-			}
-		).then(() => {
-			expect(store.getState()).toEqual(expectedStore);
-		});
-	});
+        mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
+            expect(baseUrl).toEqual(
+                `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}`
+            );
+            expect(data).toEqual(undefined);
+            expect(options).toEqual(undefined);
+            return {
+                ...returnedVersionFields
+            };
+        });
 
+        return LicenseKeyGroupsActionHelper.submitLimit(store.dispatch, {
+            licenseModelId: LICENSE_MODEL_ID,
+            version,
+            licenseKeyGroup,
+            limit: updatedLimit
+        }).then(() => {
+            expect(store.getState()).toEqual(expectedStore);
+        });
+    });
 });
diff --git a/openecomp-ui/test/licenseModel/test.js b/openecomp-ui/test/licenseModel/test.js
index 6cb2168..bbebcaf 100644
--- a/openecomp-ui/test/licenseModel/test.js
+++ b/openecomp-ui/test/licenseModel/test.js
@@ -1,5 +1,5 @@
 /*!
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2016-2018 European Support Limited
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -15,127 +15,188 @@
  */
 import deepFreeze from 'deep-freeze';
 import mockRest from 'test-utils/MockRest.js';
-import {storeCreator} from 'sdc-app/AppStore.js';
-import {cloneAndSet} from 'test-utils/Util.js';
+import { storeCreator } from 'sdc-app/AppStore.js';
+import { cloneAndSet } from 'test-utils/Util.js';
 import LicenseModelActionHelper from 'sdc-app/onboarding/licenseModel/LicenseModelActionHelper.js';
 import LicenseModelCreationActionHelper from 'sdc-app/onboarding/licenseModel/creation/LicenseModelCreationActionHelper.js';
-import {LicenseModelPostFactory, LicenseModelDispatchFactory, LicenseModelStoreFactory} from 'test-utils/factories/licenseModel/LicenseModelFactories.js';
+import {
+    LicenseModelPostFactory,
+    LicenseModelDispatchFactory,
+    LicenseModelStoreFactory
+} from 'test-utils/factories/licenseModel/LicenseModelFactories.js';
 import VersionFactory from 'test-utils/factories/common/VersionFactory.js';
-import {default as CurrentScreenFactory} from 'test-utils/factories/common/CurrentScreenFactory.js';
-import {actionsEnum as VersionControllerActionsEnum} from 'nfvo-components/panel/versionController/VersionControllerConstants.js';
-import {SyncStates} from 'sdc-app/common/merge/MergeEditorConstants.js';
-import {itemTypes} from 'sdc-app/onboarding/versionsPage/VersionsPageConstants.js';
+import { default as CurrentScreenFactory } from 'test-utils/factories/common/CurrentScreenFactory.js';
+import { actionsEnum as VersionControllerActionsEnum } from 'nfvo-components/panel/versionController/VersionControllerConstants.js';
+import { SyncStates } from 'sdc-app/common/merge/MergeEditorConstants.js';
+import { itemTypes } from 'sdc-app/onboarding/versionsPage/VersionsPageConstants.js';
 
-describe('License Model Module Tests', function () {
-	it('Add License Model', () => {
-		const store = storeCreator();
-		deepFreeze(store.getState());
+describe('License Model Module Tests', function() {
+    it('Add License Model', () => {
+        const store = storeCreator();
+        deepFreeze(store.getState());
 
-		const licenseModelPostRequest = LicenseModelPostFactory.build();
+        const licenseModelPostRequest = LicenseModelPostFactory.build();
 
-		const licenseModelToAdd = LicenseModelDispatchFactory.build();
+        const licenseModelToAdd = LicenseModelDispatchFactory.build();
 
-		const licenseModelIdFromResponse = 'ADDED_ID';
-		
-		mockRest.addHandler('post', ({options, data, baseUrl}) => {
-			expect(baseUrl).toEqual('/onboarding-api/v1.0/vendor-license-models/');
-			expect(data).toEqual(licenseModelPostRequest);
-			expect(options).toEqual(undefined);
-			return {
-				value: licenseModelIdFromResponse
-			};
-		});
+        const licenseModelIdFromResponse = 'ADDED_ID';
 
-		return LicenseModelCreationActionHelper.createLicenseModel(store.dispatch, {
-			licenseModel: licenseModelToAdd
-		}).then((response) => {
-			expect(response.value).toEqual(licenseModelIdFromResponse);
-		});
-	});
+        mockRest.addHandler('post', ({ options, data, baseUrl }) => {
+            expect(baseUrl).toEqual(
+                '/onboarding-api/v1.0/vendor-license-models/'
+            );
+            expect(data).toEqual(licenseModelPostRequest);
+            expect(options).toEqual(undefined);
+            return {
+                value: licenseModelIdFromResponse
+            };
+        });
 
-	it('Validating readonly screen after submit', () => {
-		const version = VersionFactory.build({}, {isCertified: false});
-		const itemPermissionAndProps = CurrentScreenFactory.build({}, {version});
-		const licenseModel = LicenseModelStoreFactory.build();
-		deepFreeze(licenseModel);
+        return LicenseModelCreationActionHelper.createLicenseModel(
+            store.dispatch,
+            {
+                licenseModel: licenseModelToAdd
+            }
+        ).then(response => {
+            expect(response.value).toEqual(licenseModelIdFromResponse);
+        });
+    });
 
-		const store = storeCreator({
-			currentScreen: {...itemPermissionAndProps},
-			licenseModel: {
-				licenseModelEditor: {data: licenseModel},
-			}
-		});
-		deepFreeze(store.getState());
+    it('Validating readonly screen after submit', () => {
+        const version = VersionFactory.build({}, { isCertified: false });
+        const itemPermissionAndProps = CurrentScreenFactory.build(
+            {},
+            { version }
+        );
+        const licenseModel = LicenseModelStoreFactory.build();
+        deepFreeze(licenseModel);
 
-		const certifiedVersion = {
-			...itemPermissionAndProps.props.version,
-			status: 'Certified'
-		};
+        const store = storeCreator({
+            currentScreen: { ...itemPermissionAndProps },
+            licenseModel: {
+                licenseModelEditor: { data: licenseModel }
+            }
+        });
+        deepFreeze(store.getState());
 
-		const expectedCurrentScreenProps = {
-			itemPermission: {
-				...itemPermissionAndProps.itemPermission,
-				isCertified: true
-			},
-			props: {
-				isReadOnlyMode: true,
-				version: certifiedVersion
-			}
-		};
-		const expectedSuccessModal = {
-			cancelButtonText: 'OK',
-			modalClassName: 'notification-modal',
-			msg: 'This license model successfully submitted',
-			timeout: 2000,
-			title: 'Submit Succeeded',
-			type: 'success'
-		};
+        const certifiedVersion = {
+            ...itemPermissionAndProps.props.version,
+            status: 'Certified'
+        };
 
-		const versionsList = {
-			itemType: itemTypes.LICENSE_MODEL,
-			itemId: licenseModel.id,
-			versions: [{...certifiedVersion}]
-		};
+        const expectedCurrentScreenProps = {
+            itemPermission: {
+                ...itemPermissionAndProps.itemPermission,
+                isCertified: true
+            },
+            props: {
+                isReadOnlyMode: true,
+                version: certifiedVersion
+            }
+        };
+        const expectedSuccessModal = {
+            cancelButtonText: 'OK',
+            modalClassName: 'notification-modal',
+            msg: 'This license model successfully submitted',
+            timeout: 2000,
+            title: 'Submit Succeeded',
+            type: 'success'
+        };
 
-		let expectedStore = store.getState();
-		expectedStore = cloneAndSet(expectedStore, 'currentScreen.itemPermission', expectedCurrentScreenProps.itemPermission);
-		expectedStore = cloneAndSet(expectedStore, 'currentScreen.props', expectedCurrentScreenProps.props);
-		expectedStore = cloneAndSet(expectedStore, 'modal', expectedSuccessModal);
-		expectedStore = cloneAndSet(expectedStore, 'versionsPage.versionsList', versionsList );
+        const versionsList = {
+            itemType: itemTypes.LICENSE_MODEL,
+            itemId: licenseModel.id,
+            versions: [{ ...certifiedVersion }]
+        };
 
-		mockRest.addHandler('put', ({data, options, baseUrl}) => {
-			expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${licenseModel.id}/versions/${version.id}/actions`);
-			expect(data).toEqual({action: VersionControllerActionsEnum.SUBMIT});
-			expect(options).toEqual(undefined);
-			return {returnCode: 'OK'};
-		});
+        let expectedStore = store.getState();
+        expectedStore = cloneAndSet(
+            expectedStore,
+            'currentScreen.itemPermission',
+            expectedCurrentScreenProps.itemPermission
+        );
+        expectedStore = cloneAndSet(
+            expectedStore,
+            'currentScreen.props',
+            expectedCurrentScreenProps.props
+        );
+        expectedStore = cloneAndSet(
+            expectedStore,
+            'modal',
+            expectedSuccessModal
+        );
+        expectedStore = cloneAndSet(
+            expectedStore,
+            'versionsPage.versionsList',
+            versionsList
+        );
 
-		mockRest.addHandler('put', ({data, options, baseUrl}) => {
-			expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${licenseModel.id}/versions/${version.id}/actions`);
-			expect(data).toEqual({action: VersionControllerActionsEnum.CREATE_PACKAGE});
-			expect(options).toEqual(undefined);
-			return {returnCode: 'OK'};
-		});
+        mockRest.addHandler('put', ({ data, options, baseUrl }) => {
+            expect(baseUrl).toEqual(
+                `/onboarding-api/v1.0/vendor-license-models/${
+                    licenseModel.id
+                }/versions/${version.id}/actions`
+            );
+            expect(data).toEqual({
+                action: VersionControllerActionsEnum.SUBMIT
+            });
+            expect(options).toEqual(undefined);
+            return { returnCode: 'OK' };
+        });
 
-		mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
-			expect(baseUrl).toEqual(`/onboarding-api/v1.0/items/${licenseModel.id}/versions/${version.id}`);
-			expect(data).toEqual(undefined);
-			expect(options).toEqual(undefined);
-			return {...certifiedVersion, state: {synchronizationState: SyncStates.UP_TO_DATE, dirty: false}};
-		});
+        mockRest.addHandler('put', ({ data, options, baseUrl }) => {
+            expect(baseUrl).toEqual(
+                `/onboarding-api/v1.0/vendor-license-models/${
+                    licenseModel.id
+                }/versions/${version.id}/actions`
+            );
+            expect(data).toEqual({
+                action: VersionControllerActionsEnum.CREATE_PACKAGE
+            });
+            expect(options).toEqual(undefined);
+            return { returnCode: 'OK' };
+        });
 
-		mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
-			expect(baseUrl).toEqual(`/onboarding-api/v1.0/items/${licenseModel.id}/versions`);
-			expect(data).toEqual(undefined);
-			expect(options).toEqual(undefined);
-			return {results: [{...certifiedVersion}]};
-		});
+        mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
+            expect(baseUrl).toEqual(
+                `/onboarding-api/v1.0/items/${licenseModel.id}/versions/${
+                    version.id
+                }`
+            );
+            expect(data).toEqual(undefined);
+            expect(options).toEqual(undefined);
+            return {
+                ...certifiedVersion,
+                state: {
+                    synchronizationState: SyncStates.UP_TO_DATE,
+                    dirty: false
+                }
+            };
+        });
 
-		return LicenseModelActionHelper.performSubmitAction(store.dispatch, {
-			licenseModelId: licenseModel.id,
-			version
-		}).then(() => {
-			expect(store.getState()).toEqual(expectedStore);
-		});
-	});
+        mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
+            expect(baseUrl).toEqual(
+                `/onboarding-api/v1.0/items/${licenseModel.id}`
+            );
+            expect(data).toEqual(undefined);
+            expect(options).toEqual(undefined);
+            return { ...certifiedVersion };
+        });
+
+        mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
+            expect(baseUrl).toEqual(
+                `/onboarding-api/v1.0/items/${licenseModel.id}/versions`
+            );
+            expect(data).toEqual(undefined);
+            expect(options).toEqual(undefined);
+            return { results: [{ ...certifiedVersion }] };
+        });
+
+        return LicenseModelActionHelper.performSubmitAction(store.dispatch, {
+            licenseModelId: licenseModel.id,
+            version
+        }).then(() => {
+            expect(store.getState()).toEqual(expectedStore);
+        });
+    });
 });
diff --git a/openecomp-ui/test/onboard/filter/filter.test.js b/openecomp-ui/test/onboard/filter/filter.test.js
index 1b89a30..bf9ce63 100644
--- a/openecomp-ui/test/onboard/filter/filter.test.js
+++ b/openecomp-ui/test/onboard/filter/filter.test.js
@@ -24,7 +24,8 @@
 import { FilterFactory } from 'test-utils/factories/onboard/FilterFactories.js';
 import {
     itemStatus,
-    versionStatus
+    versionStatus,
+    itemPermissions
 } from 'sdc-app/common/helpers/ItemsHelperConstants.js';
 import OnboardActionHelper from 'sdc-app/onboarding/onboard/OnboardActionHelper.js';
 import { tabsMapping } from 'sdc-app/onboarding/onboard/OnboardConstants.js';
@@ -46,7 +47,9 @@
             expect(baseUrl).toEqual(
                 `/onboarding-api/v1.0/items?&itemStatus=${
                     itemStatus.ACTIVE
-                }&versionStatus=${versionStatus.DRAFT}`
+                }&versionStatus=${versionStatus.DRAFT}&permission=${
+                    itemPermissions.OWNER
+                },${itemPermissions.CONTRIBUTOR}`
             );
             expect(data).toEqual(undefined);
             expect(options).toEqual(undefined);
@@ -62,10 +65,7 @@
             done();
         });
     });
-    /**
-     *  TODO Turn ON when FILTER TOGGLE Will BE REMOVED
-     */
-    /*
+
     it('load certifed data', done => {
         const store = storeCreator();
 
@@ -112,7 +112,7 @@
             done();
         });
     });
-    */
+
     it('onboarding tabs switching filter updates', done => {
         const store = storeCreator();
 
diff --git a/openecomp-ui/test/onboard/test.js b/openecomp-ui/test/onboard/test.js
index a75070b..b2131ce 100644
--- a/openecomp-ui/test/onboard/test.js
+++ b/openecomp-ui/test/onboard/test.js
@@ -20,6 +20,11 @@
 import { tabsMapping as onboardTabsMapping } from 'sdc-app/onboarding/onboard/OnboardConstants.js';
 import { tabsMapping as onboardCatalogTabsMapping } from 'sdc-app/onboarding/onboard/onboardingCatalog/OnboardingCatalogConstants.js';
 import { FilterFactory } from 'test-utils/factories/onboard/FilterFactories.js';
+import mockRest from 'test-utils/MockRest.js';
+import {
+    itemStatus,
+    versionStatus
+} from 'sdc-app/common/helpers/ItemsHelperConstants.js';
 
 describe('Onboard Module Tests', () => {
     it('should return default state', () => {
@@ -34,6 +39,18 @@
             activeTab: onboardTabsMapping.CATALOG,
             filter: FilterFactory.build({ versionStatus: 'Certified' })
         });
+
+        mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
+            expect(baseUrl).toEqual(
+                `/onboarding-api/v1.0/items?&itemStatus=${
+                    itemStatus.ACTIVE
+                }&versionStatus=${versionStatus.CERTIFIED}`
+            );
+            expect(data).toEqual(undefined);
+            expect(options).toEqual(undefined);
+            return { results: [] };
+        });
+
         OnboardActionHelper.changeActiveTab(
             store.dispatch,
             onboardTabsMapping.CATALOG
@@ -62,6 +79,18 @@
         const store = storeCreator();
         const expectedStore = OnboardStoreFactory.build();
         OnboardActionHelper.changeSearchValue(store.dispatch, 'hello');
+
+        mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
+            expect(baseUrl).toEqual(
+                `/onboarding-api/v1.0/items?&itemStatus=${
+                    itemStatus.ACTIVE
+                }&versionStatus=${versionStatus.CERTIFIED}`
+            );
+            expect(data).toEqual(undefined);
+            expect(options).toEqual(undefined);
+            return { results: [] };
+        });
+
         OnboardActionHelper.changeActiveTab(
             store.dispatch,
             onboardTabsMapping.CATALOG
@@ -70,6 +99,7 @@
             store.dispatch,
             onboardCatalogTabsMapping.ACTIVE
         );
+
         OnboardActionHelper.resetOnboardStore(store.dispatch, 'hello');
         expect(store.getState().onboard).toEqual(expectedStore);
     });
diff --git a/openecomp-ui/test/softwareProduct/test.js b/openecomp-ui/test/softwareProduct/test.js
index 15f7a21..91b4e7d 100644
--- a/openecomp-ui/test/softwareProduct/test.js
+++ b/openecomp-ui/test/softwareProduct/test.js
@@ -1,5 +1,5 @@
 /*!
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2016-2018 European Support Limited
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -16,101 +16,156 @@
 
 import deepFreeze from 'deep-freeze';
 import mockRest from 'test-utils/MockRest.js';
-import {cloneAndSet} from 'test-utils/Util.js';
-import {storeCreator} from 'sdc-app/AppStore.js';
+import { cloneAndSet } from 'test-utils/Util.js';
+import { storeCreator } from 'sdc-app/AppStore.js';
 
 import SoftwareProductActionHelper from 'sdc-app/onboarding/softwareProduct/SoftwareProductActionHelper.js';
-import {VSPEditorFactoryWithLicensingData} from 'test-utils/factories/softwareProduct/SoftwareProductEditorFactories.js';
+import { VSPEditorFactoryWithLicensingData } from 'test-utils/factories/softwareProduct/SoftwareProductEditorFactories.js';
 import VersionFactory from 'test-utils/factories/common/VersionFactory.js';
-import {default as CurrentScreenFactory} from 'test-utils/factories/common/CurrentScreenFactory.js';
-import {actionsEnum as VersionControllerActionsEnum} from 'nfvo-components/panel/versionController/VersionControllerConstants.js';
-import {SyncStates} from 'sdc-app/common/merge/MergeEditorConstants.js';
-import {itemTypes} from 'sdc-app/onboarding/versionsPage/VersionsPageConstants.js';
+import { default as CurrentScreenFactory } from 'test-utils/factories/common/CurrentScreenFactory.js';
+import { actionsEnum as VersionControllerActionsEnum } from 'nfvo-components/panel/versionController/VersionControllerConstants.js';
+import { SyncStates } from 'sdc-app/common/merge/MergeEditorConstants.js';
+import { itemTypes } from 'sdc-app/onboarding/versionsPage/VersionsPageConstants.js';
 
-describe('Software Product Module Tests', function () {
-	it('Validating readonly screen after submit', () => {
-		const version = VersionFactory.build({}, {isCertified: false});
-		const itemPermissionAndProps = CurrentScreenFactory.build({}, {version});
-		const softwareProduct = VSPEditorFactoryWithLicensingData.build();
-		deepFreeze(softwareProduct);
+describe('Software Product Module Tests', function() {
+    it('Validating readonly screen after submit', () => {
+        const version = VersionFactory.build({}, { isCertified: false });
+        const itemPermissionAndProps = CurrentScreenFactory.build(
+            {},
+            { version }
+        );
+        const softwareProduct = VSPEditorFactoryWithLicensingData.build();
+        deepFreeze(softwareProduct);
 
-		const store = storeCreator({
-			currentScreen: {...itemPermissionAndProps},
-			softwareProduct: {
-				softwareProductEditor: {data: softwareProduct},
-				softwareProductQuestionnaire: {qdata: 'test', qschema: {type: 'string'}}
-			}
-		});
-		deepFreeze(store.getState());
+        const store = storeCreator({
+            currentScreen: { ...itemPermissionAndProps },
+            softwareProduct: {
+                softwareProductEditor: { data: softwareProduct },
+                softwareProductQuestionnaire: {
+                    qdata: 'test',
+                    qschema: { type: 'string' }
+                }
+            }
+        });
+        deepFreeze(store.getState());
 
-		const certifiedVersion = {
-			...itemPermissionAndProps.props.version,
-			status: 'Certified'
-		};
+        const certifiedVersion = {
+            ...itemPermissionAndProps.props.version,
+            status: 'Certified'
+        };
 
-		const versionsList = {
-			itemType: itemTypes.SOFTWARE_PRODUCT,
-			itemId: softwareProduct.id,
-			versions: [{...certifiedVersion}]
-		};
-		const expectedCurrentScreenProps = {
-			itemPermission: {
-				...itemPermissionAndProps.itemPermission,
-				isCertified: true
-			},
-			props: {
-				isReadOnlyMode: true,
-				version: certifiedVersion
-			}
-		};
-		const expectedSuccessModal = {
-			cancelButtonText: 'OK',
-			modalClassName: 'notification-modal',
-			msg: 'This software product successfully submitted',
-			timeout: 2000,
-			title: 'Submit Succeeded',
-			type: 'success'
-		};
+        const versionsList = {
+            itemType: itemTypes.SOFTWARE_PRODUCT,
+            itemId: softwareProduct.id,
+            versions: [{ ...certifiedVersion }]
+        };
+        const expectedCurrentScreenProps = {
+            itemPermission: {
+                ...itemPermissionAndProps.itemPermission,
+                isCertified: true
+            },
+            props: {
+                isReadOnlyMode: true,
+                version: certifiedVersion
+            }
+        };
+        const expectedSuccessModal = {
+            cancelButtonText: 'OK',
+            modalClassName: 'notification-modal',
+            msg: 'This software product successfully submitted',
+            timeout: 2000,
+            title: 'Submit Succeeded',
+            type: 'success'
+        };
 
-		let expectedStore = store.getState();
-		expectedStore = cloneAndSet(expectedStore, 'currentScreen.itemPermission', expectedCurrentScreenProps.itemPermission);
-		expectedStore = cloneAndSet(expectedStore, 'currentScreen.props', expectedCurrentScreenProps.props);
-		expectedStore = cloneAndSet(expectedStore, 'modal', expectedSuccessModal);
-		expectedStore = cloneAndSet(expectedStore, 'versionsPage.versionsList', versionsList );
+        let expectedStore = store.getState();
+        expectedStore = cloneAndSet(
+            expectedStore,
+            'currentScreen.itemPermission',
+            expectedCurrentScreenProps.itemPermission
+        );
+        expectedStore = cloneAndSet(
+            expectedStore,
+            'currentScreen.props',
+            expectedCurrentScreenProps.props
+        );
+        expectedStore = cloneAndSet(
+            expectedStore,
+            'modal',
+            expectedSuccessModal
+        );
+        expectedStore = cloneAndSet(
+            expectedStore,
+            'versionsPage.versionsList',
+            versionsList
+        );
 
-		mockRest.addHandler('put', ({data, options, baseUrl}) => {
-			expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-software-products/${softwareProduct.id}/versions/${version.id}/actions`);
-			expect(data).toEqual({action: VersionControllerActionsEnum.SUBMIT});
-			expect(options).toEqual(undefined);
-			return {returnCode: 'OK'};
-		});
+        mockRest.addHandler('put', ({ data, options, baseUrl }) => {
+            expect(baseUrl).toEqual(
+                `/onboarding-api/v1.0/vendor-software-products/${
+                    softwareProduct.id
+                }/versions/${version.id}/actions`
+            );
+            expect(data).toEqual({
+                action: VersionControllerActionsEnum.SUBMIT
+            });
+            expect(options).toEqual(undefined);
+            return { returnCode: 'OK' };
+        });
 
-		mockRest.addHandler('put', ({data, options, baseUrl}) => {
-			expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-software-products/${softwareProduct.id}/versions/${version.id}/actions`);
-			expect(data).toEqual({action: VersionControllerActionsEnum.CREATE_PACKAGE});
-			expect(options).toEqual(undefined);
-			return {returnCode: 'OK'};
-		});
+        mockRest.addHandler('put', ({ data, options, baseUrl }) => {
+            expect(baseUrl).toEqual(
+                `/onboarding-api/v1.0/vendor-software-products/${
+                    softwareProduct.id
+                }/versions/${version.id}/actions`
+            );
+            expect(data).toEqual({
+                action: VersionControllerActionsEnum.CREATE_PACKAGE
+            });
+            expect(options).toEqual(undefined);
+            return { returnCode: 'OK' };
+        });
 
-		mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
-			expect(baseUrl).toEqual(`/onboarding-api/v1.0/items/${softwareProduct.id}/versions/${version.id}`);
-			expect(data).toEqual(undefined);
-			expect(options).toEqual(undefined);
-			return {...certifiedVersion, state: {synchronizationState: SyncStates.UP_TO_DATE, dirty: false}};
-		});
+        mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
+            expect(baseUrl).toEqual(
+                `/onboarding-api/v1.0/items/${softwareProduct.id}/versions/${
+                    version.id
+                }`
+            );
+            expect(data).toEqual(undefined);
+            expect(options).toEqual(undefined);
+            return {
+                ...certifiedVersion,
+                state: {
+                    synchronizationState: SyncStates.UP_TO_DATE,
+                    dirty: false
+                }
+            };
+        });
 
-		mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
-			expect(baseUrl).toEqual(`/onboarding-api/v1.0/items/${softwareProduct.id}/versions`);
-			expect(data).toEqual(undefined);
-			expect(options).toEqual(undefined);
-			return {results: [{...certifiedVersion}]};
-		});
+        mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
+            expect(baseUrl).toEqual(
+                `/onboarding-api/v1.0/items/${softwareProduct.id}`
+            );
+            expect(data).toEqual(undefined);
+            expect(options).toEqual(undefined);
+            return { ...certifiedVersion };
+        });
 
-		return SoftwareProductActionHelper.performSubmitAction(store.dispatch, {
-			softwareProductId: softwareProduct.id,
-			version
-		}).then(() => {
-			expect(store.getState()).toEqual(expectedStore);
-		});
-	});
-});
\ No newline at end of file
+        mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
+            expect(baseUrl).toEqual(
+                `/onboarding-api/v1.0/items/${softwareProduct.id}/versions`
+            );
+            expect(data).toEqual(undefined);
+            expect(options).toEqual(undefined);
+            return { results: [{ ...certifiedVersion }] };
+        });
+
+        return SoftwareProductActionHelper.performSubmitAction(store.dispatch, {
+            softwareProductId: softwareProduct.id,
+            version
+        }).then(() => {
+            expect(store.getState()).toEqual(expectedStore);
+        });
+    });
+});
