Skip to content

Commit

Permalink
#614 added mock data stubs for test errors
Browse files Browse the repository at this point in the history
  • Loading branch information
arawinters committed Mar 22, 2024
1 parent 56f88fb commit 5edf8ab
Show file tree
Hide file tree
Showing 13 changed files with 678 additions and 29 deletions.
12 changes: 10 additions & 2 deletions src/lib/charts/records-by-datasources/sz-donut.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,23 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { SzRecordStatsDonutChart } from './sz-donut.component';
import { SenzingSdkModule } from 'src/lib/sdk.module';
import { HTTP_INTERCEPTORS } from '@angular/common/http';
import { MockTestDataInterceptor } from 'src/lib/interceptors/mock-test-data.interceptor.service';

describe('SzRecordStatsDonutChart', () => {
let component: SzRecordStatsDonutChart;
let fixture: ComponentFixture<SzRecordStatsDonutChart>;

beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [SenzingSdkModule.forRoot()]
imports: [SenzingSdkModule.forRoot()],
providers: [
{
provide: HTTP_INTERCEPTORS,
useClass: MockTestDataInterceptor,
multi: true
}
]
})
.compileComponents();

Expand All @@ -23,7 +32,6 @@ describe('SzRecordStatsDonutChart', () => {
});

it('should create', () => {
// test fails on CI only (issue #75)
// temporarily removing until more is known
expect(component).toBeTruthy();
});
Expand Down
42 changes: 23 additions & 19 deletions src/lib/charts/records-by-datasources/sz-donut.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export class SzRecordStatsDonutChart implements OnInit, OnDestroy {
*/
@Output('dataChanged')
dataChanged: Subject<SzRecordCountDataSource[]> = new Subject<SzRecordCountDataSource[]>();

/**
* emitted when the user clicks a datasource arc node.
* @returns object with various datasource and ui properties.
Expand Down Expand Up @@ -225,19 +226,27 @@ export class SzRecordStatsDonutChart implements OnInit, OnDestroy {
}

ngOnInit() {
// get data source counts
this.getDataSourceRecordCounts().pipe(
// only execute draw once we have the data
this.dataChanged.pipe(
takeUntil(this.unsubscribe$)
).subscribe({
next: (recordCounts: SzRecordCountDataSource[])=>{
if(this._dataSourceCounts && this._dataSources) {
this.dataChanged.next(this._dataSourceCounts);
}
next: (data) => {
//console.log('counted totals', this.getTotalsFromCounts(data));
this.initDonut()
this.renderDonut(data);
},
error: (err) => {
this.exception.next(err);
}
});

// listend for datasource clicks
this.dataSourceClick.pipe(
takeUntil(this.unsubscribe$)
).subscribe((d)=>{
console.log('data source clicked', d);
})

// get data sources
this.getDataSources().pipe(
takeUntil(this.unsubscribe$),
Expand All @@ -247,33 +256,28 @@ export class SzRecordStatsDonutChart implements OnInit, OnDestroy {
this._dataSources = dataSources;
if(this._dataSourceCounts && this._dataSources) {
this.dataChanged.next(this._dataSourceCounts);
} else {
console.warn('huh?', dataSources);
}
},
error: (err) => {
this.exception.next(err);
}
});

// only execute draw once we have the data
this.dataChanged.pipe(
// get data source counts
this.getDataSourceRecordCounts().pipe(
takeUntil(this.unsubscribe$)
).subscribe({
next: (data) => {
//console.log('counted totals', this.getTotalsFromCounts(data));
this.initDonut()
this.renderDonut(data);
next: (recordCounts: SzRecordCountDataSource[])=>{
if(this._dataSourceCounts && this._dataSources) {
this.dataChanged.next(this._dataSourceCounts);
}
},
error: (err) => {
this.exception.next(err);
}
});
// listend for datasource clicks
this.dataSourceClick.pipe(
takeUntil(this.unsubscribe$)
).subscribe((d)=>{
console.log('data source clicked', d);
})

}

/** --------------------------------------- methods and subs -------------------------------------- */
Expand Down
14 changes: 12 additions & 2 deletions src/lib/charts/versus/sz-venn-diagram.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,23 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { SzVennDiagramsComponent } from './sz-venn-diagram.component';
import { SenzingSdkModule } from '../../sdk.module';

describe('SzRecordStatsDonutChart', () => {
import { HTTP_INTERCEPTORS } from '@angular/common/http';
import { MockTestDataInterceptor } from 'src/lib/interceptors/mock-test-data.interceptor.service';

describe('SzVennDiagramsComponent', () => {
let component: SzVennDiagramsComponent;
let fixture: ComponentFixture<SzVennDiagramsComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [SenzingSdkModule.forRoot()]
imports: [SenzingSdkModule.forRoot()],
providers: [
{
provide: HTTP_INTERCEPTORS,
useClass: MockTestDataInterceptor,
multi: true
}
]
})
.compileComponents();

Expand Down
30 changes: 30 additions & 0 deletions src/lib/interceptors/mock-test-data.interceptor.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Injectable, Injector } from '@angular/core';
import {
HttpEvent, HttpInterceptor, HttpHandler, HttpRequest,
HttpResponse
} from '@angular/common/http';

import { BehaviorSubject, Observable, of, Subject, throwError } from 'rxjs';
import * as datasourceStubData from '../../../stubs/datasources/datasources.json';
import * as statisticsLoadedStubData from '../../../stubs/statistics/loaded/loaded.json';
import * as statisticsSummaryStubData from '../../../stubs/statistics/summary/summary.json';

@Injectable()
export class MockTestDataInterceptor implements HttpInterceptor {
constructor(private injector: Injector) {}
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
if(request.method === "GET" && request.url.indexOf("/data-sources") > 0) {
console.log('intercepted datasource http request: ', request);
return of(new HttpResponse({ status: 200, body: datasourceStubData }));
}
if(request.method === "GET" && request.url.indexOf("/statistics/loaded") > 0) {
console.log('intercepted loaded statistics http request: ', request);
return of(new HttpResponse({ status: 200, body: statisticsLoadedStubData }));
}
if(request.method === "GET" && request.url.indexOf("/statistics/summary") > 0) {
console.log('intercepted summary statistics http request: ', request);
return of(new HttpResponse({ status: 200, body: statisticsSummaryStubData }));
}
return next.handle(request);
}
}
7 changes: 3 additions & 4 deletions src/lib/services/sz-datamart.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ import { SzCountStatsForDataSourcesResponse, SzStatCountsForDataSources } from '
import { SzPrefsService } from '../services/sz-prefs.service';
import { SzDataSourcesService } from './sz-datasources.service';

// use mock data
//import * as recordStatsStubData from '../../stubs/statistics/loaded/1.json';


/**
* methods used to get data from the poc server using the
* datamart api(s)
Expand Down Expand Up @@ -110,6 +106,9 @@ export class SzDataMartService {
return this.dataSourcesService.listDataSources().pipe(
tap((ds: string[]) => {
this._dataSources = ds;
}),
catchError((error) => {
return of(false);
})
);
}
Expand Down
4 changes: 4 additions & 0 deletions src/lib/services/sz-datasources.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,13 @@ export class SzDataSourcesService {
// get attributes
return this.configService.getDataSources()
.pipe(
tap( (resp: SzDataSourcesResponse) => {
console.log(`listDataSourcesDetails[1]: `, resp);
}),
map( (resp: SzDataSourcesResponse) => resp.data ),
tap( (data) => {
this._dataSourceDetails = data;
console.log(`listDataSourcesDetails[2]: `, data);
})
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { HTTP_INTERCEPTORS } from '@angular/common/http';
import { MockTestDataInterceptor } from '../../interceptors/mock-test-data.interceptor.service';

import { SzCrossSourceResultsDataTable } from './sz-cross-source-results.data-table';
import { SenzingSdkModule } from '../../sdk.module';

describe('SzCrossSourceResultsDataTable', () => {
let component: SzCrossSourceResultsDataTable;
let fixture: ComponentFixture<SzCrossSourceResultsDataTable>;

beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [SenzingSdkModule.forRoot()],
providers: [
{
provide: HTTP_INTERCEPTORS,
useClass: MockTestDataInterceptor,
multi: true
}
]
})
.compileComponents();

fixture = TestBed.createComponent(SzCrossSourceResultsDataTable);
component = fixture.componentInstance;
fixture.detectChanges();
}));

afterEach(() => {
fixture.destroy();
});

it('should create', () => {
// test fails on CI only (issue #75)
// temporarily removing until more is known
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { HTTP_INTERCEPTORS } from '@angular/common/http';
import { MockTestDataInterceptor } from '../../interceptors/mock-test-data.interceptor.service';

import { SzCrossSourceSelectComponent } from './sz-cross-source-select.component';
import { SenzingSdkModule } from '../../sdk.module';

describe('SzCrossSourceSelectComponent', () => {
let component: SzCrossSourceSelectComponent;
let fixture: ComponentFixture<SzCrossSourceSelectComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [SenzingSdkModule.forRoot()],
providers: [
{
provide: HTTP_INTERCEPTORS,
useClass: MockTestDataInterceptor,
multi: true
}
]
})
.compileComponents();

fixture = TestBed.createComponent(SzCrossSourceSelectComponent);
component = fixture.componentInstance;
fixture.detectChanges();
}));

afterEach(() => {
fixture.destroy();
});

it('should create', () => {
// test fails on CI only (issue #75)
// temporarily removing until more is known
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { HTTP_INTERCEPTORS } from '@angular/common/http';
import { MockTestDataInterceptor } from '../../interceptors/mock-test-data.interceptor.service';

import { SzCrossSourceStatistics } from './sz-cross-source-statistics.component';
import { SenzingSdkModule } from '../../sdk.module';

describe('SzCrossSourceStatistics', () => {
let component: SzCrossSourceStatistics;
let fixture: ComponentFixture<SzCrossSourceStatistics>;

beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [SenzingSdkModule.forRoot()],
providers: [
{
provide: HTTP_INTERCEPTORS,
useClass: MockTestDataInterceptor,
multi: true
}
]
})
.compileComponents();

fixture = TestBed.createComponent(SzCrossSourceStatistics);
component = fixture.componentInstance;
fixture.detectChanges();
}));

afterEach(() => {
fixture.destroy();
});

it('should create', () => {
// test fails on CI only (issue #75)
// temporarily removing until more is known
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { HTTP_INTERCEPTORS } from '@angular/common/http';
import { MockTestDataInterceptor } from '../../interceptors/mock-test-data.interceptor.service';

import { SzCrossSourceSummaryComponent } from './sz-cross-source-summary.component';
import { SenzingSdkModule } from '../../sdk.module';

describe('SzRecordStatsDonutChart', () => {
describe('SzCrossSourceSummaryComponent', () => {
let component: SzCrossSourceSummaryComponent;
let fixture: ComponentFixture<SzCrossSourceSummaryComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [SenzingSdkModule.forRoot()]
imports: [SenzingSdkModule.forRoot()],
providers: [
{
provide: HTTP_INTERCEPTORS,
useClass: MockTestDataInterceptor,
multi: true
}
]
})
.compileComponents();

Expand Down
23 changes: 23 additions & 0 deletions stubs/datasources/datasources.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"data": {
"dataSources": [
"TRUTHSET1",
"TRUTHSET2",
"TRUTHSET3"
],
"dataSourceDetails": {
"TRUTHSET1": {
"dataSourceCode": "TRUTHSET1",
"dataSourceId": 1006
},
"TRUTHSET2": {
"dataSourceCode": "TRUTHSET2",
"dataSourceId": 1007
},
"TRUTHSET3": {
"dataSourceCode": "TRUTHSET3",
"dataSourceId": 1008
}
}
}
}
Loading

0 comments on commit 5edf8ab

Please sign in to comment.