44a7ef1f823cd9e78db75ef62a925b809de468aa
[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 { SecurityService } from './security.service';
8 import { Observable } from 'rxjs/Observable';
9 import 'rxjs/add/observable/of';
10
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.stepNo).toEqual('2');
60       component.reportType = "test";
61
62       component.ngOnInit();
63       expect(component.stepNo).toEqual('6');
64
65       spyOn(component, 'ngOnInit').and.callThrough();
66       component.ngOnInit();
67       expect(component.ngOnInit).toHaveBeenCalled();
68   });
69  
70   it('should test addUserEditAccess method', () =>{
71     let reportUserId = 'test';
72     let index = 1;
73     component.userEditAccessArr[1] = true;
74     component.addUserEditAccess(reportUserId, index);
75
76     component.userEditAccessArr[1] = false;
77     component.addUserEditAccess(reportUserId, index);
78     
79   });
80
81   it('should test addRoleEditAccess method', () =>{
82     let reportUserId = 'test';
83     let index = 1;
84     component.addRoleEditAccessArr[1] = true;
85     component.addRoleEditAccess(reportUserId, index);
86
87     component.addRoleEditAccessArr[1] = false;
88     component.addRoleEditAccess(reportUserId, index);
89     
90   });
91
92   it("should test addReportUser method", () => {
93     component.reportUser="ind";
94     component.reportOwnerList=[{"name":"ind"}];
95       spyOn(component, 'addReportUser').and.callThrough();
96       component.addReportUser();
97       expect(component.addReportUser).toHaveBeenCalled();
98   });
99
100   it("should test removeReportUser method", () => {
101     component.reportOwnerList=[{"name":"reportUserName"}];
102     component.removeReportUser("reportUserName");
103   });
104
105   it("should test addReportRole method", () => {
106     component.reportRole="reportRole";
107     component.reportRoleList=[{"name":"reportRole"}];
108     component.addReportRole();
109   });
110
111   it("should test removeReportRole method", () => {
112     component.reportSecurityRoles=[{"id":"roleId"}];
113     component.removeReportRole("test");
114   });
115
116   it("should test saveSecurityTabData method", () => {
117       component.reportOwner="reportOwner";
118       component.reportOwnerList=[{"name":"reportOwner"}];
119       spyOn(component, 'saveSecurityTabData').and.callThrough();
120       component.saveSecurityTabData();
121       expect(component.saveSecurityTabData).toHaveBeenCalled();
122   });
123
124 });
125