mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
[CST-5337] test cases done.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
rest:
|
||||
ssl: true
|
||||
host: api7.dspace.org
|
||||
ssl: false
|
||||
host: localhost:8080
|
||||
port: 443
|
||||
nameSpace: /server
|
||||
|
@@ -1,3 +1,4 @@
|
||||
import { NO_ERRORS_SCHEMA } from '@angular/core';
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { AdminNotificationsBrokerSourcePageComponent } from './admin-notifications-broker-source-page.component';
|
||||
@@ -8,7 +9,8 @@ describe('AdminNotificationsBrokerSourcePageComponent', () => {
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
declarations: [ AdminNotificationsBrokerSourcePageComponent ]
|
||||
declarations: [ AdminNotificationsBrokerSourcePageComponent ],
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
})
|
||||
.compileComponents();
|
||||
});
|
||||
@@ -19,7 +21,7 @@ describe('AdminNotificationsBrokerSourcePageComponent', () => {
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
it('should create AdminNotificationsBrokerSourcePageComponent', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
@@ -0,0 +1,127 @@
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
|
||||
import { TestScheduler } from 'rxjs/testing';
|
||||
import { of as observableOf } from 'rxjs';
|
||||
import { cold, getTestScheduler } from 'jasmine-marbles';
|
||||
|
||||
import { RequestService } from '../../../data/request.service';
|
||||
import { buildPaginatedList } from '../../../data/paginated-list.model';
|
||||
import { RequestEntry } from '../../../data/request.reducer';
|
||||
import { RemoteDataBuildService } from '../../../cache/builders/remote-data-build.service';
|
||||
import { ObjectCacheService } from '../../../cache/object-cache.service';
|
||||
import { RestResponse } from '../../../cache/response.models';
|
||||
import { PageInfo } from '../../../shared/page-info.model';
|
||||
import { HALEndpointService } from '../../../shared/hal-endpoint.service';
|
||||
import { NotificationsService } from '../../../../shared/notifications/notifications.service';
|
||||
import { createSuccessfulRemoteDataObject } from '../../../../shared/remote-data.utils';
|
||||
import { NotificationsBrokerSourceRestService } from './notifications-broker-source-rest.service';
|
||||
import {
|
||||
notificationsBrokerSourceObjectMoreAbstract,
|
||||
notificationsBrokerSourceObjectMorePid
|
||||
} from '../../../../shared/mocks/notifications.mock';
|
||||
|
||||
describe('NotificationsBrokerSourceRestService', () => {
|
||||
let scheduler: TestScheduler;
|
||||
let service: NotificationsBrokerSourceRestService;
|
||||
let responseCacheEntry: RequestEntry;
|
||||
let requestService: RequestService;
|
||||
let rdbService: RemoteDataBuildService;
|
||||
let objectCache: ObjectCacheService;
|
||||
let halService: HALEndpointService;
|
||||
let notificationsService: NotificationsService;
|
||||
let http: HttpClient;
|
||||
let comparator: any;
|
||||
|
||||
const endpointURL = 'https://rest.api/rest/api/integration/nbsources';
|
||||
const requestUUID = '8b3c913a-5a4b-438b-9181-be1a5b4a1c8a';
|
||||
|
||||
const pageInfo = new PageInfo();
|
||||
const array = [ notificationsBrokerSourceObjectMorePid, notificationsBrokerSourceObjectMoreAbstract ];
|
||||
const paginatedList = buildPaginatedList(pageInfo, array);
|
||||
const brokerSourceObjectRD = createSuccessfulRemoteDataObject(notificationsBrokerSourceObjectMorePid);
|
||||
const paginatedListRD = createSuccessfulRemoteDataObject(paginatedList);
|
||||
|
||||
beforeEach(() => {
|
||||
scheduler = getTestScheduler();
|
||||
|
||||
responseCacheEntry = new RequestEntry();
|
||||
responseCacheEntry.response = new RestResponse(true, 200, 'Success');
|
||||
requestService = jasmine.createSpyObj('requestService', {
|
||||
generateRequestId: requestUUID,
|
||||
send: true,
|
||||
removeByHrefSubstring: {},
|
||||
getByHref: observableOf(responseCacheEntry),
|
||||
getByUUID: observableOf(responseCacheEntry),
|
||||
});
|
||||
|
||||
rdbService = jasmine.createSpyObj('rdbService', {
|
||||
buildSingle: cold('(a)', {
|
||||
a: brokerSourceObjectRD
|
||||
}),
|
||||
buildList: cold('(a)', {
|
||||
a: paginatedListRD
|
||||
}),
|
||||
});
|
||||
|
||||
objectCache = {} as ObjectCacheService;
|
||||
halService = jasmine.createSpyObj('halService', {
|
||||
getEndpoint: cold('a|', { a: endpointURL })
|
||||
});
|
||||
|
||||
notificationsService = {} as NotificationsService;
|
||||
http = {} as HttpClient;
|
||||
comparator = {} as any;
|
||||
|
||||
service = new NotificationsBrokerSourceRestService(
|
||||
requestService,
|
||||
rdbService,
|
||||
objectCache,
|
||||
halService,
|
||||
notificationsService,
|
||||
http,
|
||||
comparator
|
||||
);
|
||||
|
||||
spyOn((service as any).dataService, 'findAllByHref').and.callThrough();
|
||||
spyOn((service as any).dataService, 'findByHref').and.callThrough();
|
||||
});
|
||||
|
||||
describe('getSources', () => {
|
||||
it('should proxy the call to dataservice.findAllByHref', (done) => {
|
||||
service.getSources().subscribe(
|
||||
(res) => {
|
||||
expect((service as any).dataService.findAllByHref).toHaveBeenCalledWith(endpointURL, {}, true, true);
|
||||
}
|
||||
);
|
||||
done();
|
||||
});
|
||||
|
||||
it('should return a RemoteData<PaginatedList<NotificationsBrokerSourceObject>> for the object with the given URL', () => {
|
||||
const result = service.getSources();
|
||||
const expected = cold('(a)', {
|
||||
a: paginatedListRD
|
||||
});
|
||||
expect(result).toBeObservable(expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getSource', () => {
|
||||
it('should proxy the call to dataservice.findByHref', (done) => {
|
||||
service.getSource(notificationsBrokerSourceObjectMorePid.id).subscribe(
|
||||
(res) => {
|
||||
expect((service as any).dataService.findByHref).toHaveBeenCalledWith(endpointURL + '/' + notificationsBrokerSourceObjectMorePid.id, true, true);
|
||||
}
|
||||
);
|
||||
done();
|
||||
});
|
||||
|
||||
it('should return a RemoteData<NotificationsBrokerSourceObject> for the object with the given URL', () => {
|
||||
const result = service.getSource(notificationsBrokerSourceObjectMorePid.id);
|
||||
const expected = cold('(a)', {
|
||||
a: brokerSourceObjectRD
|
||||
});
|
||||
expect(result).toBeObservable(expected);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
@@ -1,25 +1,152 @@
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { Component, NO_ERRORS_SCHEMA } from '@angular/core';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { of as observableOf } from 'rxjs';
|
||||
import { ComponentFixture, inject, TestBed, waitForAsync } from '@angular/core/testing';
|
||||
import { createTestComponent } from '../../../shared/testing/utils.test';
|
||||
import {
|
||||
getMockNotificationsStateService,
|
||||
notificationsBrokerSourceObjectMoreAbstract,
|
||||
notificationsBrokerSourceObjectMorePid
|
||||
} from '../../../shared/mocks/notifications.mock';
|
||||
import { NotificationsBrokerSourceComponent } from './notifications-broker-source.component';
|
||||
import { NotificationsStateService } from '../../notifications-state.service';
|
||||
import { cold } from 'jasmine-marbles';
|
||||
import { PaginationServiceStub } from '../../../shared/testing/pagination-service.stub';
|
||||
import { PaginationService } from '../../../core/pagination/pagination.service';
|
||||
|
||||
describe('NotificationsBrokerSourceComponent', () => {
|
||||
let component: NotificationsBrokerSourceComponent;
|
||||
describe('NotificationsBrokerSourceComponent test suite', () => {
|
||||
let fixture: ComponentFixture<NotificationsBrokerSourceComponent>;
|
||||
let comp: NotificationsBrokerSourceComponent;
|
||||
let compAsAny: any;
|
||||
const mockNotificationsStateService = getMockNotificationsStateService();
|
||||
const activatedRouteParams = {
|
||||
notificationsBrokerSourceParams: {
|
||||
currentPage: 0,
|
||||
pageSize: 5
|
||||
}
|
||||
};
|
||||
const paginationService = new PaginationServiceStub();
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
declarations: [ NotificationsBrokerSourceComponent ]
|
||||
})
|
||||
.compileComponents();
|
||||
beforeEach(waitForAsync(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
CommonModule,
|
||||
TranslateModule.forRoot(),
|
||||
],
|
||||
declarations: [
|
||||
NotificationsBrokerSourceComponent,
|
||||
TestComponent,
|
||||
],
|
||||
providers: [
|
||||
{ provide: NotificationsStateService, useValue: mockNotificationsStateService },
|
||||
{ provide: ActivatedRoute, useValue: { data: observableOf(activatedRouteParams), params: observableOf({}) } },
|
||||
{ provide: PaginationService, useValue: paginationService },
|
||||
NotificationsBrokerSourceComponent
|
||||
],
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
}).compileComponents().then(() => {
|
||||
mockNotificationsStateService.getNotificationsBrokerSource.and.returnValue(observableOf([
|
||||
notificationsBrokerSourceObjectMorePid,
|
||||
notificationsBrokerSourceObjectMoreAbstract
|
||||
]));
|
||||
mockNotificationsStateService.getNotificationsBrokerSourceTotalPages.and.returnValue(observableOf(1));
|
||||
mockNotificationsStateService.getNotificationsBrokerSourceCurrentPage.and.returnValue(observableOf(0));
|
||||
mockNotificationsStateService.getNotificationsBrokerSourceTotals.and.returnValue(observableOf(2));
|
||||
mockNotificationsStateService.isNotificationsBrokerSourceLoaded.and.returnValue(observableOf(true));
|
||||
mockNotificationsStateService.isNotificationsBrokerSourceLoading.and.returnValue(observableOf(false));
|
||||
mockNotificationsStateService.isNotificationsBrokerSourceProcessing.and.returnValue(observableOf(false));
|
||||
});
|
||||
}));
|
||||
|
||||
// First test to check the correct component creation
|
||||
describe('', () => {
|
||||
let testComp: TestComponent;
|
||||
let testFixture: ComponentFixture<TestComponent>;
|
||||
|
||||
// synchronous beforeEach
|
||||
beforeEach(() => {
|
||||
const html = `
|
||||
<ds-notifications-broker-source></ds-notifications-broker-source>`;
|
||||
testFixture = createTestComponent(html, TestComponent) as ComponentFixture<TestComponent>;
|
||||
testComp = testFixture.componentInstance;
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
testFixture.destroy();
|
||||
});
|
||||
|
||||
it('should create NotificationsBrokerSourceComponent', inject([NotificationsBrokerSourceComponent], (app: NotificationsBrokerSourceComponent) => {
|
||||
expect(app).toBeDefined();
|
||||
}));
|
||||
});
|
||||
|
||||
describe('Main tests running with two Source', () => {
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(NotificationsBrokerSourceComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
comp = fixture.componentInstance;
|
||||
compAsAny = comp;
|
||||
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
afterEach(() => {
|
||||
fixture.destroy();
|
||||
comp = null;
|
||||
compAsAny = null;
|
||||
});
|
||||
|
||||
it(('Should init component properly'), () => {
|
||||
comp.ngOnInit();
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(comp.sources$).toBeObservable(cold('(a|)', {
|
||||
a: [
|
||||
notificationsBrokerSourceObjectMorePid,
|
||||
notificationsBrokerSourceObjectMoreAbstract
|
||||
]
|
||||
}));
|
||||
expect(comp.totalElements$).toBeObservable(cold('(a|)', {
|
||||
a: 2
|
||||
}));
|
||||
});
|
||||
|
||||
it(('Should set data properly after the view init'), () => {
|
||||
spyOn(compAsAny, 'getNotificationsBrokerSource');
|
||||
|
||||
comp.ngAfterViewInit();
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(compAsAny.getNotificationsBrokerSource).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it(('isSourceLoading should return FALSE'), () => {
|
||||
expect(comp.isSourceLoading()).toBeObservable(cold('(a|)', {
|
||||
a: false
|
||||
}));
|
||||
});
|
||||
|
||||
it(('isSourceProcessing should return FALSE'), () => {
|
||||
expect(comp.isSourceProcessing()).toBeObservable(cold('(a|)', {
|
||||
a: false
|
||||
}));
|
||||
});
|
||||
|
||||
it(('getNotificationsBrokerSource should call the service to dispatch a STATE change'), () => {
|
||||
comp.ngOnInit();
|
||||
fixture.detectChanges();
|
||||
|
||||
compAsAny.notificationsStateService.dispatchRetrieveNotificationsBrokerSource(comp.paginationConfig.pageSize, comp.paginationConfig.currentPage).and.callThrough();
|
||||
expect(compAsAny.notificationsStateService.dispatchRetrieveNotificationsBrokerSource).toHaveBeenCalledWith(comp.paginationConfig.pageSize, comp.paginationConfig.currentPage);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// declare a test component
|
||||
@Component({
|
||||
selector: 'ds-test-cmp',
|
||||
template: ``
|
||||
})
|
||||
class TestComponent {
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,68 @@
|
||||
import {
|
||||
AddSourceAction,
|
||||
RetrieveAllSourceAction,
|
||||
RetrieveAllSourceErrorAction
|
||||
} from './notifications-broker-source.actions';
|
||||
import { notificationsBrokerSourceReducer, NotificationsBrokerSourceState } from './notifications-broker-source.reducer';
|
||||
import {
|
||||
notificationsBrokerSourceObjectMoreAbstract,
|
||||
notificationsBrokerSourceObjectMorePid
|
||||
} from '../../../shared/mocks/notifications.mock';
|
||||
|
||||
describe('notificationsBrokerSourceReducer test suite', () => {
|
||||
let notificationsBrokerSourceInitialState: NotificationsBrokerSourceState;
|
||||
const elementPerPage = 3;
|
||||
const currentPage = 0;
|
||||
|
||||
beforeEach(() => {
|
||||
notificationsBrokerSourceInitialState = {
|
||||
source: [],
|
||||
processing: false,
|
||||
loaded: false,
|
||||
totalPages: 0,
|
||||
currentPage: 0,
|
||||
totalElements: 0
|
||||
};
|
||||
});
|
||||
|
||||
it('Action RETRIEVE_ALL_SOURCE should set the State property "processing" to TRUE', () => {
|
||||
const expectedState = notificationsBrokerSourceInitialState;
|
||||
expectedState.processing = true;
|
||||
|
||||
const action = new RetrieveAllSourceAction(elementPerPage, currentPage);
|
||||
const newState = notificationsBrokerSourceReducer(notificationsBrokerSourceInitialState, action);
|
||||
|
||||
expect(newState).toEqual(expectedState);
|
||||
});
|
||||
|
||||
it('Action RETRIEVE_ALL_SOURCE_ERROR should change the State to initial State but processing, loaded, and currentPage', () => {
|
||||
const expectedState = notificationsBrokerSourceInitialState;
|
||||
expectedState.processing = false;
|
||||
expectedState.loaded = true;
|
||||
expectedState.currentPage = 0;
|
||||
|
||||
const action = new RetrieveAllSourceErrorAction();
|
||||
const newState = notificationsBrokerSourceReducer(notificationsBrokerSourceInitialState, action);
|
||||
|
||||
expect(newState).toEqual(expectedState);
|
||||
});
|
||||
|
||||
it('Action ADD_SOURCE should populate the State with Notifications Broker source', () => {
|
||||
const expectedState = {
|
||||
source: [ notificationsBrokerSourceObjectMorePid, notificationsBrokerSourceObjectMoreAbstract ],
|
||||
processing: false,
|
||||
loaded: true,
|
||||
totalPages: 1,
|
||||
currentPage: 0,
|
||||
totalElements: 2
|
||||
};
|
||||
|
||||
const action = new AddSourceAction(
|
||||
[ notificationsBrokerSourceObjectMorePid, notificationsBrokerSourceObjectMoreAbstract ],
|
||||
1, 0, 2
|
||||
);
|
||||
const newState = notificationsBrokerSourceReducer(notificationsBrokerSourceInitialState, action);
|
||||
|
||||
expect(newState).toEqual(expectedState);
|
||||
});
|
||||
});
|
@@ -0,0 +1,68 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import { of as observableOf } from 'rxjs';
|
||||
import { NotificationsBrokerSourceService } from './notifications-broker-source.service';
|
||||
import { SortDirection, SortOptions } from '../../../core/cache/models/sort-options.model';
|
||||
import { PageInfo } from '../../../core/shared/page-info.model';
|
||||
import { FindListOptions } from '../../../core/data/request.models';
|
||||
import {
|
||||
getMockNotificationsBrokerSourceRestService,
|
||||
notificationsBrokerSourceObjectMoreAbstract,
|
||||
notificationsBrokerSourceObjectMorePid
|
||||
} from '../../../shared/mocks/notifications.mock';
|
||||
import { createSuccessfulRemoteDataObject } from '../../../shared/remote-data.utils';
|
||||
import { cold } from 'jasmine-marbles';
|
||||
import { buildPaginatedList } from '../../../core/data/paginated-list.model';
|
||||
import { NotificationsBrokerSourceRestService } from '../../../core/notifications/broker/source/notifications-broker-source-rest.service';
|
||||
import { RequestParam } from '../../../core/cache/models/request-param.model';
|
||||
|
||||
describe('NotificationsBrokerSourceService', () => {
|
||||
let service: NotificationsBrokerSourceService;
|
||||
let restService: NotificationsBrokerSourceRestService;
|
||||
let serviceAsAny: any;
|
||||
let restServiceAsAny: any;
|
||||
|
||||
const pageInfo = new PageInfo();
|
||||
const array = [ notificationsBrokerSourceObjectMorePid, notificationsBrokerSourceObjectMoreAbstract ];
|
||||
const paginatedList = buildPaginatedList(pageInfo, array);
|
||||
const paginatedListRD = createSuccessfulRemoteDataObject(paginatedList);
|
||||
const elementsPerPage = 3;
|
||||
const currentPage = 0;
|
||||
|
||||
beforeEach(async () => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [
|
||||
{ provide: NotificationsBrokerSourceRestService, useClass: getMockNotificationsBrokerSourceRestService },
|
||||
{ provide: NotificationsBrokerSourceService, useValue: service }
|
||||
]
|
||||
}).compileComponents();
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
restService = TestBed.get(NotificationsBrokerSourceRestService);
|
||||
restServiceAsAny = restService;
|
||||
restServiceAsAny.getSources.and.returnValue(observableOf(paginatedListRD));
|
||||
service = new NotificationsBrokerSourceService(restService);
|
||||
serviceAsAny = service;
|
||||
});
|
||||
|
||||
describe('getSources', () => {
|
||||
it('Should proxy the call to notificationsBrokerSourceRestService.getSources', () => {
|
||||
const sortOptions = new SortOptions('name', SortDirection.ASC);
|
||||
const findListOptions: FindListOptions = {
|
||||
elementsPerPage: elementsPerPage,
|
||||
currentPage: currentPage,
|
||||
sort: sortOptions
|
||||
};
|
||||
const result = service.getSources(elementsPerPage, currentPage);
|
||||
expect((service as any).notificationsBrokerSourceRestService.getSources).toHaveBeenCalledWith(findListOptions);
|
||||
});
|
||||
|
||||
it('Should return a paginated list of Notifications Broker Source', () => {
|
||||
const expected = cold('(a|)', {
|
||||
a: paginatedList
|
||||
});
|
||||
const result = service.getSources(elementsPerPage, currentPage);
|
||||
expect(result).toBeObservable(expected);
|
||||
});
|
||||
});
|
||||
});
|
@@ -1,8 +1,8 @@
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { Component, NO_ERRORS_SCHEMA } from '@angular/core';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { of as observableOf } from 'rxjs';
|
||||
import { of as observableOf, of } from 'rxjs';
|
||||
import { ComponentFixture, inject, TestBed, waitForAsync } from '@angular/core/testing';
|
||||
import { createTestComponent } from '../../../shared/testing/utils.test';
|
||||
import {
|
||||
@@ -15,6 +15,7 @@ import { NotificationsStateService } from '../../notifications-state.service';
|
||||
import { cold } from 'jasmine-marbles';
|
||||
import { PaginationServiceStub } from '../../../shared/testing/pagination-service.stub';
|
||||
import { PaginationService } from '../../../core/pagination/pagination.service';
|
||||
import { NotificationsBrokerTopicsService } from './notifications-broker-topics.service';
|
||||
|
||||
describe('NotificationsBrokerTopicsComponent test suite', () => {
|
||||
let fixture: ComponentFixture<NotificationsBrokerTopicsComponent>;
|
||||
@@ -41,9 +42,15 @@ describe('NotificationsBrokerTopicsComponent test suite', () => {
|
||||
],
|
||||
providers: [
|
||||
{ provide: NotificationsStateService, useValue: mockNotificationsStateService },
|
||||
{ provide: ActivatedRoute, useValue: { data: observableOf(activatedRouteParams), params: observableOf({}) } },
|
||||
{ provide: ActivatedRoute, useValue: { data: observableOf(activatedRouteParams), snapshot: {
|
||||
paramMap: {
|
||||
get: () => 'openaire',
|
||||
},
|
||||
}}},
|
||||
{ provide: PaginationService, useValue: paginationService },
|
||||
NotificationsBrokerTopicsComponent
|
||||
NotificationsBrokerTopicsComponent,
|
||||
// tslint:disable-next-line: no-empty
|
||||
{ provide: NotificationsBrokerTopicsService, useValue: { setSourceId: (sourceId: string) => { } }}
|
||||
],
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
}).compileComponents().then(() => {
|
||||
|
@@ -67,19 +67,14 @@ export class NotificationsBrokerTopicsComponent implements OnInit {
|
||||
private notificationsStateService: NotificationsStateService,
|
||||
private notificationsBrokerTopicsService: NotificationsBrokerTopicsService
|
||||
) {
|
||||
this.activatedRoute.paramMap.pipe(
|
||||
map((params) => params.get('sourceId')),
|
||||
take(1)
|
||||
).subscribe((id: string) => {
|
||||
this.sourceId = id;
|
||||
this.notificationsBrokerTopicsService.setSourceId(this.sourceId);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Component initialization.
|
||||
*/
|
||||
ngOnInit(): void {
|
||||
this.sourceId = this.activatedRoute.snapshot.paramMap.get('sourceId');
|
||||
this.notificationsBrokerTopicsService.setSourceId(this.sourceId);
|
||||
this.topics$ = this.notificationsStateService.getNotificationsBrokerTopics();
|
||||
this.totalElements$ = this.notificationsStateService.getNotificationsBrokerTopicsTotals();
|
||||
}
|
||||
|
@@ -13,6 +13,7 @@ import {
|
||||
import { createSuccessfulRemoteDataObject } from '../../../shared/remote-data.utils';
|
||||
import { cold } from 'jasmine-marbles';
|
||||
import { buildPaginatedList } from '../../../core/data/paginated-list.model';
|
||||
import { RequestParam } from '../../../core/cache/models/request-param.model';
|
||||
|
||||
describe('NotificationsBrokerTopicsService', () => {
|
||||
let service: NotificationsBrokerTopicsService;
|
||||
@@ -50,8 +51,10 @@ describe('NotificationsBrokerTopicsService', () => {
|
||||
const findListOptions: FindListOptions = {
|
||||
elementsPerPage: elementsPerPage,
|
||||
currentPage: currentPage,
|
||||
sort: sortOptions
|
||||
sort: sortOptions,
|
||||
searchParams: [new RequestParam('source', 'ENRICH!MORE!ABSTRACT')]
|
||||
};
|
||||
service.setSourceId('ENRICH!MORE!ABSTRACT');
|
||||
const result = service.getTopics(elementsPerPage, currentPage);
|
||||
expect((service as any).notificationsBrokerTopicRestService.getTopics).toHaveBeenCalledWith(findListOptions);
|
||||
});
|
||||
|
@@ -5,11 +5,15 @@ import { cold } from 'jasmine-marbles';
|
||||
import { notificationsReducers } from './notifications.reducer';
|
||||
import { NotificationsStateService } from './notifications-state.service';
|
||||
import {
|
||||
notificationsBrokerSourceObjectMissingPid,
|
||||
notificationsBrokerSourceObjectMoreAbstract,
|
||||
notificationsBrokerSourceObjectMorePid,
|
||||
notificationsBrokerTopicObjectMissingPid,
|
||||
notificationsBrokerTopicObjectMoreAbstract,
|
||||
notificationsBrokerTopicObjectMorePid
|
||||
} from '../shared/mocks/notifications.mock';
|
||||
import { RetrieveAllTopicsAction } from './broker/topics/notifications-broker-topics.actions';
|
||||
import { RetrieveAllSourceAction } from './broker/source/notifications-broker-source.actions';
|
||||
|
||||
describe('NotificationsStateService', () => {
|
||||
let service: NotificationsStateService;
|
||||
@@ -17,6 +21,7 @@ describe('NotificationsStateService', () => {
|
||||
let store: any;
|
||||
let initialState: any;
|
||||
|
||||
describe('Topis State', () => {
|
||||
function init(mode: string) {
|
||||
if (mode === 'empty') {
|
||||
initialState = {
|
||||
@@ -272,4 +277,265 @@ describe('NotificationsStateService', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Source State', () => {
|
||||
function init(mode: string) {
|
||||
if (mode === 'empty') {
|
||||
initialState = {
|
||||
notifications: {
|
||||
brokerSource: {
|
||||
source: [],
|
||||
processing: false,
|
||||
loaded: false,
|
||||
totalPages: 0,
|
||||
currentPage: 0,
|
||||
totalElements: 0,
|
||||
totalLoadedPages: 0
|
||||
}
|
||||
}
|
||||
};
|
||||
} else {
|
||||
initialState = {
|
||||
notifications: {
|
||||
brokerSource: {
|
||||
source: [
|
||||
notificationsBrokerSourceObjectMorePid,
|
||||
notificationsBrokerSourceObjectMoreAbstract,
|
||||
notificationsBrokerSourceObjectMissingPid
|
||||
],
|
||||
processing: false,
|
||||
loaded: true,
|
||||
totalPages: 1,
|
||||
currentPage: 1,
|
||||
totalElements: 3,
|
||||
totalLoadedPages: 1
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
describe('Testing methods with empty source objects', () => {
|
||||
beforeEach(async () => {
|
||||
init('empty');
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
StoreModule.forRoot({ notifications: notificationsReducers } as any),
|
||||
],
|
||||
providers: [
|
||||
provideMockStore({ initialState }),
|
||||
{ provide: NotificationsStateService, useValue: service }
|
||||
]
|
||||
}).compileComponents();
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
store = TestBed.get(Store);
|
||||
service = new NotificationsStateService(store);
|
||||
serviceAsAny = service;
|
||||
spyOn(store, 'dispatch');
|
||||
});
|
||||
|
||||
describe('getNotificationsBrokerSource', () => {
|
||||
it('Should return an empty array', () => {
|
||||
const result = service.getNotificationsBrokerSource();
|
||||
const expected = cold('(a)', {
|
||||
a: []
|
||||
});
|
||||
expect(result).toBeObservable(expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getNotificationsBrokerSourceTotalPages', () => {
|
||||
it('Should return zero (0)', () => {
|
||||
const result = service.getNotificationsBrokerSourceTotalPages();
|
||||
const expected = cold('(a)', {
|
||||
a: 0
|
||||
});
|
||||
expect(result).toBeObservable(expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getNotificationsBrokerSourcesCurrentPage', () => {
|
||||
it('Should return minus one (0)', () => {
|
||||
const result = service.getNotificationsBrokerSourceCurrentPage();
|
||||
const expected = cold('(a)', {
|
||||
a: 0
|
||||
});
|
||||
expect(result).toBeObservable(expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getNotificationsBrokerSourceTotals', () => {
|
||||
it('Should return zero (0)', () => {
|
||||
const result = service.getNotificationsBrokerSourceTotals();
|
||||
const expected = cold('(a)', {
|
||||
a: 0
|
||||
});
|
||||
expect(result).toBeObservable(expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe('isNotificationsBrokerSourceLoading', () => {
|
||||
it('Should return TRUE', () => {
|
||||
const result = service.isNotificationsBrokerSourceLoading();
|
||||
const expected = cold('(a)', {
|
||||
a: true
|
||||
});
|
||||
expect(result).toBeObservable(expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe('isNotificationsBrokerSourceLoaded', () => {
|
||||
it('Should return FALSE', () => {
|
||||
const result = service.isNotificationsBrokerSourceLoaded();
|
||||
const expected = cold('(a)', {
|
||||
a: false
|
||||
});
|
||||
expect(result).toBeObservable(expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe('isNotificationsBrokerSourceProcessing', () => {
|
||||
it('Should return FALSE', () => {
|
||||
const result = service.isNotificationsBrokerSourceProcessing();
|
||||
const expected = cold('(a)', {
|
||||
a: false
|
||||
});
|
||||
expect(result).toBeObservable(expected);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Testing methods with Source objects', () => {
|
||||
beforeEach(async () => {
|
||||
init('full');
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
StoreModule.forRoot({ notifications: notificationsReducers } as any),
|
||||
],
|
||||
providers: [
|
||||
provideMockStore({ initialState }),
|
||||
{ provide: NotificationsStateService, useValue: service }
|
||||
]
|
||||
}).compileComponents();
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
store = TestBed.get(Store);
|
||||
service = new NotificationsStateService(store);
|
||||
serviceAsAny = service;
|
||||
spyOn(store, 'dispatch');
|
||||
});
|
||||
|
||||
describe('getNotificationsBrokerSource', () => {
|
||||
it('Should return an array of Source', () => {
|
||||
const result = service.getNotificationsBrokerSource();
|
||||
const expected = cold('(a)', {
|
||||
a: [
|
||||
notificationsBrokerSourceObjectMorePid,
|
||||
notificationsBrokerSourceObjectMoreAbstract,
|
||||
notificationsBrokerSourceObjectMissingPid
|
||||
]
|
||||
});
|
||||
expect(result).toBeObservable(expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getNotificationsBrokerSourceTotalPages', () => {
|
||||
it('Should return one (1)', () => {
|
||||
const result = service.getNotificationsBrokerSourceTotalPages();
|
||||
const expected = cold('(a)', {
|
||||
a: 1
|
||||
});
|
||||
expect(result).toBeObservable(expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getNotificationsBrokerSourceCurrentPage', () => {
|
||||
it('Should return minus zero (1)', () => {
|
||||
const result = service.getNotificationsBrokerSourceCurrentPage();
|
||||
const expected = cold('(a)', {
|
||||
a: 1
|
||||
});
|
||||
expect(result).toBeObservable(expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getNotificationsBrokerSourceTotals', () => {
|
||||
it('Should return three (3)', () => {
|
||||
const result = service.getNotificationsBrokerSourceTotals();
|
||||
const expected = cold('(a)', {
|
||||
a: 3
|
||||
});
|
||||
expect(result).toBeObservable(expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe('isNotificationsBrokerSourceLoading', () => {
|
||||
it('Should return FALSE', () => {
|
||||
const result = service.isNotificationsBrokerSourceLoading();
|
||||
const expected = cold('(a)', {
|
||||
a: false
|
||||
});
|
||||
expect(result).toBeObservable(expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe('isNotificationsBrokerSourceLoaded', () => {
|
||||
it('Should return TRUE', () => {
|
||||
const result = service.isNotificationsBrokerSourceLoaded();
|
||||
const expected = cold('(a)', {
|
||||
a: true
|
||||
});
|
||||
expect(result).toBeObservable(expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe('isNotificationsBrokerSourceProcessing', () => {
|
||||
it('Should return FALSE', () => {
|
||||
const result = service.isNotificationsBrokerSourceProcessing();
|
||||
const expected = cold('(a)', {
|
||||
a: false
|
||||
});
|
||||
expect(result).toBeObservable(expected);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Testing the Source dispatch methods', () => {
|
||||
beforeEach(async () => {
|
||||
init('full');
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
StoreModule.forRoot({ notifications: notificationsReducers } as any),
|
||||
],
|
||||
providers: [
|
||||
provideMockStore({ initialState }),
|
||||
{ provide: NotificationsStateService, useValue: service }
|
||||
]
|
||||
}).compileComponents();
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
store = TestBed.get(Store);
|
||||
service = new NotificationsStateService(store);
|
||||
serviceAsAny = service;
|
||||
spyOn(store, 'dispatch');
|
||||
});
|
||||
|
||||
describe('dispatchRetrieveNotificationsBrokerSource', () => {
|
||||
it('Should call store.dispatch', () => {
|
||||
const elementsPerPage = 3;
|
||||
const currentPage = 1;
|
||||
const action = new RetrieveAllSourceAction(elementsPerPage, currentPage);
|
||||
service.dispatchRetrieveNotificationsBrokerSource(elementsPerPage, currentPage);
|
||||
expect(serviceAsAny.store.dispatch).toHaveBeenCalledWith(action);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
@@ -13,6 +13,7 @@ import {
|
||||
createSuccessfulRemoteDataObject$
|
||||
} from '../remote-data.utils';
|
||||
import { SearchResult } from '../search/models/search-result.model';
|
||||
import { NotificationsBrokerSourceObject } from '../../core/notifications/broker/models/notifications-broker-source.model';
|
||||
|
||||
// REST Mock ---------------------------------------------------------------------
|
||||
// -------------------------------------------------------------------------------
|
||||
@@ -1329,6 +1330,45 @@ export const NotificationsMockDspaceObject: SearchResult<DSpaceObject> = Object.
|
||||
}
|
||||
);
|
||||
|
||||
// Sources
|
||||
// -------------------------------------------------------------------------------
|
||||
|
||||
export const notificationsBrokerSourceObjectMorePid: NotificationsBrokerSourceObject = {
|
||||
type: new ResourceType('nbsource'),
|
||||
id: 'ENRICH!MORE!PID',
|
||||
lastEvent: '2020/10/09 10:11 UTC',
|
||||
totalEvents: 33,
|
||||
_links: {
|
||||
self: {
|
||||
href: 'https://rest.api/rest/api/integration/nbsources/ENRICH!MORE!PID'
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const notificationsBrokerSourceObjectMoreAbstract: NotificationsBrokerSourceObject = {
|
||||
type: new ResourceType('nbsource'),
|
||||
id: 'ENRICH!MORE!ABSTRACT',
|
||||
lastEvent: '2020/09/08 21:14 UTC',
|
||||
totalEvents: 5,
|
||||
_links: {
|
||||
self: {
|
||||
href: 'https://rest.api/rest/api/integration/nbsources/ENRICH!MORE!ABSTRACT'
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const notificationsBrokerSourceObjectMissingPid: NotificationsBrokerSourceObject = {
|
||||
type: new ResourceType('nbsource'),
|
||||
id: 'ENRICH!MISSING!PID',
|
||||
lastEvent: '2020/10/01 07:36 UTC',
|
||||
totalEvents: 4,
|
||||
_links: {
|
||||
self: {
|
||||
href: 'https://rest.api/rest/api/integration/nbsources/ENRICH!MISSING!PID'
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Topics
|
||||
// -------------------------------------------------------------------------------
|
||||
|
||||
@@ -1753,10 +1793,28 @@ export function getMockNotificationsStateService(): any {
|
||||
getNotificationsBrokerTopicsCurrentPage: jasmine.createSpy('getNotificationsBrokerTopicsCurrentPage'),
|
||||
getNotificationsBrokerTopicsTotals: jasmine.createSpy('getNotificationsBrokerTopicsTotals'),
|
||||
dispatchRetrieveNotificationsBrokerTopics: jasmine.createSpy('dispatchRetrieveNotificationsBrokerTopics'),
|
||||
getNotificationsBrokerSource: jasmine.createSpy('getNotificationsBrokerSource'),
|
||||
isNotificationsBrokerSourceLoading: jasmine.createSpy('isNotificationsBrokerSourceLoading'),
|
||||
isNotificationsBrokerSourceLoaded: jasmine.createSpy('isNotificationsBrokerSourceLoaded'),
|
||||
isNotificationsBrokerSourceProcessing: jasmine.createSpy('isNotificationsBrokerSourceProcessing'),
|
||||
getNotificationsBrokerSourceTotalPages: jasmine.createSpy('getNotificationsBrokerSourceTotalPages'),
|
||||
getNotificationsBrokerSourceCurrentPage: jasmine.createSpy('getNotificationsBrokerSourceCurrentPage'),
|
||||
getNotificationsBrokerSourceTotals: jasmine.createSpy('getNotificationsBrokerSourceTotals'),
|
||||
dispatchRetrieveNotificationsBrokerSource: jasmine.createSpy('dispatchRetrieveNotificationsBrokerSource'),
|
||||
dispatchMarkUserSuggestionsAsVisitedAction: jasmine.createSpy('dispatchMarkUserSuggestionsAsVisitedAction')
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Mock for [[NotificationsBrokerSourceRestService]]
|
||||
*/
|
||||
export function getMockNotificationsBrokerSourceRestService(): NotificationsBrokerTopicRestService {
|
||||
return jasmine.createSpyObj('NotificationsBrokerSourceRestService', {
|
||||
getSources: jasmine.createSpy('getSources'),
|
||||
getSource: jasmine.createSpy('getSource'),
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Mock for [[NotificationsBrokerTopicRestService]]
|
||||
*/
|
||||
|
Reference in New Issue
Block a user