From 62546ca8cd1eeee7ec441bf5463a04a29a384836 Mon Sep 17 00:00:00 2001 From: Indrijeet kumar Date: Wed, 1 Apr 2020 21:08:00 +0530 Subject: test cases written in cache-admin comp test cases written in cache-admin component Issue-ID: PORTAL-813 Change-Id: I99f4f737cd429554d02bf86be74e00ab5845ac2d Signed-off-by: Indrijeet Kumar --- .../cache-admin/cache-admin.component.spec.ts | 55 ++++++++++++++++++++-- 1 file changed, 51 insertions(+), 4 deletions(-) (limited to 'ecomp-sdk/epsdk-app-overlay/src') diff --git a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/pages/admin/cache-admin/cache-admin.component.spec.ts b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/pages/admin/cache-admin/cache-admin.component.spec.ts index 7a4bcec0..03d21797 100644 --- a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/pages/admin/cache-admin/cache-admin.component.spec.ts +++ b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/pages/admin/cache-admin/cache-admin.component.spec.ts @@ -2,27 +2,74 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; import { CacheAdminComponent } from './cache-admin.component'; import { MatExpansionModule } from '@angular/material'; +import { HttpClientModule } from '@angular/common/http'; import { HttpClientTestingModule } from '@angular/common/http/testing'; +import { AdminService } from '../admin.service'; +import { Observable } from 'rxjs/Observable'; +import 'rxjs/add/observable/of'; +import { CookieService } from 'ngx-cookie-service'; +import { SuccessModalComponent } from 'src/app/modals/success-modal/success-modal.component'; +import { BrowserDynamicTestingModule } from '@angular/platform-browser-dynamic/testing'; +import { NgbModule } from '@ng-bootstrap/ng-bootstrap'; + + describe('CacheAdminComponent', () => { let component: CacheAdminComponent; let fixture: ComponentFixture; + let adminService:AdminService; + + var stubData1={"data":'{"data":"cachedRegions"}'}; + var stubData2={"data":"stubData2"}; beforeEach(async(() => { + TestBed.configureTestingModule({ - imports:[MatExpansionModule, HttpClientTestingModule], - declarations: [ CacheAdminComponent ], - schemas: [CUSTOM_ELEMENTS_SCHEMA] + declarations: [ + CacheAdminComponent, + SuccessModalComponent, + ], + schemas: [CUSTOM_ELEMENTS_SCHEMA], + imports:[ + MatExpansionModule, + HttpClientModule, + HttpClientTestingModule, + NgbModule.forRoot() + ], + providers:[CookieService,AdminService], + }) + TestBed.overrideModule(BrowserDynamicTestingModule,{ + set:{ + entryComponents:[SuccessModalComponent] + } }) .compileComponents(); - })); + })); beforeEach(() => { fixture = TestBed.createComponent(CacheAdminComponent); component = fixture.componentInstance; fixture.detectChanges(); + adminService=TestBed.get(AdminService); }); it('should create', () => { expect(component).toBeTruthy(); }); + + + describe('it should test ngOnInit method',()=>{ + it('should test ngOnInit',()=>{ + let spy=spyOn(adminService,'getCacheRegions').and.returnValue(Observable.of(stubData1)); + component.ngOnInit(); + expect(spy).toHaveBeenCalled(); + }) + }) + + it('it should test showRegionDetails method',()=>{ + let spy=spyOn(adminService,'getCacheRegionDetails').and.returnValue(Observable.of(stubData2)); + component.showRegionDetails("string"); + expect(spy).toHaveBeenCalled(); + }) + }); + -- cgit 1.2.3-korg