Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/app/collection-page/collection-page.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@
[title]="'collection.page.news'">
</ds-comcol-page-content>
</header>
<ds-dso-edit-menu></ds-dso-edit-menu>
<div class="d-flex align-items-start">
<ds-dso-edit-menu></ds-dso-edit-menu>
</div>
</div>
<section class="comcol-page-browse-section">
<!-- Browse-By Links -->
Expand Down
99 changes: 99 additions & 0 deletions src/app/collection-page/collection-page.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { TranslateModule } from '@ngx-translate/core';
import { of as observableOf } from 'rxjs';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';

import { CollectionPageComponent } from './collection-page.component';
import { CollectionDataService } from '../core/data/collection-data.service';
import { SearchService } from '../core/shared/search/search.service';
import { AuthService } from '../core/auth/auth.service';
import { PaginationService } from '../core/pagination/pagination.service';
import { AuthorizationDataService } from '../core/data/feature-authorization/authorization-data.service';
import { DSONameService } from '../core/breadcrumbs/dso-name.service';
import { APP_CONFIG } from '../../config/app-config.interface';
import { VarDirective } from '../shared/utils/var.directive';

describe('CollectionPageComponent', () => {
let component: CollectionPageComponent;
let fixture: ComponentFixture<CollectionPageComponent>;

const collectionUUID = '22222222-2222-2222-2222-222222222222';
const collection = {
id: collectionUUID,
uuid: collectionUUID,
type: 'collection',
handle: '123456789/2',
introductoryText: null,
sidebarText: null,
copyrightText: null,
logo: observableOf({ hasSucceeded: true, payload: undefined })
};

const collectionRD = {
hasSucceeded: true,
hasFailed: false,
statusCode: 200,
payload: collection
};

beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
imports: [TranslateModule.forRoot(), NoopAnimationsModule],
declarations: [CollectionPageComponent, VarDirective],
providers: [
{ provide: ActivatedRoute, useValue: { data: observableOf({ dso: collectionRD }) } },
{ provide: Router, useValue: { navigateByUrl: jasmine.createSpy('navigateByUrl'), url: '/' } },
{ provide: CollectionDataService, useValue: {} },
{
provide: SearchService,
useValue: {
search: () => observableOf({ hasSucceeded: true, payload: { page: [] } })
}
},
{
provide: AuthService,
useValue: {
isAuthenticated: () => observableOf(false),
setRedirectUrl: jasmine.createSpy('setRedirectUrl')
}
},
{
provide: PaginationService,
useValue: {
getCurrentPagination: () => observableOf({ currentPage: 1, pageSize: 10 }),
getCurrentSort: () => observableOf({ field: 'dc.date.accessioned', direction: 'DESC' }),
clearPagination: jasmine.createSpy('clearPagination')
}
},
{ provide: AuthorizationDataService, useValue: { isAuthorized: () => observableOf(false) } },
{ provide: DSONameService, useValue: { getName: () => 'Test Collection' } },
{ provide: APP_CONFIG, useValue: { browseBy: { pageSize: 10 } } }
],
schemas: [NO_ERRORS_SCHEMA]
}).compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(CollectionPageComponent);
component = fixture.componentInstance;

spyOn(component, 'ngOnInit').and.callFake(() => {
component.collectionRD$ = observableOf(collectionRD as any);
component.logoRD$ = observableOf({ hasSucceeded: true, payload: undefined } as any);
component.itemRD$ = observableOf({ hasSucceeded: true, payload: { page: [] } } as any);
});

fixture.detectChanges();
});

it('should render the dso edit menu in the header action area', () => {
expect(component).toBeTruthy();

const editMenu = fixture.debugElement.query(By.css('ds-dso-edit-menu'));

expect(editMenu).toBeTruthy();
});
});
4 changes: 3 additions & 1 deletion src/app/community-page/community-page.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
[title]="'community.page.news'">
</ds-comcol-page-content>
</header>
<ds-dso-edit-menu></ds-dso-edit-menu>
<div class="d-flex align-items-start">
<ds-dso-edit-menu></ds-dso-edit-menu>
</div>
</div>
<section class="comcol-page-browse-section">

Expand Down
81 changes: 81 additions & 0 deletions src/app/community-page/community-page.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { TranslateModule } from '@ngx-translate/core';
import { of as observableOf } from 'rxjs';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';

import { CommunityPageComponent } from './community-page.component';
import { CommunityDataService } from '../core/data/community-data.service';
import { MetadataService } from '../core/metadata/metadata.service';
import { AuthService } from '../core/auth/auth.service';
import { AuthorizationDataService } from '../core/data/feature-authorization/authorization-data.service';
import { DSONameService } from '../core/breadcrumbs/dso-name.service';
import { VarDirective } from '../shared/utils/var.directive';

describe('CommunityPageComponent', () => {
let component: CommunityPageComponent;
let fixture: ComponentFixture<CommunityPageComponent>;

const communityUUID = '11111111-1111-1111-1111-111111111111';
const community = {
id: communityUUID,
uuid: communityUUID,
handle: '123456789/1',
introductoryText: null,
sidebarText: null,
copyrightText: null,
logo: observableOf({ hasSucceeded: true, payload: undefined })
};

const communityRD = {
hasSucceeded: true,
hasFailed: false,
statusCode: 200,
payload: community
};

beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
imports: [TranslateModule.forRoot(), NoopAnimationsModule],
declarations: [CommunityPageComponent, VarDirective],
providers: [
{ provide: ActivatedRoute, useValue: { data: observableOf({ dso: communityRD }) } },
{ provide: Router, useValue: { navigateByUrl: jasmine.createSpy('navigateByUrl'), url: '/' } },
{ provide: CommunityDataService, useValue: {} },
{ provide: MetadataService, useValue: {} },
{
provide: AuthService,
useValue: {
isAuthenticated: () => observableOf(false),
setRedirectUrl: jasmine.createSpy('setRedirectUrl')
}
},
{ provide: AuthorizationDataService, useValue: { isAuthorized: () => observableOf(false) } },
{ provide: DSONameService, useValue: { getName: () => 'Test Community' } }
],
schemas: [NO_ERRORS_SCHEMA]
}).compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(CommunityPageComponent);
component = fixture.componentInstance;

