forked from DSpace/dspace-angular
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merged in CST-12904-breadcrumbs-qa (pull request DSpace#1107)
CST-12904 breadcrumbs qa Approved-by: Giuseppe Digilio
- Loading branch information
Showing
6 changed files
with
166 additions
and
8 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
31 changes: 31 additions & 0 deletions
31
src/app/core/breadcrumbs/quality-assurance-breadcrumb.resolver.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,31 @@ | ||
import {QualityAssuranceBreadcrumbResolver} from './quality-assurance-breadcrumb.resolver'; | ||
|
||
describe('QualityAssuranceBreadcrumbResolver', () => { | ||
describe('resolve', () => { | ||
let resolver: QualityAssuranceBreadcrumbResolver; | ||
let qualityAssuranceBreadcrumbService: any; | ||
let route: any; | ||
const fullPath = '/test/quality-assurance/'; | ||
const expectedKey = 'testSourceId:testTopicId'; | ||
|
||
beforeEach(() => { | ||
route = { | ||
paramMap: { | ||
get: function (param) { | ||
return this[param] | ||
}, | ||
sourceId: 'testSourceId', | ||
topicId: 'testTopicId' | ||
} | ||
}; | ||
qualityAssuranceBreadcrumbService = {}; | ||
resolver = new QualityAssuranceBreadcrumbResolver(qualityAssuranceBreadcrumbService); | ||
}); | ||
|
||
it('should resolve the breadcrumb config', () => { | ||
const resolvedConfig = resolver.resolve(route as any, {url: fullPath + 'testSourceId'} as any); | ||
const expectedConfig = { provider: qualityAssuranceBreadcrumbService, key: expectedKey, url: fullPath }; | ||
expect(resolvedConfig).toEqual(expectedConfig); | ||
}); | ||
}); | ||
}); |
32 changes: 32 additions & 0 deletions
32
src/app/core/breadcrumbs/quality-assurance-breadcrumb.resolver.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,32 @@ | ||
import { Injectable } from '@angular/core'; | ||
import {QualityAssuranceBreadcrumbService} from './quality-assurance-breadcrumb.service'; | ||
import {ActivatedRouteSnapshot, Resolve, RouterStateSnapshot} from '@angular/router'; | ||
import {BreadcrumbConfig} from '../../breadcrumbs/breadcrumb/breadcrumb-config.model'; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class QualityAssuranceBreadcrumbResolver implements Resolve<BreadcrumbConfig<string>> { | ||
constructor(protected breadcrumbService: QualityAssuranceBreadcrumbService) {} | ||
|
||
/** | ||
* Method that resolve QA item into a breadcrumb | ||
* The parameter are retrieved by the url since part of the QA route config | ||
* @param {ActivatedRouteSnapshot} route The current ActivatedRouteSnapshot | ||
* @param {RouterStateSnapshot} state The current RouterStateSnapshot | ||
* @returns BreadcrumbConfig object | ||
*/ | ||
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): BreadcrumbConfig<string> { | ||
const sourceId = route.paramMap.get('sourceId'); | ||
const topicId = route.paramMap.get('topicId'); | ||
let key = sourceId; | ||
|
||
if (topicId) { | ||
key += `:${topicId}`; | ||
} | ||
const fullPath = state.url; | ||
const url = fullPath.substr(0, fullPath.indexOf(sourceId)); | ||
|
||
return { provider: this.breadcrumbService, key, url }; | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/app/core/breadcrumbs/quality-assurance-breadcrumb.service.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,40 @@ | ||
import { TestBed, waitForAsync } from '@angular/core/testing'; | ||
import { Breadcrumb } from '../../breadcrumbs/breadcrumb/breadcrumb.model'; | ||
import { getTestScheduler } from 'jasmine-marbles'; | ||
import {QualityAssuranceBreadcrumbService} from './quality-assurance-breadcrumb.service'; | ||
|
||
describe('QualityAssuranceBreadcrumbService', () => { | ||
let service: QualityAssuranceBreadcrumbService; | ||
let dataService: any; | ||
let translateService: any = { | ||
instant: (str) => str, | ||
}; | ||
|
||
let exampleString; | ||
let exampleURL; | ||
let exampleQaKey; | ||
|
||
function init() { | ||
exampleString = 'sourceId'; | ||
exampleURL = '/test/quality-assurance/'; | ||
exampleQaKey = 'admin.quality-assurance.breadcrumbs'; | ||
} | ||
|
||
beforeEach(waitForAsync(() => { | ||
init(); | ||
TestBed.configureTestingModule({}).compileComponents(); | ||
})); | ||
|
||
beforeEach(() => { | ||
service = new QualityAssuranceBreadcrumbService(dataService,translateService); | ||
}); | ||
|
||
describe('getBreadcrumbs', () => { | ||
it('should return a breadcrumb based on a string', () => { | ||
const breadcrumbs = service.getBreadcrumbs(exampleString, exampleURL); | ||
getTestScheduler().expectObservable(breadcrumbs).toBe('(a|)', { a: [new Breadcrumb(exampleQaKey, exampleURL), | ||
new Breadcrumb(exampleString, exampleURL + exampleString)] | ||
}); | ||
}); | ||
}); | ||
}); |
53 changes: 53 additions & 0 deletions
53
src/app/core/breadcrumbs/quality-assurance-breadcrumb.service.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,53 @@ | ||
import { Breadcrumb } from '../../breadcrumbs/breadcrumb/breadcrumb.model'; | ||
import { BreadcrumbsProviderService } from './breadcrumbsProviderService'; | ||
import { Observable, of as observableOf } from 'rxjs'; | ||
import { Injectable } from '@angular/core'; | ||
import {map} from 'rxjs/operators'; | ||
import {getFirstCompletedRemoteData} from '../shared/operators'; | ||
import {TranslateService} from '@ngx-translate/core'; | ||
import {QualityAssuranceTopicDataService} from "../notifications/qa/topics/quality-assurance-topic-data.service"; | ||
|
||
|
||
|
||
/** | ||
* Service to calculate QA breadcrumbs for a single part of the route | ||
*/ | ||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class QualityAssuranceBreadcrumbService implements BreadcrumbsProviderService<string> { | ||
|
||
private QUALITY_ASSURANCE_BREADCRUMB_KEY = 'admin.quality-assurance.breadcrumbs'; | ||
constructor( | ||
protected qualityAssuranceService: QualityAssuranceTopicDataService, | ||
private translationService: TranslateService, | ||
) { | ||
|
||
} | ||
|
||
|
||
/** | ||
* Method to calculate the breadcrumbs | ||
* @param key The key used to resolve the breadcrumb | ||
* @param url The url to use as a link for this breadcrumb | ||
*/ | ||
getBreadcrumbs(key: string, url: string): Observable<Breadcrumb[]> { | ||
const sourceId = key.split(':')[0]; | ||
const topicId = key.split(':')[1]; | ||
|
||
if (topicId) { | ||
return this.qualityAssuranceService.getTopic(topicId).pipe( | ||
getFirstCompletedRemoteData(), | ||
map((topic) => { | ||
return [new Breadcrumb(this.translationService.instant(this.QUALITY_ASSURANCE_BREADCRUMB_KEY), url), | ||
new Breadcrumb(sourceId, `${url}${sourceId}`), | ||
new Breadcrumb(topicId, undefined)]; | ||
}) | ||
); | ||
} else { | ||
return observableOf([new Breadcrumb(this.translationService.instant(this.QUALITY_ASSURANCE_BREADCRUMB_KEY), url), | ||
new Breadcrumb(sourceId, `${url}${sourceId}`)]); | ||
} | ||
|
||
} | ||
} |
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