Make ei-coordinator tests work
Change-Id: I5e88af5ae1b7df62cd68b5c0353154b1dbe06478
Signed-off-by: elinuxhenrik <henrik.b.andersson@est.tech>
Issue-ID: NONRTRIC-389
diff --git a/webapp-frontend/src/app/ei-coordinator/ei-coordinator.component.spec.ts b/webapp-frontend/src/app/ei-coordinator/ei-coordinator.component.spec.ts
index 3e0fbf5..f1518ce 100644
--- a/webapp-frontend/src/app/ei-coordinator/ei-coordinator.component.spec.ts
+++ b/webapp-frontend/src/app/ei-coordinator/ei-coordinator.component.spec.ts
@@ -23,8 +23,6 @@
import { FormBuilder, ReactiveFormsModule } from '@angular/forms';
import { MatIconModule, MatTableModule } from '@angular/material';
-import { of } from 'rxjs';
-
import { EICoordinatorComponent } from './ei-coordinator.component';
import { EIJobDataSource } from './ei-job.datasource';
import { EIProducerDataSource } from './ei-producer.datasource';
@@ -35,14 +33,12 @@
let fixture: ComponentFixture<EICoordinatorComponent>;
beforeEach(async(() => {
- const jobDataSourceSpy = jasmine.createSpyObj('EIJobDataSource', [ 'connect', 'getJobs', 'disconnect' ]);
- const producerDataSourceSpy = jasmine.createSpyObj('EIProducerDataSource', [ 'connect', 'loadTable', 'loadProducers', 'disconnect' ]);
+ const jobDataSourceSpy = jasmine.createSpyObj('EIJobDataSource', [ 'loadJobs', 'eiJobs' ]);
+ const producerDataSourceSpy = jasmine.createSpyObj('EIProducerDataSource', [ 'loadProducers', 'eiProducers' ]);
- jobDataSourceSpy.connect.and.returnValue(of([]));
- jobDataSourceSpy.disconnect();
- producerDataSourceSpy.connect.and.returnValue(of([]));
- producerDataSourceSpy.loadProducers.and.returnValue(of([]));
- producerDataSourceSpy.disconnect();
+ jobDataSourceSpy.eiJobs.and.returnValue([]);
+
+ producerDataSourceSpy.eiProducers.and.returnValue([]);
TestBed.configureTestingModule({
imports: [
diff --git a/webapp-frontend/src/app/ei-coordinator/ei-coordinator.component.ts b/webapp-frontend/src/app/ei-coordinator/ei-coordinator.component.ts
index 711b86f..fbd0be6 100644
--- a/webapp-frontend/src/app/ei-coordinator/ei-coordinator.component.ts
+++ b/webapp-frontend/src/app/ei-coordinator/ei-coordinator.component.ts
@@ -51,7 +51,6 @@
})
export class EICoordinatorComponent implements OnInit {
- producers$: Observable<EIProducer[]>;
@ViewChild(MatSort, { static: true }) sort: MatSort;
@ViewChild('producersTable', { static: true }) table: MatTable<Element>;
@@ -86,10 +85,10 @@
}
ngOnInit() {
- this.eiJobsDataSource.getJobs();
- this.producers$ = this.eiProducersDataSource.loadProducers();
- this.jobsDataSource = new MatTableDataSource(this.eiJobsDataSource.eiJobsSubject.value);
- this.producersDataSource = new MatTableDataSource(this.eiProducersDataSource.producerSubject.value)
+ this.eiJobsDataSource.loadJobs();
+ this.eiProducersDataSource.loadProducers();
+ this.jobsDataSource = new MatTableDataSource(this.eiJobsDataSource.eiJobs());
+ this.producersDataSource = new MatTableDataSource(this.eiProducersDataSource.eiProducers());
this.jobsFormControl.valueChanges.subscribe(value => {
const filter = {...value, id: value.id.trim().toLowerCase()} as string;
@@ -182,7 +181,7 @@
}
refreshTables() {
- this.eiJobsDataSource.getJobs();
+ this.eiJobsDataSource.loadJobs();
this.eiProducersDataSource.loadProducers();
}
}
diff --git a/webapp-frontend/src/app/ei-coordinator/ei-job.datasource.spec.ts b/webapp-frontend/src/app/ei-coordinator/ei-job.datasource.spec.ts
index e52ae6f..a891d5f 100644
--- a/webapp-frontend/src/app/ei-coordinator/ei-job.datasource.spec.ts
+++ b/webapp-frontend/src/app/ei-coordinator/ei-job.datasource.spec.ts
@@ -18,7 +18,7 @@
* ========================LICENSE_END===================================
*/
import { TestBed } from '@angular/core/testing';
-import { BehaviorSubject, of } from 'rxjs';
+import { of } from 'rxjs';
import { EIJobDataSource } from './ei-job.datasource';
import { EIService } from '../services/ei/ei.service';
@@ -50,10 +50,9 @@
});
it('#getJobs', () => {
- dataSource.getJobs();
- const jobsSubject: BehaviorSubject<EIJob[]> = dataSource.eiJobsSubject;
- const value = jobsSubject.getValue();
- expect(value).toEqual([ job, job ]);
+ dataSource.loadJobs();
+ const actualJobs: EIJob[] = dataSource.eiJobs();
+ expect(actualJobs).toEqual([ job, job ]);
expect(dataSource.rowCount).toEqual(2);
});
});
diff --git a/webapp-frontend/src/app/ei-coordinator/ei-job.datasource.ts b/webapp-frontend/src/app/ei-coordinator/ei-job.datasource.ts
index 64c948c..5fc64fc 100644
--- a/webapp-frontend/src/app/ei-coordinator/ei-job.datasource.ts
+++ b/webapp-frontend/src/app/ei-coordinator/ei-job.datasource.ts
@@ -19,7 +19,6 @@
*/
import { Injectable } from '@angular/core';
-import { MatTableDataSource } from '@angular/material';
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
@@ -30,9 +29,13 @@
providedIn: 'root'
})
-export class EIJobDataSource extends MatTableDataSource<EIJob> {
+export class EIJobDataSource {
- eiJobsSubject = new BehaviorSubject<EIJob[]>([]);
+ private eiJobsSubject = new BehaviorSubject<EIJob[]>([]);
+
+ public eiJobs(): EIJob[] {
+ return this.eiJobsSubject.value;
+ }
private loadingSubject = new BehaviorSubject<boolean>(false);
@@ -42,10 +45,9 @@
constructor(
private eiSvc: EIService) {
- super();
}
- getJobs() {
+ loadJobs() {
this.loadingSubject.next(true);
this.eiSvc.getProducerIds()
.subscribe((producerIds: string[]) => {
@@ -68,13 +70,4 @@
const updatedValue = [...currentValue, ...jobs];
this.eiJobsSubject.next(updatedValue);
}
-
- connect(): BehaviorSubject<EIJob[]> {
- return this.eiJobsSubject;
- }
-
- disconnect(): void {
- this.eiJobsSubject.complete();
- this.loadingSubject.complete();
- }
}
diff --git a/webapp-frontend/src/app/ei-coordinator/ei-producer.datasource.spec.ts b/webapp-frontend/src/app/ei-coordinator/ei-producer.datasource.spec.ts
index d5ab614..b3b2f4f 100644
--- a/webapp-frontend/src/app/ei-coordinator/ei-producer.datasource.spec.ts
+++ b/webapp-frontend/src/app/ei-coordinator/ei-producer.datasource.spec.ts
@@ -18,7 +18,7 @@
* ========================LICENSE_END===================================
*/
import { TestBed } from '@angular/core/testing';
-import { BehaviorSubject, of } from 'rxjs';
+import { of } from 'rxjs';
import { EIService } from '../services/ei/ei.service';
import { ToastrModule } from 'ngx-toastr';
@@ -74,9 +74,8 @@
it('#loadProducers', () => {
dataSource.loadProducers();
- const jobsSubject: BehaviorSubject<EIProducer[]> = dataSource.producerSubject;
- const value = jobsSubject.getValue();
- expect(value).toEqual([ expectedProducer1, expectedProducer2 ]);
+ const actualProducers: EIProducer[] = dataSource.eiProducers();
+ expect(actualProducers).toEqual([ expectedProducer1, expectedProducer2 ]);
expect(dataSource.rowCount).toEqual(2);
});
});
diff --git a/webapp-frontend/src/app/ei-coordinator/ei-producer.datasource.ts b/webapp-frontend/src/app/ei-coordinator/ei-producer.datasource.ts
index f04d9c5..255c555 100644
--- a/webapp-frontend/src/app/ei-coordinator/ei-producer.datasource.ts
+++ b/webapp-frontend/src/app/ei-coordinator/ei-producer.datasource.ts
@@ -19,11 +19,8 @@
*/
import { Injectable } from '@angular/core';
-import { MatTableDataSource } from '@angular/material';
-import { Observable } from 'rxjs/Observable';
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
-import { of } from 'rxjs/observable/of';
import { EIProducer } from '../interfaces/ei.types';
import { EIService } from '../services/ei/ei.service';
@@ -32,9 +29,13 @@
providedIn: 'root'
})
-export class EIProducerDataSource extends MatTableDataSource<EIProducer> {
+export class EIProducerDataSource {
- producerSubject = new BehaviorSubject<EIProducer[]>([]);
+ private producerSubject = new BehaviorSubject<EIProducer[]>([]);
+
+ public eiProducers(): EIProducer[] {
+ return this.producerSubject.value;
+ }
private loadingSubject = new BehaviorSubject<boolean>(false);
@@ -44,10 +45,9 @@
constructor(
private eiSvc: EIService) {
- super();
}
- loadProducers(): Observable<EIProducer[]> {
+ loadProducers() {
this.loadingSubject.next(true);
let producers: Array<EIProducer> = [];
this.eiSvc.getProducerIds()
@@ -67,7 +67,6 @@
});
this.rowCount = this.producerSubject.value.length;
});
- return of(producers);
}
private addProducerToSubject(producer: EIProducer) {
@@ -75,13 +74,4 @@
const updatedValue = [...currentValue, producer];
this.producerSubject.next(updatedValue);
}
-
- connect(): BehaviorSubject<EIProducer[]> {
- return this.producerSubject;
- }
-
- disconnect(): void {
- this.producerSubject.complete();
- this.loadingSubject.complete();
- }
}
\ No newline at end of file