1 import { async, ComponentFixture, TestBed } from '@angular/core/testing';
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';
12 describe('SecurityComponent', () => {
13 let component: SecurityComponent;
14 let fixture: ComponentFixture<SecurityComponent>;
15 let service : SecurityService;
18 baseUrl: 'just for testing'
22 beforeEach(async(() => {
23 TestBed.configureTestingModule({
24 schemas: [CUSTOM_ELEMENTS_SCHEMA],
25 declarations: [ SecurityComponent ],
26 imports: [FormsModule, HttpClientTestingModule],
27 providers: [SecurityService]
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));
47 fixture = TestBed.createComponent(SecurityComponent);
48 component = fixture.componentInstance;
49 fixture.detectChanges();
52 it('should create', () => {
53 expect(component).toBeTruthy();
56 it('should test ngOnInit method', () => {
57 component.reportType = "Dashboard";
59 expect(component.stepNo).toEqual('2');
60 component.reportType = "test";
63 expect(component.stepNo).toEqual('6');
65 spyOn(component, 'ngOnInit').and.callThrough();
67 expect(component.ngOnInit).toHaveBeenCalled();
70 it('should test addUserEditAccess method', () =>{
71 let reportUserId = 'test';
73 component.userEditAccessArr[1] = true;
74 component.addUserEditAccess(reportUserId, index);
76 component.userEditAccessArr[1] = false;
77 component.addUserEditAccess(reportUserId, index);
81 it('should test addRoleEditAccess method', () =>{
82 let reportUserId = 'test';
84 component.addRoleEditAccessArr[1] = true;
85 component.addRoleEditAccess(reportUserId, index);
87 component.addRoleEditAccessArr[1] = false;
88 component.addRoleEditAccess(reportUserId, index);
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();
100 it("should test removeReportUser method", () => {
101 component.reportOwnerList=[{"name":"reportUserName"}];
102 component.removeReportUser("reportUserName");
105 it("should test addReportRole method", () => {
106 component.reportRole="reportRole";
107 component.reportRoleList=[{"name":"reportRole"}];
108 component.addReportRole();
111 it("should test removeReportRole method", () => {
112 component.reportSecurityRoles=[{"id":"roleId"}];
113 component.removeReportRole("test");
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();