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, MatTableDataSource } from '@angular/material/table';
7 import { RunReportComponent, PeriodicElement } from './run-report.component';
8 import { CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA, SimpleChange, 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;
28 let responseformfield = 1;
31 baseUrl: 'just a link'
36 beforeEach(async(() => {
37 TestBed.configureTestingModule({
38 schemas: [CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA],
39 declarations: [ RunReportComponent ],
46 HttpClientTestingModule,
49 providers: [RunService]
50 }).compileComponents();
51 runService = TestBed.get(RunService);
52 //spyOn(runService, 'getReportDataWithFormFields').and.returnValue(Observable.of(environment));
53 //spyOn(runService, 'getReportData').and.returnValue(Observable.of(environment));
54 spyOn(runService, 'downloadReportExcel').and.returnValue(Observable.of(environment));
58 //dashboard = {"item":{"hasContent":{"name":"rupi","id":"check#check"}}};
59 fixture = TestBed.createComponent(RunReportComponent);
60 runService = TestBed.get(RunService);
61 component = fixture.componentInstance;
62 component.DashboardReportObj = DashboardReportObj1;
63 component.displayedColumnsArr = displayedColumnsArr1;
64 component.TriggerFFArr = trigger;
65 component.options = options1;
66 component.dashboard = dashboard;
67 component.responseFormFieldListLength = responseformfield;
68 //fixture.detectChanges();
71 it('should compile', () => {
72 expect(component).toBeTruthy();
75 it('should test the ngOnChanges second If condition', () => {
76 component.queryString = "test"
77 component.runButtonHitCnt = 1;
78 component.initialQueryString = "abc";
79 component.initCounter = 4;
81 component.ngOnChanges(change);
83 expect(component.runButtonHitCnt).toEqual(component.hitCnt);
84 expect(component.initialQueryString).toEqual("test");
85 spyOn(component, 'initialProcesses');
86 spyOn(component, 'afterViewInitialProcesses');
87 component.initialProcesses();
88 component.afterViewInitialProcesses();
90 expect(component.initialProcesses).toHaveBeenCalled();
91 expect(component.afterViewInitialProcesses).toHaveBeenCalled();
94 it('should test afterViewInitialProcesses method', () => {
95 component.DashboardReportObj.length = 0;
96 component.reportMode = "Regular";
97 component.initCnt = 0;
98 component.afterViewInitialProcesses();
100 expect(component.showMoreVert).toEqual(false);
101 expect(component.displayedColumnsArr).toEqual(new Array());
102 expect(component.displayedRowObj).toEqual(new Array());
103 expect(component.displayedColumns).toEqual(new Array());
104 expect(component.formFieldList).toEqual(new Array());
105 expect(component.showSpinner).toEqual(true);
106 expect(component.isReady).toEqual(false);
107 expect(component.NEWdisplayedColumns).toEqual(new Array());
110 it('should test showError method', () => {
111 let errmsg = "errormessage";
112 let stcktrace = "stacktrace";
113 component.showError("test");
114 expect(component.errorMessage).toEqual("test"[errmsg]);
115 expect(component.stackTrace).toEqual("test"[stcktrace]);
116 expect(component.error).toEqual(true);
117 expect(component.showSpinner).toEqual(false);
120 it('should test linkToReport', () => {
121 component.linkToReport("test", "abc");
124 it('should test linkToFeedback', () => {
125 component.linkToFeedback("test", "abc");
128 it('should test linkToMail', () => {
129 component.linkToMail("test");
132 it('should test openOptions method', () => {
133 component.openOptions();
134 expect(component.openOptionsFlag).toEqual(component.openOptionsFlag);
138 it('should test applyFilter method', () => {
139 let filterValue = "test"
140 component.applyFilter(filterValue);
141 expect(component.dataSource.filter).toEqual(filterValue.trim().toLowerCase());
144 it('should test the ngOnChanges first If condition', () => {
146 component.reportMode !== "Regular"
147 component.initCnt = 1;
148 component.TriggerFFArr.length = 0;
149 component.ngOnChanges(change);
150 expect(component.showMoreVert).toEqual(false);
151 expect(component.initCnt).toEqual(1);
152 expect(component.showDashboardReport).toEqual(false);
153 expect(component.displayedRowObj).toEqual(new Array());
154 expect(component.displayedColumns).toEqual(new Array());
155 expect(component.formFieldList).toEqual(new Array());
156 expect(component.showSpinner).toEqual(true);
157 expect(component.NEWdisplayedColumns).toEqual(new Array());
158 expect(component.isReady).toEqual(false);
161 it('should test initialProcess method', () => {
162 component.DashboardReportObj.length = 1;
163 component.initialProcesses();
166 // it('should test postFetchingReportDataFn method', () => {
167 // let response: any;
168 // component.postFetchingReportDataFn(response);
171 // it('should test ngOnChanges subscribe method', () => {
172 // spyOn(component, 'ngOnChanges').and.callThrough();
173 // component.ngOnChanges(change);
174 // expect(component.ngOnChanges).toHaveBeenCalled();
177 // it('should test postFetchingReportDataFn method', () => {
179 // component.postFetchingReportDataFn(obj);