[DURACOM-191] Fix tests

This commit is contained in:
Giuseppe Digilio
2024-03-17 17:34:35 +01:00
parent 788e44a770
commit 2e8817712a
8 changed files with 51 additions and 42 deletions

View File

@@ -36,7 +36,7 @@
[authorityValue]="mdValue.newValue.confidence"
[iconMode]="true"
></i>
<input class="form-control form-outline" [(ngModel)]="mdValue.newValue.authority" [disabled]="!editingAuthority"
<input class="form-control form-outline" data-test="authority-input" [(ngModel)]="mdValue.newValue.authority" [disabled]="!editingAuthority"
[attr.aria-label]="(dsoType + '.edit.metadata.edit.authority.key') | translate"
(change)="onChangeAuthorityKey()" />
<button class="btn btn-outline-secondary btn-sm ng-star-inserted" id="metadata-confirm-btn" *ngIf="!editingAuthority"

View File

@@ -37,6 +37,8 @@ import {
VIRTUAL_METADATA_PREFIX,
} from '../../../core/shared/metadata.models';
import { ItemMetadataRepresentation } from '../../../core/shared/metadata-representation/item/item-metadata-representation.model';
import { DsDynamicOneboxComponent } from '../../../shared/form/builder/ds-dynamic-form-ui/models/onebox/dynamic-onebox.component';
import { DsDynamicScrollableDropdownComponent } from '../../../shared/form/builder/ds-dynamic-form-ui/models/scrollable-dropdown/dynamic-scrollable-dropdown.component';
import { ThemedTypeBadgeComponent } from '../../../shared/object-collection/shared/badges/type-badge/themed-type-badge.component';
import { createSuccessfulRemoteDataObject$ } from '../../../shared/remote-data.utils';
import { VarDirective } from '../../../shared/utils/var.directive';
@@ -202,7 +204,7 @@ describe('DsoEditMetadataValueComponent', () => {
})
.overrideComponent(DsoEditMetadataValueComponent, {
remove: {
imports: [ThemedTypeBadgeComponent],
imports: [DsDynamicOneboxComponent, DsDynamicScrollableDropdownComponent, ThemedTypeBadgeComponent],
},
})
.compileComponents();
@@ -464,22 +466,30 @@ describe('DsoEditMetadataValueComponent', () => {
expect(component.onChangeEditingAuthorityStatus).toHaveBeenCalledWith(true);
});
it('should disable the input when editingAuthority is false', () => {
it('should disable the input when editingAuthority is false', (done) => {
component.editingAuthority = false;
fixture.detectChanges();
const inputElement = fixture.nativeElement.querySelector('input');
expect(inputElement.disabled).toBe(true);
fixture.detectChanges();
fixture.whenStable().then(() => {
const inputElement = fixture.nativeElement.querySelector('input[data-test="authority-input"]');
expect(inputElement.disabled).toBeTruthy();
done();
});
});
it('should enable the input when editingAuthority is true', () => {
it('should enable the input when editingAuthority is true', (done) => {
component.editingAuthority = true;
fixture.detectChanges();
fixture.whenStable().then(() => {
const inputElement = fixture.nativeElement.querySelector('input[data-test="authority-input"]');
expect(inputElement.disabled).toBeFalsy();
done();
});
const inputElement = fixture.nativeElement.querySelector('input');
expect(inputElement.disabled).toBe(false);
});
it('should update mdValue.newValue properties when authority is present', () => {

View File

@@ -3,6 +3,7 @@ import {
fakeAsync,
TestBed,
tick,
waitForAsync,
} from '@angular/core/testing';
import { TranslateModule } from '@ngx-translate/core';
import { NotifyRequestsStatusDataService } from 'src/app/core/data/notify-services-status-data.service';
@@ -10,6 +11,7 @@ import { NotifyRequestsStatusDataService } from 'src/app/core/data/notify-servic
import { createSuccessfulRemoteDataObject$ } from '../../../../shared/remote-data.utils';
import { NotifyRequestsStatus } from '../notify-requests-status.model';
import { RequestStatusEnum } from '../notify-status.enum';
import { RequestStatusAlertBoxComponent } from '../request-status-alert-box/request-status-alert-box.component';
import { NotifyRequestsStatusComponent } from './notify-requests-status.component';
describe('NotifyRequestsStatusComponent', () => {
@@ -22,7 +24,7 @@ describe('NotifyRequestsStatusComponent', () => {
itemuuid: 'testUuid',
});
beforeEach(() => {
beforeEach(waitForAsync(() => {
notifyInfoServiceSpy = {
getNotifyRequestsStatus:() => createSuccessfulRemoteDataObject$(mock),
};
@@ -31,8 +33,12 @@ describe('NotifyRequestsStatusComponent', () => {
providers: [
{ provide: NotifyRequestsStatusDataService, useValue: notifyInfoServiceSpy },
],
}).overrideComponent(NotifyRequestsStatusComponent, {
remove: {
imports: [RequestStatusAlertBoxComponent],
},
});
});
}));
beforeEach(() => {
fixture = TestBed.createComponent(NotifyRequestsStatusComponent);

View File

@@ -1,10 +1,6 @@
<ng-container *ngIf="data?.length > 0 && displayOptions">
<div
[ngClass]="{'align-items-center': data.length === 1}"
class="alert d-flex flex-row sections-gap {{
displayOptions.alertType
}}"
>
<div [ngClass]="{'align-items-center': data.length === 1}"
class="alert d-flex flex-row sections-gap {{displayOptions.alertType}}">
<img
class="source-logo"
src="assets/images/qa-coar-notify-logo.png"
@@ -14,17 +10,11 @@
<ds-truncatable-part [id]="status" [minLines]="1">
<div class="w-100 d-flex flex-column">
<ng-container *ngFor="let request of data">
<div
[innerHTML]="
displayOptions.text
| translate
: {
<div [innerHTML]="displayOptions.text | translate: {
serviceName: request.serviceName,
serviceUrl: request.serviceUrl,
offerType: request.offerType
}
"
></div>
}"></div>
</ng-container>
</div>
</ds-truncatable-part>

View File

@@ -2,9 +2,12 @@ import {
ComponentFixture,
fakeAsync,
TestBed,
waitForAsync,
} from '@angular/core/testing';
import { TranslateModule } from '@ngx-translate/core';
import { TruncatableComponent } from '../../../../shared/truncatable/truncatable.component';
import { TruncatablePartComponent } from '../../../../shared/truncatable/truncatable-part/truncatable-part.component';
import { RequestStatusEnum } from '../notify-status.enum';
import { RequestStatusAlertBoxComponent } from './request-status-alert-box.component';
@@ -28,11 +31,15 @@ describe('RequestStatusAlertBoxComponent', () => {
},
];
beforeEach(async () => {
await TestBed.configureTestingModule({
beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
imports: [TranslateModule.forRoot(), RequestStatusAlertBoxComponent],
}).overrideComponent(RequestStatusAlertBoxComponent, {
remove: {
imports: [TruncatablePartComponent, TruncatableComponent],
},
}).compileComponents();
});
}));
beforeEach(() => {
fixture = TestBed.createComponent(RequestStatusAlertBoxComponent);

View File

@@ -1,6 +1,7 @@
import {
NgClass,
NgForOf,
NgIf,
} from '@angular/common';
import {
ChangeDetectionStrategy,
@@ -22,6 +23,7 @@ import { RequestStatusEnum } from '../notify-status.enum';
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: true,
imports: [
NgIf,
TruncatablePartComponent,
TruncatableComponent,
NgForOf,

View File

@@ -14,6 +14,7 @@ import { SearchConfigurationService } from '../core/shared/search/search-configu
import { configureSearchComponentTestingModule } from '../shared/search/search.component.spec';
import { ConfigurationSearchPageComponent } from './configuration-search-page.component';
import createSpy = jasmine.createSpy;
import { of } from 'rxjs';
const CONFIGURATION = 'test-configuration';
const QUERY = 'test query';
@@ -52,6 +53,7 @@ describe('ConfigurationSearchPageComponent', () => {
routeService = TestBed.inject(RouteService);
routeService.setParameter = createSpy('setParameter');
routeService.getRouteParameterValue = createSpy('getRouteParameterValue').and.returnValue(of(CONFIGURATION));
fixture.detectChanges();

View File

@@ -1,21 +1,13 @@
import { AdminNotifySearchResultComponent } from '../../../../admin/admin-notify-dashboard/admin-notify-search-result/admin-notify-search-result.component';
import { AdminNotifySearchResult } from '../../../../admin/admin-notify-dashboard/models/admin-notify-message-search-result.model';
import { Context } from '../../../../core/shared/context.model';
import { ViewMode } from '../../../../core/shared/view-mode.model';
import { getTabulatableObjectsComponent } from './tabulatable-objects.decorator';
const type = 'TestType';
class TestTable {
}
describe('TabulatableObject decorator function', () => {
it('should have a decorator for table', () => {
const tableDecorator = getTabulatableObjectsComponent(['Item'], ViewMode.Table);
expect(tableDecorator.length).not.toBeNull();
});
it('should return the matching class', () => {
const component = getTabulatableObjectsComponent([type], ViewMode.Table, Context.Search);
expect(component).toEqual(TestTable);
const component = getTabulatableObjectsComponent([AdminNotifySearchResult], ViewMode.Table, Context.CoarNotify);
expect(component).toEqual(AdminNotifySearchResultComponent);
});
});