-
Notifications
You must be signed in to change notification settings - Fork 437
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1182 from atmire/w2p-79327_Fix-item-level-statistics
Fix item-level statistics pages
- Loading branch information
Showing
9 changed files
with
135 additions
and
45 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,36 @@ | ||
import { ProtractorPage } from './item-statistics.po'; | ||
import { browser } from 'protractor'; | ||
import { UIURLCombiner } from '../../../src/app/core/url-combiner/ui-url-combiner'; | ||
|
||
describe('protractor Item statics', () => { | ||
let page: ProtractorPage; | ||
|
||
beforeEach(() => { | ||
page = new ProtractorPage(); | ||
}); | ||
|
||
it('should contain element ds-item-page when navigating when navigating to an item page', () => { | ||
page.navigateToItemPage(); | ||
expect<any>(page.elementTagExists('ds-item-page')).toEqual(true); | ||
expect<any>(page.elementTagExists('ds-item-statistics-page')).toEqual(false); | ||
}); | ||
|
||
it('should redirect to the entity page when navigating to an item page', () => { | ||
page.navigateToItemPage(); | ||
expect(browser.getCurrentUrl()).toEqual(new UIURLCombiner(page.ENTITYPAGE).toString()); | ||
expect(browser.getCurrentUrl()).not.toEqual(new UIURLCombiner(page.ITEMSTATISTICSPAGE).toString()); | ||
expect(browser.getCurrentUrl()).not.toEqual(new UIURLCombiner(page.ITEMPAGE).toString()); | ||
}); | ||
|
||
it('should contain element ds-item-statistics-page when navigating when navigating to an item statistics page', () => { | ||
page.navigateToItemStatisticsPage(); | ||
expect<any>(page.elementTagExists('ds-item-statistics-page')).toEqual(true); | ||
expect<any>(page.elementTagExists('ds-item-page')).toEqual(false); | ||
}); | ||
it('should contain the item statistics page url when navigating to an item statistics page', () => { | ||
page.navigateToItemStatisticsPage(); | ||
expect(browser.getCurrentUrl()).toEqual(new UIURLCombiner(page.ITEMSTATISTICSPAGE).toString()); | ||
expect(browser.getCurrentUrl()).not.toEqual(new UIURLCombiner(page.ENTITYPAGE).toString()); | ||
expect(browser.getCurrentUrl()).not.toEqual(new UIURLCombiner(page.ITEMPAGE).toString()); | ||
}); | ||
}); |
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,18 @@ | ||
import { browser, element, by } from 'protractor'; | ||
|
||
export class ProtractorPage { | ||
ITEMPAGE = '/items/e98b0f27-5c19-49a0-960d-eb6ad5287067'; | ||
ENTITYPAGE = '/entities/publication/e98b0f27-5c19-49a0-960d-eb6ad5287067'; | ||
ITEMSTATISTICSPAGE = '/statistics/items/e98b0f27-5c19-49a0-960d-eb6ad5287067'; | ||
|
||
navigateToItemPage() { | ||
return browser.get(this.ITEMPAGE); | ||
} | ||
navigateToItemStatisticsPage() { | ||
return browser.get(this.ITEMSTATISTICSPAGE); | ||
} | ||
|
||
elementTagExists(tag: string) { | ||
return element(by.tagName(tag)).isPresent(); | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { ActivatedRouteSnapshot, Resolve, Router, RouterStateSnapshot } from '@angular/router'; | ||
import { Observable } from 'rxjs'; | ||
import { RemoteData } from '../core/data/remote-data'; | ||
import { ItemDataService } from '../core/data/item-data.service'; | ||
import { Item } from '../core/shared/item.model'; | ||
import { followLink, FollowLinkConfig } from '../shared/utils/follow-link-config.model'; | ||
import { FindListOptions } from '../core/data/request.models'; | ||
import { getFirstCompletedRemoteData } from '../core/shared/operators'; | ||
import { Store } from '@ngrx/store'; | ||
import { ResolvedAction } from '../core/resolving/resolver.actions'; | ||
|
||
/** | ||
* The self links defined in this list are expected to be requested somewhere in the near future | ||
* Requesting them as embeds will limit the number of requests | ||
*/ | ||
export const ITEM_PAGE_LINKS_TO_FOLLOW: FollowLinkConfig<Item>[] = [ | ||
followLink('owningCollection', undefined, true, true, true, | ||
followLink('parentCommunity', undefined, true, true, true, | ||
followLink('parentCommunity')) | ||
), | ||
followLink('bundles', new FindListOptions(), true, true, true, followLink('bitstreams')), | ||
followLink('relationships'), | ||
followLink('version', undefined, true, true, true, followLink('versionhistory')), | ||
]; | ||
|
||
/** | ||
* This class represents a resolver that requests a specific item before the route is activated | ||
*/ | ||
@Injectable() | ||
export class ItemResolver implements Resolve<RemoteData<Item>> { | ||
constructor( | ||
protected itemService: ItemDataService, | ||
protected store: Store<any>, | ||
protected router: Router | ||
) { | ||
} | ||
|
||
/** | ||
* Method for resolving an item based on the parameters in the current route | ||
* @param {ActivatedRouteSnapshot} route The current ActivatedRouteSnapshot | ||
* @param {RouterStateSnapshot} state The current RouterStateSnapshot | ||
* @returns Observable<<RemoteData<Item>> Emits the found item based on the parameters in the current route, | ||
* or an error if something went wrong | ||
*/ | ||
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<RemoteData<Item>> { | ||
const itemRD$ = this.itemService.findById(route.params.id, | ||
true, | ||
false, | ||
...ITEM_PAGE_LINKS_TO_FOLLOW | ||
).pipe( | ||
getFirstCompletedRemoteData(), | ||
); | ||
|
||
itemRD$.subscribe((itemRD: RemoteData<Item>) => { | ||
this.store.dispatch(new ResolvedAction(state.url, itemRD.payload)); | ||
}); | ||
|
||
return itemRD$; | ||
} | ||
} |
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
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