spyOn(component, 'ngOnInit').and.callFake(() => {
component.communityRD$ = observableOf(communityRD as any);
component.logoRD$ = observableOf({ hasSucceeded: true, payload: undefined } as any);
});

fixture.detectChanges();
});

it('should render the dso edit menu in the header action area', () => {
expect(component).toBeTruthy();

const editMenu = fixture.debugElement.query(By.css('ds-dso-edit-menu'));

expect(editMenu).toBeTruthy();
});
});
23 changes: 23 additions & 0 deletions src/app/shared/dso-page/dso-edit-menu.resolver.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,16 @@ describe('DSOEditMenuResolver', () => {
it('should return Community/Collection-specific entries', (done) => {
const result = resolver.getDsoMenus(testObject, route, state);
combineLatest(result).pipe(map(flatten)).subscribe((menu) => {
const searchEntry = menu.find(entry => entry.id === 'search-dso');
expect(searchEntry).toBeTruthy();
expect(searchEntry.active).toBeFalse();
expect(searchEntry.visible).toBeTrue();
expect(searchEntry.model.type).toEqual(MenuItemType.LINK);
expect((searchEntry.model as LinkMenuItemModel).text).toEqual('search.title');
expect((searchEntry.model as LinkMenuItemModel).link).toEqual('/search');
expect((searchEntry.model as LinkMenuItemModel).queryParams['spc.page']).toEqual('1');
expect((searchEntry.model as LinkMenuItemModel).queryParams.scope).toEqual('test-community-uuid');

const subscribeEntry = menu.find(entry => entry.id === 'subscribe');
expect(subscribeEntry).toBeTruthy();
expect(subscribeEntry.active).toBeFalse();
Expand Down Expand Up @@ -318,6 +328,16 @@ describe('DSOEditMenuResolver', () => {
it('should return Community/Collection-specific entries', (done) => {
const result = resolver.getDsoMenus(testObject, route, state);
combineLatest(result).pipe(map(flatten)).subscribe((menu) => {
const searchEntry = menu.find(entry => entry.id === 'search-dso');
expect(searchEntry).toBeTruthy();
expect(searchEntry.active).toBeFalse();
expect(searchEntry.visible).toBeTrue();
expect(searchEntry.model.type).toEqual(MenuItemType.LINK);
expect((searchEntry.model as LinkMenuItemModel).text).toEqual('search.title');
expect((searchEntry.model as LinkMenuItemModel).link).toEqual('/search');
expect((searchEntry.model as LinkMenuItemModel).queryParams['spc.page']).toEqual('1');
expect((searchEntry.model as LinkMenuItemModel).queryParams.scope).toEqual('test-collection-uuid');

const subscribeEntry = menu.find(entry => entry.id === 'subscribe');
expect(subscribeEntry).toBeTruthy();
expect(subscribeEntry.active).toBeFalse();
Expand Down Expand Up @@ -378,6 +398,9 @@ describe('DSOEditMenuResolver', () => {
it('should not return Community/Collection-specific entries', (done) => {
const result = resolver.getDsoMenus(testObject, route, state);
combineLatest(result).pipe(map(flatten)).subscribe((menu) => {
const searchEntry = menu.find(entry => entry.id === 'search-dso');
expect(searchEntry).toBeFalsy();

const subscribeEntry = menu.find(entry => entry.id === 'subscribe');
expect(subscribeEntry).toBeFalsy();
done();
Expand Down
17 changes: 17 additions & 0 deletions src/app/shared/dso-page/dso-edit-menu.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,23 @@ export class DSOEditMenuResolver implements Resolve<{ [key: string]: MenuSection
]).pipe(
map(([canSubscribe]) => {
return [
{
id: 'search-dso',
active: false,
visible: true,
model: {
type: MenuItemType.LINK,
disabled: false,
text: 'search.title',
link: '/search',
queryParams: {
'spc.page': '1',
scope: dso.uuid
}
} as LinkMenuItemModel,
icon: 'search',
index: 3
},
{
id: 'subscribe',
active: false,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<div *ngIf="!canActivate" class="dso-button-menu mb-1"
[ngbTooltip]="itemModel.text | translate">
<a *ngIf="!section.model.disabled" class="btn btn-dark btn-sm"
[routerLink]="itemModel.link">
[routerLink]="itemModel.link"
[queryParams]="itemModel.queryParams">
<i class="fas fa-{{section.icon}} fa-fw" aria-hidden="true"></i>
<span class="sr-only">{{itemModel.text | translate}}</span>
</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ describe('DsoEditMenuSectionComponent', () => {
type: MenuItemType.LINK,
disabled: false,
text: 'text',
link: 'link'
link: 'link',
queryParams: {
scope: 'test-scope-id'
}
},
icon: iconString
};
Expand Down Expand Up @@ -158,6 +161,11 @@ describe('DsoEditMenuSectionComponent', () => {
expect(fixture.debugElement.query(By.css('a'))).not.toBeNull();
});

it('should bind queryParams on the link element', () => {
const link = fixture.debugElement.query(By.css('a'));
expect(link.properties.queryParams.scope).toEqual('test-scope-id');
});

});
});

Expand Down