[DURACOM-307] fix tests

This commit is contained in:
FrancescoMolinaro
2025-02-06 17:53:31 +01:00
parent dc70ec0ef0
commit b1eb4a8bf9
8 changed files with 26 additions and 28 deletions

View File

@@ -4,7 +4,7 @@
@if (elem.href) { @if (elem.href) {
<a href="{{elem.href}}" target="_blank" rel="noopener noreferrer">{{elem.text}}</a> <a href="{{elem.href}}" target="_blank" rel="noopener noreferrer">{{elem.text}}</a>
} @else { } @else {
{{ elem }} {{ elem.text }}
} }
} }
</div> </div>

View File

@@ -84,7 +84,7 @@ export class ContextHelpWrapperComponent implements OnInit, OnDestroy {
@Input() set content(translateKey: string) { @Input() set content(translateKey: string) {
this.content$.next(translateKey); this.content$.next(translateKey);
} }
private content$: BehaviorSubject<string | undefined> = new BehaviorSubject(undefined); private content$: BehaviorSubject<string> = new BehaviorSubject(null);
parsedContent$: Observable<ParsedContent>; parsedContent$: Observable<ParsedContent>;
@@ -100,7 +100,7 @@ export class ContextHelpWrapperComponent implements OnInit, OnDestroy {
this.content$.pipe(distinctUntilChanged(), mergeMap(translateKey => this.translateService.get(translateKey))), this.content$.pipe(distinctUntilChanged(), mergeMap(translateKey => this.translateService.get(translateKey))),
this.dontParseLinks$.pipe(distinctUntilChanged()), this.dontParseLinks$.pipe(distinctUntilChanged()),
]).pipe( ]).pipe(
map(([text, dontParseLinks]) => map(([text, dontParseLinks]: [string, boolean]) =>
dontParseLinks ? [{ text }] : this.parseLinks(text)), dontParseLinks ? [{ text }] : this.parseLinks(text)),
); );
this.shouldShowIcon$ = this.contextHelpService.shouldShowIcons$(); this.shouldShowIcon$ = this.contextHelpService.shouldShowIcons$();

View File

