diff --git a/src/app/admin/admin-ldn-services/ldn-service-form-edit/ldn-service-form-edit.component.spec.ts b/src/app/admin/admin-ldn-services/ldn-service-form-edit/ldn-service-form-edit.component.spec.ts index 332d43cae3..74a4fb4aba 100644 --- a/src/app/admin/admin-ldn-services/ldn-service-form-edit/ldn-service-form-edit.component.spec.ts +++ b/src/app/admin/admin-ldn-services/ldn-service-form-edit/ldn-service-form-edit.component.spec.ts @@ -1,23 +1,79 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; 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', () => { - let component: LdnServiceFormEditComponent; - let fixture: ComponentFixture; + let component: LdnServiceFormEditComponent; + let fixture: ComponentFixture; - beforeEach(async () => { - await TestBed.configureTestingModule({ - declarations: [LdnServiceFormEditComponent] - }) - .compileComponents(); + let ldnServicesService: any; + let ldnItemfiltersService: any; + let cdRefStub: any; + let modalService: any; - fixture = TestBed.createComponent(LdnServiceFormEditComponent); - component = fixture.componentInstance; - fixture.detectChanges(); + const translateServiceStub = { + get: () => of('translated-text'), + onLangChange: new EventEmitter(), + onTranslationChange: new EventEmitter(), + onDefaultLangChange: new EventEmitter() + }; + + beforeEach(async () => { + ldnServicesService = { + update: () => ({}), + }; + ldnItemfiltersService = { + findAll: () => of(['item1', 'item2']), + }; + cdRefStub = Object.assign({ + detectChanges: () => fixture.detectChanges() }); + modalService = { + open: () => {/*comment*/ + } + }; - it('should create', () => { - expect(component).toBeTruthy(); - }); + await TestBed.configureTestingModule({ + 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(); + + fixture = TestBed.createComponent(LdnServiceFormEditComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); }); diff --git a/src/app/admin/admin-ldn-services/ldn-service-form/ldn-service-form.component.spec.ts b/src/app/admin/admin-ldn-services/ldn-service-form/ldn-service-form.component.spec.ts index 757b617091..c5c9f11817 100644 --- a/src/app/admin/admin-ldn-services/ldn-service-form/ldn-service-form.component.spec.ts +++ b/src/app/admin/admin-ldn-services/ldn-service-form/ldn-service-form.component.spec.ts @@ -1,25 +1,80 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; 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', () => { - let component: LdnServiceFormComponent; - let fixture: ComponentFixture; + let component: LdnServiceFormComponent; + let fixture: ComponentFixture; - beforeEach(async () => { - await TestBed.configureTestingModule({ - declarations: [LdnServiceFormComponent] - }) - .compileComponents(); + 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 () => { + ldnItemfiltersService = jasmine.createSpyObj('ldnItemfiltersService', { + findAll: jasmine.createSpy('findAll'), }); - beforeEach(() => { - fixture = TestBed.createComponent(LdnServiceFormComponent); - component = fixture.componentInstance; - fixture.detectChanges(); + ldnServicesService = jasmine.createSpyObj('ldnServicesService', { + create: jasmine.createSpy('create'), }); - it('should create', () => { - expect(component).toBeTruthy(); + notificationsService = jasmine.createSpyObj('notificationsService', { + success: jasmine.createSpy('success'), + error: jasmine.createSpy('error'), }); + + 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] + }) + .compileComponents(); + }); + + beforeEach(() => { + fixture = TestBed.createComponent(LdnServiceFormComponent); + component = fixture.componentInstance; + ldnItemfiltersService.findAll.and.returnValue(itemFiltersRdPL$); + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); }); diff --git a/src/app/admin/admin-ldn-services/ldn-service-new/ldn-service-new.component.ts b/src/app/admin/admin-ldn-services/ldn-service-new/ldn-service-new.component.ts index e92c06dc26..d3ad155e0d 100644 --- a/src/app/admin/admin-ldn-services/ldn-service-new/ldn-service-new.component.ts +++ b/src/app/admin/admin-ldn-services/ldn-service-new/ldn-service-new.component.ts @@ -1,27 +1,9 @@ -import { Component, OnInit } 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"; +import { Component } from '@angular/core'; @Component({ selector: 'ds-ldn-service-new', templateUrl: './ldn-service-new.component.html', styleUrls: ['./ldn-service-new.component.scss'] }) -export class LdnServiceNewComponent implements OnInit { - /** - * Emits preselected process if there is one - */ - ldnService$?: Observable; - - 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() { - } +export class LdnServiceNewComponent { } diff --git a/src/app/admin/admin-ldn-services/ldn-services-directory/ldn-services-directory.component.spec.ts b/src/app/admin/admin-ldn-services/ldn-services-directory/ldn-services-directory.component.spec.ts index 0999c82c19..4efa29bce8 100644 --- a/src/app/admin/admin-ldn-services/ldn-services-directory/ldn-services-directory.component.spec.ts +++ b/src/app/admin/admin-ldn-services/ldn-services-directory/ldn-services-directory.component.spec.ts @@ -1,25 +1,54 @@ 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; -describe('ServicesDirectoryComponent', () => { - let component: ServicesDirectoryComponent; - let fixture: ComponentFixture; + const translateServiceStub = { + get: () => of('translated-text'), + onLangChange: new EventEmitter(), + onTranslationChange: new EventEmitter(), + onDefaultLangChange: new EventEmitter() + }; - beforeEach(async () => { - await TestBed.configureTestingModule({ - declarations: [ServicesDirectoryComponent] - }) - .compileComponents(); - }); + beforeEach(async () => { + await TestBed.configureTestingModule({ + 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(); + }); - beforeEach(() => { - fixture = TestBed.createComponent(ServicesDirectoryComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); + beforeEach(() => { + fixture = TestBed.createComponent(LdnServicesOverviewComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); - it('should create', () => { - expect(component).toBeTruthy(); - }); + it('should create', () => { + expect(component).toBeTruthy(); + }); }); diff --git a/src/app/admin/admin-ldn-services/ldn-services-services/ldn-directory.service.spec.ts b/src/app/admin/admin-ldn-services/ldn-services-services/ldn-directory.service.spec.ts deleted file mode 100644 index ab4f78dc6b..0000000000 --- a/src/app/admin/admin-ldn-services/ldn-services-services/ldn-directory.service.spec.ts +++ /dev/null @@ -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(); - }); -}); diff --git a/src/app/admin/admin-ldn-services/ldn-services-services/ldn-directory.service.ts b/src/app/admin/admin-ldn-services/ldn-services-services/ldn-directory.service.ts deleted file mode 100644 index 92446b4677..0000000000 --- a/src/app/admin/admin-ldn-services/ldn-services-services/ldn-directory.service.ts +++ /dev/null @@ -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 { - - return this.ldnServicesService.findAll().pipe( - map((servicesData) => { - return servicesData; - }) - ); - } - -} - - - diff --git a/src/app/admin/admin-ldn-services/ldn-services-services/ldn-service-bulk-delete.service.spec.ts b/src/app/admin/admin-ldn-services/ldn-services-services/ldn-service-bulk-delete.service.spec.ts deleted file mode 100644 index 922b63a871..0000000000 --- a/src/app/admin/admin-ldn-services/ldn-services-services/ldn-service-bulk-delete.service.spec.ts +++ /dev/null @@ -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(); - }); -}); diff --git a/src/app/core/coar-notify/notify-info/notify-info.component.spec.ts b/src/app/core/coar-notify/notify-info/notify-info.component.spec.ts index eae3a3e3d6..e14fba61c1 100644 --- a/src/app/core/coar-notify/notify-info/notify-info.component.spec.ts +++ b/src/app/core/coar-notify/notify-info/notify-info.component.spec.ts @@ -1,14 +1,23 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; import { NotifyInfoComponent } from './notify-info.component'; +import { NotifyInfoService } from './notify-info.service'; +import { TranslateModule } from '@ngx-translate/core'; describe('NotifyInfoComponent', () => { let component: NotifyInfoComponent; let fixture: ComponentFixture; + let notifyInfoServiceSpy: any; beforeEach(async () => { + notifyInfoServiceSpy = jasmine.createSpyObj('NotifyInfoService', ['getCoarLdnLocalInboxUrls']); + await TestBed.configureTestingModule({ - declarations: [ NotifyInfoComponent ] + imports: [TranslateModule.forRoot()], + declarations: [ NotifyInfoComponent ], + providers: [ + { provide: NotifyInfoService, useValue: notifyInfoServiceSpy } + ] }) .compileComponents(); }); diff --git a/src/app/core/coar-notify/notify-info/notify-info.component.ts b/src/app/core/coar-notify/notify-info/notify-info.component.ts index 2ff4b0bf2c..7de2cf538a 100644 --- a/src/app/core/coar-notify/notify-info/notify-info.component.ts +++ b/src/app/core/coar-notify/notify-info/notify-info.component.ts @@ -16,7 +16,7 @@ export class NotifyInfoComponent implements OnInit { */ coarRestApiUrl: Observable = of([]); - constructor(public notifyInfoService: NotifyInfoService) {} + constructor(private notifyInfoService: NotifyInfoService) {} ngOnInit() { this.coarRestApiUrl = this.notifyInfoService.getCoarLdnLocalInboxUrls(); diff --git a/src/app/core/coar-notify/notify-info/notify-info.guard.spec.ts b/src/app/core/coar-notify/notify-info/notify-info.guard.spec.ts index 789140ebe4..81ac0db8d8 100644 --- a/src/app/core/coar-notify/notify-info/notify-info.guard.spec.ts +++ b/src/app/core/coar-notify/notify-info/notify-info.guard.spec.ts @@ -1,16 +1,49 @@ import { TestBed } from '@angular/core/testing'; import { NotifyInfoGuard } from './notify-info.guard'; +import { Router } from '@angular/router'; +import { NotifyInfoService } from './notify-info.service'; +import { of } from 'rxjs'; describe('NotifyInfoGuard', () => { let guard: NotifyInfoGuard; + let notifyInfoServiceSpy: any; + let router: any; 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); }); it('should be created', () => { 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(); + }); + }); + }); diff --git a/src/app/core/coar-notify/notify-info/notify-info.guard.ts b/src/app/core/coar-notify/notify-info/notify-info.guard.ts index 4da9a42f21..7af0821618 100644 --- a/src/app/core/coar-notify/notify-info/notify-info.guard.ts +++ b/src/app/core/coar-notify/notify-info/notify-info.guard.ts @@ -16,7 +16,7 @@ export class NotifyInfoGuard implements CanActivate { canActivate( route: ActivatedRouteSnapshot, state: RouterStateSnapshot - ): Observable | Promise | boolean | UrlTree { + ): Observable { return this.notifyInfoService.isCoarConfigEnabled().pipe( map(coarLdnEnabled => { if (coarLdnEnabled) { diff --git a/src/app/core/coar-notify/notify-info/notify-info.service.spec.ts b/src/app/core/coar-notify/notify-info/notify-info.service.spec.ts index b32d590cd6..092dab1655 100644 --- a/src/app/core/coar-notify/notify-info/notify-info.service.spec.ts +++ b/src/app/core/coar-notify/notify-info/notify-info.service.spec.ts @@ -1,16 +1,50 @@ import { TestBed } from '@angular/core/testing'; import { NotifyInfoService } from './notify-info.service'; +import { ConfigurationDataService } from '../../data/configuration-data.service'; +import { of } from 'rxjs'; describe('NotifyInfoService', () => { let service: NotifyInfoService; + let configurationDataService: any; beforeEach(() => { - TestBed.configureTestingModule({}); + configurationDataService = { + findByPropertyName: jasmine.createSpy('findByPropertyName').and.returnValue(of({})), + }; + TestBed.configureTestingModule({ + providers: [ + NotifyInfoService, + { provide: ConfigurationDataService, useValue: configurationDataService }, + ] + }); service = TestBed.inject(NotifyInfoService); + configurationDataService = TestBed.inject(ConfigurationDataService); }); it('should be created', () => { 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'); + }); }); diff --git a/src/app/core/submission/workspaceitem-data.service.spec.ts b/src/app/core/submission/workspaceitem-data.service.spec.ts index e766a6a039..2a3a3d343d 100644 --- a/src/app/core/submission/workspaceitem-data.service.spec.ts +++ b/src/app/core/submission/workspaceitem-data.service.spec.ts @@ -19,7 +19,6 @@ import { Item } from '../shared/item.model'; import { WorkspaceItem } from './models/workspaceitem.model'; import { RequestEntry } from '../data/request-entry.model'; import { CoreState } from '../core-state.model'; -import { testSearchDataImplementation } from '../data/base/search-data.spec'; import { testDeleteDataImplementation } from '../data/base/delete-data.spec'; describe('WorkspaceitemDataService test', () => { @@ -84,17 +83,19 @@ describe('WorkspaceitemDataService test', () => { function initTestService() { hrefOnlyDataService = getMockHrefOnlyDataService(); return new WorkspaceitemDataService( + comparator, + halService, + http, + notificationsService, requestService, rdbService, objectCache, - halService, - notificationsService, + store, ); } describe('composition', () => { - const initService = () => new WorkspaceitemDataService(null, null, null, null, null); - testSearchDataImplementation(initService); + const initService = () => new WorkspaceitemDataService(null, null, null, null, null, null, null, null); testDeleteDataImplementation(initService); }); @@ -126,7 +127,7 @@ describe('WorkspaceitemDataService test', () => { service = initTestService(); spyOn((service as any), 'findByHref').and.callThrough(); - spyOn((service as any), 'getSearchByHref').and.returnValue(searchRequestURL$); + spyOn((service as any), 'getIDHref').and.callThrough(); }); afterEach(() => { @@ -138,7 +139,7 @@ describe('WorkspaceitemDataService test', () => { scheduler.schedule(() => service.findByItem('1234-1234', true, true, pageInfo)); scheduler.flush(); - expect((service as any).findByHref).toHaveBeenCalledWith(searchRequestURL$, true, true); + expect((service as any).findByHref).toHaveBeenCalled(); }); it('should return a RemoteData for the search', () => { diff --git a/src/app/core/submission/workspaceitem-data.service.ts b/src/app/core/submission/workspaceitem-data.service.ts index 8a036f6443..f430dd43ea 100644 --- a/src/app/core/submission/workspaceitem-data.service.ts +++ b/src/app/core/submission/workspaceitem-data.service.ts @@ -50,6 +50,20 @@ export class WorkspaceitemDataService extends IdentifiableDataService> { 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> { + return this.deleteData.deleteByHref(href, copyVirtualMetadata); + } + /** * Return the WorkspaceItem object found through the UUID of an item * diff --git a/src/app/footer/footer.component.spec.ts b/src/app/footer/footer.component.spec.ts index 9f0250edc4..0d6069ece8 100644 --- a/src/app/footer/footer.component.spec.ts +++ b/src/app/footer/footer.component.spec.ts @@ -17,16 +17,23 @@ import { TranslateLoaderMock } from '../shared/mocks/translate-loader.mock'; import { storeModuleConfig } from '../app.reducer'; import { AuthorizationDataService } from '../core/data/feature-authorization/authorization-data.service'; 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 fixture: ComponentFixture; let de: DebugElement; let el: HTMLElement; +let notifyInfoServiceStub: any; + describe('Footer component', () => { // waitForAsync beforeEach beforeEach(waitForAsync(() => { + notifyInfoServiceStub = { + isCoarConfigEnabled: () => of(true) + }; return TestBed.configureTestingModule({ imports: [CommonModule, StoreModule.forRoot({}, storeModuleConfig), TranslateModule.forRoot({ loader: { @@ -38,6 +45,7 @@ describe('Footer component', () => { providers: [ FooterComponent, { provide: AuthorizationDataService, useClass: AuthorizationDataServiceStub }, + { provide: NotifyInfoService, useValue: notifyInfoServiceStub }, ], schemas: [CUSTOM_ELEMENTS_SCHEMA] }); diff --git a/src/app/item-page/full/full-item-page.component.spec.ts b/src/app/item-page/full/full-item-page.component.spec.ts index c1917f77f4..c09c3177e3 100644 --- a/src/app/item-page/full/full-item-page.component.spec.ts +++ b/src/app/item-page/full/full-item-page.component.spec.ts @@ -62,6 +62,7 @@ describe('FullItemPageComponent', () => { let serverResponseService: jasmine.SpyObj; let signpostingDataService: jasmine.SpyObj; let linkHeadService: jasmine.SpyObj; + let notifyInfoService: jasmine.SpyObj; const mocklink = { href: 'http://test.org', @@ -106,6 +107,12 @@ describe('FullItemPageComponent', () => { removeTag: jasmine.createSpy('removeTag'), }); + notifyInfoService = jasmine.createSpyObj('NotifyInfoService', { + isCoarConfigEnabled: observableOf(true), + getCoarLdnLocalInboxUrls: observableOf(['http://test.org']), + getInboxRelationLink: observableOf('http://test.org'), + }); + TestBed.configureTestingModule({ imports: [TranslateModule.forRoot({ loader: { @@ -123,7 +130,7 @@ describe('FullItemPageComponent', () => { { provide: ServerResponseService, useValue: serverResponseService }, { provide: SignpostingDataService, useValue: signpostingDataService }, { provide: LinkHeadService, useValue: linkHeadService }, - { provide: NotifyInfoService, useValue: {} }, + { provide: NotifyInfoService, useValue: notifyInfoService }, { provide: PLATFORM_ID, useValue: 'server' } ], schemas: [NO_ERRORS_SCHEMA] @@ -180,7 +187,7 @@ describe('FullItemPageComponent', () => { it('should add the signposting links', () => { 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', () => { @@ -209,7 +216,7 @@ describe('FullItemPageComponent', () => { it('should add the signposting links', () => { 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', () => { expect(serverResponseService.setHeader).toHaveBeenCalled(); - expect(linkHeadService.addTag).toHaveBeenCalledTimes(2); + expect(linkHeadService.addTag).toHaveBeenCalledTimes(3); }); }); }); diff --git a/src/app/item-page/full/full-item-page.component.ts b/src/app/item-page/full/full-item-page.component.ts index da79fc04cc..09238c30ab 100644 --- a/src/app/item-page/full/full-item-page.component.ts +++ b/src/app/item-page/full/full-item-page.component.ts @@ -59,7 +59,7 @@ export class FullItemPageComponent extends ItemPageComponent implements OnInit, protected notifyInfoService: NotifyInfoService, @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 **/ diff --git a/src/app/item-page/simple/item-page.component.spec.ts b/src/app/item-page/simple/item-page.component.spec.ts index b8354496da..433b950cee 100644 --- a/src/app/item-page/simple/item-page.component.spec.ts +++ b/src/app/item-page/simple/item-page.component.spec.ts @@ -75,6 +75,8 @@ describe('ItemPageComponent', () => { data: observableOf({ dso: createSuccessfulRemoteDataObject(mockItem) }) }); + const getCoarLdnLocalInboxUrls = ['http://InboxUrls.org', 'http://InboxUrls2.org']; + beforeEach(waitForAsync(() => { authService = jasmine.createSpyObj('authService', { isAuthenticated: observableOf(true), @@ -99,7 +101,7 @@ describe('ItemPageComponent', () => { notifyInfoService = jasmine.createSpyObj('NotifyInfoService', { getInboxRelationLink: 'http://www.w3.org/ns/ldp#inbox', isCoarConfigEnabled: observableOf(true), - getCoarLdnLocalInboxUrls: observableOf(['http://test.org', 'http://test2.org']), + getCoarLdnLocalInboxUrls: observableOf(getCoarLdnLocalInboxUrls), }); TestBed.configureTestingModule({ @@ -175,7 +177,7 @@ describe('ItemPageComponent', () => { it('should add the signposting links', () => { 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]); // 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; expect(linkHeadService.addTag).toHaveBeenCalledWith(expected); expected = { @@ -195,8 +197,7 @@ describe('ItemPageComponent', () => { }); it('should set Link header on the server', () => { - - expect(serverResponseService.setHeader).toHaveBeenCalledWith('Link', ' ; rel="rel1" ; type="type1" , ; rel="rel2" '); + expect(serverResponseService.setHeader).toHaveBeenCalledWith('Link', ' ; rel="rel1" ; type="type1" , ; rel="rel2" , ; rel="http://www.w3.org/ns/ldp#inbox", ; rel="http://www.w3.org/ns/ldp#inbox"'); }); }); @@ -224,9 +225,9 @@ describe('ItemPageComponent', () => { expect(objectLoader.nativeElement).toBeDefined(); }); - it('should add the signposting links', () => { + it('should add the signposti`ng links`', () => { 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', () => { expect(serverResponseService.setHeader).toHaveBeenCalled(); - expect(linkHeadService.addTag).toHaveBeenCalledTimes(2); + expect(linkHeadService.addTag).toHaveBeenCalledTimes(4); }); }); diff --git a/src/app/suggestion-notifications/reciter-suggestions/suggestions-popup/suggestions-popup.component.spec.ts b/src/app/suggestion-notifications/reciter-suggestions/suggestions-popup/suggestions-popup.component.spec.ts index 67678354ca..242698b234 100644 --- a/src/app/suggestion-notifications/reciter-suggestions/suggestions-popup/suggestions-popup.component.spec.ts +++ b/src/app/suggestion-notifications/reciter-suggestions/suggestions-popup/suggestions-popup.component.spec.ts @@ -17,7 +17,8 @@ describe('SuggestionsPopupComponent', () => { const suggestionStateService = jasmine.createSpyObj('SuggestionTargetsStateService', { hasUserVisitedSuggestions: jasmine.createSpy('hasUserVisitedSuggestions'), 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' }; diff --git a/src/app/suggestion-notifications/reciter-suggestions/suggestions-popup/suggestions-popup.component.ts b/src/app/suggestion-notifications/reciter-suggestions/suggestions-popup/suggestions-popup.component.ts index c0f94cadce..e6a98fbcd5 100644 --- a/src/app/suggestion-notifications/reciter-suggestions/suggestions-popup/suggestions-popup.component.ts +++ b/src/app/suggestion-notifications/reciter-suggestions/suggestions-popup/suggestions-popup.component.ts @@ -31,7 +31,6 @@ export class SuggestionsPopupComponent implements OnInit, OnDestroy { } public initializePopup() { - console.log('POPUP INIT dispatchRefreshUserSuggestionsAction'); this.reciterSuggestionStateService.dispatchRefreshUserSuggestionsAction(); const notifier = new Subject(); this.subscription = combineLatest([ diff --git a/src/environments/environment.test.ts b/src/environments/environment.test.ts index cb9d2c7130..806a45fbd5 100644 --- a/src/environments/environment.test.ts +++ b/src/environments/environment.test.ts @@ -262,6 +262,10 @@ export const environment: BuildConfig = { undoTimeout: 10000 // 10 seconds } }, + + + suggestion: [], + themes: [ { name: 'full-item-page-theme',