mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 18:14:17 +00:00
added tests for popups
This commit is contained in:
@@ -12,6 +12,7 @@ import { AuthService } from '../../core/auth/auth.service';
|
||||
|
||||
import { of as observableOf } from 'rxjs';
|
||||
import { By } from '@angular/platform-browser';
|
||||
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
|
||||
|
||||
describe('AdminSidebarComponent', () => {
|
||||
let comp: AdminSidebarComponent;
|
||||
@@ -26,7 +27,13 @@ describe('AdminSidebarComponent', () => {
|
||||
{ provide: Injector, useValue: {} },
|
||||
{ provide: MenuService, useValue: menuService },
|
||||
{ provide: CSSVariableService, useClass: CSSVariableServiceStub },
|
||||
{ provide: AuthService, useClass: AuthServiceStub }
|
||||
{ provide: AuthService, useClass: AuthServiceStub },
|
||||
{
|
||||
provide: NgbModal, useValue: {
|
||||
open: () => {
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
}).overrideComponent(AdminSidebarComponent, {
|
||||
@@ -96,7 +103,10 @@ describe('AdminSidebarComponent', () => {
|
||||
beforeEach(() => {
|
||||
spyOn(menuService, 'toggleMenu');
|
||||
const sidebarToggler = fixture.debugElement.query(By.css('#sidebar-collapse-toggle')).query(By.css('a.shortcut-icon'));
|
||||
sidebarToggler.triggerEventHandler('click', {preventDefault: () => {/**/}});
|
||||
sidebarToggler.triggerEventHandler('click', {
|
||||
preventDefault: () => {/**/
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('should call toggleMenu on the menuService', () => {
|
||||
@@ -108,7 +118,10 @@ describe('AdminSidebarComponent', () => {
|
||||
beforeEach(() => {
|
||||
spyOn(menuService, 'toggleMenu');
|
||||
const sidebarToggler = fixture.debugElement.query(By.css('#sidebar-collapse-toggle')).query(By.css('.sidebar-collapsible')).query(By.css('a'));
|
||||
sidebarToggler.triggerEventHandler('click', {preventDefault: () => {/**/}});
|
||||
sidebarToggler.triggerEventHandler('click', {
|
||||
preventDefault: () => {/**/
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('should call toggleMenu on the menuService', () => {
|
||||
@@ -120,7 +133,10 @@ describe('AdminSidebarComponent', () => {
|
||||
it('should call expandPreview on the menuService after 100ms', fakeAsync(() => {
|
||||
spyOn(menuService, 'expandMenuPreview');
|
||||
const sidebarToggler = fixture.debugElement.query(By.css('nav.navbar'));
|
||||
sidebarToggler.triggerEventHandler('mouseenter', {preventDefault: () => {/**/}});
|
||||
sidebarToggler.triggerEventHandler('mouseenter', {
|
||||
preventDefault: () => {/**/
|
||||
}
|
||||
});
|
||||
tick(99);
|
||||
expect(menuService.expandMenuPreview).not.toHaveBeenCalled();
|
||||
tick(1);
|
||||
@@ -132,7 +148,10 @@ describe('AdminSidebarComponent', () => {
|
||||
it('should call collapseMenuPreview on the menuService after 400ms', fakeAsync(() => {
|
||||
spyOn(menuService, 'collapseMenuPreview');
|
||||
const sidebarToggler = fixture.debugElement.query(By.css('nav.navbar'));
|
||||
sidebarToggler.triggerEventHandler('mouseleave', {preventDefault: () => {/**/}});
|
||||
sidebarToggler.triggerEventHandler('mouseleave', {
|
||||
preventDefault: () => {/**/
|
||||
}
|
||||
});
|
||||
tick(399);
|
||||
expect(menuService.collapseMenuPreview).not.toHaveBeenCalled();
|
||||
tick(1);
|
||||
|
@@ -15,9 +15,9 @@ import { OnClickMenuItemModel } from '../../shared/menu/menu-item/models/onclick
|
||||
import { CreateCommunityParentSelectorComponent } from '../../shared/dso-selector/modal-wrappers/create-community-parent-selector/create-community-parent-selector.component';
|
||||
import { CreateItemParentSelectorComponent } from '../../shared/dso-selector/modal-wrappers/create-item-parent-selector/create-item-parent-selector.component';
|
||||
import { CreateCollectionParentSelectorComponent } from '../../shared/dso-selector/modal-wrappers/create-collection-parent-selector/create-collection-parent-selector.component';
|
||||
import { EditItemSelectorComponent } from '../../shared/dso-selector/modal-wrappers/edit-item-parent-selector/edit-item-selector.component';
|
||||
import { EditCommunitySelectorComponent } from '../../shared/dso-selector/modal-wrappers/edit-community-parent-selector/edit-community-selector.component';
|
||||
import { EditCollectionSelectorComponent } from '../../shared/dso-selector/modal-wrappers/edit-collection-parent-selector/edit-collection-selector.component';
|
||||
import { EditItemSelectorComponent } from '../../shared/dso-selector/modal-wrappers/edit-item-selector/edit-item-selector.component';
|
||||
import { EditCommunitySelectorComponent } from '../../shared/dso-selector/modal-wrappers/edit-community-selector/edit-community-selector.component';
|
||||
import { EditCollectionSelectorComponent } from '../../shared/dso-selector/modal-wrappers/edit-collection-selector/edit-collection-selector.component';
|
||||
|
||||
/**
|
||||
* Component representing the admin sidebar
|
||||
|
@@ -11,7 +11,7 @@ import { Item } from '../../../core/shared/item.model';
|
||||
import { of as observableOf } from 'rxjs';
|
||||
import { PaginatedList } from '../../../core/data/paginated-list';
|
||||
|
||||
fdescribe('DSOSelectorComponent', () => {
|
||||
describe('DSOSelectorComponent', () => {
|
||||
let component: DSOSelectorComponent;
|
||||
let fixture: ComponentFixture<DSOSelectorComponent>;
|
||||
let debugElement: DebugElement;
|
||||
@@ -35,8 +35,7 @@ fdescribe('DSOSelectorComponent', () => {
|
||||
{ provide: SearchService, useValue: searchService },
|
||||
],
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
})
|
||||
.compileComponents();
|
||||
}).compileComponents();
|
||||
|
||||
}));
|
||||
|
||||
|
@@ -0,0 +1,65 @@
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { DebugElement, NO_ERRORS_SCHEMA } from '@angular/core';
|
||||
import { of as observableOf } from 'rxjs';
|
||||
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { RemoteData } from '../../../../core/data/remote-data';
|
||||
import { RouterStub } from '../../../testing/router-stub';
|
||||
import * as collectionRouter from '../../../../+collection-page/collection-page-routing.module';
|
||||
import { Community } from '../../../../core/shared/community.model';
|
||||
import { CreateCollectionParentSelectorComponent } from './create-collection-parent-selector.component';
|
||||
|
||||
describe('CreateCollectionParentSelectorComponent', () => {
|
||||
let component: CreateCollectionParentSelectorComponent;
|
||||
let fixture: ComponentFixture<CreateCollectionParentSelectorComponent>;
|
||||
let debugElement: DebugElement;
|
||||
|
||||
const community = new Community();
|
||||
community.uuid = '1234-1234-1234-1234';
|
||||
community.metadata = { 'dc.title': [{ value: 'Community title', language: undefined }] };
|
||||
const router = new RouterStub();
|
||||
const communityRD = new RemoteData(false, false, true, undefined, community);
|
||||
const modalStub = jasmine.createSpyObj('modalStub', ['close']);
|
||||
const createPath = 'testCreatePath';
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [TranslateModule.forRoot()],
|
||||
declarations: [CreateCollectionParentSelectorComponent],
|
||||
providers: [
|
||||
{ provide: NgbActiveModal, useValue: modalStub },
|
||||
{
|
||||
provide: ActivatedRoute,
|
||||
useValue: { root: { firstChild: { firstChild: { data: observableOf({ community: communityRD }) } } } }
|
||||
},
|
||||
{
|
||||
provide: Router, useValue: router
|
||||
}
|
||||
],
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
}).compileComponents();
|
||||
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
spyOnProperty(collectionRouter, 'getCollectionCreatePath').and.callFake(() => {
|
||||
return () => createPath;
|
||||
});
|
||||
|
||||
fixture = TestBed.createComponent(CreateCollectionParentSelectorComponent);
|
||||
component = fixture.componentInstance;
|
||||
debugElement = fixture.debugElement;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should call navigate on the router with the correct edit path when navigate is called', () => {
|
||||
component.navigate(community);
|
||||
expect(router.navigate).toHaveBeenCalledWith([createPath], { queryParams: { parent: community.uuid } } );
|
||||
});
|
||||
|
||||
});
|
@@ -0,0 +1,65 @@
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { DebugElement, NO_ERRORS_SCHEMA } from '@angular/core';
|
||||
import { of as observableOf } from 'rxjs';
|
||||
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { RemoteData } from '../../../../core/data/remote-data';
|
||||
import { RouterStub } from '../../../testing/router-stub';
|
||||
import * as communityRouter from '../../../../+community-page/community-page-routing.module';
|
||||
import { Community } from '../../../../core/shared/community.model';
|
||||
import { CreateCommunityParentSelectorComponent } from './create-community-parent-selector.component';
|
||||
|
||||
describe('CreateCommunityParentSelectorComponent', () => {
|
||||
let component: CreateCommunityParentSelectorComponent;
|
||||
let fixture: ComponentFixture<CreateCommunityParentSelectorComponent>;
|
||||
let debugElement: DebugElement;
|
||||
|
||||
const community = new Community();
|
||||
community.uuid = '1234-1234-1234-1234';
|
||||
community.metadata = { 'dc.title': [{ value: 'Community title', language: undefined }] };
|
||||
const router = new RouterStub();
|
||||
const communityRD = new RemoteData(false, false, true, undefined, community);
|
||||
const modalStub = jasmine.createSpyObj('modalStub', ['close']);
|
||||
const createPath = 'testCreatePath';
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [TranslateModule.forRoot()],
|
||||
declarations: [CreateCommunityParentSelectorComponent],
|
||||
providers: [
|
||||
{ provide: NgbActiveModal, useValue: modalStub },
|
||||
{
|
||||
provide: ActivatedRoute,
|
||||
useValue: { root: { firstChild: { firstChild: { data: observableOf({ community: communityRD }) } } } }
|
||||
},
|
||||
{
|
||||
provide: Router, useValue: router
|
||||
}
|
||||
],
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
}).compileComponents();
|
||||
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
spyOnProperty(communityRouter, 'getCommunityCreatePath').and.callFake(() => {
|
||||
return () => createPath;
|
||||
});
|
||||
|
||||
fixture = TestBed.createComponent(CreateCommunityParentSelectorComponent);
|
||||
component = fixture.componentInstance;
|
||||
debugElement = fixture.debugElement;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should call navigate on the router with the correct edit path when navigate is called', () => {
|
||||
component.navigate(community);
|
||||
expect(router.navigate).toHaveBeenCalledWith([createPath], { queryParams: { parent: community.uuid } });
|
||||
});
|
||||
|
||||
});
|
@@ -1,13 +1,9 @@
|
||||
import { Component, Input, OnInit } from '@angular/core';
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { ActivatedRoute, NavigationExtras, Router } from '@angular/router';
|
||||
import { Community } from '../../../../core/shared/community.model';
|
||||
import { RemoteData } from '../../../../core/data/remote-data';
|
||||
import { DSpaceObjectType } from '../../../../core/shared/dspace-object-type.model';
|
||||
import { DSpaceObject } from '../../../../core/shared/dspace-object.model';
|
||||
import { hasValue } from '../../../empty.util';
|
||||
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { Observable } from 'rxjs';
|
||||
import {
|
||||
COMMUNITY_PARENT_PARAMETER,
|
||||
getCommunityCreatePath
|
||||
|
@@ -0,0 +1,65 @@
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { DebugElement, NO_ERRORS_SCHEMA } from '@angular/core';
|
||||
import { of as observableOf } from 'rxjs';
|
||||
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { RemoteData } from '../../../../core/data/remote-data';
|
||||
import { RouterStub } from '../../../testing/router-stub';
|
||||
import { Collection } from '../../../../core/shared/collection.model';
|
||||
import { CreateItemParentSelectorComponent } from './create-item-parent-selector.component';
|
||||
|
||||
describe('CreateItemParentSelectorComponent', () => {
|
||||
let component: CreateItemParentSelectorComponent;
|
||||
let fixture: ComponentFixture<CreateItemParentSelectorComponent>;
|
||||
let debugElement: DebugElement;
|
||||
|
||||
const collection = new Collection();
|
||||
collection.uuid = '1234-1234-1234-1234';
|
||||
collection.metadata = { 'dc.title': [{ value: 'Collection title', language: undefined }] };
|
||||
const router = new RouterStub();
|
||||
const collectionRD = new RemoteData(false, false, true, undefined, collection);
|
||||
const modalStub = jasmine.createSpyObj('modalStub', ['close']);
|
||||
const createPath = 'testCreatePath';
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [TranslateModule.forRoot()],
|
||||
declarations: [CreateItemParentSelectorComponent],
|
||||
providers: [
|
||||
{ provide: NgbActiveModal, useValue: modalStub },
|
||||
{
|
||||
provide: ActivatedRoute,
|
||||
useValue: { root: { firstChild: { firstChild: { data: observableOf({ collection: collectionRD }) } } } }
|
||||
},
|
||||
{
|
||||
provide: Router, useValue: router
|
||||
}
|
||||
],
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
}).compileComponents();
|
||||
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
// spyOnProperty(itemRouter, 'getItemCreatePath').and.callFake(() => {
|
||||
// return () => createPath;
|
||||
// });
|
||||
|
||||
fixture = TestBed.createComponent(CreateItemParentSelectorComponent);
|
||||
component = fixture.componentInstance;
|
||||
debugElement = fixture.debugElement;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should call navigate on the router with the correct create path when navigate is called', () => {
|
||||
/* TODO when there is a specific submission path */
|
||||
// component.navigate(item);
|
||||
// expect(router.navigate).toHaveBeenCalledWith([createPath]);
|
||||
});
|
||||
|
||||
});
|
@@ -29,8 +29,6 @@ export class CreateItemParentSelectorComponent extends DSOSelectorModalWrapperCo
|
||||
}
|
||||
|
||||
navigate(dso: DSpaceObject) {
|
||||
let path;
|
||||
// path = this.createPath;
|
||||
// this.router.navigate([path]);
|
||||
//There's no submit path per collection yet...
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,129 @@
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { Component, DebugElement, NO_ERRORS_SCHEMA, OnInit } from '@angular/core';
|
||||
import { DSpaceObjectType } from '../../../core/shared/dspace-object-type.model';
|
||||
import { RemoteData } from '../../../core/data/remote-data';
|
||||
import { Item } from '../../../core/shared/item.model';
|
||||
import { of as observableOf } from 'rxjs';
|
||||
import {
|
||||
DSOSelectorModalWrapperComponent,
|
||||
SelectorActionType
|
||||
} from './dso-selector-modal-wrapper.component';
|
||||
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { DSpaceObject } from '../../../core/shared/dspace-object.model';
|
||||
import { first } from 'rxjs/operators';
|
||||
import { By } from '@angular/platform-browser';
|
||||
import { DSOSelectorComponent } from '../dso-selector/dso-selector.component';
|
||||
import { MockComponent } from 'ng-mocks';
|
||||
|
||||
describe('DSOSelectorModalWrapperComponent', () => {
|
||||
let component: DSOSelectorModalWrapperComponent;
|
||||
let fixture: ComponentFixture<DSOSelectorModalWrapperComponent>;
|
||||
let debugElement: DebugElement;
|
||||
|
||||
const item = new Item();
|
||||
item.uuid = '1234-1234-1234-1234';
|
||||
item.metadata = { 'dc.title': [{ value: 'Item title', language: undefined }] };
|
||||
|
||||
const itemRD = new RemoteData(false, false, true, undefined, item);
|
||||
const modalStub = jasmine.createSpyObj('modalStub', ['close']);
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [TranslateModule.forRoot()],
|
||||
declarations: [TestComponent, MockComponent(DSOSelectorComponent)],
|
||||
providers: [
|
||||
{ provide: NgbActiveModal, useValue: modalStub },
|
||||
{
|
||||
provide: ActivatedRoute,
|
||||
useValue: { root: { firstChild: { firstChild: { data: observableOf({ item: itemRD }) } } } }
|
||||
}
|
||||
],
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
}).compileComponents();
|
||||
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(TestComponent);
|
||||
component = fixture.componentInstance;
|
||||
debugElement = fixture.debugElement;
|
||||
fixture.detectChanges();
|
||||
component.ngOnInit();
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should initially set the DSO to the activated route\'s item/collection/community', () => {
|
||||
component.dsoRD$
|
||||
.pipe(first())
|
||||
.subscribe((a) => {
|
||||
expect(a).toEqual(itemRD);
|
||||
})
|
||||
});
|
||||
|
||||
describe('selectObject', () => {
|
||||
beforeEach(() => {
|
||||
spyOn(component, 'navigate');
|
||||
spyOn(component, 'close');
|
||||
component.selectObject(item)
|
||||
});
|
||||
it('should call the close and navigate method on the component with the given DSO', () => {
|
||||
expect(component.close).toHaveBeenCalled();
|
||||
expect(component.navigate).toHaveBeenCalledWith(item);
|
||||
});
|
||||
});
|
||||
|
||||
describe('close', () => {
|
||||
beforeEach(() => {
|
||||
component.close();
|
||||
});
|
||||
it('should call the close method on the æctive modal', () => {
|
||||
expect(modalStub.close).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('when the onSelect method emits on the child component', () => {
|
||||
beforeEach(() => {
|
||||
spyOn(component, 'selectObject');
|
||||
debugElement.query(By.css('ds-dso-selector')).componentInstance.onSelect.emit(item);
|
||||
fixture.detectChanges();
|
||||
});
|
||||
it('should call the selectObject method on the component with the correct object', () => {
|
||||
expect(component.selectObject).toHaveBeenCalledWith(item);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when the click method emits on close button', () => {
|
||||
beforeEach(() => {
|
||||
spyOn(component, 'close');
|
||||
debugElement.query(By.css('button.close')).triggerEventHandler('click', {});
|
||||
fixture.detectChanges();
|
||||
});
|
||||
it('should call the close method on the component', () => {
|
||||
expect(component.close).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@Component({
|
||||
selector: 'ds-test-cmp',
|
||||
templateUrl: './dso-selector-modal-wrapper.component.html'
|
||||
})
|
||||
class TestComponent extends DSOSelectorModalWrapperComponent implements OnInit {
|
||||
objectType = DSpaceObjectType.ITEM;
|
||||
selectorType = DSpaceObjectType.ITEM;
|
||||
action = SelectorActionType.EDIT;
|
||||
|
||||
constructor(protected activeModal: NgbActiveModal, protected route: ActivatedRoute) {
|
||||
super(activeModal, route);
|
||||
}
|
||||
|
||||
navigate(dso: DSpaceObject) {
|
||||
}
|
||||
}
|
@@ -1,4 +1,4 @@
|
||||
import { Component, Input, OnInit } from '@angular/core';
|
||||
import { Component, Injectable, Input, OnInit } from '@angular/core';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { Observable } from 'rxjs';
|
||||
import { DSpaceObject } from '../../../core/shared/dspace-object.model';
|
||||
@@ -10,33 +10,59 @@ import { DSpaceObjectType } from '../../../core/shared/dspace-object-type.model'
|
||||
export enum SelectorActionType {
|
||||
CREATE = 'create',
|
||||
EDIT = 'edit'
|
||||
};
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'ds-dso-selector-modal-wrapper',
|
||||
templateUrl: './dso-selector-modal-wrapper.component.html',
|
||||
})
|
||||
@Injectable()
|
||||
export abstract class DSOSelectorModalWrapperComponent implements OnInit {
|
||||
/**
|
||||
* The current page's DSO
|
||||
*/
|
||||
@Input() dsoRD$: Observable<RemoteData<DSpaceObject>>;
|
||||
|
||||
/**
|
||||
* The type of the DSO that's being edited or created
|
||||
*/
|
||||
objectType: DSpaceObjectType;
|
||||
|
||||
/**
|
||||
* The type of DSO that can be selected from this list
|
||||
*/
|
||||
selectorType: DSpaceObjectType;
|
||||
|
||||
/**
|
||||
* The type of action to perform
|
||||
*/
|
||||
action: SelectorActionType;
|
||||
|
||||
constructor(protected activeModal: NgbActiveModal, protected route: ActivatedRoute) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get de current page's DSO based on the selectorType
|
||||
*/
|
||||
ngOnInit(): void {
|
||||
const typeString = this.selectorType.toString().toLowerCase();
|
||||
this.dsoRD$ = this.route.root.firstChild.firstChild.data.pipe(map(data => data[typeString]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Method called when an object has been selected
|
||||
* @param dso The selected DSpaceObject
|
||||
*/
|
||||
selectObject(dso: DSpaceObject) {
|
||||
this.close();
|
||||
this.navigate(dso);
|
||||
}
|
||||
|
||||
/**
|
||||
* Navigate to a page based on the DSpaceObject provided
|
||||
* @param dso The DSpaceObject which can be used to calculate the page to navigate to
|
||||
*/
|
||||
abstract navigate(dso: DSpaceObject);
|
||||
|
||||
/**
|
||||
* Close the modal
|
||||
*/
|
||||
close() {
|
||||
this.activeModal.close();
|
||||
}
|
||||
|
@@ -0,0 +1,65 @@
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { DebugElement, NO_ERRORS_SCHEMA } from '@angular/core';
|
||||
import { of as observableOf } from 'rxjs';
|
||||
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { RemoteData } from '../../../../core/data/remote-data';
|
||||
import { RouterStub } from '../../../testing/router-stub';
|
||||
import * as collectionRouter from '../../../../+collection-page/collection-page-routing.module';
|
||||
import { EditCollectionSelectorComponent } from './edit-collection-selector.component';
|
||||
import { Collection } from '../../../../core/shared/collection.model';
|
||||
|
||||
describe('EditCollectionSelectorComponent', () => {
|
||||
let component: EditCollectionSelectorComponent;
|
||||
let fixture: ComponentFixture<EditCollectionSelectorComponent>;
|
||||
let debugElement: DebugElement;
|
||||
|
||||
const collection = new Collection();
|
||||
collection.uuid = '1234-1234-1234-1234';
|
||||
collection.metadata = { 'dc.title': [{ value: 'Collection title', language: undefined }] };
|
||||
const router = new RouterStub();
|
||||
const collectionRD = new RemoteData(false, false, true, undefined, collection);
|
||||
const modalStub = jasmine.createSpyObj('modalStub', ['close']);
|
||||
const editPath = 'testEditPath';
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [TranslateModule.forRoot()],
|
||||
declarations: [EditCollectionSelectorComponent],
|
||||
providers: [
|
||||
{ provide: NgbActiveModal, useValue: modalStub },
|
||||
{
|
||||
provide: ActivatedRoute,
|
||||
useValue: { root: { firstChild: { firstChild: { data: observableOf({ collection: collectionRD }) } } } }
|
||||
},
|
||||
{
|
||||
provide: Router, useValue: router
|
||||
}
|
||||
],
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
}).compileComponents();
|
||||
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
spyOnProperty(collectionRouter, 'getCollectionEditPath').and.callFake(() => {
|
||||
return () => editPath;
|
||||
});
|
||||
|
||||
fixture = TestBed.createComponent(EditCollectionSelectorComponent);
|
||||
component = fixture.componentInstance;
|
||||
debugElement = fixture.debugElement;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should call navigate on the router with the correct edit path when navigate is called', () => {
|
||||
component.navigate(collection);
|
||||
expect(router.navigate).toHaveBeenCalledWith([editPath]);
|
||||
});
|
||||
|
||||
});
|
@@ -0,0 +1,65 @@
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { DebugElement, NO_ERRORS_SCHEMA } from '@angular/core';
|
||||
import { of as observableOf } from 'rxjs';
|
||||
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { RemoteData } from '../../../../core/data/remote-data';
|
||||
import { RouterStub } from '../../../testing/router-stub';
|
||||
import * as communityRouter from '../../../../+community-page/community-page-routing.module';
|
||||
import { EditCommunitySelectorComponent } from './edit-community-selector.component';
|
||||
import { Community } from '../../../../core/shared/community.model';
|
||||
|
||||
describe('EditCommunitySelectorComponent', () => {
|
||||
let component: EditCommunitySelectorComponent;
|
||||
let fixture: ComponentFixture<EditCommunitySelectorComponent>;
|
||||
let debugElement: DebugElement;
|
||||
|
||||
const community = new Community();
|
||||
community.uuid = '1234-1234-1234-1234';
|
||||
community.metadata = { 'dc.title': [{ value: 'Community title', language: undefined }] };
|
||||
const router = new RouterStub();
|
||||
const communityRD = new RemoteData(false, false, true, undefined, community);
|
||||
const modalStub = jasmine.createSpyObj('modalStub', ['close']);
|
||||
const editPath = 'testEditPath';
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [TranslateModule.forRoot()],
|
||||
declarations: [EditCommunitySelectorComponent],
|
||||
providers: [
|
||||
{ provide: NgbActiveModal, useValue: modalStub },
|
||||
{
|
||||
provide: ActivatedRoute,
|
||||
useValue: { root: { firstChild: { firstChild: { data: observableOf({ community: communityRD }) } } } }
|
||||
},
|
||||
{
|
||||
provide: Router, useValue: router
|
||||
}
|
||||
],
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
}).compileComponents();
|
||||
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
spyOnProperty(communityRouter, 'getCommunityEditPath').and.callFake(() => {
|
||||
return () => editPath;
|
||||
});
|
||||
|
||||
fixture = TestBed.createComponent(EditCommunitySelectorComponent);
|
||||
component = fixture.componentInstance;
|
||||
debugElement = fixture.debugElement;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should call navigate on the router with the correct edit path when navigate is called', () => {
|
||||
component.navigate(community);
|
||||
expect(router.navigate).toHaveBeenCalledWith([editPath]);
|
||||
});
|
||||
|
||||
});
|
@@ -0,0 +1,65 @@
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { DebugElement, NO_ERRORS_SCHEMA } from '@angular/core';
|
||||
import { of as observableOf } from 'rxjs';
|
||||
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { EditItemSelectorComponent } from './edit-item-selector.component';
|
||||
import { Item } from '../../../../core/shared/item.model';
|
||||
import { RemoteData } from '../../../../core/data/remote-data';
|
||||
import { RouterStub } from '../../../testing/router-stub';
|
||||
import * as itemRouter from '../../../../+item-page/item-page-routing.module';
|
||||
|
||||
describe('EditItemSelectorComponent', () => {
|
||||
let component: EditItemSelectorComponent;
|
||||
let fixture: ComponentFixture<EditItemSelectorComponent>;
|
||||
let debugElement: DebugElement;
|
||||
|
||||
const item = new Item();
|
||||
item.uuid = '1234-1234-1234-1234';
|
||||
item.metadata = { 'dc.title': [{ value: 'Item title', language: undefined }] };
|
||||
const router = new RouterStub();
|
||||
const itemRD = new RemoteData(false, false, true, undefined, item);
|
||||
const modalStub = jasmine.createSpyObj('modalStub', ['close']);
|
||||
const editPath = 'testEditPath';
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [TranslateModule.forRoot()],
|
||||
declarations: [EditItemSelectorComponent],
|
||||
providers: [
|
||||
{ provide: NgbActiveModal, useValue: modalStub },
|
||||
{
|
||||
provide: ActivatedRoute,
|
||||
useValue: { root: { firstChild: { firstChild: { data: observableOf({ item: itemRD }) } } } }
|
||||
},
|
||||
{
|
||||
provide: Router, useValue: router
|
||||
}
|
||||
],
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
}).compileComponents();
|
||||
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
spyOnProperty(itemRouter, 'getItemEditPath').and.callFake(() => {
|
||||
return () => editPath;
|
||||
});
|
||||
|
||||
fixture = TestBed.createComponent(EditItemSelectorComponent);
|
||||
component = fixture.componentInstance;
|
||||
debugElement = fixture.debugElement;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should call navigate on the router with the correct edit path when navigate is called', () => {
|
||||
component.navigate(item);
|
||||
expect(router.navigate).toHaveBeenCalledWith([editPath]);
|
||||
});
|
||||
|
||||
});
|
@@ -0,0 +1,51 @@
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { TextMenuItemComponent } from './text-menu-item.component';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { DebugElement, NO_ERRORS_SCHEMA } from '@angular/core';
|
||||
import { By } from '@angular/platform-browser';
|
||||
import { OnClickMenuItemComponent } from './onclick-menu-item.component';
|
||||
import { OnClickMenuItemModel } from './models/onclick.model';
|
||||
|
||||
describe('OnClickMenuItemComponent', () => {
|
||||
let component: OnClickMenuItemComponent;
|
||||
let fixture: ComponentFixture<OnClickMenuItemComponent>;
|
||||
let debugElement: DebugElement;
|
||||
const text = 'HELLO';
|
||||
const func = () => {
|
||||
};
|
||||
const item = Object.assign(new OnClickMenuItemModel(), { text, function: func });
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [TranslateModule.forRoot()],
|
||||
declarations: [OnClickMenuItemComponent],
|
||||
providers: [
|
||||
{ provide: 'itemModelProvider', useValue: item },
|
||||
],
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
})
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
spyOn(item, 'function');
|
||||
fixture = TestBed.createComponent(OnClickMenuItemComponent);
|
||||
component = fixture.componentInstance;
|
||||
debugElement = fixture.debugElement;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should contain the correct text', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should contain the text element', () => {
|
||||
const textContent = debugElement.query(By.css('a')).nativeElement.textContent;
|
||||
expect(textContent).toEqual(text);
|
||||
});
|
||||
|
||||
it('should contain call the function on the item when clicked', () => {
|
||||
debugElement.query(By.css('a.nav-link')).triggerEventHandler('click', {});
|
||||
expect(item.function).toHaveBeenCalled();
|
||||
});
|
||||
});
|
@@ -1,11 +1,10 @@
|
||||
import { Component, Inject } from '@angular/core';
|
||||
import { MenuItemType } from '../initial-menus-state';
|
||||
import { rendersMenuItemForType } from '../menu-item.decorator';
|
||||
import { GLOBAL_CONFIG, GlobalConfig } from '../../../../config';
|
||||
import { OnClickMenuItemModel } from './models/onclick.model';
|
||||
|
||||
/**
|
||||
* Component that renders a menu section of type LINK
|
||||
* Component that renders a menu section of type ONCLICK
|
||||
*/
|
||||
@Component({
|
||||
selector: 'ds-onclick-menu-item',
|
||||
@@ -14,7 +13,7 @@ import { OnClickMenuItemModel } from './models/onclick.model';
|
||||
@rendersMenuItemForType(MenuItemType.ONCLICK)
|
||||
export class OnClickMenuItemComponent {
|
||||
item: OnClickMenuItemModel;
|
||||
constructor(@Inject('itemModelProvider') item: OnClickMenuItemModel, @Inject(GLOBAL_CONFIG) private EnvConfig: GlobalConfig) {
|
||||
constructor(@Inject('itemModelProvider') item: OnClickMenuItemModel) {
|
||||
this.item = item;
|
||||
}
|
||||
}
|
||||
|
@@ -102,9 +102,10 @@ import { CreateCollectionParentSelectorComponent } from './dso-selector/modal-wr
|
||||
import { CommunitySearchResultListElementComponent } from './object-list/search-result-list-element/community-search-result/community-search-result-list-element.component';
|
||||
import { CollectionSearchResultListElementComponent } from './object-list/search-result-list-element/collection-search-result/collection-search-result-list-element.component';
|
||||
import { ItemSearchResultListElementComponent } from './object-list/search-result-list-element/item-search-result/item-search-result-list-element.component';
|
||||
import { EditItemSelectorComponent } from './dso-selector/modal-wrappers/edit-item-parent-selector/edit-item-selector.component';
|
||||
import { EditCommunitySelectorComponent } from './dso-selector/modal-wrappers/edit-community-parent-selector/edit-community-selector.component';
|
||||
import { EditCollectionSelectorComponent } from './dso-selector/modal-wrappers/edit-collection-parent-selector/edit-collection-selector.component';
|
||||
import { EditItemSelectorComponent } from './dso-selector/modal-wrappers/edit-item-selector/edit-item-selector.component';
|
||||
import { EditCommunitySelectorComponent } from './dso-selector/modal-wrappers/edit-community-selector/edit-community-selector.component';
|
||||
import { EditCollectionSelectorComponent } from './dso-selector/modal-wrappers/edit-collection-selector/edit-collection-selector.component';
|
||||
import { DSOSelectorModalWrapperComponent } from './dso-selector/modal-wrappers/dso-selector-modal-wrapper.component';
|
||||
|
||||
const MODULES = [
|
||||
// Do NOT include UniversalModule, HttpModule, or JsonpModule here
|
||||
|
Reference in New Issue
Block a user