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
119
120
121
122
123
124
125
126
|
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { MatTableModule } from '@angular/material';
import { RunDashboardReportComponent } from './run-dashboard-report.component';
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { RouterModule, Router } from '@angular/router';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { DashboardReportService } from './dashboard-report.service';
import { MockBackend, MockConnection } from '@angular/http/testing';
import { Http, BaseRequestOptions } from '@angular/http';
import { Observable } from 'rxjs';
import 'rxjs/add/observable/empty';
import 'rxjs/add/observable/of';
import { environment } from 'src/environments/environment';
describe('RunDashboardReportComponent', () => {
let component: RunDashboardReportComponent;
let fixture: ComponentFixture<RunDashboardReportComponent>;
let dashboardService : DashboardReportService;
let router: Router;
beforeEach(async(() => {
TestBed.configureTestingModule({
schemas: [CUSTOM_ELEMENTS_SCHEMA],
declarations: [ RunDashboardReportComponent ],
imports: [MatTableModule, RouterTestingModule, HttpClientTestingModule],
providers:[DashboardReportService, MockBackend, BaseRequestOptions, {
provide: Http,
useFactory: (backend: MockBackend, defaultOptions: BaseRequestOptions) => {
return new Http(backend, defaultOptions);
},
deps: [MockBackend, BaseRequestOptions],
}]
})
.compileComponents();
dashboardService = TestBed.get(DashboardReportService);
router = TestBed.get(Router);
}));
beforeEach(() => {
fixture = TestBed.createComponent(RunDashboardReportComponent);
component = fixture.componentInstance;
});
it('should create', () => {
expect(component).toBeTruthy();
});
it('should test ngOnInit method', () => {
component.queryString = "test";
component.ngOnInit();
expect(component.initialQueryString).toEqual("test");
expect(component.initCounter).toEqual(component.initCounter++);
spyOn(component, 'initialProcesses');
component.initialProcesses();
expect(component.initialProcesses).toHaveBeenCalled();
});
it('should test initialProcess method', () => {
component.initialProcesses();
expect(component.dataSource.paginator).toEqual(component.paginator);
});
it('should test ngOnChanges methods if condition', () => {
component.hitCnt = 1;
component.queryString = "testing"
component.initialQueryString === "test";
component.initCounter > 0;
component.runButtonHitCounter === 2;
component.ngOnChanges();
expect(component.initialQueryString).toEqual(component.queryString);
expect(component.runButtonHitCounter).toEqual(component.hitCnt);
spyOn(component, 'initialProcesses');
spyOn(component, 'afterViewInitProcesses');
component.initialProcesses();
component.afterViewInitProcesses();
expect(component.initialProcesses).toHaveBeenCalled();
expect(component.afterViewInitProcesses).toHaveBeenCalled();
});
it('should test ngOnChanges methods else condition', () => {
component.hitCnt = 1;
component.queryString = "testing"
component.initialQueryString === "testing";
component.initCounter = 0;
component.runButtonHitCounter === 1;
component.ngOnChanges();
expect(component.runButtonHitCounter).toBe(component.hitCnt);
expect(component.initialQueryString).toBe(component.queryString);
});
it('should test applyFilter method', () => {
component.applyFilter("testing");
expect(component.dataSource.filter).toEqual("testing".trim().toLowerCase());
});
it('should test afterViewInitProcesses method', () => {
component.afterViewInitProcesses();
expect(component.displayedColumnsArr).toEqual(new Array());
expect(component.displayedRowObj).toEqual(new Array());
expect(component.displayedColumns).toEqual(new Array());
expect(component.formFieldList).toEqual(new Array());
expect(component.showSpinner).toEqual(true);
expect(component.isReady).toEqual(false);
expect(component.NEWdisplayedColumns).toEqual(new Array());
});
it('should test linkToReport method', () => {
let reportId = "abc";
let queryParameters = "def";
component.linkToReport(reportId, queryParameters);
});
it('should test linkToMail method', () => {
let mailID = "abc";
component.linkToMail(mailID);
});
});
|