mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
108586: Fixed ItemListElementComponent not pointing to the ItemSearchResultListElementComponent from the themes folder when present
This commit is contained in:
@@ -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<ListableObjectComponentLoaderComponent>;
|
||||
|
||||
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';
|
||||
});
|
||||
|
||||
|
@@ -1 +1,5 @@
|
||||
<ds-item-search-result-list-element [showLabel]="showLabel" [object]="{ indexableObject: object, hitHighlights: {} }" [linkType]="linkType"></ds-item-search-result-list-element>
|
||||
<ds-listable-object-component-loader
|
||||
[object]="transformItemToItemSearchResult(object)"
|
||||
[viewMode]="viewMode"
|
||||
[linkType]="linkType">
|
||||
</ds-listable-object-component-loader>
|
||||
|
@@ -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<ItemListElementComponent>;
|
||||
|
||||
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],
|
||||
providers: [
|
||||
{ provide: DSONameService, useValue: new DSONameServiceMock() },
|
||||
{ provide: TruncatableService, useValue: truncatableServiceStub },
|
||||
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: 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();
|
||||
|
@@ -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<Item> {
|
||||
|
||||
transformItemToItemSearchResult(object: Item): ItemSearchResult {
|
||||
const itemSearchResult = new ItemSearchResult();
|
||||
itemSearchResult.indexableObject = object;
|
||||
return itemSearchResult;
|
||||
}
|
||||
|
||||
}
|
||||
|
21
src/app/shared/testing/truncatable-service.stub.ts
Normal file
21
src/app/shared/testing/truncatable-service.stub.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { Observable, of as observableOf } from 'rxjs';
|
||||
|
||||
export class TruncatableServiceStub {
|
||||
|
||||
isCollapsed(_id: string): Observable<boolean> {
|
||||
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 {
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user