Skip to content

Commit

Permalink
Fix frontend test errors and remove logs (#462)
Browse files Browse the repository at this point in the history
* add karma verbose reporter

* Move fontawesome imports to separate module for easier testing imports

* add some missing imports/declarations

* remove console.logs

* add .catch where i got rid of empty .then
  • Loading branch information
jean-the-coder committed May 1, 2024
1 parent d280e93 commit 3b6d262
Show file tree
Hide file tree
Showing 67 changed files with 116 additions and 224 deletions.
9 changes: 7 additions & 2 deletions frontend/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ module.exports = function(config) {
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage'),
require('@angular-devkit/build-angular/plugins/karma')
require('karma-verbose-reporter'),
require('@angular-devkit/build-angular/plugins/karma'),
],
client: {
jasmine: {
Expand Down Expand Up @@ -41,7 +42,11 @@ module.exports = function(config) {
},

// coverage reporter generates the coverage
reporters: ['progress', 'coverage'],
reporters: [
'progress',
'coverage',
// 'verbose'
],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
Expand Down
1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
"karma-coverage-istanbul-reporter": "~3.0.2",
"karma-jasmine": "~5.1.0",
"karma-jasmine-html-reporter": "^2.1.0",
"karma-verbose-reporter": "^0.0.8",
"protractor": "~7.0.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/app/app.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { TestBed, async } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { AppComponent } from './app.component';
import {HttpClientTestingModule} from '@angular/common/http/testing';
import { ToastComponent } from './components/toast/toast.component';

describe('AppComponent', () => {
beforeEach(async(() => {
Expand All @@ -11,7 +12,7 @@ describe('AppComponent', () => {
HttpClientTestingModule
],
declarations: [
AppComponent
AppComponent, ToastComponent
],
}).compileComponents();
}));
Expand Down
3 changes: 0 additions & 3 deletions frontend/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ export class AppComponent implements OnInit {
if (event.url?.startsWith('/auth') || event.url?.startsWith('/desktop')) {
this.showHeader = false;
} else {
// console.log("NU")
this.showHeader = true;
}

Expand All @@ -48,5 +47,3 @@ export class AppComponent implements OnInit {
}
}
}


14 changes: 4 additions & 10 deletions frontend/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ import { DashboardComponent } from './pages/dashboard/dashboard.component';
import { MedicalSourcesComponent } from './pages/medical-sources/medical-sources.component';
import { NgChartsModule } from 'ng2-charts';
import {SharedModule} from './components/shared.module';
import { FontAwesomeModule, FaIconLibrary } from '@fortawesome/angular-fontawesome'
import { fas } from '@fortawesome/free-solid-svg-icons';
import { far } from '@fortawesome/free-regular-svg-icons';
import { ResourceDetailComponent } from './pages/resource-detail/resource-detail.component';
import { AuthSignupComponent } from './pages/auth-signup/auth-signup.component';
import { AuthSigninComponent } from './pages/auth-signin/auth-signin.component';
Expand Down Expand Up @@ -42,6 +39,7 @@ import {FhirCardModule} from './components/fhir-card/fhir-card.module';
import {FhirDatatableModule} from './components/fhir-datatable/fhir-datatable.module';
import { AuthSignupWizardComponent } from './pages/auth-signup-wizard/auth-signup-wizard.component';
import {ShowFirstRunWizardGuard} from './auth-guards/show-first-run-wizard-guard';
import { IconsModule } from './icon-module';

@NgModule({
declarations: [
Expand All @@ -67,7 +65,6 @@ import {ShowFirstRunWizardGuard} from './auth-guards/show-first-run-wizard-guard
FormsModule,
ReactiveFormsModule,
BrowserModule,
FontAwesomeModule,
SharedModule,
FhirCardModule,
FhirDatatableModule,
Expand All @@ -82,7 +79,8 @@ import {ShowFirstRunWizardGuard} from './auth-guards/show-first-run-wizard-guard
InfiniteScrollModule,
NgSelectModule,
WidgetsModule,
DirectivesModule
DirectivesModule,
IconsModule,
],
providers: [
{
Expand Down Expand Up @@ -112,8 +110,4 @@ import {ShowFirstRunWizardGuard} from './auth-guards/show-first-run-wizard-guard
bootstrap: [AppComponent],
schemas: [CUSTOM_ELEMENTS_SCHEMA] //required for lhncbc/lforms (webcomponent)
})
export class AppModule {
constructor(library: FaIconLibrary) {
library.addIconPacks(fas, far);
}
}
export class AppModule {}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe('TableComponent', () => {
it('encodes urls properly', () => {
spyOn(console, 'log').and.callThrough();
const link = fixture.debugElement.nativeElement.querySelector('a');
console.log(link);

expect(link.href).toContain(
'/explore/123-456-789%3D/resource/aHR0cHM6Ly93d3cubWVyY3kubmV0L3NpdGVzL2RlZmF1bHQvZmlsZXMvZG9jdG9yX2ltYWdlcy9kZXNrdG9wLzE2NTk4ODYwNTktbS5qcGc%3D'
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';

import { RtfComponent } from './rtf.component';
import { BinaryModel } from 'src/lib/models/resources/binary-model';
import { RTFJS } from 'rtf.js';

describe('RtfComponent', () => {
let component: RtfComponent;
Expand All @@ -15,6 +16,8 @@ describe('RtfComponent', () => {
})
.compileComponents();

RTFJS.loggingEnabled(false);

fixture = TestBed.createComponent(RtfComponent);
component = fixture.componentInstance;
component.displayModel = new BinaryModel({});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ export class FhirCardComponent implements OnInit, OnChanges {

let componentType = this.typeLookup(this.displayModel?.source_resource_type)
if(componentType != null){
console.log("Attempting to create fhir display component", this.displayModel, componentType)
const componentRef = viewContainerRef.createComponent<FhirCardComponentInterface>(componentType);
componentRef.instance.displayModel = this.displayModel;
componentRef.instance.showDetails = this.showDetails;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { FallbackComponent } from './fallback.component';
import { HIGHLIGHT_OPTIONS } from 'ngx-highlightjs';

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

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [ FallbackComponent ]
imports: [ FallbackComponent ],
providers: [
{
provide: HIGHLIGHT_OPTIONS,
useValue: {
coreLibraryLoader: () => import('highlight.js/lib/core'),
lineNumbersLoader: () => import('highlightjs-line-numbers.js'), // Optional, only if you want the line numbers
languages: {
json: () => import('highlight.js/lib/languages/json')
},
}
},
]
})
.compileComponents();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { DatatableGenericResourceComponent } from './datatable-generic-resource.
import {HTTP_CLIENT_TOKEN} from '../../../dependency-injection';
import {HttpClient} from '@angular/common/http';
import {HttpClientTestingModule} from '@angular/common/http/testing';
import { NgxDatatableModule } from '@swimlane/ngx-datatable';

describe('ListGenericResourceComponent', () => {
let component: DatatableGenericResourceComponent;
Expand All @@ -12,7 +13,7 @@ describe('ListGenericResourceComponent', () => {
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ DatatableGenericResourceComponent ],
imports: [HttpClientTestingModule],
imports: [HttpClientTestingModule, NgxDatatableModule],
providers: [
{
provide: HTTP_CLIENT_TOKEN,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ export class DatatableGenericResourceComponent implements OnInit, ResourceListCo
}

ngOnInit(): void {
console.log("INIT GENERIC RESOURCE")
this.currentPage = {offset: 0}

this.changePage(this.currentPage)
Expand All @@ -75,7 +74,6 @@ export class DatatableGenericResourceComponent implements OnInit, ResourceListCo
}

changePage(page: PageInfo){
console.log("Requesting page:" + JSON.stringify(page))
this.currentPage = page;
this.fastenApi.getResources(this.resourceListType, this.sourceId, null, this.currentPage.offset)
.subscribe((resourceList: ResourceFhir[]) => {
Expand All @@ -100,7 +98,6 @@ export class DatatableGenericResourceComponent implements OnInit, ResourceListCo


renderList(resourceList: ResourceFhir[]){
console.log("GENERIC RESOURCE RENDERLSIT")
this.columns = this.columnDefinitions.map((defn) => {
let column = {name: defn.title, prop: defn.title.replace(/[^A-Z0-9]/ig, "_"), sortable: false}
return column
Expand Down Expand Up @@ -152,15 +149,3 @@ export class DatatableGenericResourceComponent implements OnInit, ResourceListCo
///////////////////////////////////////////////////////////////////////////////////////
// START OVERRIDES
///////////////////////////////////////////////////////////////////////////////////////












Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ export class FhirDatatableComponent implements OnInit, OnChanges {

let componentType = this.typeLookup(this.resourceListType)
if(componentType != null){
console.log("Attempting to create component", this.resourceListType, componentType)
const componentRef = viewContainerRef.createComponent<ResourceListComponentInterface>(componentType);
componentRef.instance.totalElements = this.selectedTotalElements;
componentRef.instance.resourceListType = this.resourceListType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export class GlossaryLookupComponent implements OnInit {
ngOnInit(): void {
this.fastenApi.getGlossarySearchByCode(this.code, this.codeSystem).subscribe(result => {
this.loading = false
console.log(result)
this.url = result?.url
this.source = result?.publisher
this.description = this.sanitized.bypassSecurityTrustHtml(result?.description)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,10 @@ const withHttpClientProvider: DecoratorFunction<any> = (storyFunc, context) => {
class MockHttpClient extends HttpClient {

get(): Observable<any> {
// console.log("CALLED getGlossarySearchByCode in MockFastenApiService")
return of(httpClientResp)
}
}

// console.log("Inside withHttpClientProvider DecoratorFunction", code, codeSystem)
return moduleMetadata({ providers: [{ provide: HTTP_CLIENT_TOKEN, useClass: MockHttpClient }] })(
storyFunc,
context
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/app/components/header/header.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ import {RouterModule} from '@angular/router';
import {RouterTestingModule} from '@angular/router/testing';
import {HTTP_CLIENT_TOKEN} from '../../dependency-injection';
import {HttpClient} from '@angular/common/http';
import { IconsModule } from 'src/app/icon-module';

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

beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [ HttpClientTestingModule, RouterTestingModule, RouterModule ],
imports: [ HttpClientTestingModule, RouterTestingModule, RouterModule, IconsModule ],
declarations: [ HeaderComponent ],
providers: [
{
Expand Down
2 changes: 0 additions & 2 deletions frontend/src/app/components/header/header.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,10 @@ export class HeaderComponent implements OnInit, OnDestroy {
this.newSupportRequest = newSupportRequest
}
submitSupportForm() {
console.log("submitting support form", this.newSupportRequest)
this.loading = false

this.fastenApi.supportRequest(this.newSupportRequest).subscribe((resp: any) => {
this.loading = false
console.log(resp);
this.submitSuccess = true
//show success toast? close modal?
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export class MedicalRecordWizardAddAttachmentComponent implements OnInit {
}

onAttachmentFileChange($event){
console.log("onAttachmentFileChange")
let fileInput = $event.target as HTMLInputElement;
if (fileInput.files && fileInput.files[0]) {
let processingFile = fileInput.files[0]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ export class MedicalRecordWizardAddEncounterComponent implements OnInit {
}
}
selectionChanged(event) {
console.log("SELECTION CHANGED", event)
this.selectedEncounter = event
}
get submitEnabled() {
Expand Down Expand Up @@ -108,7 +107,6 @@ export class MedicalRecordWizardAddEncounterComponent implements OnInit {
let parsed = RecResourceRelatedDisplayModel(graphResponse.results["Encounter"]?.[0])
let encounterDisplayModelWithRelated = parsed.displayModel as EncounterModel

console.log("Found encounter (and related resources)", encounterDisplayModelWithRelated)
this.activeModal.close({
action: this.activeId,
data: encounterDisplayModelWithRelated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ export class MedicalRecordWizardAddLabResultsComponent implements OnInit {
ngOnInit(): void {

// const parent: HTMLElement = document.getElementById('lhcFormContainer');
// console.log("Adding Form to page", this.questionnaire)
// LForms.Util.addFormToPage(this.questionnaire, parent);
this.resetLabPanelForm()
}
Expand All @@ -60,26 +59,18 @@ export class MedicalRecordWizardAddLabResultsComponent implements OnInit {
null,
{bundleType: "transaction"}
)
console.log(formData)

this.activeModal.close({
action: 'create',
data: formData
});
}
onFormReady(e){
console.log("onFormReady", e)
}
onError(e){
console.log("onError", e)
}

private resetLabPanelForm() {
this.newLabPanelTypeaheadForm = new FormGroup({
data: new FormControl(null, Validators.required),
})
this.newLabPanelTypeaheadForm.valueChanges.subscribe(form => {
console.log("CHANGE LabPanel IN MODAL", form)
let val = form.data
if(val && val.id){
this.loading = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ export class MedicalRecordWizardAddOrganizationComponent implements OnInit {
}
}
selectionChanged(event) {
console.log("SELECTION CHANGED", event)
this.selectedOrganization = event
}
get submitEnabled() {
Expand Down Expand Up @@ -160,7 +159,6 @@ export class MedicalRecordWizardAddOrganizationComponent implements OnInit {
data: new FormControl(null, Validators.required),
})
this.newOrganizationTypeaheadForm.valueChanges.subscribe(form => {
console.log("CHANGE Organization IN MODAL", form)
let val = form.data

if(val == null){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ export class MedicalRecordWizardAddPractitionerComponent implements OnInit {
}
}
selectionChanged(event) {
console.log("SELECTION CHANGED", event)
this.selectedPractitioner = event
}
get submitEnabled() {
Expand Down Expand Up @@ -168,7 +167,6 @@ export class MedicalRecordWizardAddPractitionerComponent implements OnInit {
data: new FormControl(null, Validators.required),
})
this.newPractitionerTypeaheadForm.valueChanges.subscribe(form => {
console.log("CHANGE INDIVIDUAL IN MODAL", form)
let val = form.data
if(val == null){
//reset the dependant fields (user cleared the text box)
Expand Down

0 comments on commit 3b6d262

Please sign in to comment.