add tests

This commit is contained in:
FrancescoMolinaro
2024-01-20 13:36:24 +01:00
parent b77aa2d9d8
commit e4eb8b5a63
7 changed files with 292 additions and 4 deletions

View File

@@ -78,6 +78,7 @@ describe('LdnServicesService test', () => {
rdbService = jasmine.createSpyObj('rdbService', {
buildSingle: createSuccessfulRemoteDataObject$({}, 500),
buildFromRequestUUID: createSuccessfulRemoteDataObject$({}, 500),
buildList: cold('a', { a: remoteDataMocks.Success })
});
@@ -111,6 +112,20 @@ describe('LdnServicesService test', () => {
done();
});
});
it('should invoke service', (done) => {
const constraints = [{void: true}];
const files = [new File([],'fileName')];
spyOn(service as any, 'getInvocationFormData');
spyOn(service, 'getBrowseEndpoint').and.returnValue(observableOf('testEndpoint'));
service.invoke('serviceName', 'serviceId', constraints, files).subscribe(result => {
expect((service as any).getInvocationFormData).toHaveBeenCalledWith(constraints, files);
expect(service.getBrowseEndpoint).toHaveBeenCalled();
expect(result).toBeInstanceOf(RemoteData);
done();
});
});
});
});

View File

@@ -0,0 +1,81 @@
import { NotifyRequestsStatusDataService } from './notify-services-status-data.service';
import { ObjectCacheService } from '../cache/object-cache.service';
import { TestScheduler } from 'rxjs/testing';
import { RequestService } from './request.service';
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
import { HALEndpointService } from '../shared/hal-endpoint.service';
import { RequestEntry } from './request-entry.model';
import { RemoteData } from './remote-data';
import { RequestEntryState } from './request-entry-state.model';
import { cold, getTestScheduler } from 'jasmine-marbles';
import { RestResponse } from '../cache/response.models';
import { of } from 'rxjs';
import { createSuccessfulRemoteDataObject, createSuccessfulRemoteDataObject$ } from '../../shared/remote-data.utils';
import { NotifyRequestsStatus } from '../../item-page/simple/notify-requests-status/notify-requests-status.model';
describe('NotifyRequestsStatusDataService test', () => {
let scheduler: TestScheduler;
let service: NotifyRequestsStatusDataService;
let requestService: RequestService;
let rdbService: RemoteDataBuildService;
let objectCache: ObjectCacheService;
let halService: HALEndpointService;
let responseCacheEntry: RequestEntry;
const endpointURL = `https://rest.api/rest/api/suggestiontargets`;
const requestUUID = '8b3c613a-5a4b-438b-9686-be1d5b4a1c5a';
const remoteDataMocks = {
Success: new RemoteData(null, null, null, RequestEntryState.Success, null, null, 200),
};
function initTestService() {
return new NotifyRequestsStatusDataService(
requestService,
rdbService,
objectCache,
halService,
);
}
beforeEach(() => {
scheduler = getTestScheduler();
objectCache = {} as ObjectCacheService;
responseCacheEntry = new RequestEntry();
responseCacheEntry.request = { href: 'https://rest.api/' } as any;
responseCacheEntry.response = new RestResponse(true, 200, 'Success');
requestService = jasmine.createSpyObj('requestService', {
generateRequestId: requestUUID,
send: true,
removeByHrefSubstring: {},
getByHref: of(responseCacheEntry),
getByUUID: of(responseCacheEntry),
});
halService = jasmine.createSpyObj('halService', {
getEndpoint: of(endpointURL)
});
rdbService = jasmine.createSpyObj('rdbService', {
buildSingle: createSuccessfulRemoteDataObject$({}, 500),
buildList: cold('a', { a: remoteDataMocks.Success }),
buildFromHref: createSuccessfulRemoteDataObject$({test: 'test'})
});
service = initTestService();
});
describe('getNotifyRequestsStatus', () => {
it('should get notify status', (done) => {
service.getNotifyRequestsStatus(requestUUID).subscribe((status) => {
expect(halService.getEndpoint).toHaveBeenCalled();
expect(requestService.generateRequestId).toHaveBeenCalled();
expect(status).toEqual(createSuccessfulRemoteDataObject({test: 'test'} as unknown as NotifyRequestsStatus));
done();
});
});
});
});

View File

