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:
|
rest:
|
||||||
ssl: true
|
ssl: false
|
||||||
host: api7.dspace.org
|
host: localhost:8080
|
||||||
port: 443
|
port: 443
|
||||||
nameSpace: /server
|
nameSpace: /server
|
||||||
|
@@ -1,3 +1,4 @@
|
|||||||
|
import { NO_ERRORS_SCHEMA } from '@angular/core';
|
||||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
import { AdminNotificationsBrokerSourcePageComponent } from './admin-notifications-broker-source-page.component';
|
import { AdminNotificationsBrokerSourcePageComponent } from './admin-notifications-broker-source-page.component';
|
||||||
@@ -8,7 +9,8 @@ describe('AdminNotificationsBrokerSourcePageComponent', () => {
|
|||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await TestBed.configureTestingModule({
|
await TestBed.configureTestingModule({
|
||||||
declarations: [ AdminNotificationsBrokerSourcePageComponent ]
|
declarations: [ AdminNotificationsBrokerSourcePageComponent ],
|
||||||
|
schemas: [NO_ERRORS_SCHEMA]
|
||||||
})
|
})
|
||||||
.compileComponents();
|
.compileComponents();
|
||||||
});
|
});
|
||||||
@@ -19,7 +21,7 @@ describe('AdminNotificationsBrokerSourcePageComponent', () => {
|
|||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should create', () => {
|
it('should create AdminNotificationsBrokerSourcePageComponent', () => {
|
||||||
expect(component).toBeTruthy();
|
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 { 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', () => {
|
describe('NotificationsBrokerSourceComponent test suite', () => {
|
||||||
let component: NotificationsBrokerSourceComponent;
|
|
||||||
let fixture: ComponentFixture<NotificationsBrokerSourceComponent>;
|
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 () => {
|
beforeEach(waitForAsync(() => {
|
||||||
await TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
declarations: [ NotificationsBrokerSourceComponent ]
|
imports: [
|
||||||
})
|
CommonModule,
|
||||||
.compileComponents();
|
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();
|
||||||
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(() => {
|
describe('Main tests running with two Source', () => {
|
||||||
fixture = TestBed.createComponent(NotificationsBrokerSourceComponent);
|
beforeEach(() => {
|
||||||
component = fixture.componentInstance;
|
fixture = TestBed.createComponent(NotificationsBrokerSourceComponent);
|
||||||
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 { CommonModule } from '@angular/common';
|
||||||
import { Component, NO_ERRORS_SCHEMA } from '@angular/core';
|
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 { 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 { ComponentFixture, inject, TestBed, waitForAsync } from '@angular/core/testing';
|
||||||
import { createTestComponent } from '../../../shared/testing/utils.test';
|
import { createTestComponent } from '../../../shared/testing/utils.test';
|
||||||
import {
|
import {
|
||||||
@@ -15,6 +15,7 @@ import { NotificationsStateService } from '../../notifications-state.service';
|
|||||||
import { cold } from 'jasmine-marbles';
|
import { cold } from 'jasmine-marbles';
|
||||||
import { PaginationServiceStub } from '../../../shared/testing/pagination-service.stub';
|
import { PaginationServiceStub } from '../../../shared/testing/pagination-service.stub';
|
||||||
import { PaginationService } from '../../../core/pagination/pagination.service';
|
import { PaginationService } from '../../../core/pagination/pagination.service';
|
||||||
|
import { NotificationsBrokerTopicsService } from './notifications-broker-topics.service';
|
||||||
|
|
||||||
describe('NotificationsBrokerTopicsComponent test suite', () => {
|
describe('NotificationsBrokerTopicsComponent test suite', () => {
|
||||||
let fixture: ComponentFixture<NotificationsBrokerTopicsComponent>;
|
let fixture: ComponentFixture<NotificationsBrokerTopicsComponent>;
|
||||||
@@ -41,9 +42,15 @@ describe('NotificationsBrokerTopicsComponent test suite', () => {
|
|||||||
],
|
],
|
||||||
providers: [
|
providers: [
|
||||||
{ provide: NotificationsStateService, useValue: mockNotificationsStateService },
|
{ 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 },
|
{ provide: PaginationService, useValue: paginationService },
|
||||||
NotificationsBrokerTopicsComponent
|
NotificationsBrokerTopicsComponent,
|
||||||
|
// tslint:disable-next-line: no-empty
|
||||||
|
{ provide: NotificationsBrokerTopicsService, useValue: { setSourceId: (sourceId: string) => { } }}
|
||||||
],
|
],
|
||||||
schemas: [NO_ERRORS_SCHEMA]
|
schemas: [NO_ERRORS_SCHEMA]
|
||||||
}).compileComponents().then(() => {
|
}).compileComponents().then(() => {
|
||||||
|
@@ -67,19 +67,14 @@ export class NotificationsBrokerTopicsComponent implements OnInit {
|
|||||||
private notificationsStateService: NotificationsStateService,
|
private notificationsStateService: NotificationsStateService,
|
||||||
private notificationsBrokerTopicsService: NotificationsBrokerTopicsService
|
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.
|
* Component initialization.
|
||||||
*/
|
*/
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
|
this.sourceId = this.activatedRoute.snapshot.paramMap.get('sourceId');
|
||||||
|
this.notificationsBrokerTopicsService.setSourceId(this.sourceId);
|
||||||
this.topics$ = this.notificationsStateService.getNotificationsBrokerTopics();
|
this.topics$ = this.notificationsStateService.getNotificationsBrokerTopics();
|
||||||
this.totalElements$ = this.notificationsStateService.getNotificationsBrokerTopicsTotals();
|
this.totalElements$ = this.notificationsStateService.getNotificationsBrokerTopicsTotals();
|
||||||
}
|
}
|
||||||
|
@@ -13,6 +13,7 @@ import {
|
|||||||
import { createSuccessfulRemoteDataObject } from '../../../shared/remote-data.utils';
|
import { createSuccessfulRemoteDataObject } from '../../../shared/remote-data.utils';
|
||||||
import { cold } from 'jasmine-marbles';
|
import { cold } from 'jasmine-marbles';
|
||||||
import { buildPaginatedList } from '../../../core/data/paginated-list.model';
|
import { buildPaginatedList } from '../../../core/data/paginated-list.model';
|
||||||
|
import { RequestParam } from '../../../core/cache/models/request-param.model';
|
||||||
|
|
||||||
describe('NotificationsBrokerTopicsService', () => {
|
describe('NotificationsBrokerTopicsService', () => {
|
||||||
let service: NotificationsBrokerTopicsService;
|
let service: NotificationsBrokerTopicsService;
|
||||||
@@ -50,8 +51,10 @@ describe('NotificationsBrokerTopicsService', () => {
|
|||||||
const findListOptions: FindListOptions = {
|
const findListOptions: FindListOptions = {
|
||||||
elementsPerPage: elementsPerPage,
|
elementsPerPage: elementsPerPage,
|
||||||
currentPage: currentPage,
|
currentPage: currentPage,
|
||||||
sort: sortOptions
|
sort: sortOptions,
|
||||||
|
searchParams: [new RequestParam('source', 'ENRICH!MORE!ABSTRACT')]
|
||||||
};
|
};
|
||||||
|
service.setSourceId('ENRICH!MORE!ABSTRACT');
|
||||||
const result = service.getTopics(elementsPerPage, currentPage);
|
const result = service.getTopics(elementsPerPage, currentPage);
|
||||||
expect((service as any).notificationsBrokerTopicRestService.getTopics).toHaveBeenCalledWith(findListOptions);
|
expect((service as any).notificationsBrokerTopicRestService.getTopics).toHaveBeenCalledWith(findListOptions);
|
||||||
});
|
});
|
||||||
|
@@ -5,11 +5,15 @@ import { cold } from 'jasmine-marbles';
|
|||||||
import { notificationsReducers } from './notifications.reducer';
|
import { notificationsReducers } from './notifications.reducer';
|
||||||
import { NotificationsStateService } from './notifications-state.service';
|
import { NotificationsStateService } from './notifications-state.service';
|
||||||
import {
|
import {
|
||||||
|
notificationsBrokerSourceObjectMissingPid,
|
||||||
|
notificationsBrokerSourceObjectMoreAbstract,
|
||||||
|
notificationsBrokerSourceObjectMorePid,
|
||||||
notificationsBrokerTopicObjectMissingPid,
|
notificationsBrokerTopicObjectMissingPid,
|
||||||
notificationsBrokerTopicObjectMoreAbstract,
|
notificationsBrokerTopicObjectMoreAbstract,
|
||||||
notificationsBrokerTopicObjectMorePid
|
notificationsBrokerTopicObjectMorePid
|
||||||
} from '../shared/mocks/notifications.mock';
|
} from '../shared/mocks/notifications.mock';
|
||||||
import { RetrieveAllTopicsAction } from './broker/topics/notifications-broker-topics.actions';
|
import { RetrieveAllTopicsAction } from './broker/topics/notifications-broker-topics.actions';
|
||||||
|
import { RetrieveAllSourceAction } from './broker/source/notifications-broker-source.actions';
|
||||||
|
|
||||||
describe('NotificationsStateService', () => {
|
describe('NotificationsStateService', () => {
|
||||||
let service: NotificationsStateService;
|
let service: NotificationsStateService;
|
||||||
@@ -17,259 +21,521 @@ describe('NotificationsStateService', () => {
|
|||||||
let store: any;
|
let store: any;
|
||||||
let initialState: any;
|
let initialState: any;
|
||||||
|
|
||||||
function init(mode: string) {
|
describe('Topis State', () => {
|
||||||
if (mode === 'empty') {
|
function init(mode: string) {
|
||||||
initialState = {
|
if (mode === 'empty') {
|
||||||
notifications: {
|
initialState = {
|
||||||
brokerTopic: {
|
notifications: {
|
||||||
topics: [],
|
brokerTopic: {
|
||||||
processing: false,
|
topics: [],
|
||||||
loaded: false,
|
processing: false,
|
||||||
totalPages: 0,
|
loaded: false,
|
||||||
currentPage: 0,
|
totalPages: 0,
|
||||||
totalElements: 0,
|
currentPage: 0,
|
||||||
totalLoadedPages: 0
|
totalElements: 0,
|
||||||
|
totalLoadedPages: 0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
};
|
} else {
|
||||||
} else {
|
initialState = {
|
||||||
initialState = {
|
notifications: {
|
||||||
notifications: {
|
brokerTopic: {
|
||||||
brokerTopic: {
|
topics: [
|
||||||
topics: [
|
notificationsBrokerTopicObjectMorePid,
|
||||||
|
notificationsBrokerTopicObjectMoreAbstract,
|
||||||
|
notificationsBrokerTopicObjectMissingPid
|
||||||
|
],
|
||||||
|
processing: false,
|
||||||
|
loaded: true,
|
||||||
|
totalPages: 1,
|
||||||
|
currentPage: 1,
|
||||||
|
totalElements: 3,
|
||||||
|
totalLoadedPages: 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('Testing methods with empty topic 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('getNotificationsBrokerTopics', () => {
|
||||||
|
it('Should return an empty array', () => {
|
||||||
|
const result = service.getNotificationsBrokerTopics();
|
||||||
|
const expected = cold('(a)', {
|
||||||
|
a: []
|
||||||
|
});
|
||||||
|
expect(result).toBeObservable(expected);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('getNotificationsBrokerTopicsTotalPages', () => {
|
||||||
|
it('Should return zero (0)', () => {
|
||||||
|
const result = service.getNotificationsBrokerTopicsTotalPages();
|
||||||
|
const expected = cold('(a)', {
|
||||||
|
a: 0
|
||||||
|
});
|
||||||
|
expect(result).toBeObservable(expected);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('getNotificationsBrokerTopicsCurrentPage', () => {
|
||||||
|
it('Should return minus one (0)', () => {
|
||||||
|
const result = service.getNotificationsBrokerTopicsCurrentPage();
|
||||||
|
const expected = cold('(a)', {
|
||||||
|
a: 0
|
||||||
|
});
|
||||||
|
expect(result).toBeObservable(expected);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('getNotificationsBrokerTopicsTotals', () => {
|
||||||
|
it('Should return zero (0)', () => {
|
||||||
|
const result = service.getNotificationsBrokerTopicsTotals();
|
||||||
|
const expected = cold('(a)', {
|
||||||
|
a: 0
|
||||||
|
});
|
||||||
|
expect(result).toBeObservable(expected);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('isNotificationsBrokerTopicsLoading', () => {
|
||||||
|
it('Should return TRUE', () => {
|
||||||
|
const result = service.isNotificationsBrokerTopicsLoading();
|
||||||
|
const expected = cold('(a)', {
|
||||||
|
a: true
|
||||||
|
});
|
||||||
|
expect(result).toBeObservable(expected);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('isNotificationsBrokerTopicsLoaded', () => {
|
||||||
|
it('Should return FALSE', () => {
|
||||||
|
const result = service.isNotificationsBrokerTopicsLoaded();
|
||||||
|
const expected = cold('(a)', {
|
||||||
|
a: false
|
||||||
|
});
|
||||||
|
expect(result).toBeObservable(expected);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('isNotificationsBrokerTopicsProcessing', () => {
|
||||||
|
it('Should return FALSE', () => {
|
||||||
|
const result = service.isNotificationsBrokerTopicsProcessing();
|
||||||
|
const expected = cold('(a)', {
|
||||||
|
a: false
|
||||||
|
});
|
||||||
|
expect(result).toBeObservable(expected);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Testing methods with topic 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('getNotificationsBrokerTopics', () => {
|
||||||
|
it('Should return an array of topics', () => {
|
||||||
|
const result = service.getNotificationsBrokerTopics();
|
||||||
|
const expected = cold('(a)', {
|
||||||
|
a: [
|
||||||
notificationsBrokerTopicObjectMorePid,
|
notificationsBrokerTopicObjectMorePid,
|
||||||
notificationsBrokerTopicObjectMoreAbstract,
|
notificationsBrokerTopicObjectMoreAbstract,
|
||||||
notificationsBrokerTopicObjectMissingPid
|
notificationsBrokerTopicObjectMissingPid
|
||||||
],
|
]
|
||||||
processing: false,
|
});
|
||||||
loaded: true,
|
expect(result).toBeObservable(expected);
|
||||||
totalPages: 1,
|
});
|
||||||
currentPage: 1,
|
});
|
||||||
totalElements: 3,
|
|
||||||
totalLoadedPages: 1
|
describe('getNotificationsBrokerTopicsTotalPages', () => {
|
||||||
}
|
it('Should return one (1)', () => {
|
||||||
}
|
const result = service.getNotificationsBrokerTopicsTotalPages();
|
||||||
};
|
const expected = cold('(a)', {
|
||||||
}
|
a: 1
|
||||||
}
|
});
|
||||||
|
expect(result).toBeObservable(expected);
|
||||||
describe('Testing methods with empty topic objects', () => {
|
});
|
||||||
beforeEach(async () => {
|
});
|
||||||
init('empty');
|
|
||||||
TestBed.configureTestingModule({
|
describe('getNotificationsBrokerTopicsCurrentPage', () => {
|
||||||
imports: [
|
it('Should return minus zero (1)', () => {
|
||||||
StoreModule.forRoot({ notifications: notificationsReducers } as any),
|
const result = service.getNotificationsBrokerTopicsCurrentPage();
|
||||||
],
|
const expected = cold('(a)', {
|
||||||
providers: [
|
a: 1
|
||||||
provideMockStore({ initialState }),
|
});
|
||||||
{ provide: NotificationsStateService, useValue: service }
|
expect(result).toBeObservable(expected);
|
||||||
]
|
});
|
||||||
}).compileComponents();
|
});
|
||||||
});
|
|
||||||
|
describe('getNotificationsBrokerTopicsTotals', () => {
|
||||||
beforeEach(() => {
|
it('Should return three (3)', () => {
|
||||||
store = TestBed.get(Store);
|
const result = service.getNotificationsBrokerTopicsTotals();
|
||||||
service = new NotificationsStateService(store);
|
const expected = cold('(a)', {
|
||||||
serviceAsAny = service;
|
a: 3
|
||||||
spyOn(store, 'dispatch');
|
});
|
||||||
});
|
expect(result).toBeObservable(expected);
|
||||||
|
});
|
||||||
describe('getNotificationsBrokerTopics', () => {
|
});
|
||||||
it('Should return an empty array', () => {
|
|
||||||
const result = service.getNotificationsBrokerTopics();
|
describe('isNotificationsBrokerTopicsLoading', () => {
|
||||||
const expected = cold('(a)', {
|
it('Should return FALSE', () => {
|
||||||
a: []
|
const result = service.isNotificationsBrokerTopicsLoading();
|
||||||
|
const expected = cold('(a)', {
|
||||||
|
a: false
|
||||||
|
});
|
||||||
|
expect(result).toBeObservable(expected);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('isNotificationsBrokerTopicsLoaded', () => {
|
||||||
|
it('Should return TRUE', () => {
|
||||||
|
const result = service.isNotificationsBrokerTopicsLoaded();
|
||||||
|
const expected = cold('(a)', {
|
||||||
|
a: true
|
||||||
|
});
|
||||||
|
expect(result).toBeObservable(expected);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('isNotificationsBrokerTopicsProcessing', () => {
|
||||||
|
it('Should return FALSE', () => {
|
||||||
|
const result = service.isNotificationsBrokerTopicsProcessing();
|
||||||
|
const expected = cold('(a)', {
|
||||||
|
a: false
|
||||||
|
});
|
||||||
|
expect(result).toBeObservable(expected);
|
||||||
});
|
});
|
||||||
expect(result).toBeObservable(expected);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('getNotificationsBrokerTopicsTotalPages', () => {
|
describe('Testing the topic dispatch methods', () => {
|
||||||
it('Should return zero (0)', () => {
|
beforeEach(async () => {
|
||||||
const result = service.getNotificationsBrokerTopicsTotalPages();
|
init('full');
|
||||||
const expected = cold('(a)', {
|
TestBed.configureTestingModule({
|
||||||
a: 0
|
imports: [
|
||||||
});
|
StoreModule.forRoot({ notifications: notificationsReducers } as any),
|
||||||
expect(result).toBeObservable(expected);
|
],
|
||||||
});
|
providers: [
|
||||||
});
|
provideMockStore({ initialState }),
|
||||||
|
{ provide: NotificationsStateService, useValue: service }
|
||||||
describe('getNotificationsBrokerTopicsCurrentPage', () => {
|
|
||||||
it('Should return minus one (0)', () => {
|
|
||||||
const result = service.getNotificationsBrokerTopicsCurrentPage();
|
|
||||||
const expected = cold('(a)', {
|
|
||||||
a: 0
|
|
||||||
});
|
|
||||||
expect(result).toBeObservable(expected);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('getNotificationsBrokerTopicsTotals', () => {
|
|
||||||
it('Should return zero (0)', () => {
|
|
||||||
const result = service.getNotificationsBrokerTopicsTotals();
|
|
||||||
const expected = cold('(a)', {
|
|
||||||
a: 0
|
|
||||||
});
|
|
||||||
expect(result).toBeObservable(expected);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('isNotificationsBrokerTopicsLoading', () => {
|
|
||||||
it('Should return TRUE', () => {
|
|
||||||
const result = service.isNotificationsBrokerTopicsLoading();
|
|
||||||
const expected = cold('(a)', {
|
|
||||||
a: true
|
|
||||||
});
|
|
||||||
expect(result).toBeObservable(expected);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('isNotificationsBrokerTopicsLoaded', () => {
|
|
||||||
it('Should return FALSE', () => {
|
|
||||||
const result = service.isNotificationsBrokerTopicsLoaded();
|
|
||||||
const expected = cold('(a)', {
|
|
||||||
a: false
|
|
||||||
});
|
|
||||||
expect(result).toBeObservable(expected);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('isNotificationsBrokerTopicsProcessing', () => {
|
|
||||||
it('Should return FALSE', () => {
|
|
||||||
const result = service.isNotificationsBrokerTopicsProcessing();
|
|
||||||
const expected = cold('(a)', {
|
|
||||||
a: false
|
|
||||||
});
|
|
||||||
expect(result).toBeObservable(expected);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('Testing methods with topic 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('getNotificationsBrokerTopics', () => {
|
|
||||||
it('Should return an array of topics', () => {
|
|
||||||
const result = service.getNotificationsBrokerTopics();
|
|
||||||
const expected = cold('(a)', {
|
|
||||||
a: [
|
|
||||||
notificationsBrokerTopicObjectMorePid,
|
|
||||||
notificationsBrokerTopicObjectMoreAbstract,
|
|
||||||
notificationsBrokerTopicObjectMissingPid
|
|
||||||
]
|
]
|
||||||
});
|
}).compileComponents();
|
||||||
expect(result).toBeObservable(expected);
|
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
describe('getNotificationsBrokerTopicsTotalPages', () => {
|
beforeEach(() => {
|
||||||
it('Should return one (1)', () => {
|
store = TestBed.get(Store);
|
||||||
const result = service.getNotificationsBrokerTopicsTotalPages();
|
service = new NotificationsStateService(store);
|
||||||
const expected = cold('(a)', {
|
serviceAsAny = service;
|
||||||
a: 1
|
spyOn(store, 'dispatch');
|
||||||
});
|
|
||||||
expect(result).toBeObservable(expected);
|
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
describe('getNotificationsBrokerTopicsCurrentPage', () => {
|
describe('dispatchRetrieveNotificationsBrokerTopics', () => {
|
||||||
it('Should return minus zero (1)', () => {
|
it('Should call store.dispatch', () => {
|
||||||
const result = service.getNotificationsBrokerTopicsCurrentPage();
|
const elementsPerPage = 3;
|
||||||
const expected = cold('(a)', {
|
const currentPage = 1;
|
||||||
a: 1
|
const action = new RetrieveAllTopicsAction(elementsPerPage, currentPage);
|
||||||
|
service.dispatchRetrieveNotificationsBrokerTopics(elementsPerPage, currentPage);
|
||||||
|
expect(serviceAsAny.store.dispatch).toHaveBeenCalledWith(action);
|
||||||
});
|
});
|
||||||
expect(result).toBeObservable(expected);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('getNotificationsBrokerTopicsTotals', () => {
|
|
||||||
it('Should return three (3)', () => {
|
|
||||||
const result = service.getNotificationsBrokerTopicsTotals();
|
|
||||||
const expected = cold('(a)', {
|
|
||||||
a: 3
|
|
||||||
});
|
|
||||||
expect(result).toBeObservable(expected);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('isNotificationsBrokerTopicsLoading', () => {
|
|
||||||
it('Should return FALSE', () => {
|
|
||||||
const result = service.isNotificationsBrokerTopicsLoading();
|
|
||||||
const expected = cold('(a)', {
|
|
||||||
a: false
|
|
||||||
});
|
|
||||||
expect(result).toBeObservable(expected);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('isNotificationsBrokerTopicsLoaded', () => {
|
|
||||||
it('Should return TRUE', () => {
|
|
||||||
const result = service.isNotificationsBrokerTopicsLoaded();
|
|
||||||
const expected = cold('(a)', {
|
|
||||||
a: true
|
|
||||||
});
|
|
||||||
expect(result).toBeObservable(expected);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('isNotificationsBrokerTopicsProcessing', () => {
|
|
||||||
it('Should return FALSE', () => {
|
|
||||||
const result = service.isNotificationsBrokerTopicsProcessing();
|
|
||||||
const expected = cold('(a)', {
|
|
||||||
a: false
|
|
||||||
});
|
|
||||||
expect(result).toBeObservable(expected);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Testing the topic dispatch methods', () => {
|
describe('Source State', () => {
|
||||||
beforeEach(async () => {
|
function init(mode: string) {
|
||||||
init('full');
|
if (mode === 'empty') {
|
||||||
TestBed.configureTestingModule({
|
initialState = {
|
||||||
imports: [
|
notifications: {
|
||||||
StoreModule.forRoot({ notifications: notificationsReducers } as any),
|
brokerSource: {
|
||||||
],
|
source: [],
|
||||||
providers: [
|
processing: false,
|
||||||
provideMockStore({ initialState }),
|
loaded: false,
|
||||||
{ provide: NotificationsStateService, useValue: service }
|
totalPages: 0,
|
||||||
]
|
currentPage: 0,
|
||||||
}).compileComponents();
|
totalElements: 0,
|
||||||
});
|
totalLoadedPages: 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
initialState = {
|
||||||
|
notifications: {
|
||||||
|
brokerSource: {
|
||||||
|
source: [
|
||||||
|
notificationsBrokerSourceObjectMorePid,
|
||||||
|
notificationsBrokerSourceObjectMoreAbstract,
|
||||||
|
notificationsBrokerSourceObjectMissingPid
|
||||||
|
],
|
||||||
|
processing: false,
|
||||||
|
loaded: true,
|
||||||
|
totalPages: 1,
|
||||||
|
currentPage: 1,
|
||||||
|
totalElements: 3,
|
||||||
|
totalLoadedPages: 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
beforeEach(() => {
|
describe('Testing methods with empty source objects', () => {
|
||||||
store = TestBed.get(Store);
|
beforeEach(async () => {
|
||||||
service = new NotificationsStateService(store);
|
init('empty');
|
||||||
serviceAsAny = service;
|
TestBed.configureTestingModule({
|
||||||
spyOn(store, 'dispatch');
|
imports: [
|
||||||
});
|
StoreModule.forRoot({ notifications: notificationsReducers } as any),
|
||||||
|
],
|
||||||
|
providers: [
|
||||||
|
provideMockStore({ initialState }),
|
||||||
|
{ provide: NotificationsStateService, useValue: service }
|
||||||
|
]
|
||||||
|
}).compileComponents();
|
||||||
|
});
|
||||||
|
|
||||||
describe('dispatchRetrieveNotificationsBrokerTopics', () => {
|
beforeEach(() => {
|
||||||
it('Should call store.dispatch', () => {
|
store = TestBed.get(Store);
|
||||||
const elementsPerPage = 3;
|
service = new NotificationsStateService(store);
|
||||||
const currentPage = 1;
|
serviceAsAny = service;
|
||||||
const action = new RetrieveAllTopicsAction(elementsPerPage, currentPage);
|
spyOn(store, 'dispatch');
|
||||||
service.dispatchRetrieveNotificationsBrokerTopics(elementsPerPage, currentPage);
|
});
|
||||||
expect(serviceAsAny.store.dispatch).toHaveBeenCalledWith(action);
|
|
||||||
|
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$
|
createSuccessfulRemoteDataObject$
|
||||||
} from '../remote-data.utils';
|
} from '../remote-data.utils';
|
||||||
import { SearchResult } from '../search/models/search-result.model';
|
import { SearchResult } from '../search/models/search-result.model';
|
||||||
|
import { NotificationsBrokerSourceObject } from '../../core/notifications/broker/models/notifications-broker-source.model';
|
||||||
|
|
||||||
// REST Mock ---------------------------------------------------------------------
|
// 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
|
// Topics
|
||||||
// -------------------------------------------------------------------------------
|
// -------------------------------------------------------------------------------
|
||||||
|
|
||||||
@@ -1753,10 +1793,28 @@ export function getMockNotificationsStateService(): any {
|
|||||||
getNotificationsBrokerTopicsCurrentPage: jasmine.createSpy('getNotificationsBrokerTopicsCurrentPage'),
|
getNotificationsBrokerTopicsCurrentPage: jasmine.createSpy('getNotificationsBrokerTopicsCurrentPage'),
|
||||||
getNotificationsBrokerTopicsTotals: jasmine.createSpy('getNotificationsBrokerTopicsTotals'),
|
getNotificationsBrokerTopicsTotals: jasmine.createSpy('getNotificationsBrokerTopicsTotals'),
|
||||||
dispatchRetrieveNotificationsBrokerTopics: jasmine.createSpy('dispatchRetrieveNotificationsBrokerTopics'),
|
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')
|
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]]
|
* Mock for [[NotificationsBrokerTopicRestService]]
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user