1 import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2 import { NoopAnimationsModule } from '@angular/platform-browser/animations';
3 import { MatPaginatorModule } from '@angular/material/paginator';
4 import { MatSortModule } from '@angular/material/sort';
5 import { MatTableModule} from '@angular/material/table';
7 import { RunReportComponent} from './run-report.component';
8 import { CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA, SimpleChanges } from '@angular/core';
9 import { MatMenuModule } from '@angular/material';
10 import { HttpClientTestingModule } from '@angular/common/http/testing';
11 import { RouterTestingModule } from '@angular/router/testing';
12 import { RunService } from '../run.service';
13 import 'rxjs/add/observable/empty';
14 import 'rxjs/add/observable/of';
15 import { Observable } from 'rxjs';
17 describe('RunReportComponent', () => {
18 let component: RunReportComponent;
19 let fixture: ComponentFixture<RunReportComponent>;
20 const displayedColumnsArr1 = [];
21 const DashboardReportObj1 = [];
22 const trigger = ["a","b"];
23 let change : SimpleChanges;
24 let runService : RunService;
27 let responseformfield = 1;
30 baseUrl: 'just a link'
35 beforeEach(async(() => {
36 TestBed.configureTestingModule({
37 schemas: [CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA],
38 declarations: [ RunReportComponent ],
45 HttpClientTestingModule,
48 providers: [RunService]
49 }).compileComponents();
50 runService = TestBed.get(RunService);
51 spyOn(runService, 'downloadReportExcel').and.returnValue(Observable.of(environment));
55 fixture = TestBed.createComponent(RunReportComponent);
56 runService = TestBed.get(RunService);
57 component = fixture.componentInstance;
58 component.DashboardReportObj = DashboardReportObj1;
59 component.displayedColumnsArr = displayedColumnsArr1;
60 component.TriggerFFArr = trigger;
61 component.options = options1;
62 component.dashboard = dashboard;
63 component.responseFormFieldListLength = responseformfield;
64 fixture.detectChanges();
67 it('should compile', () => {
68 expect(component).toBeTruthy();
71 it('should test the ngOnChanges second If condition', () => {
72 component.queryString = "test"
73 component.runButtonHitCnt = 1;
74 component.initialQueryString = "abc";
75 component.initCounter = 4;
77 component.ngOnChanges(change);
79 expect(component.runButtonHitCnt).toEqual(component.hitCnt);
80 expect(component.initialQueryString).toEqual("test");
81 spyOn(component, 'initialProcesses');
82 spyOn(component, 'afterViewInitialProcesses');
83 component.initialProcesses();
84 component.afterViewInitialProcesses();
86 expect(component.initialProcesses).toHaveBeenCalled();
87 expect(component.afterViewInitialProcesses).toHaveBeenCalled();
90 it('should test afterViewInitialProcesses method', () => {
91 component.DashboardReportObj.length = 0;
92 component.reportMode = "Regular";
93 component.initCnt = 0;
94 component.afterViewInitialProcesses();
96 expect(component.showMoreVert).toEqual(false);
97 expect(component.displayedColumnsArr).toEqual(new Array());
98 expect(component.displayedRowObj).toEqual(new Array());
99 expect(component.displayedColumns).toEqual(new Array());
100 expect(component.formFieldList).toEqual(new Array());
101 expect(component.showSpinner).toEqual(true);
102 expect(component.isReady).toEqual(false);
103 expect(component.NEWdisplayedColumns).toEqual(new Array());
107 it('should test showError method', () => {
108 let errmsg = "errormessage";
109 let stcktrace = "stacktrace";
110 component.showError("test");
111 expect(component.errorMessage).toEqual("test"[errmsg]);
112 expect(component.stackTrace).toEqual("test"[stcktrace]);
113 expect(component.error).toEqual(true);
114 expect(component.showSpinner).toEqual(false);
117 it('should test linkToReport', () => {
118 component.linkToReport("test", "abc");
121 it('should test linkToFeedback', () => {
122 component.linkToFeedback("test", "abc");
125 it('should test linkToMail', () => {
126 component.linkToMail("test");
129 it('should test openOptions method', () => {
130 component.openOptions();
131 expect(component.openOptionsFlag).toEqual(component.openOptionsFlag);
134 it('should test downloadReportExcel method', () => {
135 spyOn(component, 'downloadReportExcel').and.callThrough();
136 component.downloadReportExcel();
137 expect(component.downloadReportExcel).toHaveBeenCalled();
140 it('should test applyFilter method', () => {
141 let filterValue = "test"
142 component.applyFilter(filterValue);
143 expect(component.dataSource.filter).toEqual(filterValue.trim().toLowerCase());
146 it('should test the ngOnChanges first If condition', () => {
148 component.queryString="queryString";
149 component.reportId1="reportId1";
150 var response={"errormessage":true}
151 component.reportMode !== "Regular"
152 component.initCnt = 1;
153 component.TriggerFFArr.length = 0;
154 let spy=spyOn(runService,'getReportDataWithFormFields').and.returnValue(Observable.of(response));
155 component.ngOnChanges(change);
156 expect(spy).toHaveBeenCalled();
157 expect(component.initCnt).toEqual(1);
158 expect(component.showDashboardReport).toEqual(false);
159 expect(component.displayedRowObj).toEqual(new Array());
160 expect(component.displayedColumns).toEqual(new Array());
161 expect(component.formFieldList).toEqual(new Array());
162 expect(component.NEWdisplayedColumns).toEqual(new Array());
163 expect(component.isReady).toEqual(false);
168 it('should test initialProcess method', () => {
169 component.DashboardReportObj.length = 1;
170 component.initialProcesses();
173 // it('should test postFetchingReportDataFn method',()=>{
175 // "reportName":"reportName",
176 // "reportDataColumns":[{"columnTitle":"columnTitle","colId":"colId"}],
177 // "reportDataRows":[{"value":"value"}]
179 // component.displayedColumnsArr=["string"]
180 // component.postFetchingReportDataFn(response)