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);
+        });
+    });
 });
