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