417b3a1857204c8877a4c12ebfe879720cb3e37e
[portal/sdk.git] /
1 import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2
3 import { SecurityComponent } from './security.component';
4 import { FormsModule } from '@angular/forms';
5 import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
6 import { HttpClientTestingModule } from '@angular/common/http/testing';
7 import { componentRefresh } from '@angular/core/src/render3/instructions';
8 import { SecurityService } from './security.service';
9 import { Observable } from 'rxjs/Observable';
10 import 'rxjs/add/observable/of';
11
12 describe('SecurityComponent', () => {
13   let component: SecurityComponent;
14   let fixture: ComponentFixture<SecurityComponent>;
15   let service : SecurityService;
16   let environment =[
17     {
18       baseUrl: 'just for testing'
19     }
20   ]
21
22   beforeEach(async(() => {
23     TestBed.configureTestingModule({
24       schemas: [CUSTOM_ELEMENTS_SCHEMA],
25       declarations: [ SecurityComponent ],
26       imports: [FormsModule, HttpClientTestingModule],
27       providers: [SecurityService]
28     })
29     .compileComponents();
30     service = TestBed.get(SecurityService);
31     spyOn(service, 'getReportOwnerList').and.returnValue(Observable.of(environment));
32     spyOn(service, 'getReportSecurityInfo').and.returnValue(Observable.of(environment));
33     spyOn(service, 'getReportUserList').and.returnValue(Observable.of(environment));
34     spyOn(service, 'getReportSecurityRoles').and.returnValue(Observable.of(environment));
35     spyOn(service, 'getReportRoleList').and.returnValue(Observable.of(environment));
36     spyOn(service, 'addReportUser').and.returnValue(Observable.of(environment));
37     spyOn(service, 'removeReportUser').and.returnValue(Observable.of(environment));
38     spyOn(service, 'addUserEditAccess').and.returnValue(Observable.of(environment));
39     spyOn(service, 'addReportRole').and.returnValue(Observable.of(environment));
40     spyOn(service, 'removeReportRole').and.returnValue(Observable.of(environment));
41     spyOn(service, 'addRoleEditAccess').and.returnValue(Observable.of(environment));
42     spyOn(service, 'saveSecurityTabInfo').and.returnValue(Observable.of(environment));
43
44   }));
45
46   beforeEach(() => {
47     fixture = TestBed.createComponent(SecurityComponent);
48     component = fixture.componentInstance;
49     fixture.detectChanges();
50   });
51
52   it('should create', () => {
53     expect(component).toBeTruthy();
54   });
55
56   it('should test ngOnInit method', () => {
57       component.reportType = "Dashboard";
58        component.ngOnInit();
59      // expect(component.showSpinner).toEqual(true);
60       expect(component.stepNo).toEqual('2');
61       component.reportType = "test";
62
63       component.ngOnInit();
64       expect(component.stepNo).toEqual('6');
65
66       spyOn(component, 'ngOnInit').and.callThrough();
67       component.ngOnInit();
68       expect(component.ngOnInit).toHaveBeenCalled();
69   });
70  
71   it('should test addUserEditAccess method', () =>{
72     let reportUserId = 'test';
73     let index = 1;
74     component.userEditAccessArr[1] = true;
75     component.addUserEditAccess(reportUserId, index);
76
77     component.userEditAccessArr[1] = false;
78     component.addUserEditAccess(reportUserId, index);
79     
80   });
81
82   it('should test addRoleEditAccess method', () =>{
83     let reportUserId = 'test';
84     let index = 1;
85     component.addRoleEditAccessArr[1] = true;
86     component.addRoleEditAccess(reportUserId, index);
87
88     component.addRoleEditAccessArr[1] = false;
89     component.addRoleEditAccess(reportUserId, index);
90     
91   });
92
93   it("should test addReportUser method", () => {
94       spyOn(component, 'addReportUser').and.callThrough();
95       component.addReportUser();
96       expect(component.addReportUser).toHaveBeenCalled();
97   });
98
99   it("should test removeReportUser method", () => {
100     component.removeReportUser("test");
101   });
102
103   it("should test addReportRole method", () => {
104     component.addReportRole();
105   });
106
107   it("should test removeReportRole method", () => {
108     component.removeReportRole("test");
109   });
110
111   it("should test saveSecurityTabData method", () => {
112       spyOn(component, 'saveSecurityTabData').and.callThrough();
113       component.saveSecurityTabData();
114       expect(component.saveSecurityTabData).toHaveBeenCalled();
115   });
116
117 });
118