@@ -1,4 +1,3 @@
import { NgIf } from '@angular/common';
import { import {
Component, Component,
DebugElement, DebugElement,
@@ -164,7 +163,6 @@ describe('DSOSelectorModalWrapperComponent', () => {
templateUrl: './dso-selector-modal-wrapper.component.html', templateUrl: './dso-selector-modal-wrapper.component.html',
imports: [ imports: [
DSOSelectorComponent, DSOSelectorComponent,
NgIf,
TranslateModule, TranslateModule,
], ],
standalone: true, standalone: true,

View File

@@ -59,11 +59,12 @@ describe('ChipsComponent test suite', () => {
// synchronous beforeEach // synchronous beforeEach
beforeEach(() => { beforeEach(() => {
html = ` html = `
<ds-chips @if(chips.hasItems()) {
*ngIf="chips.hasItems()" <ds-chips
[chips]="chips" [chips]="chips"
[editable]="editable" [editable]="editable"
(selected)="onChipSelected($event)"></ds-chips>`; (selected)="onChipSelected($event)"></ds-chips>
}`;
testFixture = createTestComponent(html, TestComponent) as ComponentFixture<TestComponent>; testFixture = createTestComponent(html, TestComponent) as ComponentFixture<TestComponent>;
testComp = testFixture.componentInstance; testComp = testFixture.componentInstance;

View File

@@ -195,11 +195,13 @@ describe('FormComponent test suite', () => {
// synchronous beforeEach // synchronous beforeEach
beforeEach(() => { beforeEach(() => {
html = ` html = `
<ds-form *ngIf="formModel" #formRef="formComponent" @if('formModel') {
<ds-form #formRef="formComponent"
[formId]="formId" [formId]="formId"
[formModel]="formModel" [formModel]="formModel"
[displaySubmit]="displaySubmit" [displaySubmit]="displaySubmit"
[displayCancel]="displayCancel"></ds-form>`; [displayCancel]="displayCancel"></ds-form>
}`;
testFixture = createTestComponent(html, TestComponent) as ComponentFixture<TestComponent>; testFixture = createTestComponent(html, TestComponent) as ComponentFixture<TestComponent>;
testComp = testFixture.componentInstance; testComp = testFixture.componentInstance;

View File

@@ -1,7 +1,4 @@
import { import { NgClass } from '@angular/common';
NgClass,
NgIf,
} from '@angular/common';
import { import {
ComponentFixture, ComponentFixture,
TestBed, TestBed,
@@ -24,7 +21,6 @@ describe('OrcidBadgeAndTooltipComponent', () => {
OrcidBadgeAndTooltipComponent, OrcidBadgeAndTooltipComponent,
NgbTooltipModule, NgbTooltipModule,
NgClass, NgClass,
NgIf,
], ],
providers: [ providers: [
{ provide: TranslateService, useValue: { instant: (key: string) => key } }, { provide: TranslateService, useValue: { instant: (key: string) => key } },

View File

@@ -6,7 +6,9 @@ import {
} from '@angular/core'; } from '@angular/core';
import { import {
ComponentFixture, ComponentFixture,
fakeAsync,
TestBed, TestBed,
tick,
waitForAsync, waitForAsync,
} from '@angular/core/testing'; } from '@angular/core/testing';
import { import {
@@ -210,6 +212,11 @@ describe('SubmissionSectionDuplicatesComponent test suite', () => {
formOperationsService = TestBed.inject(SectionFormOperationsService); formOperationsService = TestBed.inject(SectionFormOperationsService);
collectionDataService = TestBed.inject(CollectionDataService); collectionDataService = TestBed.inject(CollectionDataService);
compAsAny.pathCombiner = new JsonPatchOperationPathCombiner('sections', sectionObject.id); 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(() => { afterEach(() => {
@@ -219,18 +226,13 @@ describe('SubmissionSectionDuplicatesComponent test suite', () => {
}); });
// Test initialisation of the submission section // Test initialisation of the submission section
it('Should init section properly', () => { it('Should init section properly', fakeAsync(() => {
collectionDataService.findById.and.returnValue(createSuccessfulRemoteDataObject$(mockCollection));
sectionsServiceStub.getSectionErrors.and.returnValue(observableOf([]));
sectionsServiceStub.isSectionReadOnly.and.returnValue(observableOf(false));
compAsAny.submissionService.getSubmissionScope.and.returnValue(SubmissionScopeType.WorkspaceItem);
spyOn(comp, 'getSectionStatus').and.returnValue(observableOf(true)); spyOn(comp, 'getSectionStatus').and.returnValue(observableOf(true));
spyOn(comp, 'getDuplicateData').and.returnValue(observableOf({ potentialDuplicates: duplicates }));
expect(comp.isLoading).toBeTruthy(); expect(comp.isLoading).toBeTruthy();
comp.onSectionInit(); comp.onSectionInit();
fixture.detectChanges(); tick(100);
expect(comp.isLoading).toBeFalsy(); expect(comp.isLoading).toBeFalsy();
}); }));
// The following tests look for proper logic in the getSectionStatus() implementation // 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 // 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', () => { it('Should return FALSE', () => {
compAsAny.isLoadin = true; compAsAny.isLoading = true;
expect(compAsAny.getSectionStatus()).toBeObservable(cold('(a|)', { expect(compAsAny.getSectionStatus()).toBeObservable(cold('(a|)', {
a: false, a: false,
})); }));

View File

@@ -1,4 +1,3 @@
import { NgFor } from '@angular/common';
import { Component } from '@angular/core'; import { Component } from '@angular/core';
import { import {
FormsModule, FormsModule,
@@ -15,7 +14,7 @@ import { StartsWithDateComponent as BaseComponent } from '../../../../../../app/
// templateUrl: './starts-with-date.component.html', // templateUrl: './starts-with-date.component.html',
templateUrl: '../../../../../../app/shared/starts-with/date/starts-with-date.component.html', templateUrl: '../../../../../../app/shared/starts-with/date/starts-with-date.component.html',
standalone: true, standalone: true,
imports: [FormsModule, ReactiveFormsModule, NgFor, TranslateModule], imports: [FormsModule, ReactiveFormsModule, TranslateModule],
}) })
export class StartsWithDateComponent extends BaseComponent { export class StartsWithDateComponent extends BaseComponent {
} }