@@ -21,7 +21,6 @@ export class NotifyRequestsStatusDataService extends IdentifiableDataService<Not
protected rdbService: RemoteDataBuildService,
protected objectCache: ObjectCacheService,
protected halService: HALEndpointService,
protected rdb: RemoteDataBuildService,
) {
super('notifyrequests', requestService, rdbService, objectCache, halService);
}
@@ -41,6 +40,6 @@ export class NotifyRequestsStatusDataService extends IdentifiableDataService<Not
this.requestService.send(request, true);
});
return this.rdb.buildFromHref(href$);
return this.rdbService.buildFromHref(href$);
}
}

View File

@@ -43,6 +43,7 @@ import { PaginationService } from '../../../core/pagination/pagination.service';
import { PaginationServiceStub } from '../../../shared/testing/pagination-service.stub';
import { FindListOptions } from '../../../core/data/find-list-options.model';
import { ItemDataService } from 'src/app/core/data/item-data.service';
import { Item } from '../../../core/shared/item.model';
describe('QualityAssuranceEventsComponent test suite', () => {
let fixture: ComponentFixture<QualityAssuranceEventsComponent>;
@@ -50,6 +51,38 @@ describe('QualityAssuranceEventsComponent test suite', () => {
let compAsAny: any;
let scheduler: TestScheduler;
const item = Object.assign(new Item(), {
id: '1234-1234',
uuid: '1234-1234',
bundles: observableOf({}),
metadata: {
'dc.title': [
{
language: 'en_US',
value: 'This is just another title'
}
],
'dc.type': [
{
language: null,
value: 'Article'
}
],
'dc.contributor.author': [
{
language: 'en_US',
value: 'Smith, Donald'
}
],
'dc.date.issued': [
{
language: null,
value: '2015-06-26'
}
]
}
});
const modalStub = {
open: () => ( {result: new Promise((res, rej) => 'do')} ),
close: () => null,
@@ -285,6 +318,12 @@ describe('QualityAssuranceEventsComponent test suite', () => {
});
});
describe('getItemPageRoute', () => {
it('should get item page route"', () => {
expect(comp.getItemPageRoute(item)).toEqual('/items/1234-1234');
});
});
describe('getQualityAssuranceEvents', () => {
it('should call the "qualityAssuranceEventRestService.getEventsByTopic" to take data and "fetchEvents" to populate eventData', () => {
comp.paginationConfig = new PaginationComponentOptions();

View File

@@ -0,0 +1,23 @@
import { ViewMode } from '../../../../core/shared/view-mode.model';
import { getTabulatableObjectsComponent, tabulatableObjectsComponent } from './tabulatable-objects.decorator';
import { Context } from '../../../../core/shared/context.model';
import { PaginatedList } from '../../../../core/data/paginated-list.model';
const type = 'TestType';
@tabulatableObjectsComponent(PaginatedList<any>, ViewMode.Table, Context.Search)
class TestTable {
}
describe('TabulatableObject decorator function', () => {
it('should have a decorator for table', () => {
const tableDecorator = tabulatableObjectsComponent('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);
});
});

View File

@@ -16,7 +16,7 @@ const map = new Map();
/**
* Decorator used for rendering tabulatable objects
* @param objectType The object type or entity type the component represents
* @param objectsType The object type or entity type the component represents
* @param viewMode The view mode the component represents
* @param context The optional context the component represents
* @param theme The optional theme for the component
@@ -54,6 +54,8 @@ export function getTabulatableObjectsComponent(types: (string | GenericConstruct
let currentBestMatch: MatchRelevancy = null;
for (const type of types) {
const typeMap = map.get(PaginatedList<typeof type>);
console.log(typeMap, 'd3ewfde');
if (hasValue(typeMap)) {
const match = getMatch(typeMap, [viewMode, context, theme], [DEFAULT_VIEW_MODE, DEFAULT_CONTEXT, DEFAULT_THEME]);
if (hasNoValue(currentBestMatch) || currentBestMatch.isLessRelevantThan(match)) {

View File

@@ -1,10 +1,13 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { ObjectTableComponent } from './object-table.component';
describe('ObjectTableComponent', () => {
let component: ObjectTableComponent;
let fixture: ComponentFixture<ObjectTableComponent>;
const testEvent: any = { test: 'test' };
beforeEach(async () => {
await TestBed.configureTestingModule({
@@ -20,4 +23,130 @@ describe('ObjectTableComponent', () => {
it('should create', () => {
expect(component).toBeTruthy();
});
describe('when the pageChange output on the pagination is triggered', () => {
beforeEach(() => {
spyOn(component, 'onPageChange');
const paginationEl = fixture.debugElement.query(By.css('ds-pagination'));
paginationEl.triggerEventHandler('pageChange', testEvent);
});
it('should call onPageChange on the componentonent', () => {
expect(component.onPageChange).toHaveBeenCalledWith(testEvent);
});
});
describe('when the pageSizeChange output on the pagination is triggered', () => {
beforeEach(() => {
spyOn(component, 'onPageSizeChange');
const paginationEl = fixture.debugElement.query(By.css('ds-pagination'));
paginationEl.triggerEventHandler('pageSizeChange', testEvent);
});
it('should call onPageSizeChange on the componentonent', () => {
expect(component.onPageSizeChange).toHaveBeenCalledWith(testEvent);
});
});
describe('when the sortDirectionChange output on the pagination is triggered', () => {
beforeEach(() => {
spyOn(component, 'onSortDirectionChange');
const paginationEl = fixture.debugElement.query(By.css('ds-pagination'));
paginationEl.triggerEventHandler('sortDirectionChange', testEvent);
});
it('should call onSortDirectionChange on the componentonent', () => {
expect(component.onSortDirectionChange).toHaveBeenCalledWith(testEvent);
});
});
describe('when the sortFieldChange output on the pagination is triggered', () => {
beforeEach(() => {
spyOn(component, 'onSortFieldChange');
const paginationEl = fixture.debugElement.query(By.css('ds-pagination'));
paginationEl.triggerEventHandler('sortFieldChange', testEvent);
});
it('should call onSortFieldChange on the componentonent', () => {
expect(component.onSortFieldChange).toHaveBeenCalledWith(testEvent);
});
});
describe('when the paginationChange output on the pagination is triggered', () => {
beforeEach(() => {
spyOn(component, 'onPaginationChange');
const paginationEl = fixture.debugElement.query(By.css('ds-pagination'));
paginationEl.triggerEventHandler('paginationChange', testEvent);
});
it('should call onPaginationChange on the componentonent', () => {
expect(component.onPaginationChange).toHaveBeenCalledWith(testEvent);
});
});
describe('when onPageChange is triggered with an event', () => {
beforeEach(() => {
spyOn(component.pageChange, 'emit');
component.onPageChange(testEvent);
});
it('should emit the value from the pageChange EventEmitter', fakeAsync(() => {
tick(1);
expect(component.pageChange.emit).toHaveBeenCalled();
expect(component.pageChange.emit).toHaveBeenCalledWith(testEvent);
}));
});
describe('when onPageSizeChange is triggered with an event', () => {
beforeEach(() => {
spyOn(component.pageSizeChange, 'emit');
component.onPageSizeChange(testEvent);
});
it('should emit the value from the pageSizeChange EventEmitter', fakeAsync(() => {
tick(1);
expect(component.pageSizeChange.emit).toHaveBeenCalled();
expect(component.pageSizeChange.emit).toHaveBeenCalledWith(testEvent);
}));
});
describe('when onSortDirectionChange is triggered with an event', () => {
beforeEach(() => {
spyOn(component.sortDirectionChange, 'emit');
component.onSortDirectionChange(testEvent);
});
it('should emit the value from the sortDirectionChange EventEmitter', fakeAsync(() => {
tick(1);
expect(component.sortDirectionChange.emit).toHaveBeenCalled();
expect(component.sortDirectionChange.emit).toHaveBeenCalledWith(testEvent);
}));
});
describe('when onSortFieldChange is triggered with an event', () => {
beforeEach(() => {
spyOn(component.sortFieldChange, 'emit');
component.onSortFieldChange(testEvent);
});
it('should emit the value from the sortFieldChange EventEmitter', fakeAsync(() => {
tick(1);
expect(component.sortFieldChange.emit).toHaveBeenCalled();
expect(component.sortFieldChange.emit).toHaveBeenCalledWith(testEvent);
}));
});
describe('when onPaginationChange is triggered with an event', () => {
beforeEach(() => {
spyOn(component.paginationChange, 'emit');
component.onPaginationChange(testEvent);
});
it('should emit the value from the paginationChange EventEmitter', fakeAsync(() => {
tick(1);
expect(component.paginationChange.emit).toHaveBeenCalled();
expect(component.paginationChange.emit).toHaveBeenCalledWith(testEvent);
}));
});
});