From 00c22d16c29c85aca48e9cce2ea2261339dadf7d Mon Sep 17 00:00:00 2001 From: Indrijeet kumar Date: Wed, 1 Apr 2020 21:27:39 +0530 Subject: test cases written for new-menu component test cases written for new-menu component Issue-ID: PORTAL-813 Change-Id: I864be7bcb70f38badb0afb306439bc2b3e155b68 Signed-off-by: Indrijeet Kumar --- .../menus/new-menu/new-menu.component.spec.ts | 141 +++++++++++---------- 1 file changed, 73 insertions(+), 68 deletions(-) diff --git a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/pages/admin/menus/new-menu/new-menu.component.spec.ts b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/pages/admin/menus/new-menu/new-menu.component.spec.ts index 7ddaf632..5c22346e 100644 --- a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/pages/admin/menus/new-menu/new-menu.component.spec.ts +++ b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/pages/admin/menus/new-menu/new-menu.component.spec.ts @@ -46,35 +46,42 @@ import { HttpClientTestingModule } from '@angular/common/http/testing'; import { NgbActiveModal, NgbModalModule } from '@ng-bootstrap/ng-bootstrap'; import { RouterTestingModule } from '@angular/router/testing'; import { CookieService } from 'ngx-cookie-service'; -import { MockBackend } from '@angular/http/testing'; -import { BaseRequestOptions, Http } from '@angular/http'; import { AdminService } from '../../admin.service'; import 'rxjs/add/operator/toPromise'; import { ConfirmationModalComponent } from 'src/app/modals/confirmation-modal/confirmation-modal.component'; import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; -import { MaterialModule } from 'portalsdk-tag-lib/material-module'; import 'rxjs/add/observable/of'; import { Observable } from 'rxjs/Observable'; +import 'rxjs/add/operator/catch'; +import 'rxjs/add/observable/throw'; +import { BrowserDynamicTestingModule } from '@angular/platform-browser-dynamic/testing'; describe('NewMenuComponent', () => { let component: NewMenuComponent; let fixture: ComponentFixture; let adminService:AdminService; - // let entryComponents:any; beforeEach(async(() => { TestBed.configureTestingModule({ - declarations: [ NewMenuComponent ], - imports:[FormsModule, HttpClientTestingModule,RouterTestingModule,NgbModalModule,BrowserAnimationsModule], - providers:[AdminService,NgbActiveModal,CookieService,MockBackend,BaseRequestOptions,{ - provide:Http, - useFactory:(backend:MockBackend,defaultOptions:BaseRequestOptions)=>{ - return new Http(backend,defaultOptions); - }, - deps:[MockBackend,BaseRequestOptions], - entryComponents:[ConfirmationModalComponent] - }], + declarations: [ NewMenuComponent,ConfirmationModalComponent ], + imports:[ + FormsModule, + HttpClientTestingModule, + RouterTestingModule, + NgbModalModule, + BrowserAnimationsModule + ], + providers:[ + AdminService, + NgbActiveModal, + CookieService + ], + }) + TestBed.overrideModule(BrowserDynamicTestingModule,{ + set:{ + entryComponents:[ConfirmationModalComponent ] + } }) .compileComponents(); @@ -87,57 +94,55 @@ describe('NewMenuComponent', () => { adminService=TestBed.get(AdminService); }); -// // it('should create', () => { -// // expect(component).toBeTruthy(); -// // }); - -// it('testing ngOnInit method for if condition',()=>{ -// component.selectedMenu=1; -// component.ngOnInit(); -// expect(component.menu).toEqual(component.selectedMenu); -// }) - -// it('testing ngOnInit method for else condition',()=>{ -// component.selectedMenu=0; -// component.ngOnInit(); -// expect(component.menu.menuSetCode).toEqual('APP'); -// }) - -// it('testing sortItems method',()=>{ -// let prop: any; -// component.sortItems(prop); - -// }) - -// it('testing getParentLabel method',()=>{ -// component.getParentLabel(1,"data"); -// }) - -// describe('should test getParentData',()=>{ -// it('testing getParentData',()=>{ -// let spy=spyOn(adminService,'getParentData').and.returnValue(Observable.of('you object')); -// component.getParentData(); -// expect(spy).toHaveBeenCalled(); - -// }) -// }) - -// describe('should test getLeftMenuItems',()=>{ -// it('testing getLeftMenuItems',()=>{ -// component.getLeftMenuItems(); -// }) -// }) - -// describe('should test getFunctionCDselectData',()=>{ -// it('testing getFunctionCDselectData',()=>{ -// let spy=spyOn(adminService,'getFunctionCdList').and.returnValue(Observable.of(1,1)); -// component.getFunctionCDselectData(); -// expect(spy).toHaveBeenCalled(); -// }) -// }) - -// it('should test updateFnMenu method',()=>{ -// //component.updateFnMenu(); -// }) - - }); + it('should create', () => { + expect(component).toBeTruthy(); + }); + + it('testing ngOnInit method for if condition',()=>{ + component.selectedMenu=1; + component.ngOnInit(); + expect(component.menu).toEqual(component.selectedMenu); + }) + + it('testing ngOnInit method for else condition',()=>{ + component.selectedMenu=0; + component.ngOnInit(); + expect(component.menu.menuSetCode).toEqual('APP'); + }) + + it('testing sortItems method',()=>{ + let prop: any; + component.sortItems(prop); + + }) + + it('testing getParentLabel method',()=>{ + component.getParentLabel(1,"data"); + }) + + + it('should test getParentData method1 ',()=>{ + const children="children"; + let spy=spyOn(adminService,'getParentData').and.returnValue(Observable.of('you object')); + component.getParentData(); + expect(spy).toHaveBeenCalled(); + }) + + describe('should test getLeftMenuItems',()=>{ + it('testing getLeftMenuItems',()=>{ + component.getLeftMenuItems(); + }) + }) + + it('testing getFunctionCDselectData method1',()=>{ + let spy=spyOn(adminService,'getFunctionCdList').and.returnValue(Observable.of('your object')); + component.getFunctionCDselectData(); + expect(spy).toHaveBeenCalled(); + }) + + it('should test updateFnMenu method',()=>{ + component.menu.label!=null; + component.updateFnMenu(); + }) + +}); -- cgit 1.2.3-korg