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 { 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';
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.showSpinner).toEqual(true);
60 expect(component.stepNo).toEqual('2');
61 component.reportType = "test";
64 expect(component.stepNo).toEqual('6');
66 spyOn(component, 'ngOnInit').and.callThrough();
68 expect(component.ngOnInit).toHaveBeenCalled();
71 it('should test addUserEditAccess method', () =>{
72 let reportUserId = 'test';
74 component.userEditAccessArr[1] = true;
75 component.addUserEditAccess(reportUserId, index);
77 component.userEditAccessArr[1] = false;
78 component.addUserEditAccess(reportUserId, index);
82 it('should test addRoleEditAccess method', () =>{
83 let reportUserId = 'test';
85 component.addRoleEditAccessArr[1] = true;
86 component.addRoleEditAccess(reportUserId, index);
88 component.addRoleEditAccessArr[1] = false;
89 component.addRoleEditAccess(reportUserId, index);
93 it("should test addReportUser method", () => {
94 spyOn(component, 'addReportUser').and.callThrough();
95 component.addReportUser();
96 expect(component.addReportUser).toHaveBeenCalled();
99 it("should test removeReportUser method", () => {
100 component.removeReportUser("test");
103 it("should test addReportRole method", () => {
104 component.addReportRole();
107 it("should test removeReportRole method", () => {
108 component.removeReportRole("test");
111 it("should test saveSecurityTabData method", () => {
112 spyOn(component, 'saveSecurityTabData').and.callThrough();
113 component.saveSecurityTabData();
114 expect(component.saveSecurityTabData).toHaveBeenCalled();