Skip to content

Commit d00fc5d

Browse files
108586: Fixed ItemListElementComponent not pointing to the ItemSearchResultListElementComponent from the themes folder when present
1 parent 7529ed8 commit d00fc5d

File tree

5 files changed

+128
-31
lines changed

5 files changed

+128
-31
lines changed

src/app/shared/object-collection/shared/listable-object/listable-object-component-loader.component.spec.ts

Lines changed: 45 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,31 @@
11
import { ComponentFixture, fakeAsync, TestBed, tick, waitForAsync } from '@angular/core/testing';
2-
import { ChangeDetectionStrategy, NO_ERRORS_SCHEMA } from '@angular/core';
32
import { ListableObjectComponentLoaderComponent } from './listable-object-component-loader.component';
43
import { ListableObject } from '../listable-object.model';
54
import { GenericConstructor } from '../../../../core/shared/generic-constructor';
65
import { Context } from '../../../../core/shared/context.model';
76
import { ViewMode } from '../../../../core/shared/view-mode.model';
8-
import {
9-
ItemListElementComponent
10-
} from '../../../object-list/item-list-element/item-types/item/item-list-element.component';
117
import { ListableObjectDirective } from './listable-object.directive';
128
import { TranslateModule } from '@ngx-translate/core';
139
import { By } from '@angular/platform-browser';
14-
import { provideMockStore } from '@ngrx/store/testing';
1510
import { ThemeService } from '../../../theme-support/theme.service';
11+
import { ItemSearchResultListElementComponent } from '../../../object-list/search-result-list-element/item-search-result/item-types/item/item-search-result-list-element.component';
12+
import { ActivatedRouteStub } from '../../../testing/active-router.stub';
13+
import { AuthServiceStub } from '../../../testing/auth-service.stub';
14+
import { AuthorizationDataServiceStub } from '../../../testing/authorization-service.stub';
15+
import { FileServiceStub } from '../../../testing/file-service.stub';
16+
import { TruncatableServiceStub } from '../../../testing/truncatable-service.stub';
17+
import { getMockThemeService } from '../../../mocks/theme-service.mock';
18+
import { APP_CONFIG } from '../../../../../config/app-config.interface';
19+
import { environment } from '../../../../../environments/environment.test';
20+
import { ActivatedRoute } from '@angular/router';
21+
import { AuthService } from '../../../../core/auth/auth.service';
22+
import { AuthorizationDataService } from '../../../../core/data/feature-authorization/authorization-data.service';
23+
import { DSONameService } from '../../../../core/breadcrumbs/dso-name.service';
24+
import { DSONameServiceMock } from '../../../mocks/dso-name.service.mock';
25+
import { FileService } from '../../../../core/shared/file.service';
26+
import { TruncatableService } from '../../../truncatable/truncatable.service';
27+
import { ChangeDetectionStrategy } from '@angular/core';
28+
import { SearchResultListElementComponent } from '../../../object-list/search-result-list-element/search-result-list-element.component';
1629

