diff --git a/src/app/shared/object-collection/shared/listable-object/listable-object-component-loader.component.spec.ts b/src/app/shared/object-collection/shared/listable-object/listable-object-component-loader.component.spec.ts index e893fe807b7..e3d2ad64b12 100644 --- a/src/app/shared/object-collection/shared/listable-object/listable-object-component-loader.component.spec.ts +++ b/src/app/shared/object-collection/shared/listable-object/listable-object-component-loader.component.spec.ts @@ -1,18 +1,31 @@ import { ComponentFixture, fakeAsync, TestBed, tick, waitForAsync } from '@angular/core/testing'; -import { ChangeDetectionStrategy, NO_ERRORS_SCHEMA } from '@angular/core'; import { ListableObjectComponentLoaderComponent } from './listable-object-component-loader.component'; import { ListableObject } from '../listable-object.model'; import { GenericConstructor } from '../../../../core/shared/generic-constructor'; import { Context } from '../../../../core/shared/context.model'; import { ViewMode } from '../../../../core/shared/view-mode.model'; -import { - ItemListElementComponent -} from '../../../object-list/item-list-element/item-types/item/item-list-element.component'; import { ListableObjectDirective } from './listable-object.directive'; import { TranslateModule } from '@ngx-translate/core'; import { By } from '@angular/platform-browser'; -import { provideMockStore } from '@ngrx/store/testing'; import { ThemeService } from '../../../theme-support/theme.service'; +import { ItemSearchResultListElementComponent } from '../../../object-list/search-result-list-element/item-search-result/item-types/item/item-search-result-list-element.component'; +import { ActivatedRouteStub } from '../../../testing/active-router.stub'; +import { AuthServiceStub } from '../../../testing/auth-service.stub'; +import { AuthorizationDataServiceStub } from '../../../testing/authorization-service.stub'; +import { FileServiceStub } from '../../../testing/file-service.stub'; +import { TruncatableServiceStub } from '../../../testing/truncatable-service.stub'; +import { getMockThemeService } from '../../../mocks/theme-service.mock'; +import { APP_CONFIG } from '../../../../../config/app-config.interface'; +import { environment } from '../../../../../environments/environment.test'; +import { ActivatedRoute } from '@angular/router'; +import { AuthService } from '../../../../core/auth/auth.service'; +import { AuthorizationDataService } from '../../../../core/data/feature-authorization/authorization-data.service'; +import { DSONameService } from '../../../../core/breadcrumbs/dso-name.service'; +import { DSONameServiceMock } from '../../../mocks/dso-name.service.mock'; +import { FileService } from '../../../../core/shared/file.service'; +import { TruncatableService } from '../../../truncatable/truncatable.service'; +import { ChangeDetectionStrategy } from '@angular/core'; +import { SearchResultListElementComponent } from '../../../object-list/search-result-list-element/search-result-list-element.component'; const testType = 'TestType'; const testContext = Context.Search; @@ -28,24 +41,41 @@ describe('ListableObjectComponentLoaderComponent', () => { let comp: ListableObjectComponentLoaderComponent; let fixture: ComponentFixture; + let activatedRoute: ActivatedRouteStub; + let authService: AuthServiceStub; + let authorizationService: AuthorizationDataServiceStub; + let fileService: FileServiceStub; let themeService: ThemeService; + let truncatableService: TruncatableServiceStub; beforeEach(waitForAsync(() => { - themeService = jasmine.createSpyObj('themeService', { - getThemeName: 'dspace', - }); - TestBed.configureTestingModule({ + activatedRoute = new ActivatedRouteStub(); + authService = new AuthServiceStub(); + authorizationService = new AuthorizationDataServiceStub(); + fileService = new FileServiceStub(); + themeService = getMockThemeService(); + truncatableService = new TruncatableServiceStub(); + + void TestBed.configureTestingModule({ imports: [TranslateModule.forRoot()], - declarations: [ListableObjectComponentLoaderComponent, ItemListElementComponent, ListableObjectDirective], - schemas: [NO_ERRORS_SCHEMA], + declarations: [ + ItemSearchResultListElementComponent, + ListableObjectComponentLoaderComponent, + ListableObjectDirective, + ], providers: [ - provideMockStore({}), + { provide: APP_CONFIG, useValue: environment }, + { provide: ActivatedRoute, useValue: activatedRoute }, + { provide: AuthService, useValue: authService }, + { provide: AuthorizationDataService, useValue: authorizationService }, + { provide: DSONameService, useValue: new DSONameServiceMock() }, + { provide: FileService, useValue: fileService }, { provide: ThemeService, useValue: themeService }, + { provide: TruncatableService, useValue: truncatableService }, ] }).overrideComponent(ListableObjectComponentLoaderComponent, { set: { changeDetection: ChangeDetectionStrategy.Default, - entryComponents: [ItemListElementComponent] } }).compileComponents(); })); @@ -57,7 +87,7 @@ describe('ListableObjectComponentLoaderComponent', () => { comp.object = new TestType(); comp.viewMode = testViewMode; comp.context = testContext; - spyOn(comp, 'getComponent').and.returnValue(ItemListElementComponent as any); + spyOn(comp, 'getComponent').and.returnValue(SearchResultListElementComponent as any); spyOn(comp as any, 'connectInputsAndOutputs').and.callThrough(); fixture.detectChanges(); @@ -81,7 +111,7 @@ describe('ListableObjectComponentLoaderComponent', () => { spyOn((comp as any), 'instantiateComponent').and.returnValue(null); spyOn((comp as any).contentChange, 'emit').and.returnValue(null); - listableComponent = fixture.debugElement.query(By.css('ds-item-list-element')).componentInstance; + listableComponent = fixture.debugElement.query(By.css('ds-search-result-list-element')).componentInstance; reloadedObject = 'object'; }); diff --git a/src/app/shared/object-list/item-list-element/item-types/item/item-list-element.component.html b/src/app/shared/object-list/item-list-element/item-types/item/item-list-element.component.html index 3877e2f335b..7f8dde1c4ec 100644 --- a/src/app/shared/object-list/item-list-element/item-types/item/item-list-element.component.html +++ b/src/app/shared/object-list/item-list-element/item-types/item/item-list-element.component.html @@ -1 +1,5 @@ - + + diff --git a/src/app/shared/object-list/item-list-element/item-types/item/item-list-element.component.spec.ts b/src/app/shared/object-list/item-list-element/item-types/item/item-list-element.component.spec.ts index d75576e8ebc..46dba497f5e 100644 --- a/src/app/shared/object-list/item-list-element/item-types/item/item-list-element.component.spec.ts +++ b/src/app/shared/object-list/item-list-element/item-types/item/item-list-element.component.spec.ts @@ -1,13 +1,26 @@ -import { TestBed, waitForAsync } from '@angular/core/testing'; -import { ChangeDetectionStrategy, NO_ERRORS_SCHEMA } from '@angular/core'; +import { TestBed, waitForAsync, ComponentFixture } from '@angular/core/testing'; +import { ChangeDetectionStrategy } from '@angular/core'; import { By } from '@angular/platform-browser'; import { ItemListElementComponent } from './item-list-element.component'; import { Item } from '../../../../../core/shared/item.model'; -import { TruncatePipe } from '../../../../utils/truncate.pipe'; import { TruncatableService } from '../../../../truncatable/truncatable.service'; import { of as observableOf } from 'rxjs'; -import { DSONameService } from '../../../../../core/breadcrumbs/dso-name.service'; -import { DSONameServiceMock } from '../../../../mocks/dso-name.service.mock'; +import { ListableObjectComponentLoaderComponent } from '../../../../object-collection/shared/listable-object/listable-object-component-loader.component'; +import { getMockThemeService } from '../../../../mocks/theme-service.mock'; +import { ThemeService } from '../../../../theme-support/theme.service'; +import { ListableObjectDirective } from '../../../../object-collection/shared/listable-object/listable-object.directive'; +import { APP_CONFIG } from '../../../../../../config/app-config.interface'; +import { environment } from '../../../../../../environments/environment.test'; +import { TranslateModule } from '@ngx-translate/core'; +import { ActivatedRouteStub } from '../../../../testing/active-router.stub'; +import { ActivatedRoute } from '@angular/router'; +import { AuthService } from '../../../../../core/auth/auth.service'; +import { AuthServiceStub } from '../../../../testing/auth-service.stub'; +import { AuthorizationDataService } from '../../../../../core/data/feature-authorization/authorization-data.service'; +import { AuthorizationDataServiceStub } from '../../../../testing/authorization-service.stub'; +import { FileService } from '../../../../../core/shared/file.service'; +import { FileServiceStub } from '../../../../testing/file-service.stub'; +import { TruncatableServiceStub } from '../../../../testing/truncatable-service.stub'; const mockItem: Item = Object.assign(new Item(), { bundles: observableOf({}), @@ -46,21 +59,42 @@ const mockItem: Item = Object.assign(new Item(), { }); describe('ItemListElementComponent', () => { - let comp; - let fixture; + let comp: ItemListElementComponent; + let fixture: ComponentFixture; - const truncatableServiceStub: any = { - isCollapsed: (id: number) => observableOf(true), - }; + let activatedRoute: ActivatedRouteStub; + let authService: AuthServiceStub; + let authorizationService: AuthorizationDataServiceStub; + let fileService: FileServiceStub; + let themeService: ThemeService; + let truncatableService: TruncatableServiceStub; beforeEach(waitForAsync(() => { - TestBed.configureTestingModule({ - declarations: [ItemListElementComponent, TruncatePipe], + activatedRoute = new ActivatedRouteStub(); + authService = new AuthServiceStub(); + authorizationService = new AuthorizationDataServiceStub(); + fileService = new FileServiceStub(); + themeService = getMockThemeService(); + truncatableService = new TruncatableServiceStub(); + + void TestBed.configureTestingModule({ + imports: [ + TranslateModule.forRoot(), + ], + declarations: [ + ItemListElementComponent, + ListableObjectComponentLoaderComponent, + ListableObjectDirective, + ], providers: [ - { provide: DSONameService, useValue: new DSONameServiceMock() }, - { provide: TruncatableService, useValue: truncatableServiceStub }, + { provide: APP_CONFIG, useValue: environment }, + { provide: ActivatedRoute, useValue: activatedRoute }, + { provide: AuthService, useValue: authService }, + { provide: AuthorizationDataService, useValue: authorizationService }, + { provide: FileService, useValue: fileService }, + { provide: ThemeService, useValue: themeService }, + { provide: TruncatableService, useValue: truncatableService }, ], - schemas: [NO_ERRORS_SCHEMA] }).overrideComponent(ItemListElementComponent, { set: { changeDetection: ChangeDetectionStrategy.Default } }).compileComponents(); diff --git a/src/app/shared/object-list/item-list-element/item-types/item/item-list-element.component.ts b/src/app/shared/object-list/item-list-element/item-types/item/item-list-element.component.ts index a3bd2a1ce00..8682a5a024b 100644 --- a/src/app/shared/object-list/item-list-element/item-types/item/item-list-element.component.ts +++ b/src/app/shared/object-list/item-list-element/item-types/item/item-list-element.component.ts @@ -3,6 +3,7 @@ import { ViewMode } from '../../../../../core/shared/view-mode.model'; import { listableObjectComponent } from '../../../../object-collection/shared/listable-object/listable-object.decorator'; import { AbstractListableElementComponent } from '../../../../object-collection/shared/object-collection-element/abstract-listable-element.component'; import { Item } from '../../../../../core/shared/item.model'; +import { ItemSearchResult } from '../../../../object-collection/shared/item-search-result.model'; @listableObjectComponent('Publication', ViewMode.ListElement) @listableObjectComponent(Item, ViewMode.ListElement) @@ -15,4 +16,11 @@ import { Item } from '../../../../../core/shared/item.model'; * The component for displaying a list element for an item of the type Publication */ export class ItemListElementComponent extends AbstractListableElementComponent { + + transformItemToItemSearchResult(object: Item): ItemSearchResult { + const itemSearchResult = new ItemSearchResult(); + itemSearchResult.indexableObject = object; + return itemSearchResult; + } + } diff --git a/src/app/shared/testing/truncatable-service.stub.ts b/src/app/shared/testing/truncatable-service.stub.ts new file mode 100644 index 00000000000..080cd98469a --- /dev/null +++ b/src/app/shared/testing/truncatable-service.stub.ts @@ -0,0 +1,21 @@ +import { Observable, of as observableOf } from 'rxjs'; + +export class TruncatableServiceStub { + + isCollapsed(_id: string): Observable { + return observableOf(false); + } + + // eslint-disable-next-line no-empty, @typescript-eslint/no-empty-function + public toggle(_id: string): void { + } + + // eslint-disable-next-line no-empty, @typescript-eslint/no-empty-function + public collapse(_id: string): void { + } + + // eslint-disable-next-line no-empty, @typescript-eslint/no-empty-function + public expand(_id: string): void { + } + +}