03d21797169008ff22bd1278250ce40c9531668a
[portal/sdk.git] /
1 import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2 import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
3 import { CacheAdminComponent } from './cache-admin.component';
4 import { MatExpansionModule } from '@angular/material';
5 import { HttpClientModule } from '@angular/common/http';
6 import { HttpClientTestingModule } from '@angular/common/http/testing';
7 import { AdminService } from '../admin.service';
8 import { Observable } from 'rxjs/Observable';
9 import 'rxjs/add/observable/of';
10 import { CookieService } from 'ngx-cookie-service';
11 import { SuccessModalComponent } from 'src/app/modals/success-modal/success-modal.component';
12 import { BrowserDynamicTestingModule } from '@angular/platform-browser-dynamic/testing';
13 import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
14
15
16 describe('CacheAdminComponent', () => {
17   let component: CacheAdminComponent;
18   let fixture: ComponentFixture<CacheAdminComponent>;
19   let adminService:AdminService;
20   
21  var stubData1={"data":'{"data":"cachedRegions"}'};
22  var stubData2={"data":"stubData2"};
23
24   beforeEach(async(() => {
25     
26     TestBed.configureTestingModule({
27       declarations: [ 
28         CacheAdminComponent,
29         SuccessModalComponent,
30        ],
31       schemas: [CUSTOM_ELEMENTS_SCHEMA],
32       imports:[
33         MatExpansionModule,
34          HttpClientModule,
35          HttpClientTestingModule,
36          NgbModule.forRoot()
37         ],
38       providers:[CookieService,AdminService],  
39     })
40     TestBed.overrideModule(BrowserDynamicTestingModule,{
41       set:{
42         entryComponents:[SuccessModalComponent]
43       }
44     })
45     .compileComponents();
46   }));
47
48   beforeEach(() => {
49     fixture = TestBed.createComponent(CacheAdminComponent);
50     component = fixture.componentInstance;
51     fixture.detectChanges();
52     adminService=TestBed.get(AdminService);
53   });
54
55   it('should create', () => {
56     expect(component).toBeTruthy();
57   });
58
59  
60   describe('it should test ngOnInit method',()=>{
61     it('should test ngOnInit',()=>{
62       let spy=spyOn(adminService,'getCacheRegions').and.returnValue(Observable.of(stubData1));
63       component.ngOnInit();
64       expect(spy).toHaveBeenCalled();    
65     })
66   })
67
68   it('it should test showRegionDetails method',()=>{
69     let spy=spyOn(adminService,'getCacheRegionDetails').and.returnValue(Observable.of(stubData2));
70     component.showRegionDetails("string");
71     expect(spy).toHaveBeenCalled();
72   })
73  
74 });
75