1730
const testType = 'TestType';
1831
const testContext = Context.Search;
@@ -28,24 +41,41 @@ describe('ListableObjectComponentLoaderComponent', () => {
2841
let comp: ListableObjectComponentLoaderComponent;
2942
let fixture: ComponentFixture<ListableObjectComponentLoaderComponent>;
3043

44+
let activatedRoute: ActivatedRouteStub;
45+
let authService: AuthServiceStub;
46+
let authorizationService: AuthorizationDataServiceStub;
47+
let fileService: FileServiceStub;
3148
let themeService: ThemeService;
49+
let truncatableService: TruncatableServiceStub;
3250

3351
beforeEach(waitForAsync(() => {
34-
themeService = jasmine.createSpyObj('themeService', {
35-
getThemeName: 'dspace',
36-
});
37-
TestBed.configureTestingModule({
52+
activatedRoute = new ActivatedRouteStub();
53+
authService = new AuthServiceStub();
54+
authorizationService = new AuthorizationDataServiceStub();
55+
fileService = new FileServiceStub();
56+
themeService = getMockThemeService();
57+
truncatableService = new TruncatableServiceStub();
58+
59+
void TestBed.configureTestingModule({
3860
imports: [TranslateModule.forRoot()],
39-
declarations: [ListableObjectComponentLoaderComponent, ItemListElementComponent, ListableObjectDirective],
40-
schemas: [NO_ERRORS_SCHEMA],
61+
declarations: [
62+
ItemSearchResultListElementComponent,
63+
ListableObjectComponentLoaderComponent,
64+
ListableObjectDirective,
65+
],
4166
providers: [
42-
provideMockStore({}),
67+
{ provide: APP_CONFIG, useValue: environment },
68+
{ provide: ActivatedRoute, useValue: activatedRoute },
69+
{ provide: AuthService, useValue: authService },
70+
{ provide: AuthorizationDataService, useValue: authorizationService },
71+
{ provide: DSONameService, useValue: new DSONameServiceMock() },
72+
{ provide: FileService, useValue: fileService },
4373
{ provide: ThemeService, useValue: themeService },
74+
{ provide: TruncatableService, useValue: truncatableService },
4475
]
4576
}).overrideComponent(ListableObjectComponentLoaderComponent, {
4677
set: {
4778
changeDetection: ChangeDetectionStrategy.Default,
48-
entryComponents: [ItemListElementComponent]
4979
}
5080
}).compileComponents();
5181
}));
@@ -57,7 +87,7 @@ describe('ListableObjectComponentLoaderComponent', () => {
5787
comp.object = new TestType();
5888
comp.viewMode = testViewMode;
5989
comp.context = testContext;
60-
spyOn(comp, 'getComponent').and.returnValue(ItemListElementComponent as any);
90+
spyOn(comp, 'getComponent').and.returnValue(SearchResultListElementComponent as any);
6191
spyOn(comp as any, 'connectInputsAndOutputs').and.callThrough();
6292
fixture.detectChanges();
6393

@@ -81,7 +111,7 @@ describe('ListableObjectComponentLoaderComponent', () => {
81111
spyOn((comp as any), 'instantiateComponent').and.returnValue(null);
82112
spyOn((comp as any).contentChange, 'emit').and.returnValue(null);
83113

84-
listableComponent = fixture.debugElement.query(By.css('ds-item-list-element')).componentInstance;
114+
listableComponent = fixture.debugElement.query(By.css('ds-search-result-list-element')).componentInstance;
85115
reloadedObject = 'object';
86116
});
87117

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
<ds-item-search-result-list-element [showLabel]="showLabel" [object]="{ indexableObject: object, hitHighlights: {} }" [linkType]="linkType"></ds-item-search-result-list-element>
1+
<ds-listable-object-component-loader
2+
[object]="transformItemToItemSearchResult(object)"
3+
[viewMode]="viewMode"
4+
[linkType]="linkType">
5+
</ds-listable-object-component-loader>

src/app/shared/object-list/item-list-element/item-types/item/item-list-element.component.spec.ts

Lines changed: 49 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,26 @@
1-
import { TestBed, waitForAsync } from '@angular/core/testing';
2-
import { ChangeDetectionStrategy, NO_ERRORS_SCHEMA } from '@angular/core';
1+
import { TestBed, waitForAsync, ComponentFixture } from '@angular/core/testing';
2+
import { ChangeDetectionStrategy } from '@angular/core';
33
import { By } from '@angular/platform-browser';
44
import { ItemListElementComponent } from './item-list-element.component';
55
import { Item } from '../../../../../core/shared/item.model';
6-
import { TruncatePipe } from '../../../../utils/truncate.pipe';
76
import { TruncatableService } from '../../../../truncatable/truncatable.service';
87
import { of as observableOf } from 'rxjs';
9-
import { DSONameService } from '../../../../../core/breadcrumbs/dso-name.service';
10-
import { DSONameServiceMock } from '../../../../mocks/dso-name.service.mock';
8+
import { ListableObjectComponentLoaderComponent } from '../../../../object-collection/shared/listable-object/listable-object-component-loader.component';
9+
import { getMockThemeService } from '../../../../mocks/theme-service.mock';
10+
import { ThemeService } from '../../../../theme-support/theme.service';
11+
import { ListableObjectDirective } from '../../../../object-collection/shared/listable-object/listable-object.directive';
12+
import { APP_CONFIG } from '../../../../../../config/app-config.interface';
13+
import { environment } from '../../../../../../environments/environment.test';
14+
import { TranslateModule } from '@ngx-translate/core';
15+
import { ActivatedRouteStub } from '../../../../testing/active-router.stub';
16+
import { ActivatedRoute } from '@angular/router';
17+
import { AuthService } from '../../../../../core/auth/auth.service';
18+
import { AuthServiceStub } from '../../../../testing/auth-service.stub';
19+
import { AuthorizationDataService } from '../../../../../core/data/feature-authorization/authorization-data.service';
20+
import { AuthorizationDataServiceStub } from '../../../../testing/authorization-service.stub';
21+
import { FileService } from '../../../../../core/shared/file.service';
22+
import { FileServiceStub } from '../../../../testing/file-service.stub';
23+
import { TruncatableServiceStub } from '../../../../testing/truncatable-service.stub';
1124

1225
const mockItem: Item = Object.assign(new Item(), {
1326
bundles: observableOf({}),
@@ -46,21 +59,42 @@ const mockItem: Item = Object.assign(new Item(), {
4659
});
4760

4861
describe('ItemListElementComponent', () => {
49-
let comp;
50-
let fixture;
62+
let comp: ItemListElementComponent;
63+
let fixture: ComponentFixture<ItemListElementComponent>;
5164

52-
const truncatableServiceStub: any = {
53-
isCollapsed: (id: number) => observableOf(true),
54-
};
65+
let activatedRoute: ActivatedRouteStub;
66+
let authService: AuthServiceStub;
67+
let authorizationService: AuthorizationDataServiceStub;
68+
let fileService: FileServiceStub;
69+
let themeService: ThemeService;
70+
let truncatableService: TruncatableServiceStub;
5571

5672
beforeEach(waitForAsync(() => {
57-
TestBed.configureTestingModule({
58-
declarations: [ItemListElementComponent, TruncatePipe],
73+
activatedRoute = new ActivatedRouteStub();
74+
authService = new AuthServiceStub();
75+
authorizationService = new AuthorizationDataServiceStub();
76+
fileService = new FileServiceStub();
77+
themeService = getMockThemeService();
78+
truncatableService = new TruncatableServiceStub();
79+
80+
void TestBed.configureTestingModule({
81+
imports: [
82+
TranslateModule.forRoot(),
83+
],
84+
declarations: [
85+
ItemListElementComponent,
86+
ListableObjectComponentLoaderComponent,
87+
ListableObjectDirective,
88+
],
5989
providers: [
60-
{ provide: DSONameService, useValue: new DSONameServiceMock() },
61-
{ provide: TruncatableService, useValue: truncatableServiceStub },
90+
{ provide: APP_CONFIG, useValue: environment },
91+
{ provide: ActivatedRoute, useValue: activatedRoute },
92+
{ provide: AuthService, useValue: authService },
93+
{ provide: AuthorizationDataService, useValue: authorizationService },
94+
{ provide: FileService, useValue: fileService },
95+
{ provide: ThemeService, useValue: themeService },
96+
{ provide: TruncatableService, useValue: truncatableService },
6297
],
63-
schemas: [NO_ERRORS_SCHEMA]
6498
}).overrideComponent(ItemListElementComponent, {
6599
set: { changeDetection: ChangeDetectionStrategy.Default }
66100
}).compileComponents();

src/app/shared/object-list/item-list-element/item-types/item/item-list-element.component.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { ViewMode } from '../../../../../core/shared/view-mode.model';
33
import { listableObjectComponent } from '../../../../object-collection/shared/listable-object/listable-object.decorator';
44
import { AbstractListableElementComponent } from '../../../../object-collection/shared/object-collection-element/abstract-listable-element.component';
55
import { Item } from '../../../../../core/shared/item.model';
6+
import { ItemSearchResult } from '../../../../object-collection/shared/item-search-result.model';
67

78
@listableObjectComponent('Publication', ViewMode.ListElement)
89
@listableObjectComponent(Item, ViewMode.ListElement)
@@ -15,4 +16,11 @@ import { Item } from '../../../../../core/shared/item.model';
1516
* The component for displaying a list element for an item of the type Publication
1617
*/
1718
export class ItemListElementComponent extends AbstractListableElementComponent<Item> {
19+
20+
transformItemToItemSearchResult(object: Item): ItemSearchResult {
21+
const itemSearchResult = new ItemSearchResult();
22+
itemSearchResult.indexableObject = object;
23+
return itemSearchResult;
24+
}
25+
1826
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { Observable, of as observableOf } from 'rxjs';
2+
3+
export class TruncatableServiceStub {
4+
5+
isCollapsed(_id: string): Observable<boolean> {
6+
return observableOf(false);
7+
}
8+
9+
// eslint-disable-next-line no-empty, @typescript-eslint/no-empty-function
10+
public toggle(_id: string): void {
11+
}
12+
13+
// eslint-disable-next-line no-empty, @typescript-eslint/no-empty-function
14+
public collapse(_id: string): void {
15+
}
16+
17+
// eslint-disable-next-line no-empty, @typescript-eslint/no-empty-function
18+
public expand(_id: string): void {
19+
}
20+
21+
}

0 commit comments

Comments
 (0)