From b1eb4a8bf9a40ab3098f8afa5afb11a29ffefbbd Mon Sep 17 00:00:00 2001 From: FrancescoMolinaro Date: Thu, 6 Feb 2025 17:53:31 +0100 Subject: [PATCH] [DURACOM-307] fix tests --- .../context-help-wrapper.component.html | 2 +- .../context-help-wrapper.component.ts | 4 ++-- ...o-selector-modal-wrapper.component.spec.ts | 2 -- .../shared/form/chips/chips.component.spec.ts | 11 +++++----- src/app/shared/form/form.component.spec.ts | 6 ++++-- .../orcid-badge-and-tooltip.component.spec.ts | 6 +----- .../section-duplicates.component.spec.ts | 20 ++++++++++--------- .../date/starts-with-date.component.ts | 3 +-- 8 files changed, 26 insertions(+), 28 deletions(-) diff --git a/src/app/shared/context-help-wrapper/context-help-wrapper.component.html b/src/app/shared/context-help-wrapper/context-help-wrapper.component.html index 82714fb366..bb17493c52 100644 --- a/src/app/shared/context-help-wrapper/context-help-wrapper.component.html +++ b/src/app/shared/context-help-wrapper/context-help-wrapper.component.html @@ -4,7 +4,7 @@ @if (elem.href) { {{elem.text}} } @else { - {{ elem }} + {{ elem.text }} } } diff --git a/src/app/shared/context-help-wrapper/context-help-wrapper.component.ts b/src/app/shared/context-help-wrapper/context-help-wrapper.component.ts index 3bb7205234..57fcb888cb 100644 --- a/src/app/shared/context-help-wrapper/context-help-wrapper.component.ts +++ b/src/app/shared/context-help-wrapper/context-help-wrapper.component.ts @@ -84,7 +84,7 @@ export class ContextHelpWrapperComponent implements OnInit, OnDestroy { @Input() set content(translateKey: string) { this.content$.next(translateKey); } - private content$: BehaviorSubject = new BehaviorSubject(undefined); + private content$: BehaviorSubject = new BehaviorSubject(null); parsedContent$: Observable; @@ -100,7 +100,7 @@ export class ContextHelpWrapperComponent implements OnInit, OnDestroy { this.content$.pipe(distinctUntilChanged(), mergeMap(translateKey => this.translateService.get(translateKey))), this.dontParseLinks$.pipe(distinctUntilChanged()), ]).pipe( - map(([text, dontParseLinks]) => + map(([text, dontParseLinks]: [string, boolean]) => dontParseLinks ? [{ text }] : this.parseLinks(text)), ); this.shouldShowIcon$ = this.contextHelpService.shouldShowIcons$(); diff --git a/src/app/shared/dso-selector/modal-wrappers/dso-selector-modal-wrapper.component.spec.ts b/src/app/shared/dso-selector/modal-wrappers/dso-selector-modal-wrapper.component.spec.ts index 4bbdd11a04..91dc1598af 100644 --- a/src/app/shared/dso-selector/modal-wrappers/dso-selector-modal-wrapper.component.spec.ts +++ b/src/app/shared/dso-selector/modal-wrappers/dso-selector-modal-wrapper.component.spec.ts @@ -1,4 +1,3 @@ -import { NgIf } from '@angular/common'; import { Component, DebugElement, @@ -164,7 +163,6 @@ describe('DSOSelectorModalWrapperComponent', () => { templateUrl: './dso-selector-modal-wrapper.component.html', imports: [ DSOSelectorComponent, - NgIf, TranslateModule, ], standalone: true, diff --git a/src/app/shared/form/chips/chips.component.spec.ts b/src/app/shared/form/chips/chips.component.spec.ts index 6035da3d15..7d4ba95345 100644 --- a/src/app/shared/form/chips/chips.component.spec.ts +++ b/src/app/shared/form/chips/chips.component.spec.ts @@ -59,11 +59,12 @@ describe('ChipsComponent test suite', () => { // synchronous beforeEach beforeEach(() => { html = ` - `; + @if(chips.hasItems()) { + + }`; testFixture = createTestComponent(html, TestComponent) as ComponentFixture; testComp = testFixture.componentInstance; diff --git a/src/app/shared/form/form.component.spec.ts b/src/app/shared/form/form.component.spec.ts index f593d9bad6..b8933a64cc 100644 --- a/src/app/shared/form/form.component.spec.ts +++ b/src/app/shared/form/form.component.spec.ts @@ -195,11 +195,13 @@ describe('FormComponent test suite', () => { // synchronous beforeEach beforeEach(() => { html = ` - `; + [displayCancel]="displayCancel"> + }`; testFixture = createTestComponent(html, TestComponent) as ComponentFixture; testComp = testFixture.componentInstance; diff --git a/src/app/shared/orcid-badge-and-tooltip/orcid-badge-and-tooltip.component.spec.ts b/src/app/shared/orcid-badge-and-tooltip/orcid-badge-and-tooltip.component.spec.ts index dd47fd918b..8ed97ddb37 100644 --- a/src/app/shared/orcid-badge-and-tooltip/orcid-badge-and-tooltip.component.spec.ts +++ b/src/app/shared/orcid-badge-and-tooltip/orcid-badge-and-tooltip.component.spec.ts @@ -1,7 +1,4 @@ -import { - NgClass, - NgIf, -} from '@angular/common'; +import { NgClass } from '@angular/common'; import { ComponentFixture, TestBed, @@ -24,7 +21,6 @@ describe('OrcidBadgeAndTooltipComponent', () => { OrcidBadgeAndTooltipComponent, NgbTooltipModule, NgClass, - NgIf, ], providers: [ { provide: TranslateService, useValue: { instant: (key: string) => key } }, diff --git a/src/app/submission/sections/duplicates/section-duplicates.component.spec.ts b/src/app/submission/sections/duplicates/section-duplicates.component.spec.ts index a86d44ab17..8aa2cfee24 100644 --- a/src/app/submission/sections/duplicates/section-duplicates.component.spec.ts +++ b/src/app/submission/sections/duplicates/section-duplicates.component.spec.ts @@ -6,7 +6,9 @@ import { } from '@angular/core'; import { ComponentFixture, + fakeAsync, TestBed, + tick, waitForAsync, } from '@angular/core/testing'; import { @@ -210,6 +212,11 @@ describe('SubmissionSectionDuplicatesComponent test suite', () => { formOperationsService = TestBed.inject(SectionFormOperationsService); collectionDataService = TestBed.inject(CollectionDataService); compAsAny.pathCombiner = new JsonPatchOperationPathCombiner('sections', sectionObject.id); + spyOn(comp, 'getDuplicateData').and.returnValue(observableOf({ potentialDuplicates: duplicates })); + collectionDataService.findById.and.returnValue(createSuccessfulRemoteDataObject$(mockCollection)); + sectionsServiceStub.getSectionErrors.and.returnValue(observableOf([])); + sectionsServiceStub.isSectionReadOnly.and.returnValue(observableOf(false)); + compAsAny.submissionService.getSubmissionScope.and.returnValue(SubmissionScopeType.WorkspaceItem); }); afterEach(() => { @@ -219,18 +226,13 @@ describe('SubmissionSectionDuplicatesComponent test suite', () => { }); // Test initialisation of the submission section - it('Should init section properly', () => { - collectionDataService.findById.and.returnValue(createSuccessfulRemoteDataObject$(mockCollection)); - sectionsServiceStub.getSectionErrors.and.returnValue(observableOf([])); - sectionsServiceStub.isSectionReadOnly.and.returnValue(observableOf(false)); - compAsAny.submissionService.getSubmissionScope.and.returnValue(SubmissionScopeType.WorkspaceItem); + it('Should init section properly', fakeAsync(() => { spyOn(comp, 'getSectionStatus').and.returnValue(observableOf(true)); - spyOn(comp, 'getDuplicateData').and.returnValue(observableOf({ potentialDuplicates: duplicates })); expect(comp.isLoading).toBeTruthy(); comp.onSectionInit(); - fixture.detectChanges(); + tick(100); expect(comp.isLoading).toBeFalsy(); - }); + })); // The following tests look for proper logic in the getSectionStatus() implementation // These are very simple as we don't really have a 'false' state unless we're still loading @@ -241,7 +243,7 @@ describe('SubmissionSectionDuplicatesComponent test suite', () => { })); }); it('Should return FALSE', () => { - compAsAny.isLoadin = true; + compAsAny.isLoading = true; expect(compAsAny.getSectionStatus()).toBeObservable(cold('(a|)', { a: false, })); diff --git a/src/themes/custom/app/shared/starts-with/date/starts-with-date.component.ts b/src/themes/custom/app/shared/starts-with/date/starts-with-date.component.ts index 3f57274d36..f14d1f39c5 100644 --- a/src/themes/custom/app/shared/starts-with/date/starts-with-date.component.ts +++ b/src/themes/custom/app/shared/starts-with/date/starts-with-date.component.ts @@ -1,4 +1,3 @@ -import { NgFor } from '@angular/common'; import { Component } from '@angular/core'; import { FormsModule, @@ -15,7 +14,7 @@ import { StartsWithDateComponent as BaseComponent } from '../../../../../../app/ // templateUrl: './starts-with-date.component.html', templateUrl: '../../../../../../app/shared/starts-with/date/starts-with-date.component.html', standalone: true, - imports: [FormsModule, ReactiveFormsModule, NgFor, TranslateModule], + imports: [FormsModule, ReactiveFormsModule, TranslateModule], }) export class StartsWithDateComponent extends BaseComponent { }