From 4fbdb8cd698be40027ab6b3bca0a62b6cee167c7 Mon Sep 17 00:00:00 2001 From: Arundathi Patil Date: Mon, 23 Jul 2018 17:20:53 +0530 Subject: wrote test case for mapping-editor service Wrote unit test cases for mapping-editor service. The covarage for this file is now 75.96% Issue-ID: APPC-1064 Change-Id: I4c413a076dd6194da9a19481c0fdc42f0ffe5789 Signed-off-by: Arundathi Patil --- .../shared/services/mapping-editor.service.spec.ts | 197 ++++++++++++++++++++- 1 file changed, 196 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/app/shared/services/mapping-editor.service.spec.ts b/src/app/shared/services/mapping-editor.service.spec.ts index 7659e4e..d7d042d 100644 --- a/src/app/shared/services/mapping-editor.service.spec.ts +++ b/src/app/shared/services/mapping-editor.service.spec.ts @@ -21,13 +21,86 @@ limitations under the License. */ import { inject, TestBed, ComponentFixture } from '@angular/core/testing'; +import { By, BrowserModule } from '@angular/platform-browser'; +import { Component, OnInit, ViewChild, Input, NO_ERRORS_SCHEMA } from '@angular/core'; import { MappingEditorService } from './mapping-editor.service'; +import { GoldenConfigurationComponent } from '../../vnfs/build-artifacts/template-holder/template-configuration/template-configuration.component'; +import { ArtifactRequest } from '../../shared/models/index'; +import { UtilityService } from '../../shared/services/utilityService/utility.service'; +import { ActivatedRoute, Router } from "@angular/router"; +import { NgxSpinnerService } from 'ngx-spinner'; +import { saveAs } from "file-saver"; +import { NotificationService } from '../../shared/services/notification.service'; +import { HttpUtilService } from '../../shared/services/httpUtil/http-util.service'; +import { NotificationsService } from "angular2-notifications" +import { ParamShareService } from '../../shared/services/paramShare.service'; +import { DialogService } from "ng2-bootstrap-modal"; +import { ConfirmComponent } from '../../shared/confirmModal/confirm.component'; +import { BuildDesignComponent } from '../../vnfs/build-artifacts/build-artifacts.component'; +import { ModalComponent } from 'ng2-bs3-modal/ng2-bs3-modal' +import { FormsModule } from '@angular/forms'; +import { RouterTestingModule } from '@angular/router/testing'; +import { HomeComponent } from '../../home/home/home.component'; +import { LogoutComponent } from '../../shared/components/logout/logout.component'; +import { HelpComponent } from '../../shared/components/help/help/help.component'; +import { AboutUsComponent } from '../../about-us/aboutus.component'; +import { TestComponent } from '../../test/test.component'; +import { HttpModule } from '@angular/http'; +import { AceEditorComponent } from 'ng2-ace-editor'; +import { Ng2Bs3ModalModule } from 'ng2-bs3-modal/ng2-bs3-modal'; +import { SimpleNotificationsModule } from 'angular2-notifications'; +import { NgProgress } from 'ngx-progressbar'; +import { BaseRequestOptions, Response, ResponseOptions, Http } from '@angular/http'; +import { MockBackend, MockConnection } from '@angular/http/testing'; + describe('MappingEditorService', () => { let service; + let component: GoldenConfigurationComponent; + let fixture: ComponentFixture; + let httpUtil: HttpUtilService; + const routes = [ + { + path: 'home', + component: HomeComponent + }, { + path: 'vnfs', + loadChildren: '../../../../vnfs/vnfs.module#VnfsModule' + }, { + path: 'test', + component: TestComponent + }, + { + path: 'help', + component: HelpComponent + }, { + path: 'aboutUs', + component: AboutUsComponent + }, { + path: 'logout', + component: LogoutComponent + }, { + path: '', + redirectTo: '/home', + pathMatch: 'full' + } + ]; beforeEach(() => { TestBed.configureTestingModule({ - providers: [MappingEditorService] + imports: [FormsModule, BrowserModule, RouterTestingModule.withRoutes(routes), HttpModule, Ng2Bs3ModalModule, SimpleNotificationsModule.forRoot()], + declarations: [GoldenConfigurationComponent, HomeComponent, TestComponent, HelpComponent, AboutUsComponent, LogoutComponent, AceEditorComponent], + providers: [MappingEditorService, BuildDesignComponent, NgProgress, ParamShareService, DialogService, NotificationService, NgxSpinnerService, MockBackend, + BaseRequestOptions, UtilityService, + { + provide: Http, + useFactory: (backend: MockBackend, defaultOptions: BaseRequestOptions) => { + return new Http(backend, defaultOptions); + }, + deps: [MockBackend, BaseRequestOptions], + }, + HttpUtilService, MappingEditorService, NotificationsService], + schemas: [NO_ERRORS_SCHEMA] + // providers: [MappingEditorService] }); }); @@ -108,4 +181,126 @@ describe('MappingEditorService', () => { let toAdd = service.checkToDataAdd('.'); expect(toAdd).toBe(false); }); + + it('should test getStartBeforeAfterSelection function', () => { + let selection = { start: { column: 12 }, end: { column: 12 } }; + let beforeCOunt = 2; + let afterCount = 4; + + expect(service.getStartBeforeAfterSelection(selection, beforeCOunt, afterCount)).toEqual({ start: { column: 10 }, end: { column: 16 } }); + }); + + it('should test autoAnnotateDataForParams function', () => { + fixture = TestBed.createComponent(GoldenConfigurationComponent); + component = fixture.componentInstance; + component.configMappingEditorContent = "\n 15.1X49-D50.3\n \n node0\n \n \n ${sync_auto-pop_name1}\n ${sync_auto-pop_address1}\n \n \n ${node0_tacplus_server_name2}\n ${sync_auto-pop_address1}\n \n \n \n "; + + localStorage["paramsContent"] = JSON.stringify({ "sync_auto-pop_name1": "10.0.1.34", "sync_auto-pop_address1": "", "node0_tacplus_server_name2": "192.34.45.5" }); + service.initialise(component.templateeditor.getEditor(), component.configMappingEditorContent, component.modal); + service.autoAnnotateDataForParams(); + + }); + + it('should test checkApplied function', () => { + fixture = TestBed.createComponent(GoldenConfigurationComponent); + component = fixture.componentInstance; + component.configMappingEditorContent = "\n 15.1X49-D50.3\n \n node0\n \n \n ${sync_auto-pop_name1}\n ${sync_auto-pop_address1}\n \n \n ${node0_tacplus_server_name2}\n ${sync_auto-pop_address1}\n \n \n \n "; + service.initialise(component.templateeditor.getEditor(), component.configMappingEditorContent, component.modal); + service.checkApplied({ start: { column: 12 }, end: { column: 12 } }); + }); + + it('should test checkComments function', () => { + fixture = TestBed.createComponent(GoldenConfigurationComponent); + component = fixture.componentInstance; + component.configMappingEditorContent = "\n 15.1X49-D50.3\n \n node0\n \n \n ${sync_auto-pop_name1}\n ${sync_auto-pop_address1}\n \n \n ${node0_tacplus_server_name2}\n ${sync_auto-pop_address1}\n \n \n \n "; + service.initialise(component.templateeditor.getEditor(), component.configMappingEditorContent, component.modal); + service.checkComments({ start: { column: 12 }, end: { column: 12 } }); + }); + + it('should test checkDelimiters function', () => { + fixture = TestBed.createComponent(GoldenConfigurationComponent); + component = fixture.componentInstance; + component.configMappingEditorContent = "\n 15.1X49-D50.3\n \n node0\n \n \n ${sync_auto-pop_name1}\n ${sync_auto-pop_address1}\n \n \n ${node0_tacplus_server_name2}\n ${sync_auto-pop_address1}\n \n \n \n "; + service.initialise(component.templateeditor.getEditor(), component.configMappingEditorContent, component.modal); + service.checkDelimiters({ start: { column: 12 }, end: { column: 12 } }); + }); + + it('should test checkAppliedForNamesOnly function', () => { + fixture = TestBed.createComponent(GoldenConfigurationComponent); + component = fixture.componentInstance; + component.configMappingEditorContent = "\n 15.1X49-D50.3\n \n node0\n \n \n ${sync_auto-pop_name1}\n ${sync_auto-pop_address1}\n \n \n ${node0_tacplus_server_name2}\n ${sync_auto-pop_address1}\n \n \n \n "; + service.initialise(component.templateeditor.getEditor(), component.configMappingEditorContent, component.modal); + service.checkAppliedForNamesOnly({ start: { column: 12 }, end: { column: 12 } }); + }); + + it('should test checkToDataAddForJson function', () => { + fixture = TestBed.createComponent(GoldenConfigurationComponent); + component = fixture.componentInstance; + component.configMappingEditorContent = "\n 15.1X49-D50.3\n \n node0\n \n \n ${sync_auto-pop_name1}\n ${sync_auto-pop_address1}\n \n \n ${node0_tacplus_server_name2}\n ${sync_auto-pop_address1}\n \n \n \n "; + service.initialise(component.templateeditor.getEditor(), component.configMappingEditorContent, component.modal); + expect(service.checkToDataAddForJson("dsjfds")).toEqual(true); + }); + + + it('should test replaceNamesWithBlankValues function', () => { + fixture = TestBed.createComponent(GoldenConfigurationComponent); + component = fixture.componentInstance; + component.configMappingEditorContent = "\n 15.1X49-D50.3\n \n node0\n \n \n ${sync_auto-pop_name1}\n ${sync_auto-pop_address1}\n \n \n ${node0_tacplus_server_name2}\n ${sync_auto-pop_address1}\n \n \n \n "; + service.initialise(component.templateeditor.getEditor(), component.configMappingEditorContent, component.modal); + service.replaceNamesWithBlankValues(); + }); + + + it('should test autoAnnotateTemplateForParam function', () => { + fixture = TestBed.createComponent(GoldenConfigurationComponent); + component = fixture.componentInstance; + component.configMappingEditorContent = "\n 15.1X49-D50.3\n \n node0\n \n \n ${sync_auto-pop_name1}\n ${sync_auto-pop_address1}\n \n \n ${node0_tacplus_server_name2}\n ${sync_auto-pop_address1}\n \n \n \n "; + service.initialise(component.templateeditor.getEditor(), component.configMappingEditorContent, component.modal); + service.autoAnnotateTemplateForParam(); + }); + + it('should test generateTemplate function', () => { + fixture = TestBed.createComponent(GoldenConfigurationComponent); + component = fixture.componentInstance; + component.configMappingEditorContent = "\n 15.1X49-D50.3\n \n node0\n \n \n ${sync_auto-pop_name1}\n ${sync_auto-pop_address1}\n \n \n ${node0_tacplus_server_name2}\n ${sync_auto-pop_address1}\n \n \n \n "; + service.initialise(component.templateeditor.getEditor(), component.configMappingEditorContent, component.modal); + service.generateTemplate(component.templateeditor.getEditor()); + }); + + it('should test generateParams function', () => { + fixture = TestBed.createComponent(GoldenConfigurationComponent); + component = fixture.componentInstance; + component.configMappingEditorContent = "\n 15.1X49-D50.3\n \n node0\n \n \n ${sync_auto-pop_name1}\n ${sync_auto-pop_address1}\n \n \n ${node0_tacplus_server_name2}\n ${sync_auto-pop_address1}\n \n \n \n "; + service.initialise(component.templateeditor.getEditor(), component.configMappingEditorContent, component.modal); + service.generateParams(component.templateeditor.getEditor(), component.templateeditor.getEditor()); + }); + + it('should test removeTheSelectedMarkers function', () => { + service.initialise(component.templateeditor.getEditor(), component.configMappingEditorContent, component.modal); + service.removeTheSelectedMarkers(); + }); + + + it('should test getsaveMarkers function', () => { + service.initialise(component.templateeditor.getEditor(), component.configMappingEditorContent, component.modal); + service.getsaveMarkers(); + }); + + it('should test getTemplateMappingDataFromStore function', () => { + service.getTemplateMappingDataFromStore(); + }); + + it('should test setTemplateMappingDataFromStore function', () => { + service.setTemplateMappingDataFromStore({ data: 'data' }); + }); + + it('should test setReferenceList function', () => { + service.setReferenceList(); + }); + + it('should test getReferenceList function', () => { + service.getReferenceList(); + }); + }); + -- cgit 1.2.3-korg