summaryrefslogtreecommitdiffstats
path: root/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/pages/analytics/Report_List/Report/run/run-report/run-report.component.spec.ts
blob: 4d4fe2695f2003754b5340e41bb232fc01fab960 (plain)
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
127
128
129
130
131
132
133
134
135
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { MatPaginatorModule } from '@angular/material/paginator';
import { MatSortModule } from '@angular/material/sort';
import { MatTableModule, MatTableDataSource } from '@angular/material/table';

import { RunReportComponent, PeriodicElement } from './run-report.component';
import { CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA, SimpleChange, SimpleChanges } from '@angular/core';
import { MatMenuModule } from '@angular/material';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { RunService } from '../run.service';
import { GridsterConfig, GridsterItem, GridType } from 'angular-gridster2';

describe('RunReportComponent', () => {
  let component: RunReportComponent;
  let fixture: ComponentFixture<RunReportComponent>;
  const displayedColumnsArr1 = [];
  const DashboardReportObj1 = [];
  const trigger = ["a","b"];
  let change : SimpleChanges;
  let runService : RunService;
  let options1 = {};

  beforeEach(async(() => {
    TestBed.configureTestingModule({
      schemas: [CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA],
      declarations: [ RunReportComponent ],
      imports: [
        NoopAnimationsModule,
        MatPaginatorModule,
        MatSortModule,
        MatTableModule,
        MatMenuModule,
        HttpClientTestingModule,
        RouterTestingModule
      ],
      providers: [RunService]
    }).compileComponents();
    runService = TestBed.get(RunService);
  }));

  beforeEach(() => {
    fixture = TestBed.createComponent(RunReportComponent);
    runService = TestBed.get(RunService);
    component = fixture.componentInstance;
    component.DashboardReportObj = DashboardReportObj1;
    component.displayedColumnsArr = displayedColumnsArr1;
    component.TriggerFFArr = trigger;
    component.options = options1;
    fixture.detectChanges();
  });

  it('should compile', () => {
    expect(component).toBeTruthy();
  });

  it('should test the ngOnChanges method', () => {
        fixture.detectChanges();
        component.reportMode !== "Regular";
        component.initCnt > 0;
        component.TriggerFFArr.length == 0;
    
        component.ngOnChanges(change);
        expect(component.showMoreVert).toEqual(false);
        expect(component.initCnt).toEqual(1);
        expect(component.showDashboardReport).toEqual(false);
        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.NEWdisplayedColumns).toEqual(new Array());
        expect(component.isReady).toEqual(false);

        runService.getReportDataWithFormFields("for", "test").subscribe((Response) => {
          component.reportMode !== "FormField";
          expect(component.showMoreVert).toEqual(true);
          expect(component.showDashboardReport).toEqual(true);
        });
        
        component.initialQueryString !== component.queryString;
        component.initCounter > 0;
        component.hitCnt !== component.runButtonHitCnt;
        expect(component.runButtonHitCnt).toEqual(component.hitCnt);
        expect(component.initialQueryString).toEqual(component.queryString);
  });

  it('should test initialProcess method', () => {
      component.initialProcesses();
      component.DashboardReportObj.length > 0;
      expect(component.dashboard).toEqual(component.DashboardReportObj);
      expect(component.hitCnt).toEqual(component.runButtonHitCnt);
      expect(component.initialQueryString).toEqual(component.queryString);
      expect(component.initCounter).toEqual(component.initCounter++);
  });

  it('should test afterViewInitialProcesses method', () => {
      component.afterViewInitialProcesses();
      component.DashboardReportObj.length === 0;
      component.reportMode === "Regular";
      component.initCnt == 0;
      
      expect(component.showMoreVert).toEqual(false);
      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 showError method', () => {
       let errmsg = "errormessage";
       let stcktrace = "stacktrace";
      component.showError("test");
       expect(component.errorMessage).toEqual("test"[errmsg]);
       expect(component.stackTrace).toEqual("test"[stcktrace]);
       expect(component.error).toEqual(true);
       expect(component.showSpinner).toEqual(false);

    });

  it('should test openOptions method', () => {
        component.openOptions();
        expect(component.openOptionsFlag).toEqual(component.openOptionsFlag);
  });

  it('should test applyFilter method', () => {
      let filterValue = "test"
      component.applyFilter(filterValue);
      expect(component.dataSource.filter).toEqual(filterValue.trim().toLowerCase());
  });
  
});