aboutsummaryrefslogtreecommitdiffstats
path: root/src/app/shared
diff options
context:
space:
mode:
authorsj108s <sj108s@us.att.com>2018-03-13 20:29:58 +0530
committersj108s <sj108s@us.att.com>2018-03-13 20:30:50 +0530
commitf1e61ce405cf11ea77fe98abd5e10f7ed2d72611 (patch)
tree0d6f464a3c8e275b2b74359f81282aaf589074fe /src/app/shared
parent8ac6f161c2260e48a743df82e57b4ba24ce9795c (diff)
Fixed defects in test screen & updated test cases
Fixed few defects raised by ST in test screen and also updated test cases to improve coverage. Also,changed code to match onap standards, and rectfied grep code violations. Issue-ID: APPC-730 Change-Id: I0286c38eb4f76dc8c0253a4ccab721b3ccfeff9d Signed-off-by: sj108s <sj108s@us.att.com>
Diffstat (limited to 'src/app/shared')
-rw-r--r--src/app/shared/components/navigation/navigation.component.spec.ts91
-rw-r--r--src/app/shared/directives/collapse.component.spec.ts31
-rw-r--r--src/app/shared/directives/drop-down-toggle.directive.spec.ts22
-rw-r--r--src/app/shared/directives/dropdown.spec.ts15
-rw-r--r--src/app/shared/directives/dropdownnotclosablezone.spec.ts52
-rw-r--r--src/app/shared/directives/dropdownopen.spec.ts51
-rw-r--r--src/app/shared/modules/tidy-table/order-by.pipe.spec.ts36
-rw-r--r--src/app/shared/modules/tidy-table/table-filter.pipe.spec.ts11
-rw-r--r--src/app/shared/pipes/vm-filtering.pipe.spec.ts49
-rw-r--r--src/app/shared/pipes/vm-filtering.pipe.ts42
-rw-r--r--src/app/shared/services/emitter.service.spec.ts9
-rw-r--r--src/app/shared/services/mapping-editor.service.ts105
-rw-r--r--src/app/shared/services/utilityService/utility.service.spec.ts12
13 files changed, 401 insertions, 125 deletions
diff --git a/src/app/shared/components/navigation/navigation.component.spec.ts b/src/app/shared/components/navigation/navigation.component.spec.ts
index c5a436b..9516e3d 100644
--- a/src/app/shared/components/navigation/navigation.component.spec.ts
+++ b/src/app/shared/components/navigation/navigation.component.spec.ts
@@ -21,11 +21,27 @@ ECOMP is a trademark and service mark of AT&T Intellectual Property.
============LICENSE_END============================================
*/
+import { async, ComponentFixture, TestBed, fakeAsync, tick, inject } from '@angular/core/testing';
+import { RouterTestingModule } from "@angular/router/testing";
+import { Router, ActivatedRoute } from "@angular/router";
+import { Observable } from 'rxjs/Observable';
+import 'rxjs/add/observable/empty';
+import {DialogService} from 'ng2-bootstrap-modal';
+import {FormsModule} from '@angular/forms';
+import {HttpModule} from '@angular/http';
+import {HttpUtilService} from '../../../shared/services/httpUtil/http-util.service';
+import {MappingEditorService} from '../../..//shared/services/mapping-editor.service';
+import {NO_ERRORS_SCHEMA} from '@angular/core';
+import {NgModule} from '@angular/core';
+import {NgProgress} from 'ngx-progressbar';
+import {NgbModule} from '@ng-bootstrap/ng-bootstrap';
+import {NotificationService} from '../../../shared/services/notification.service';
+import {ParamShareService} from '../../..//shared/services/paramShare.service';
+import {SharedModule} from '../../../shared/shared.module';
+import {environment} from '../../../../environments/environment';
-/* tslint:disable:no-unused-variable */
-import {async, ComponentFixture, TestBed} from '@angular/core/testing';
-
-import {NavigationComponent} from './navigation.component';
+import { NavigationComponent } from './navigation.component';
+import { EmitterService } from '../../services/emitter.service';
describe('NavigationComponent', () => {
let component: NavigationComponent;
@@ -33,7 +49,9 @@ describe('NavigationComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
- declarations: [NavigationComponent]
+ declarations: [NavigationComponent],
+ imports: [RouterTestingModule.withRoutes([]),FormsModule, RouterTestingModule, HttpModule, NgbModule.forRoot()],
+ providers: []
})
.compileComponents();
}));
@@ -47,4 +65,67 @@ describe('NavigationComponent', () => {
it('should create', () => {
expect(component).toBeTruthy();
});
+
+ it('should set userLoggedIn on ngOnInit', () => {
+ component.userId = 'testingId';
+
+ component.ngOnInit();
+ });
+
+ it('should validate on ngOnChanges', () => {
+ let spy = spyOn(EmitterService, 'get').and.callFake( ({}) => {
+ return Observable.empty();
+ });
+ component.id = 'userLogin';
+
+ component.ngOnChanges();
+
+ expect(spy).toHaveBeenCalled();
+ });
+
+ it('should go to /vnfs/list if url = vnfs and userId is not null or undefined', inject([Router],(router: Router) => {
+ let navigateSpy = spyOn(router, 'navigate');
+ localStorage['userId'] = 'testingId';
+ let testUrl = 'vnfs';
+
+ component.gotoDetail(testUrl);
+ }));
+
+ it('should go to /vnfs if url = vnfs and userId is null or undefined', inject([Router],(router: Router) => {
+ let navigateSpy = spyOn(router, 'navigate');
+ localStorage['userId'] = '';
+ let testUrl = 'vnfs';
+
+ component.gotoDetail(testUrl);
+ }));
+
+ it('should go to passed url if url != vnfs', inject([Router],(router: Router) => {
+ let navigateSpy = spyOn(router, 'navigate');
+ let testUrl = 'test';
+
+ component.gotoDetail(testUrl);
+ }));
+
+ it('should logout', inject([Router],(router: Router) => {
+ let navigateSpy = spyOn(router, 'navigate');
+
+ component.logout();
+ }));
+ it('should ngOnChanges', () => {
+ component.id="uday"
+ component.ngOnChanges()
+ expect(component.userLoggedIn).toBeFalsy();
+ });
+ it('should ngOnInit()', () => {
+ localStorage['userId']="uday"
+ component.ngOnInit()
+ expect(component.userLoggedIn).toBeTruthy();
+ });
+ it('should gotoDetail(url)', () => {
+ component.gotoDetail('vnfs')
+ });
+ it('should logout()', () => {
+ component.logout()
+ expect(component.userLoggedIn).toBeFalsy();
+ });
});
diff --git a/src/app/shared/directives/collapse.component.spec.ts b/src/app/shared/directives/collapse.component.spec.ts
new file mode 100644
index 0000000..0d234d7
--- /dev/null
+++ b/src/app/shared/directives/collapse.component.spec.ts
@@ -0,0 +1,31 @@
+import { Collapse } from './collapse.component';
+import { ElementRef } from '@angular/core';
+
+
+describe('CollapseComponent', () => {
+ let directive;
+
+ beforeEach(() => {
+ directive = new Collapse();
+ });
+
+ it('should create an instance', () => {
+ expect(directive).toBeTruthy();
+ });
+
+ describe('should toggle', () => {
+ it('should call hide() if isExpanded is true', () => {
+ directive.isExpanded = true;
+
+ directive.toggle();
+ });
+
+ it('should call show() if isExpanded is false', () => {
+ directive.isExpanded = false;
+
+ directive.toggle();
+ });
+
+
+ });
+}); \ No newline at end of file
diff --git a/src/app/shared/directives/drop-down-toggle.directive.spec.ts b/src/app/shared/directives/drop-down-toggle.directive.spec.ts
index b08d334..81b08c8 100644
--- a/src/app/shared/directives/drop-down-toggle.directive.spec.ts
+++ b/src/app/shared/directives/drop-down-toggle.directive.spec.ts
@@ -21,16 +21,26 @@ ECOMP is a trademark and service mark of AT&T Intellectual Property.
============LICENSE_END============================================
*/
+import { TestBed } from '@angular/core/testing';
+import { DropDownToggleDirective } from './drop-down-toggle.directive';
+import { ElementRef } from '@angular/core';
-/* tslint:disable:no-unused-variable */
-import {DropDownToggleDirective} from './drop-down-toggle.directive';
-import {ElementRef} from '@angular/core';
+describe('DropDownToggleDirective', () => {
+ let directive;
+ beforeEach(() => {
+ TestBed.configureTestingModule({
+ declarations: [DropDownToggleDirective]
+ });
+ });
+ beforeEach(() => {
+ directive = new DropDownToggleDirective(new ElementRef(''));
+ });
-describe('DropDownToggleDirective', () => {
it('should create an instance', () => {
- const directive = new DropDownToggleDirective(new ElementRef(''));
- expect(directive).toBeTruthy();
+ let el: HTMLElement;
+ directive.type = 'dropdown';
+ expect(directive).toBeTruthy();
});
});
diff --git a/src/app/shared/directives/dropdown.spec.ts b/src/app/shared/directives/dropdown.spec.ts
index 2dbebd2..1aedfa5 100644
--- a/src/app/shared/directives/dropdown.spec.ts
+++ b/src/app/shared/directives/dropdown.spec.ts
@@ -24,15 +24,22 @@ ECOMP is a trademark and service mark of AT&T Intellectual Property.
/* tslint:disable:no-unused-variable */
-import {Dropdown} from './dropdown';
-import {ElementRef} from '@angular/core';
+import { Dropdown } from './dropdown';
+import { ElementRef } from '@angular/core';
describe('DropDown', () => {
+ let directive;
+
+ beforeEach(() => {
+ directive = new Dropdown(new ElementRef('<dropdown></dropdown>'));
+ });
it('should create an instance', () => {
- const directive = new Dropdown(new ElementRef('<dropdown></dropdown>'));
expect(directive).toBeTruthy();
});
-
+ it('should test open method', () => {
+ let elementRef: ElementRef;
+ console.log(directive);
+ });
});
diff --git a/src/app/shared/directives/dropdownnotclosablezone.spec.ts b/src/app/shared/directives/dropdownnotclosablezone.spec.ts
new file mode 100644
index 0000000..e397f83
--- /dev/null
+++ b/src/app/shared/directives/dropdownnotclosablezone.spec.ts
@@ -0,0 +1,52 @@
+/*
+============LICENSE_START==========================================
+===================================================================
+Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+===================================================================
+
+Unless otherwise specified, all software contained herein is licensed
+under the Apache License, Version 2.0 (the License);
+you may not use this software except in compliance with the License.
+You may obtain a copy of the License at
+
+ 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.
+
+ECOMP is a trademark and service mark of AT&T Intellectual Property.
+============LICENSE_END============================================
+*/
+
+import { TestBed } from '@angular/core/testing';
+import { DropdownNotClosableZone } from './dropdownnotclosablezone';
+import { ElementRef } from '@angular/core';
+
+
+describe('DropdownNotClosableZone', () => {
+ let directive;
+ beforeEach(() => {
+ TestBed.configureTestingModule({
+ declarations: [DropdownNotClosableZone]
+ });
+ });
+
+ beforeEach(() => {
+ directive = new DropdownNotClosableZone(new ElementRef('<dropdown-not-closable-zone></dropdown-not-closable-zone>'));
+ });
+
+ it('should create an instance', () => {
+
+ expect(directive).toBeTruthy();
+ });
+
+ it('should test contain method', () => {
+ let el: HTMLElement;
+ let dropdownNotClosabledZone = false;
+
+
+ });
+});
diff --git a/src/app/shared/directives/dropdownopen.spec.ts b/src/app/shared/directives/dropdownopen.spec.ts
new file mode 100644
index 0000000..b7a7aa6
--- /dev/null
+++ b/src/app/shared/directives/dropdownopen.spec.ts
@@ -0,0 +1,51 @@
+import { DropdownOpen } from './dropdownopen';
+import { Dropdown } from './dropdown';
+import { ElementRef, Host, HostListener } from '@angular/core';
+import { async, TestBed, inject } from '@angular/core/testing';
+
+
+describe('DropdownOpen', () => {
+ let directive;
+ let dropdown = new Dropdown(new ElementRef(''));
+
+ beforeEach(() => {
+ directive = new DropdownOpen(dropdown, new ElementRef(''));
+ });
+
+ it('should create an instance', () => {
+ expect(directive).toBeTruthy();
+ });
+
+ describe('should validate on Host click event', () => {
+ it('should validate openDropdown method if activateOnFocus, openedByFocus are true', () => {
+ let event = new Event('click');
+ let dispatchEvent = window.dispatchEvent(event);
+ dropdown.activateOnFocus = true;
+ directive.openedByFocus = true;
+
+ directive.openDropdown();
+ });
+
+ it('should validate openDropdown method if dropdown.isOpened(), dropdown.toggleClick false', () => {
+ });
+ });
+
+ it('should validate on Host keydown event', () => {
+ let spy = spyOn(directive, 'openDropdown')
+ var event = new KeyboardEvent("keydown");
+
+ Object.defineProperty(event, "keyCode", {"value" : 40})
+
+ directive.dropdownKeydown(event);
+
+ expect(spy).toHaveBeenCalled()
+ });
+
+ it('should validate on Host focus event', () => {
+
+ dropdown.activateOnFocus = false;
+
+ directive.onFocus();
+
+ });
+}); \ No newline at end of file
diff --git a/src/app/shared/modules/tidy-table/order-by.pipe.spec.ts b/src/app/shared/modules/tidy-table/order-by.pipe.spec.ts
index 82c57a1..5746fe9 100644
--- a/src/app/shared/modules/tidy-table/order-by.pipe.spec.ts
+++ b/src/app/shared/modules/tidy-table/order-by.pipe.spec.ts
@@ -20,10 +20,6 @@ limitations under the License.
ECOMP is a trademark and service mark of AT&T Intellectual Property.
============LICENSE_END============================================
*/
-
-
-/* tslint:disable:no-unused-variable */
-
import {OrderBy} from './order-by.pipe';
describe('OrderByPipe', () => {
@@ -31,4 +27,36 @@ describe('OrderByPipe', () => {
const pipe = new OrderBy();
expect(pipe).toBeTruthy();
});
+
+ it('ascending sorting', () => {
+ const pipe = new OrderBy();
+
+ let data =[
+ {'vnf-type':'vnf1','vnfc-type':'vnfc1','artifact-name':'artf1'},
+ {'vnf-type':'vnf2','vnfc-type':'vnfc2','artifact-name':'artf2'}
+
+ ]
+ expect(pipe.transform(data,"vnf-type",true)[0]['vnf-type']).toBe('vnf1');
+
+ });
+ it('descending sorting', () => {
+ const pipe = new OrderBy();
+
+ let data =[
+ {'vnf-type':'vnf1','vnfc-type':'vnfc1','artifact-name':'artf1'},
+ {'vnf-type':'vnf2','vnfc-type':'vnfc2','artifact-name':'artf2'}
+
+ ]
+ expect(pipe.transform(data,"vnf-type",false)[0]['vnf-type']).toBe('vnf2');
+ });
+ it('descending sorting', () => {
+ const pipe = new OrderBy();
+
+ let data =[
+ {'vnf-type':undefined,'vnfc-type':'vnfc1','artifact-name':'artf1'},
+ {'vnf-type':'vnf2','vnfc-type':'vnfc2','artifact-name':'artf2'}
+
+ ]
+ expect(pipe.transform(data,"vnf-type",false)[0]['vnf-type']).toBe('vnf2');
+ });
});
diff --git a/src/app/shared/modules/tidy-table/table-filter.pipe.spec.ts b/src/app/shared/modules/tidy-table/table-filter.pipe.spec.ts
index d8fe6c7..5d73a14 100644
--- a/src/app/shared/modules/tidy-table/table-filter.pipe.spec.ts
+++ b/src/app/shared/modules/tidy-table/table-filter.pipe.spec.ts
@@ -31,4 +31,15 @@ describe('TableFilterPipe', () => {
const pipe = new TableFilterPipe();
expect(pipe).toBeTruthy();
});
+ it('filter table based on input ', () => {
+ const pipe = new TableFilterPipe();
+
+ let data =[
+ {'vnf-type':'vnf1','vnfc-type':'vnfc1','artifact-name':'artf1'},
+ {'vnf-type':'vnf2','vnfc-type':'vnfc2','artifact-name':'artf2'}
+
+ ]
+ let filter = ['vnf-type', 'vnfc-type', 'artifact-name'];
+ expect(pipe.transform(data,'vnf1',filter).length).toBe(1);
+ });
});
diff --git a/src/app/shared/pipes/vm-filtering.pipe.spec.ts b/src/app/shared/pipes/vm-filtering.pipe.spec.ts
new file mode 100644
index 0000000..523abfb
--- /dev/null
+++ b/src/app/shared/pipes/vm-filtering.pipe.spec.ts
@@ -0,0 +1,49 @@
+/*
+============LICENSE_START==========================================
+===================================================================
+Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+===================================================================
+
+Unless otherwise specified, all software contained herein is licensed
+under the Apache License, Version 2.0 (the License);
+you may not use this software except in compliance with the License.
+You may obtain a copy of the License at
+
+ 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.
+
+ECOMP is a trademark and service mark of AT&T Intellectual Property.
+============LICENSE_END============================================ */
+import {VmFilteringPipe} from './vm-filtering.pipe';
+
+describe('VmFilteringPipe', () => {
+ it('create an instance', () => {
+ const pipe = new VmFilteringPipe();
+ expect(pipe).toBeTruthy();
+ });
+ it('should return configscaleout values if template id matches',()=>{
+ const pipe = new VmFilteringPipe();
+
+ let objArray = [
+ {action:"Configure","template-id":2,"type":"con"},
+ {action:"ConfigScaleout","template-id":1,"type":"conScale"}
+ ]
+ expect(pipe.transform(objArray,"ConfigScaleOut",1)[0].type).toBe("conScale")
+
+ });
+ it('should return configure calues',()=>{
+ const pipe = new VmFilteringPipe();
+
+ let objArray = [
+ {action:"Configure","template-id":2,"type":"con"},
+ {action:"ConfigScaleout","template-id":1,"type":"conScale"}
+ ]
+ expect(pipe.transform(objArray,"ConfigScaleOut",2)[0].type).toBe("con")
+
+ });
+});
diff --git a/src/app/shared/pipes/vm-filtering.pipe.ts b/src/app/shared/pipes/vm-filtering.pipe.ts
new file mode 100644
index 0000000..c20397b
--- /dev/null
+++ b/src/app/shared/pipes/vm-filtering.pipe.ts
@@ -0,0 +1,42 @@
+/*
+============LICENSE_START==========================================
+===================================================================
+Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+===================================================================
+
+Unless otherwise specified, all software contained herein is licensed
+under the Apache License, Version 2.0 (the License);
+you may not use this software except in compliance with the License.
+You may obtain a copy of the License at
+
+ 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.
+
+ECOMP is a trademark and service mark of AT&T Intellectual Property.
+============LICENSE_END============================================ */
+import {Pipe, PipeTransform} from '@angular/core';
+
+@Pipe({name: 'vmFiltering', pure: false})
+export class VmFilteringPipe implements PipeTransform {
+
+ transform(value: any, action: any, templateId): any {
+
+ if (action == 'ConfigScaleOut') {
+ let x = value.filter(obj => {
+ //return value
+ return obj['template-id'] == templateId;
+ });
+
+ return x;
+ } else {
+ return value;
+
+ }
+ }
+
+}
diff --git a/src/app/shared/services/emitter.service.spec.ts b/src/app/shared/services/emitter.service.spec.ts
index f12154f..6521311 100644
--- a/src/app/shared/services/emitter.service.spec.ts
+++ b/src/app/shared/services/emitter.service.spec.ts
@@ -21,9 +21,6 @@ ECOMP is a trademark and service mark of AT&T Intellectual Property.
============LICENSE_END============================================
*/
-
-/* tslint:disable:no-unused-variable */
-
import {inject, TestBed} from '@angular/core/testing';
import {EmitterService} from './emitter.service';
@@ -37,4 +34,10 @@ describe('EmitterService', () => {
it('should ...', inject([EmitterService], (service: EmitterService) => {
expect(service).toBeTruthy();
}));
+
+ it('should test static get method', () => {
+ let id = 'login';
+
+ EmitterService.get(id);
+ })
});
diff --git a/src/app/shared/services/mapping-editor.service.ts b/src/app/shared/services/mapping-editor.service.ts
index 00ef211..fe70722 100644
--- a/src/app/shared/services/mapping-editor.service.ts
+++ b/src/app/shared/services/mapping-editor.service.ts
@@ -39,7 +39,6 @@ export class MappingEditorService {
paramContent: string = '{}';
KEY_EXPRESSION: string = '\\${\\(.+?\\)}';//new RegExp('${.+?}'); // \${.+?}
- //SYNC_KEY_EXPRESSION: string = '\\${\\)}';
KEY_START: string = '${(';
KEY_MID: string = ')=(';
KEY_END: string = ')}';
@@ -89,19 +88,16 @@ export class MappingEditorService {
changeNav(object) {
this._navItem = object;
- // this._observer.next(object);
this.referenceNameObjects = object;
}
changeNavAppData(object) {
this._navItem = object;
- // this._observer.next(object);
this.appDataObject = object;
}
changeNavDownloadData(object) {
this._navItem = object;
- // this._observer.next(object);
this.downloadDataObject = object;
}
@@ -127,7 +123,7 @@ export class MappingEditorService {
public setParamContent(paramContent: string): void {
this.paramContent = paramContent;
- // localStorage["paramContent"]=paramContent;
+
}
public initialise(editor: any, editorContent: string, modal: any): void {
@@ -144,15 +140,6 @@ export class MappingEditorService {
public initialiseCommands(modal): void {
- /* this.editor.commands.addCommand({
- name: 'annotateCommand',
- bindKey: { win: 'ENTER', mac: 'ENTER' },
- exec: (editor: any) => {
- this.handleAnnotation(modal);
- }
- });*/
-
-
this.editor.commands.addCommand({
name: 'keyCompletionCommand',
bindKey: {win: 'Ctrl-s', mac: 'Command-s'},
@@ -165,7 +152,7 @@ export class MappingEditorService {
name: 'autoAnnotateCommand',
bindKey: {win: 'Ctrl-2', mac: 'Command-2'},
exec: (editor: any) => {
- this.autoAnnotateDataForParams(this.fileType);
+ this.autoAnnotateDataForParams();
}
});
@@ -200,9 +187,8 @@ export class MappingEditorService {
return toAdd;
}
- public autoAnnotateDataForParams(fileType: any): boolean {
+ public autoAnnotateDataForParams(): boolean {
this.paramContent = localStorage['paramsContent'];
- //console.log("Param content=="+ this.paramContent)
var mergeStatus: boolean = false;
if (this.paramContent) {
var paramJson: JSON = JSON.parse(this.paramContent);
@@ -230,51 +216,6 @@ export class MappingEditorService {
return mergeStatus;
}
- /* syncTemplateNames() {
- if (this.paramContent != '{}') {
- var paramJson: JSON = JSON.parse(this.paramContent);
- for (var prop in paramJson) {
- let value: string = paramJson[prop]
- if (value) {
- var occurances = this.editor.findAll(value, { regExp: false });
- var ranges = this.editor.getSelection().getAllRanges();
- if (ranges) {
- for (var r = 0; r < ranges.length; r++) {
- let selectedRange: any = ranges[r];
- let selectedWord: string = this.editor.session.getTextRange(selectedRange);
- let prefixSuffixselectedWord: string = this.editor.session.getTextRange(this.getStartBeforeAfterSelection(selectedRange, 1, 1));
- if (selectedWord && this.checkApplied(selectedRange)) {
- let replaceWord: any = this.KEY_START + selectedWord + this.KEY_MID + prop + this.KEY_END;
- this.editor.session.replace(selectedRange, replaceWord);
- }
- }
- }
- }
- }
- for (var prop in paramJson) {
- var occurances = this.editor.findAll(prop, { regExp: false });
- var ranges = this.editor.getSelection().getAllRanges();
- if (ranges) {
- for (var r = 0; r < ranges.length; r++) {
- let selectedRange: any = ranges[r];
- let selectedWord: string = this.editor.session.getTextRange(selectedRange);
- if (selectedWord && this.checkApplied(selectedRange)) {
- let replaceWord: any = '(' + paramJson[prop] + this.KEY_MID + selectedWord + ')';
- this.editor.session.replace(selectedRange, replaceWord);
- }
- }
- }
- else {
- this.replaceNamesWithBlankValues();
- }
- }
- }
- else {
- this.replaceNamesWithBlankValues()
- }
- }*/
-
-
checkComments(selectedRange: any) {
var tempStartColumn = selectedRange.start.column;
var result = false;
@@ -394,35 +335,14 @@ export class MappingEditorService {
this.refreshEditor();
}
- /* public handleAnnotation(modal): void {
- let selectedWord: string = this.editor.session.getTextRange(this.editor.selectionRange);
- this.setSelectedWord(selectedWord);
- modal.open();
-
- /* let selectedWord: string = this.editor.session.getTextRange(this.editor.selectionRange);
- if (selectedWord) {
- if (selectedWord.startsWith('${(')) {
- var replaceWord = selectedWord.substring(3, selectedWord.indexOf(')=('));
- this.editor.session.replace(this.editor.session.selection.getRange(), replaceWord);
- } else {
- let mappingKey = this.getKeysForValues(selectedWord);
- var replaceWord = '${(' + selectedWord + ')=()}';
- this.editor.session.replace(this.editor.session.selection.getRange(), replaceWord);
- }
- }
- this.refreshEditor();
- }*/
-
public checkMethodCall(modal): void {
-//this.handleAnnotation(modal)
+ //this.handleAnnotation(modal)
}
public refreshEditor(): void {
if (this.editor) {
- // this.replaceNamesWithBlankValues();
var occurances = this.editor.findAll(this.KEY_EXPRESSION, {regExp: true});
- //console.log("Occurances from save" + occurances)
var ranges = this.editor.getSelection().getAllRanges();
if (ranges) {
this.refreshParams(ranges);
@@ -435,8 +355,7 @@ export class MappingEditorService {
}
this.refreshMarker();
}
- // console.log("Param data from refresh editor=="+this.paramData)
-
+
}
replaceNamesWithBlankValues() {
@@ -446,23 +365,19 @@ export class MappingEditorService {
if (ranges) {
for (var r = 0; r < ranges.length; r++) {
let selectedRange: any = ranges[r];
- // console.log("Selected range == " + selectedRange)
let selectedWord: string = this.editor.session.getTextRange(selectedRange);
let specialKeys = (selectedWord.substring(2, selectedWord.length - 1)).match(this.checkSpecialCharsReg);
- // console.log("Selected word == " + selectedWord.length)
- //if (!selectedWord.startsWith('<') || !selectedWord.startsWith('{')) {
if (selectedWord && this.checkAppliedForNamesOnly(selectedRange) && !specialKeys) {
let replaceWord: any = this.KEY_START + '' + this.KEY_MID + selectedWord.substring(2, selectedWord.length - 1) + this.KEY_END;
this.editor.session.replace(selectedRange, replaceWord);
}
- // }
+
}
}
}
}
public refreshParams(ranges: any): void {
- // console.log("This param content==="+ this.paramContent);
var paramData = [];
if (this.paramContent === undefined) this.paramContent = '{}';
if (this.editor && ranges) {
@@ -470,17 +385,12 @@ export class MappingEditorService {
this.hasErrorCode = false;
for (var r = 0; r < ranges.length; r++) {
let keyValue: string = this.editor.session.getTextRange(ranges[r]);
- //console.log("keyValues==="+keyValue)
if (keyValue && keyValue.startsWith(this.KEY_START) && keyValue.endsWith(this.KEY_END) && keyValue.includes(this.KEY_MID)) {
let key: string = keyValue.substring(keyValue.indexOf(this.KEY_MID) + this.KEY_MID_LENGTH, keyValue.indexOf(this.KEY_END));
let value: string = keyValue.substring(this.KEY_START_LENGTH, keyValue.indexOf(this.KEY_MID));
let specialKeys = key.match(this.checkSpecialCharsReg);
- //console.log("Special keys=="+specialKeys)
- //console.log("Keys=="+key+",values=="+value);
if (specialKeys && specialKeys.length) {
- // this.paramData = [];
- // this.hasErrorCode = true;
- // break;
+
} else {
if (this.fromScreen === 'TemplateScreen') {
if (key) {
@@ -506,7 +416,6 @@ export class MappingEditorService {
}
}
}
- // console.log("Param data=="+ JSON.stringify(paramData))
this.paramData = paramData;
this.paramContent = JSON.stringify(paramJson);
diff --git a/src/app/shared/services/utilityService/utility.service.spec.ts b/src/app/shared/services/utilityService/utility.service.spec.ts
index c11927a..85b4818 100644
--- a/src/app/shared/services/utilityService/utility.service.spec.ts
+++ b/src/app/shared/services/utilityService/utility.service.spec.ts
@@ -21,9 +21,6 @@ ECOMP is a trademark and service mark of AT&T Intellectual Property.
============LICENSE_END============================================
*/
-
-/* tslint:disable:no-unused-variable */
-
import {inject, TestBed} from '@angular/core/testing';
import {UtilityService} from './utility.service';
import {NotificationsService} from 'angular2-notifications';
@@ -39,11 +36,16 @@ describe('UtilityService', () => {
expect(service).toBeTruthy();
}));
+ it('should generate random id', inject([UtilityService],(service: UtilityService) => {
+ let ret = service.randomId();
+
+ expect(ret).not.toBeNull();
+ }));
it('should apply slashes for a string...', inject([UtilityService], (service: UtilityService) => {
- let text = {'vnf-host-ip-address': '135.21.166.36'};
+ let text = {'vnf-host-ip-address': 'testidaddress'};
- expect(service.appendSlashes(JSON.stringify(text))).toEqual('{\\"vnf-host-ip-address\\":\\"135.21.166.36\\"}');
+ expect(service.appendSlashes(JSON.stringify(text))).toEqual('{\\"vnf-host-ip-address\\":\\"testidaddress\\"}');
}));