[CST-12490] unit test fixes

This commit is contained in:
Alisa Ismailati
2023-11-03 17:54:45 +01:00
parent 5b3bcf4271
commit f74efd62a5
21 changed files with 324 additions and 154 deletions

View File

@@ -1,14 +1,70 @@
import { ComponentFixture, TestBed } from '@angular/core/testing'; import { ComponentFixture, TestBed } from '@angular/core/testing';
import { LdnServiceFormEditComponent } from './ldn-service-form-edit.component'; import { LdnServiceFormEditComponent } from './ldn-service-form-edit.component';
import { ChangeDetectorRef, EventEmitter } from '@angular/core';
import { ReactiveFormsModule, FormBuilder } from '@angular/forms';
import { ActivatedRoute, Router } from '@angular/router';
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
import { TranslateModule, TranslateService } from '@ngx-translate/core';
import { PaginationService } from 'ngx-pagination';
import { NotificationsService } from '../../../shared/notifications/notifications.service';
import { LdnItemfiltersService } from '../ldn-services-data/ldn-itemfilters-data.service';
import { LdnServicesService } from '../ldn-services-data/ldn-services-data.service';
import { RouterStub } from '../../../shared/testing/router.stub';
import { MockActivatedRoute } from '../../../shared/mocks/active-router.mock';
import { NotificationsServiceStub } from '../../../shared/testing/notifications-service.stub';
import { of } from 'rxjs';
import { RouteService } from '../../../core/services/route.service';
import { provideMockStore } from '@ngrx/store/testing';
describe('LdnServiceFormEditComponent', () => { describe('LdnServiceFormEditComponent', () => {
let component: LdnServiceFormEditComponent; let component: LdnServiceFormEditComponent;
let fixture: ComponentFixture<LdnServiceFormEditComponent>; let fixture: ComponentFixture<LdnServiceFormEditComponent>;
let ldnServicesService: any;
let ldnItemfiltersService: any;
let cdRefStub: any;
let modalService: any;
const translateServiceStub = {
get: () => of('translated-text'),
onLangChange: new EventEmitter(),
onTranslationChange: new EventEmitter(),
onDefaultLangChange: new EventEmitter()
};
beforeEach(async () => { beforeEach(async () => {
ldnServicesService = {
update: () => ({}),
};
ldnItemfiltersService = {
findAll: () => of(['item1', 'item2']),
};
cdRefStub = Object.assign({
detectChanges: () => fixture.detectChanges()
});
modalService = {
open: () => {/*comment*/
}
};
await TestBed.configureTestingModule({ await TestBed.configureTestingModule({
declarations: [LdnServiceFormEditComponent] imports: [ReactiveFormsModule, TranslateModule.forRoot()],
declarations: [LdnServiceFormEditComponent],
providers: [
{ provide: LdnServicesService, useValue: ldnServicesService },
{ provide: LdnItemfiltersService, useValue: ldnItemfiltersService },
{ provide: Router, useValue: new RouterStub() },
{ provide: ActivatedRoute, useValue: new MockActivatedRoute() },
{ provide: ChangeDetectorRef, useValue: cdRefStub },
{ provide: NgbModal, useValue: modalService },
{ provide: NotificationsService, useValue: NotificationsServiceStub },
{ provide: TranslateService, useValue: translateServiceStub },
{ provide: PaginationService, useValue: {} },
FormBuilder,
RouteService,
provideMockStore({ }),
]
}) })
.compileComponents(); .compileComponents();

View File

@@ -1,13 +1,67 @@
import { ComponentFixture, TestBed } from '@angular/core/testing'; import { ComponentFixture, TestBed } from '@angular/core/testing';
import { LdnServiceFormComponent } from './ldn-service-form.component'; import { LdnServiceFormComponent } from './ldn-service-form.component';
import { FormBuilder, ReactiveFormsModule } from '@angular/forms';
import { RouterTestingModule } from '@angular/router/testing';
import { NgbModal, NgbModalModule } from '@ng-bootstrap/ng-bootstrap';
import { TranslateModule, TranslateService } from '@ngx-translate/core';
import { LdnItemfiltersService } from '../ldn-services-data/ldn-itemfilters-data.service';
import { LdnServicesService } from '../ldn-services-data/ldn-services-data.service';
import { NotificationsService } from 'src/app/shared/notifications/notifications.service';
import { Router } from '@angular/router';
import { RouterStub } from 'src/app/shared/testing/router.stub';
import { createPaginatedList } from 'src/app/shared/testing/utils.test';
import { Itemfilter } from '../ldn-services-model/ldn-service-itemfilters';
import { createSuccessfulRemoteDataObject$ } from 'src/app/shared/remote-data.utils';
import { of } from 'rxjs';
import { EventEmitter } from '@angular/core';
describe('LdnServiceFormComponent', () => { describe('LdnServiceFormComponent', () => {
let component: LdnServiceFormComponent; let component: LdnServiceFormComponent;
let fixture: ComponentFixture<LdnServiceFormComponent>; let fixture: ComponentFixture<LdnServiceFormComponent>;
let ldnServicesService: any;
let ldnItemfiltersService: any;
let notificationsService: any;
const itemFiltersRdPL$ = createSuccessfulRemoteDataObject$(createPaginatedList([new Itemfilter()]));
const translateServiceStub = {
get: () => of('translated-text'),
onLangChange: new EventEmitter(),
onTranslationChange: new EventEmitter(),
onDefaultLangChange: new EventEmitter()
};
beforeEach(async () => { beforeEach(async () => {
ldnItemfiltersService = jasmine.createSpyObj('ldnItemfiltersService', {
findAll: jasmine.createSpy('findAll'),
});
ldnServicesService = jasmine.createSpyObj('ldnServicesService', {
create: jasmine.createSpy('create'),
});
notificationsService = jasmine.createSpyObj('notificationsService', {
success: jasmine.createSpy('success'),
error: jasmine.createSpy('error'),
});
await TestBed.configureTestingModule({ await TestBed.configureTestingModule({
imports: [
ReactiveFormsModule,
RouterTestingModule,
NgbModalModule,
TranslateModule.forRoot()
],
providers: [
{ provide: LdnItemfiltersService, useValue: ldnItemfiltersService },
{ provide: LdnServicesService, useValue: ldnServicesService },
{ provide: NotificationsService, useValue: notificationsService },
{ provide: TranslateService, useValue: translateServiceStub },
{ provide: Router, useValue: new RouterStub() },
{ provide: NgbModal, useValue: { open: () => {/*comment*/ } } },
FormBuilder
],
declarations: [LdnServiceFormComponent] declarations: [LdnServiceFormComponent]
}) })
.compileComponents(); .compileComponents();
@@ -16,6 +70,7 @@ describe('LdnServiceFormComponent', () => {
beforeEach(() => { beforeEach(() => {
fixture = TestBed.createComponent(LdnServiceFormComponent); fixture = TestBed.createComponent(LdnServiceFormComponent);
component = fixture.componentInstance; component = fixture.componentInstance;
ldnItemfiltersService.findAll.and.returnValue(itemFiltersRdPL$);
fixture.detectChanges(); fixture.detectChanges();
}); });

View File

@@ -1,27 +1,9 @@
import { Component, OnInit } from '@angular/core'; import { Component } from '@angular/core';
import { Observable } from 'rxjs';
import { LdnService } from "../ldn-services-model/ldn-services.model";
import { ActivatedRoute } from "@angular/router";
import { ProcessDataService } from "../../../core/data/processes/process-data.service";
import { LinkService } from "../../../core/cache/builders/link.service";
@Component({ @Component({
selector: 'ds-ldn-service-new', selector: 'ds-ldn-service-new',
templateUrl: './ldn-service-new.component.html', templateUrl: './ldn-service-new.component.html',
styleUrls: ['./ldn-service-new.component.scss'] styleUrls: ['./ldn-service-new.component.scss']
}) })
export class LdnServiceNewComponent implements OnInit { export class LdnServiceNewComponent {
/**
* Emits preselected process if there is one
*/
ldnService$?: Observable<LdnService>;
constructor(private route: ActivatedRoute, private processService: ProcessDataService, private linkService: LinkService) {
}
/**
* If there's an id parameter, use this the process with this identifier as presets for the form
*/
ngOnInit() {
}
} }

View File

@@ -1,20 +1,49 @@
import { ComponentFixture, TestBed } from '@angular/core/testing'; import { ComponentFixture, TestBed } from '@angular/core/testing';
import { LdnServicesOverviewComponent } from './ldn-services-directory.component';
import { ChangeDetectorRef, EventEmitter } from '@angular/core';
import { NotificationsService } from '../../../shared/notifications/notifications.service';
import { NotificationsServiceStub } from '../../../shared/testing/notifications-service.stub';
import { TranslateModule, TranslateService } from '@ngx-translate/core';
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
import { LdnServicesService } from '../ldn-services-data/ldn-services-data.service';
import { PaginationService } from '../../../core/pagination/pagination.service';
import { PaginationServiceStub } from '../../../shared/testing/pagination-service.stub';
import { of } from 'rxjs';
import { ServicesDirectoryComponent } from './services-directory.component'; describe('LdnServicesOverviewComponent', () => {
let component: LdnServicesOverviewComponent;
let fixture: ComponentFixture<LdnServicesOverviewComponent>;
describe('ServicesDirectoryComponent', () => { const translateServiceStub = {
let component: ServicesDirectoryComponent; get: () => of('translated-text'),
let fixture: ComponentFixture<ServicesDirectoryComponent>; onLangChange: new EventEmitter(),
onTranslationChange: new EventEmitter(),
onDefaultLangChange: new EventEmitter()
};
beforeEach(async () => { beforeEach(async () => {
await TestBed.configureTestingModule({ await TestBed.configureTestingModule({
declarations: [ServicesDirectoryComponent] imports: [TranslateModule.forRoot()],
declarations: [LdnServicesOverviewComponent],
providers: [
{ provide: LdnServicesService, useValue: {} },
{ provide: PaginationService, useValue: new PaginationServiceStub() },
{
provide: NgbModal, useValue: {
open: () => {/*comment*/
}
}
},
{ provide: ChangeDetectorRef, useValue: {} },
{ provide: NotificationsService, useValue: NotificationsServiceStub },
{ provide: TranslateService, useValue: translateServiceStub },
]
}) })
.compileComponents(); .compileComponents();
}); });
beforeEach(() => { beforeEach(() => {
fixture = TestBed.createComponent(ServicesDirectoryComponent); fixture = TestBed.createComponent(LdnServicesOverviewComponent);
component = fixture.componentInstance; component = fixture.componentInstance;
fixture.detectChanges(); fixture.detectChanges();
}); });

View File

@@ -1,17 +0,0 @@
import { TestBed } from '@angular/core/testing';
import { LdnDirectoryService } from './ldn-directory.service';
describe('LdnDirectoryService', () => {
let service: LdnDirectoryService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(LdnDirectoryService);
});
it('should be created', () => {
// @ts-ignore
expect(service).toBeTruthy();
});
});

View File

@@ -1,29 +0,0 @@
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { map, Observable } from 'rxjs';
import { LdnServicesService } from "../ldn-services-data/ldn-services-data.service";
@Injectable({
providedIn: 'root',
})
export class LdnDirectoryService {
private itemFilterEndpoint = 'http://localhost:8080/server/api/config/itemfilters';
constructor(private http: HttpClient,
private ldnServicesService: LdnServicesService) {
}
public getItemFilters(): Observable<any> {
return this.ldnServicesService.findAll().pipe(
map((servicesData) => {
return servicesData;
})
);
}
}

View File

@@ -1,17 +0,0 @@
import { TestBed } from '@angular/core/testing';
import { LdnServicesBulkDeleteService } from './ldn-service-bulk-delete.service';
describe('LdnServiceBulkDeleteService', () => {
let service: LdnServicesBulkDeleteService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(LdnServicesBulkDeleteService);
});
it('should be created', () => {
// @ts-ignore
expect(service).toBeTruthy();
});
});

View File

@@ -1,14 +1,23 @@
import { ComponentFixture, TestBed } from '@angular/core/testing'; import { ComponentFixture, TestBed } from '@angular/core/testing';
import { NotifyInfoComponent } from './notify-info.component'; import { NotifyInfoComponent } from './notify-info.component';
import { NotifyInfoService } from './notify-info.service';
import { TranslateModule } from '@ngx-translate/core';
describe('NotifyInfoComponent', () => { describe('NotifyInfoComponent', () => {
let component: NotifyInfoComponent; let component: NotifyInfoComponent;
let fixture: ComponentFixture<NotifyInfoComponent>; let fixture: ComponentFixture<NotifyInfoComponent>;
let notifyInfoServiceSpy: any;
beforeEach(async () => { beforeEach(async () => {
notifyInfoServiceSpy = jasmine.createSpyObj('NotifyInfoService', ['getCoarLdnLocalInboxUrls']);
await TestBed.configureTestingModule({ await TestBed.configureTestingModule({
declarations: [ NotifyInfoComponent ] imports: [TranslateModule.forRoot()],
declarations: [ NotifyInfoComponent ],
providers: [
{ provide: NotifyInfoService, useValue: notifyInfoServiceSpy }
]
}) })
.compileComponents(); .compileComponents();
}); });

View File

@@ -16,7 +16,7 @@ export class NotifyInfoComponent implements OnInit {
*/ */
coarRestApiUrl: Observable<string[]> = of([]); coarRestApiUrl: Observable<string[]> = of([]);
constructor(public notifyInfoService: NotifyInfoService) {} constructor(private notifyInfoService: NotifyInfoService) {}
ngOnInit() { ngOnInit() {
this.coarRestApiUrl = this.notifyInfoService.getCoarLdnLocalInboxUrls(); this.coarRestApiUrl = this.notifyInfoService.getCoarLdnLocalInboxUrls();

View File

@@ -1,16 +1,49 @@
import { TestBed } from '@angular/core/testing'; import { TestBed } from '@angular/core/testing';
import { NotifyInfoGuard } from './notify-info.guard'; import { NotifyInfoGuard } from './notify-info.guard';
import { Router } from '@angular/router';
import { NotifyInfoService } from './notify-info.service';
import { of } from 'rxjs';
describe('NotifyInfoGuard', () => { describe('NotifyInfoGuard', () => {
let guard: NotifyInfoGuard; let guard: NotifyInfoGuard;
let notifyInfoServiceSpy: any;
let router: any;
beforeEach(() => { beforeEach(() => {
TestBed.configureTestingModule({}); notifyInfoServiceSpy = jasmine.createSpyObj('NotifyInfoService', ['isCoarConfigEnabled']);
router = jasmine.createSpyObj('Router', ['parseUrl']);
TestBed.configureTestingModule({
providers: [
NotifyInfoGuard,
{ provide: NotifyInfoService, useValue: notifyInfoServiceSpy},
{ provide: Router, useValue: router}
]
});
guard = TestBed.inject(NotifyInfoGuard); guard = TestBed.inject(NotifyInfoGuard);
}); });
it('should be created', () => { it('should be created', () => {
expect(guard).toBeTruthy(); expect(guard).toBeTruthy();
}); });
it('should return true if COAR config is enabled', (done) => {
notifyInfoServiceSpy.isCoarConfigEnabled.and.returnValue(of(true));
guard.canActivate(null, null).subscribe((result) => {
expect(result).toBe(true);
done();
});
});
it('should call parseUrl method of Router if COAR config is not enabled', (done) => {
notifyInfoServiceSpy.isCoarConfigEnabled.and.returnValue(of(false));
router.parseUrl.and.returnValue(of('/404'));
guard.canActivate(null, null).subscribe(() => {
expect(router.parseUrl).toHaveBeenCalledWith('/404');
done();
});
});
}); });

View File

@@ -16,7 +16,7 @@ export class NotifyInfoGuard implements CanActivate {
canActivate( canActivate(
route: ActivatedRouteSnapshot, route: ActivatedRouteSnapshot,
state: RouterStateSnapshot state: RouterStateSnapshot
): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree { ): Observable<boolean | UrlTree> {
return this.notifyInfoService.isCoarConfigEnabled().pipe( return this.notifyInfoService.isCoarConfigEnabled().pipe(
map(coarLdnEnabled => { map(coarLdnEnabled => {
if (coarLdnEnabled) { if (coarLdnEnabled) {

View File

@@ -1,16 +1,50 @@
import { TestBed } from '@angular/core/testing'; import { TestBed } from '@angular/core/testing';
import { NotifyInfoService } from './notify-info.service'; import { NotifyInfoService } from './notify-info.service';
import { ConfigurationDataService } from '../../data/configuration-data.service';
import { of } from 'rxjs';
describe('NotifyInfoService', () => { describe('NotifyInfoService', () => {
let service: NotifyInfoService; let service: NotifyInfoService;
let configurationDataService: any;
beforeEach(() => { beforeEach(() => {
TestBed.configureTestingModule({}); configurationDataService = {
findByPropertyName: jasmine.createSpy('findByPropertyName').and.returnValue(of({})),
};
TestBed.configureTestingModule({
providers: [
NotifyInfoService,
{ provide: ConfigurationDataService, useValue: configurationDataService },
]
});
service = TestBed.inject(NotifyInfoService); service = TestBed.inject(NotifyInfoService);
configurationDataService = TestBed.inject(ConfigurationDataService);
}); });
it('should be created', () => { it('should be created', () => {
expect(service).toBeTruthy(); expect(service).toBeTruthy();
}); });
it('should retrieve and map coar configuration', () => {
const mockResponse = { payload: { values: ['true'] } };
(configurationDataService.findByPropertyName as jasmine.Spy).and.returnValue(of(mockResponse));
service.isCoarConfigEnabled().subscribe((result) => {
expect(result).toBe(true);
});
});
it('should retrieve and map LDN local inbox URLs', () => {
const mockResponse = { values: ['inbox1', 'inbox2'] };
(configurationDataService.findByPropertyName as jasmine.Spy).and.returnValue(of(mockResponse));
service.getCoarLdnLocalInboxUrls().subscribe((result) => {
expect(result).toEqual(['inbox1', 'inbox2']);
});
});
it('should return the inbox relation link', () => {
expect(service.getInboxRelationLink()).toBe('http://www.w3.org/ns/ldp#inbox');
});
}); });

View File

@@ -19,7 +19,6 @@ import { Item } from '../shared/item.model';
import { WorkspaceItem } from './models/workspaceitem.model'; import { WorkspaceItem } from './models/workspaceitem.model';
import { RequestEntry } from '../data/request-entry.model'; import { RequestEntry } from '../data/request-entry.model';
import { CoreState } from '../core-state.model'; import { CoreState } from '../core-state.model';
import { testSearchDataImplementation } from '../data/base/search-data.spec';
import { testDeleteDataImplementation } from '../data/base/delete-data.spec'; import { testDeleteDataImplementation } from '../data/base/delete-data.spec';
describe('WorkspaceitemDataService test', () => { describe('WorkspaceitemDataService test', () => {
@@ -84,17 +83,19 @@ describe('WorkspaceitemDataService test', () => {
function initTestService() { function initTestService() {
hrefOnlyDataService = getMockHrefOnlyDataService(); hrefOnlyDataService = getMockHrefOnlyDataService();
return new WorkspaceitemDataService( return new WorkspaceitemDataService(
comparator,
halService,
http,
notificationsService,
requestService, requestService,
rdbService, rdbService,
objectCache, objectCache,
halService, store,
notificationsService,
); );
} }
describe('composition', () => { describe('composition', () => {
const initService = () => new WorkspaceitemDataService(null, null, null, null, null); const initService = () => new WorkspaceitemDataService(null, null, null, null, null, null, null, null);
testSearchDataImplementation(initService);
testDeleteDataImplementation(initService); testDeleteDataImplementation(initService);
}); });
@@ -126,7 +127,7 @@ describe('WorkspaceitemDataService test', () => {
service = initTestService(); service = initTestService();
spyOn((service as any), 'findByHref').and.callThrough(); spyOn((service as any), 'findByHref').and.callThrough();
spyOn((service as any), 'getSearchByHref').and.returnValue(searchRequestURL$); spyOn((service as any), 'getIDHref').and.callThrough();
}); });
afterEach(() => { afterEach(() => {
@@ -138,7 +139,7 @@ describe('WorkspaceitemDataService test', () => {
scheduler.schedule(() => service.findByItem('1234-1234', true, true, pageInfo)); scheduler.schedule(() => service.findByItem('1234-1234', true, true, pageInfo));
scheduler.flush(); scheduler.flush();
expect((service as any).findByHref).toHaveBeenCalledWith(searchRequestURL$, true, true); expect((service as any).findByHref).toHaveBeenCalled();
}); });
it('should return a RemoteData<WorkspaceItem> for the search', () => { it('should return a RemoteData<WorkspaceItem> for the search', () => {

View File

@@ -50,6 +50,20 @@ export class WorkspaceitemDataService extends IdentifiableDataService<WorkspaceI
public delete(objectId: string, copyVirtualMetadata?: string[]): Observable<RemoteData<NoContent>> { public delete(objectId: string, copyVirtualMetadata?: string[]): Observable<RemoteData<NoContent>> {
return this.deleteData.delete(objectId, copyVirtualMetadata); return this.deleteData.delete(objectId, copyVirtualMetadata);
} }
/**
* Delete an existing object on the server
* @param href The self link of the object to be removed
* @param copyVirtualMetadata (optional parameter) the identifiers of the relationship types for which the virtual
* metadata should be saved as real metadata
* @return A RemoteData observable with an empty payload, but still representing the state of the request: statusCode,
* errorMessage, timeCompleted, etc
* Only emits once all request related to the DSO has been invalidated.
*/
public deleteByHref(href: string, copyVirtualMetadata?: string[]): Observable<RemoteData<NoContent>> {
return this.deleteData.deleteByHref(href, copyVirtualMetadata);
}
/** /**
* Return the WorkspaceItem object found through the UUID of an item * Return the WorkspaceItem object found through the UUID of an item
* *

View File

@@ -17,16 +17,23 @@ import { TranslateLoaderMock } from '../shared/mocks/translate-loader.mock';
import { storeModuleConfig } from '../app.reducer'; import { storeModuleConfig } from '../app.reducer';
import { AuthorizationDataService } from '../core/data/feature-authorization/authorization-data.service'; import { AuthorizationDataService } from '../core/data/feature-authorization/authorization-data.service';
import { AuthorizationDataServiceStub } from '../shared/testing/authorization-service.stub'; import { AuthorizationDataServiceStub } from '../shared/testing/authorization-service.stub';
import { NotifyInfoService } from '../core/coar-notify/notify-info/notify-info.service';
import { of } from 'rxjs';
let comp: FooterComponent; let comp: FooterComponent;
let fixture: ComponentFixture<FooterComponent>; let fixture: ComponentFixture<FooterComponent>;
let de: DebugElement; let de: DebugElement;
let el: HTMLElement; let el: HTMLElement;
let notifyInfoServiceStub: any;
describe('Footer component', () => { describe('Footer component', () => {
// waitForAsync beforeEach // waitForAsync beforeEach
beforeEach(waitForAsync(() => { beforeEach(waitForAsync(() => {
notifyInfoServiceStub = {
isCoarConfigEnabled: () => of(true)
};
return TestBed.configureTestingModule({ return TestBed.configureTestingModule({
imports: [CommonModule, StoreModule.forRoot({}, storeModuleConfig), TranslateModule.forRoot({ imports: [CommonModule, StoreModule.forRoot({}, storeModuleConfig), TranslateModule.forRoot({
loader: { loader: {
@@ -38,6 +45,7 @@ describe('Footer component', () => {
providers: [ providers: [
FooterComponent, FooterComponent,
{ provide: AuthorizationDataService, useClass: AuthorizationDataServiceStub }, { provide: AuthorizationDataService, useClass: AuthorizationDataServiceStub },
{ provide: NotifyInfoService, useValue: notifyInfoServiceStub },
], ],
schemas: [CUSTOM_ELEMENTS_SCHEMA] schemas: [CUSTOM_ELEMENTS_SCHEMA]
}); });

View File

@@ -62,6 +62,7 @@ describe('FullItemPageComponent', () => {
let serverResponseService: jasmine.SpyObj<ServerResponseService>; let serverResponseService: jasmine.SpyObj<ServerResponseService>;
let signpostingDataService: jasmine.SpyObj<SignpostingDataService>; let signpostingDataService: jasmine.SpyObj<SignpostingDataService>;
let linkHeadService: jasmine.SpyObj<LinkHeadService>; let linkHeadService: jasmine.SpyObj<LinkHeadService>;
let notifyInfoService: jasmine.SpyObj<NotifyInfoService>;
const mocklink = { const mocklink = {
href: 'http://test.org', href: 'http://test.org',
@@ -106,6 +107,12 @@ describe('FullItemPageComponent', () => {
removeTag: jasmine.createSpy('removeTag'), removeTag: jasmine.createSpy('removeTag'),
}); });
notifyInfoService = jasmine.createSpyObj('NotifyInfoService', {
isCoarConfigEnabled: observableOf(true),
getCoarLdnLocalInboxUrls: observableOf(['http://test.org']),
getInboxRelationLink: observableOf('http://test.org'),
});
TestBed.configureTestingModule({ TestBed.configureTestingModule({
imports: [TranslateModule.forRoot({ imports: [TranslateModule.forRoot({
loader: { loader: {
@@ -123,7 +130,7 @@ describe('FullItemPageComponent', () => {
{ provide: ServerResponseService, useValue: serverResponseService }, { provide: ServerResponseService, useValue: serverResponseService },
{ provide: SignpostingDataService, useValue: signpostingDataService }, { provide: SignpostingDataService, useValue: signpostingDataService },
{ provide: LinkHeadService, useValue: linkHeadService }, { provide: LinkHeadService, useValue: linkHeadService },
{ provide: NotifyInfoService, useValue: {} }, { provide: NotifyInfoService, useValue: notifyInfoService },
{ provide: PLATFORM_ID, useValue: 'server' } { provide: PLATFORM_ID, useValue: 'server' }
], ],
schemas: [NO_ERRORS_SCHEMA] schemas: [NO_ERRORS_SCHEMA]
@@ -180,7 +187,7 @@ describe('FullItemPageComponent', () => {
it('should add the signposting links', () => { it('should add the signposting links', () => {
expect(serverResponseService.setHeader).toHaveBeenCalled(); expect(serverResponseService.setHeader).toHaveBeenCalled();
expect(linkHeadService.addTag).toHaveBeenCalledTimes(2); expect(linkHeadService.addTag).toHaveBeenCalledTimes(3);
}); });
}); });
describe('when the item is withdrawn and the user is not an admin', () => { describe('when the item is withdrawn and the user is not an admin', () => {
@@ -209,7 +216,7 @@ describe('FullItemPageComponent', () => {
it('should add the signposting links', () => { it('should add the signposting links', () => {
expect(serverResponseService.setHeader).toHaveBeenCalled(); expect(serverResponseService.setHeader).toHaveBeenCalled();
expect(linkHeadService.addTag).toHaveBeenCalledTimes(2); expect(linkHeadService.addTag).toHaveBeenCalledTimes(3);
}); });
}); });
@@ -226,7 +233,7 @@ describe('FullItemPageComponent', () => {
it('should add the signposting links', () => { it('should add the signposting links', () => {
expect(serverResponseService.setHeader).toHaveBeenCalled(); expect(serverResponseService.setHeader).toHaveBeenCalled();
expect(linkHeadService.addTag).toHaveBeenCalledTimes(2); expect(linkHeadService.addTag).toHaveBeenCalledTimes(3);
}); });
}); });
}); });

View File

@@ -59,7 +59,7 @@ export class FullItemPageComponent extends ItemPageComponent implements OnInit,
protected notifyInfoService: NotifyInfoService, protected notifyInfoService: NotifyInfoService,
@Inject(PLATFORM_ID) protected platformId: string, @Inject(PLATFORM_ID) protected platformId: string,
) { ) {
super(route, router, items, authService, authorizationService, responseService, signpostingDataService, linkHeadService,notifyInfoService, platformId); super(route, router, items, authService, authorizationService, responseService, signpostingDataService, linkHeadService, notifyInfoService, platformId);
} }
/*** AoT inheritance fix, will hopefully be resolved in the near future **/ /*** AoT inheritance fix, will hopefully be resolved in the near future **/

View File

@@ -75,6 +75,8 @@ describe('ItemPageComponent', () => {
data: observableOf({ dso: createSuccessfulRemoteDataObject(mockItem) }) data: observableOf({ dso: createSuccessfulRemoteDataObject(mockItem) })
}); });
const getCoarLdnLocalInboxUrls = ['http://InboxUrls.org', 'http://InboxUrls2.org'];
beforeEach(waitForAsync(() => { beforeEach(waitForAsync(() => {
authService = jasmine.createSpyObj('authService', { authService = jasmine.createSpyObj('authService', {
isAuthenticated: observableOf(true), isAuthenticated: observableOf(true),
@@ -99,7 +101,7 @@ describe('ItemPageComponent', () => {
notifyInfoService = jasmine.createSpyObj('NotifyInfoService', { notifyInfoService = jasmine.createSpyObj('NotifyInfoService', {
getInboxRelationLink: 'http://www.w3.org/ns/ldp#inbox', getInboxRelationLink: 'http://www.w3.org/ns/ldp#inbox',
isCoarConfigEnabled: observableOf(true), isCoarConfigEnabled: observableOf(true),
getCoarLdnLocalInboxUrls: observableOf(['http://test.org', 'http://test2.org']), getCoarLdnLocalInboxUrls: observableOf(getCoarLdnLocalInboxUrls),
}); });
TestBed.configureTestingModule({ TestBed.configureTestingModule({
@@ -175,7 +177,7 @@ describe('ItemPageComponent', () => {
it('should add the signposting links', () => { it('should add the signposting links', () => {
expect(serverResponseService.setHeader).toHaveBeenCalled(); expect(serverResponseService.setHeader).toHaveBeenCalled();
expect(linkHeadService.addTag).toHaveBeenCalledTimes(2); expect(linkHeadService.addTag).toHaveBeenCalledTimes(4);
}); });
@@ -184,7 +186,7 @@ describe('ItemPageComponent', () => {
expect(comp.signpostingLinks).toEqual([mocklink, mocklink2]); expect(comp.signpostingLinks).toEqual([mocklink, mocklink2]);
// Check if linkHeadService.addTag() was called with the correct arguments // Check if linkHeadService.addTag() was called with the correct arguments
expect(linkHeadService.addTag).toHaveBeenCalledTimes(mockSignpostingLinks.length); expect(linkHeadService.addTag).toHaveBeenCalledTimes(mockSignpostingLinks.length + getCoarLdnLocalInboxUrls.length);
let expected: LinkDefinition = mockSignpostingLinks[0] as LinkDefinition; let expected: LinkDefinition = mockSignpostingLinks[0] as LinkDefinition;
expect(linkHeadService.addTag).toHaveBeenCalledWith(expected); expect(linkHeadService.addTag).toHaveBeenCalledWith(expected);
expected = { expected = {
@@ -195,8 +197,7 @@ describe('ItemPageComponent', () => {
}); });
it('should set Link header on the server', () => { it('should set Link header on the server', () => {
expect(serverResponseService.setHeader).toHaveBeenCalledWith('Link', '<http://test.org> ; rel="rel1" ; type="type1" , <http://test2.org> ; rel="rel2" , <http://InboxUrls.org> ; rel="http://www.w3.org/ns/ldp#inbox", <http://InboxUrls2.org> ; rel="http://www.w3.org/ns/ldp#inbox"');
expect(serverResponseService.setHeader).toHaveBeenCalledWith('Link', '<http://test.org> ; rel="rel1" ; type="type1" , <http://test2.org> ; rel="rel2" ');
}); });
}); });
@@ -224,9 +225,9 @@ describe('ItemPageComponent', () => {
expect(objectLoader.nativeElement).toBeDefined(); expect(objectLoader.nativeElement).toBeDefined();
}); });
it('should add the signposting links', () => { it('should add the signposti`ng links`', () => {
expect(serverResponseService.setHeader).toHaveBeenCalled(); expect(serverResponseService.setHeader).toHaveBeenCalled();
expect(linkHeadService.addTag).toHaveBeenCalledTimes(2); expect(linkHeadService.addTag).toHaveBeenCalledTimes(4);
}); });
}); });
@@ -243,7 +244,7 @@ describe('ItemPageComponent', () => {
it('should add the signposting links', () => { it('should add the signposting links', () => {
expect(serverResponseService.setHeader).toHaveBeenCalled(); expect(serverResponseService.setHeader).toHaveBeenCalled();
expect(linkHeadService.addTag).toHaveBeenCalledTimes(2); expect(linkHeadService.addTag).toHaveBeenCalledTimes(4);
}); });
}); });

View File

@@ -17,7 +17,8 @@ describe('SuggestionsPopupComponent', () => {
const suggestionStateService = jasmine.createSpyObj('SuggestionTargetsStateService', { const suggestionStateService = jasmine.createSpyObj('SuggestionTargetsStateService', {
hasUserVisitedSuggestions: jasmine.createSpy('hasUserVisitedSuggestions'), hasUserVisitedSuggestions: jasmine.createSpy('hasUserVisitedSuggestions'),
getCurrentUserSuggestionTargets: jasmine.createSpy('getCurrentUserSuggestionTargets'), getCurrentUserSuggestionTargets: jasmine.createSpy('getCurrentUserSuggestionTargets'),
dispatchMarkUserSuggestionsAsVisitedAction: jasmine.createSpy('dispatchMarkUserSuggestionsAsVisitedAction') dispatchMarkUserSuggestionsAsVisitedAction: jasmine.createSpy('dispatchMarkUserSuggestionsAsVisitedAction'),
dispatchRefreshUserSuggestionsAction: jasmine.createSpy('dispatchRefreshUserSuggestionsAction')
}); });
const mockNotificationInterpolation = { count: 12, source: 'source', suggestionId: 'id', displayName: 'displayName' }; const mockNotificationInterpolation = { count: 12, source: 'source', suggestionId: 'id', displayName: 'displayName' };

View File

@@ -31,7 +31,6 @@ export class SuggestionsPopupComponent implements OnInit, OnDestroy {
} }
public initializePopup() { public initializePopup() {
console.log('POPUP INIT dispatchRefreshUserSuggestionsAction');
this.reciterSuggestionStateService.dispatchRefreshUserSuggestionsAction(); this.reciterSuggestionStateService.dispatchRefreshUserSuggestionsAction();
const notifier = new Subject(); const notifier = new Subject();
this.subscription = combineLatest([ this.subscription = combineLatest([

View File

@@ -262,6 +262,10 @@ export const environment: BuildConfig = {
undoTimeout: 10000 // 10 seconds undoTimeout: 10000 // 10 seconds
} }
}, },
suggestion: [],
themes: [ themes: [
{ {
name: 'full-item-page-theme', name: 'full-item-page-theme',