Skip to content

Commit

Permalink
refactor: update tests for the new call
Browse files Browse the repository at this point in the history
  • Loading branch information
mehmetcanay committed Oct 25, 2024
1 parent bdaa453 commit 0468654
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 9 deletions.
62 changes: 56 additions & 6 deletions frontend/src/app/biomarkers/biomarkers.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { provideHttpClient } from '@angular/common/http';
import {
HttpClientTestingModule,
provideHttpClientTesting,
HttpTestingController,
} from '@angular/common/http/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
Expand All @@ -23,12 +24,12 @@ describe('BiomarkersComponent', () => {
]);

await TestBed.configureTestingModule({
imports: [
HttpClientTestingModule,
BrowserAnimationsModule,
BiomarkersComponent,
imports: [BrowserAnimationsModule, BiomarkersComponent],
providers: [
provideHttpClient(),
provideHttpClientTesting(),
{ provide: BoxplotService, useValue: boxplotSpy },
],
providers: [{ provide: BoxplotService, useValue: boxplotSpy }],
}).compileComponents();

fixture = TestBed.createComponent(BiomarkersComponent);
Expand Down Expand Up @@ -60,6 +61,13 @@ describe('BiomarkersComponent', () => {
cohort1: { Color: '#FF0000' },
cohort2: { Color: '#00FF00' },
});
const reqMappings = httpMock.expectOne(
'./assets/lower_to_original_case.json'
);
reqMappings.flush({
'feature name': 'Feature Name',
'another feature': 'Another Feature',
});

expect(component).toBeTruthy();
});
Expand All @@ -83,6 +91,13 @@ describe('BiomarkersComponent', () => {
cohort1: { Color: '#FF0000' },
cohort2: { Color: '#00FF00' },
});
const reqMappings = httpMock.expectOne(
'./assets/lower_to_original_case.json'
);
reqMappings.flush({
'feature name': 'Feature Name',
'another feature': 'Another Feature',
});

// Verify the component's state
expect(component.biomarkers).toEqual(['A', 'B']);
Expand All @@ -106,6 +121,13 @@ describe('BiomarkersComponent', () => {
cohort1: { Color: '#FF0000' },
cohort2: { Color: '#00FF00' },
});
const reqMappings = httpMock.expectOne(
'./assets/lower_to_original_case.json'
);
reqMappings.flush({
'feature name': 'Feature Name',
'another feature': 'Another Feature',
});

const event = {
value: 'New Cohort',
Expand All @@ -129,6 +151,13 @@ describe('BiomarkersComponent', () => {
cohort1: { Color: '#FF0000' },
cohort2: { Color: '#00FF00' },
});
const reqMappings = httpMock.expectOne(
'./assets/lower_to_original_case.json'
);
reqMappings.flush({
'feature name': 'Feature Name',
'another feature': 'Another Feature',
});

const event = {
option: { value: 'Biomarker' },
Expand All @@ -155,6 +184,13 @@ describe('BiomarkersComponent', () => {
cohort1: { Color: '#FF0000' },
cohort2: { Color: '#00FF00' },
});
const reqMappings = httpMock.expectOne(
'./assets/lower_to_original_case.json'
);
reqMappings.flush({
'feature name': 'Feature Name',
'another feature': 'Another Feature',
});

const event = {
option: { value: 'Cohort' },
Expand All @@ -179,6 +215,13 @@ describe('BiomarkersComponent', () => {
cohort1: { Color: '#FF0000' },
cohort2: { Color: '#00FF00' },
});
const reqMappings = httpMock.expectOne(
'./assets/lower_to_original_case.json'
);
reqMappings.flush({
'feature name': 'Feature Name',
'another feature': 'Another Feature',
});

component.selectedCohorts = ['Cohort1', 'Cohort2'];
component.removeCohort('Cohort1');
Expand Down Expand Up @@ -211,6 +254,13 @@ describe('BiomarkersComponent', () => {
cohort1: { Color: '#FF0000' },
cohort2: { Color: '#00FF00' },
});
const reqMappings = httpMock.expectOne(
'./assets/lower_to_original_case.json'
);
reqMappings.flush({
'feature name': 'Feature Name',
'another feature': 'Another Feature',
});

component.generateBoxplot();
expect(boxplotService.createBoxplot).toHaveBeenCalled();
Expand Down
35 changes: 32 additions & 3 deletions frontend/src/app/longitudinal/longitudinal.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { provideHttpClient } from '@angular/common/http';
import {
HttpClientTestingModule,
provideHttpClientTesting,
HttpTestingController,
} from '@angular/common/http/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
Expand All @@ -21,8 +22,12 @@ describe('LongitudinalComponent', () => {
const spy = jasmine.createSpyObj('LineplotService', ['createLineplot']);

await TestBed.configureTestingModule({
imports: [BrowserAnimationsModule, HttpClientTestingModule],
providers: [{ provide: LineplotService, useValue: spy }],
imports: [BrowserAnimationsModule],
providers: [
provideHttpClient(),
provideHttpClientTesting(),
{ provide: LineplotService, useValue: spy },
],
}).compileComponents();

httpMock = TestBed.inject(HttpTestingController);
Expand Down Expand Up @@ -75,6 +80,14 @@ describe('LongitudinalComponent', () => {
const reqTables = httpMock.expectOne(`${environment.API_URL}/longitudinal`);
reqTables.flush(['longitudinal_table1', 'longitudinal_table2']);

const reqMappings = httpMock.expectOne(
'./assets/lower_to_original_case.json'
);
reqMappings.flush({
'feature name': 'Feature Name',
'another feature': 'Another Feature',
});

expect(component).toBeTruthy();
});

Expand Down Expand Up @@ -116,6 +129,14 @@ describe('LongitudinalComponent', () => {
const reqTables = httpMock.expectOne(`${environment.API_URL}/longitudinal`);
reqTables.flush(['longitudinal_table1', 'longitudinal_table2']);

const reqMappings = httpMock.expectOne(
'./assets/lower_to_original_case.json'
);
reqMappings.flush({
'feature name': 'Feature Name',
'another feature': 'Another Feature',
});

expect(component.colors).toEqual({
cohort1: '#ff0000',
cohort2: '#00ff00',
Expand Down Expand Up @@ -161,6 +182,14 @@ describe('LongitudinalComponent', () => {
expect(reqTables.request.method).toBe('GET');
reqTables.flush(mockTables);

const reqMappings = httpMock.expectOne(
'./assets/lower_to_original_case.json'
);
reqMappings.flush({
'feature name': 'Feature Name',
'another feature': 'Another Feature',
});

expect(component.longitudinalTables).toEqual(['Table1', 'Table2']);
});

Expand Down

0 comments on commit 0468654

Please sign in to comment.