Skip to content

Commit b8b9da2

Browse files
Fix BrowseByComponent no expectation tests
- Because the custom theme is disabled by default I replaced it with the dspace theme who is still enabled by default - Because the child components use a themed component the changes need to be detected twice, this is a side effect from the component being created dynamically
1 parent 430b3b2 commit b8b9da2

3 files changed

Lines changed: 29 additions & 46 deletions

File tree

src/app/browse-by/browse-by.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { ThemedBrowseByTaxonomyPageComponent } from './browse-by-taxonomy-page/t
1414
import { SharedBrowseByModule } from '../shared/browse-by/shared-browse-by.module';
1515
import { DsoPageModule } from '../shared/dso-page/dso-page.module';
1616
import { FormModule } from '../shared/form/form.module';
17+
import { SharedModule } from '../shared/shared.module';
1718

1819
const ENTRY_COMPONENTS = [
1920
// put only entry components that use custom decorator
@@ -35,6 +36,7 @@ const ENTRY_COMPONENTS = [
3536
ComcolModule,
3637
DsoPageModule,
3738
FormModule,
39+
SharedModule,
3840
],
3941
declarations: [
4042
BrowseBySwitcherComponent,

src/app/shared/browse-by/browse-by.component.spec.ts

Lines changed: 18 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { By } from '@angular/platform-browser';
55
import { Component, NO_ERRORS_SCHEMA } from '@angular/core';
66
import { of as observableOf } from 'rxjs';
77
import { CommonModule } from '@angular/common';
8-
import { Item } from '../../core/shared/item.model';
98
import { buildPaginatedList } from '../../core/data/paginated-list.model';
109
import { PageInfo } from '../../core/shared/page-info.model';
1110
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
@@ -48,10 +47,10 @@ import { SharedModule } from '../shared.module';
4847
import { BrowseByRoutingModule } from '../../browse-by/browse-by-routing.module';
4948
import { AccessControlRoutingModule } from '../../access-control/access-control-routing.module';
5049

51-
@listableObjectComponent(BrowseEntry, ViewMode.ListElement, DEFAULT_CONTEXT, 'custom')
50+
@listableObjectComponent(BrowseEntry, ViewMode.ListElement, DEFAULT_CONTEXT, 'dspace')
5251
@Component({
5352
// eslint-disable-next-line @angular-eslint/component-selector
54-
selector: '',
53+
selector: 'ds-browse-entry-list-element',
5554
template: ''
5655
})
5756
class MockThemedBrowseEntryListElementComponent {
@@ -61,28 +60,6 @@ describe('BrowseByComponent', () => {
6160
let comp: BrowseByComponent;
6261
let fixture: ComponentFixture<BrowseByComponent>;
6362

64-
const mockItems = [
65-
Object.assign(new Item(), {
66-
id: 'fakeId-1',
67-
metadata: [
68-
{
69-
key: 'dc.title',
70-
value: 'First Fake Title'
71-
}
72-
]
73-
}),
74-
Object.assign(new Item(), {
75-
id: 'fakeId-2',
76-
metadata: [
77-
{
78-
key: 'dc.title',
79-
value: 'Second Fake Title'
80-
}
81-
]
82-
})
83-
];
84-
const mockItemsRD$ = createSuccessfulRemoteDataObject$(buildPaginatedList(new PageInfo(), mockItems));
85-
8663
const groupDataService = jasmine.createSpyObj('groupsDataService', {
8764
findListByHref: createSuccessfulRemoteDataObject$(createPaginatedList([])),
8865
getGroupRegistryRouterLink: '',
@@ -113,8 +90,8 @@ describe('BrowseByComponent', () => {
11390
let themeService;
11491

11592
beforeEach(waitForAsync(() => {
116-
themeService = getMockThemeService('dspace');
117-
TestBed.configureTestingModule({
93+
themeService = getMockThemeService('base');
94+
void TestBed.configureTestingModule({
11895
imports: [
11996
BrowseByRoutingModule,
12097
AccessControlRoutingModule,
@@ -200,40 +177,40 @@ describe('BrowseByComponent', () => {
200177
});
201178

202179
describe('when theme is base', () => {
203-
beforeEach(() => {
180+
beforeEach(async () => {
204181
themeService.getThemeName.and.returnValue('base');
205182
themeService.getThemeName$.and.returnValue(observableOf('base'));
206183
fixture.detectChanges();
184+
await fixture.whenStable();
185+
fixture.detectChanges();
207186
});
208187

209188
it('should use the base component to render browse entries', () => {
210-
waitForAsync(() => {
211-
const componentLoaders = fixture.debugElement.queryAll(By.directive(ListableObjectComponentLoaderComponent));
212-
expect(componentLoaders.length).toEqual(browseEntries.length);
213-
componentLoaders.forEach((componentLoader) => {
214-
const browseEntry = componentLoader.query(By.css('ds-browse-entry-list-element'));
215-
expect(browseEntry.componentInstance).toBeInstanceOf(BrowseEntryListElementComponent);
216-
});
189+
const componentLoaders = fixture.debugElement.queryAll(By.directive(ListableObjectComponentLoaderComponent));
190+
expect(componentLoaders.length).toEqual(browseEntries.length);
191+
componentLoaders.forEach((componentLoader) => {
192+
const browseEntry = componentLoader.query(By.css('ds-browse-entry-list-element'));
193+
expect(browseEntry.componentInstance).toBeInstanceOf(BrowseEntryListElementComponent);
217194
});
218195
});
219196
});
220197

221-
describe('when theme is custom', () => {
222-
beforeEach(() => {
223-
themeService.getThemeName.and.returnValue('custom');
224-
themeService.getThemeName$.and.returnValue(observableOf('custom'));
198+
describe('when theme is dspace', () => {
199+
beforeEach(async () => {
200+
themeService.getThemeName.and.returnValue('dspace');
201+
themeService.getThemeName$.and.returnValue(observableOf('dspace'));
202+
fixture.detectChanges();
203+
await fixture.whenStable();
225204
fixture.detectChanges();
226205
});
227206

228207
it('should use the themed component to render browse entries', () => {
229-
waitForAsync(() => {
230208
const componentLoaders = fixture.debugElement.queryAll(By.directive(ListableObjectComponentLoaderComponent));
231209
expect(componentLoaders.length).toEqual(browseEntries.length);
232210
componentLoaders.forEach((componentLoader) => {
233211
const browseEntry = componentLoader.query(By.css('ds-browse-entry-list-element'));
234212
expect(browseEntry.componentInstance).toBeInstanceOf(MockThemedBrowseEntryListElementComponent);
235213
});
236-
});
237214
});
238215
});
239216
});

src/app/shared/browse-by/shared-browse-by.module.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@ import { ResultsBackButtonModule } from '../results-back-button/results-back-but
66
import { BrowseByRoutingModule } from '../../browse-by/browse-by-routing.module';
77
import { AccessControlRoutingModule } from '../../access-control/access-control-routing.module';
88

9+
const DECLARATIONS = [
10+
BrowseByComponent,
11+
];
12+
913
@NgModule({
1014
declarations: [
11-
BrowseByComponent,
12-
],
15+
...DECLARATIONS,
16+
],
1317
imports: [
1418
ResultsBackButtonModule,
1519
BrowseByRoutingModule,
@@ -18,8 +22,8 @@ import { AccessControlRoutingModule } from '../../access-control/access-control-
1822
SharedModule,
1923
],
2024
exports: [
21-
BrowseByComponent,
22-
SharedModule,
25+
...DECLARATIONS,
2326
]
2427
})
25-
export class SharedBrowseByModule { }
28+
export class SharedBrowseByModule {
29+
}

0 commit comments

Comments
 (0)