forked from DSpace/dspace-angular
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created BrowseByPageComponent that uses the new refactored BrowseBySw…
…itcherComponent extending AbstractComponentLoaderComponent - Added the context to the rendersBrowseBy decorator - Created AbstractBrowseByTypeComponent that is extended by all the browse type sections
- Loading branch information
1 parent
14d42b0
commit a83d69e
Showing
25 changed files
with
269 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { Component, Input, OnDestroy } from '@angular/core'; | ||
import { BrowseByDataType } from './browse-by-switcher/browse-by-decorator'; | ||
import { Context } from '../core/shared/context.model'; | ||
import { Subscription } from 'rxjs'; | ||
import { hasValue } from '../shared/empty.util'; | ||
|
||
@Component({ | ||
selector: 'ds-abstract-browse-by-type', | ||
template: '', | ||
}) | ||
export abstract class AbstractBrowseByTypeComponent implements OnDestroy { | ||
|
||
/** | ||
* The optional context | ||
*/ | ||
@Input() context: Context; | ||
|
||
/** | ||
* The {@link BrowseByDataType} of this Component | ||
*/ | ||
@Input() browseByType: BrowseByDataType; | ||
|
||
/** | ||
* List of subscriptions | ||
*/ | ||
subs: Subscription[] = []; | ||
|
||
ngOnDestroy(): void { | ||
this.subs.filter((sub: Subscription) => hasValue(sub)).forEach((sub: Subscription) => sub.unsubscribe()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
src/app/browse-by/browse-by-page/browse-by-page.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<ds-browse-by-switcher [browseByType]="browseByType$ | async"> | ||
</ds-browse-by-switcher> |
File renamed without changes.
69 changes: 69 additions & 0 deletions
69
src/app/browse-by/browse-by-page/browse-by-page.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// eslint-disable-next-line max-classes-per-file | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { BrowseByPageComponent } from './browse-by-page.component'; | ||
import { BrowseBySwitcherComponent } from '../browse-by-switcher/browse-by-switcher.component'; | ||
import { DynamicComponentLoaderDirective } from '../../shared/abstract-component-loader/dynamic-component-loader.directive'; | ||
import { ActivatedRoute } from '@angular/router'; | ||
import { ActivatedRouteStub } from '../../shared/testing/active-router.stub'; | ||
import { getMockThemeService } from '../../shared/mocks/theme-service.mock'; | ||
import { ThemeService } from '../../shared/theme-support/theme.service'; | ||
import { rendersBrowseBy, BrowseByDataType } from '../browse-by-switcher/browse-by-decorator'; | ||
import { Component } from '@angular/core'; | ||
import { AbstractBrowseByTypeComponent } from '../abstract-browse-by-type.component'; | ||
import { BrowseDefinition } from '../../core/shared/browse-definition.model'; | ||
import { By } from '@angular/platform-browser'; | ||
|
||
@rendersBrowseBy('BrowseByPageComponent' as BrowseByDataType) | ||
@Component({ | ||
// eslint-disable-next-line @angular-eslint/component-selector | ||
selector: '', | ||
template: '<span id="BrowseByTestComponent"></span>', | ||
}) | ||
class BrowseByTestComponent extends AbstractBrowseByTypeComponent { | ||
} | ||
|
||
class TestBrowseByPageBrowseDefinition extends BrowseDefinition { | ||
getRenderType(): BrowseByDataType { | ||
return 'BrowseByPageComponent' as BrowseByDataType; | ||
} | ||
} | ||
|
||
describe('BrowseByPageComponent', () => { | ||
let component: BrowseByPageComponent; | ||
let fixture: ComponentFixture<BrowseByPageComponent>; | ||
|
||
let activatedRoute: ActivatedRouteStub; | ||
let themeService: ThemeService; | ||
|
||
beforeEach(async () => { | ||
activatedRoute = new ActivatedRouteStub(); | ||
themeService = getMockThemeService(); | ||
|
||
await TestBed.configureTestingModule({ | ||
declarations: [ | ||
BrowseByPageComponent, | ||
BrowseBySwitcherComponent, | ||
DynamicComponentLoaderDirective, | ||
], | ||
providers: [ | ||
BrowseByTestComponent, | ||
{ provide: ActivatedRoute, useValue: activatedRoute }, | ||
{ provide: ThemeService, useValue: themeService }, | ||
], | ||
}).compileComponents(); | ||
|
||
fixture = TestBed.createComponent(BrowseByPageComponent); | ||
component = fixture.componentInstance; | ||
}); | ||
|
||
it('should create the correct browse section based on the route browseDefinition', () => { | ||
activatedRoute.testData = { | ||
browseDefinition: new TestBrowseByPageBrowseDefinition(), | ||
}; | ||
|
||
fixture.detectChanges(); | ||
|
||
expect(component).toBeTruthy(); | ||
expect(fixture.debugElement.query(By.css('#BrowseByTestComponent'))).not.toBeNull(); | ||
}); | ||
}); |
31 changes: 31 additions & 0 deletions
31
src/app/browse-by/browse-by-page/browse-by-page.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { Component, OnInit } from '@angular/core'; | ||
import { map } from 'rxjs/operators'; | ||
import { BrowseDefinition } from '../../core/shared/browse-definition.model'; | ||
import { ActivatedRoute } from '@angular/router'; | ||
import { Observable } from 'rxjs'; | ||
import { BrowseByDataType } from '../browse-by-switcher/browse-by-decorator'; | ||
|
||
@Component({ | ||
selector: 'ds-browse-by-page', | ||
templateUrl: './browse-by-page.component.html', | ||
styleUrls: ['./browse-by-page.component.scss'], | ||
}) | ||
export class BrowseByPageComponent implements OnInit { | ||
|
||
browseByType$: Observable<BrowseByDataType>; | ||
|
||
constructor( | ||
protected route: ActivatedRoute, | ||
) { | ||
} | ||
|
||
/** | ||
* Fetch the correct browse-by component by using the relevant config from the route data | ||
*/ | ||
ngOnInit(): void { | ||
this.browseByType$ = this.route.data.pipe( | ||
map((data: { browseDefinition: BrowseDefinition }) => data.browseDefinition.getRenderType()), | ||
); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
src/app/browse-by/browse-by-switcher/browse-by-switcher.component.html
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.