summaryrefslogtreecommitdiffstats
path: root/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/pages/analytics/Report_List/report-list.component.spec.ts
blob: 78113e4291fe7d11217895885b4b7502f2c98176 (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
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 { ReportListComponent } from './report-list.component';
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { Router } from '@angular/router';
import { AllReportsDataSource } from './report-list-datasource';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
import 'rxjs/add/observable/empty';
import 'rxjs/add/observable/of';
import { environment } from 'src/environments/environment';
import { ReportListService } from './report-list.service';

describe('ReportListComponent', () => {
  let component: ReportListComponent;
  let fixture: ComponentFixture<ReportListComponent>;
  let http: HttpClient;
  let reportService : ReportListService;
  let environment = [
    { baseUrl : 'just for test' }
  ]

  beforeEach(async(() => {
    TestBed.configureTestingModule({
      schemas: [CUSTOM_ELEMENTS_SCHEMA],
      declarations: [ ReportListComponent ],
      imports: [
        NoopAnimationsModule,
        MatPaginatorModule,
        MatSortModule,
        MatTableModule,
        HttpClientTestingModule,
        RouterTestingModule,
      ],
      providers: [HttpClient, ReportListService]
    }).compileComponents();
    
    reportService = TestBed.get(ReportListService);
    http = TestBed.get(HttpClient);
    spyOn(reportService, 'deleteReport').and.returnValue(Observable.of(environment));
  }));

  beforeEach(() => {
    fixture = TestBed.createComponent(ReportListComponent);
    component = fixture.componentInstance;
    fixture.detectChanges();
  });

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

  it('should test initializeReportList method', () => {
    component.initializeReportList();
    expect(component.showSpinner).toEqual(true);
    expect(component.dataSource).toEqual(new AllReportsDataSource());
    expect(component.intermediateDisplayedColumns).toEqual(new Array());
    expect(component.finalGETObj).toEqual(new Object());
    expect(component.finalGETObjRowsArr).toEqual(new Array());
    expect(component.rowArr).toEqual(new Array());
    expect(component.reportIdArr).toEqual(new Array());
    expect(component.toggle).toEqual(false);
    expect(component.toggle1).toEqual(false);
    expect(component.finalRowArr).toEqual(new Array());
  });

  it('should test ngOnInit method', () => {
      component.ngOnInit();
      expect(component.toggle).toEqual(false);
  });

  it('should test confirmDelete method', () => {
    component.confirmDelete("test");
    expect(component.showDialog).toEqual(true);
    expect(component.closable).toEqual(true);
    expect(component.newReportId).toEqual("test");
  });

  it('should test ngAfterViewInit method', () => {
     component.ngAfterViewInit();
     expect(component.dataSource.sort).toEqual(component.sort);
     expect(component.dataSource.paginator).toEqual(component.paginator);
     expect(component.table.dataSource).toEqual(component.dataSource); 
  });

  it('should test displayReport method', () => {
      component.displayReport("Testing");
      expect(component.reportId).toEqual("Testing");
  });

  it('should test runReport method', () => {
    component.runReport("Test");
    expect(component.reportId).toEqual("Test");
  });

  it('should test applyFilter method', () => {
      component.applyFilter("ABC");
      expect(component.dataSource1.filter).toEqual("abc");

  });

  it('should test close method', () => {
      component.close();
      expect(component.showDialog).toEqual(true);
      expect(component.closable).toEqual(false);
  });

  it('should test deleteReport method', () => {
        spyOn(component, 'deleteReport').and.callThrough();
        component.deleteReport();
        expect(component.deleteReport).toHaveBeenCalled();
  });

  it('should test openReportSchedule method', () => {
    component.openReportSchedule("test");
  });

});