mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
63669: Edit Col/Com Tabs Tests + JSDocs
This commit is contained in:
@@ -0,0 +1,39 @@
|
|||||||
|
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
import { TranslateModule } from '@ngx-translate/core';
|
||||||
|
import { SharedModule } from '../../../shared/shared.module';
|
||||||
|
import { CommonModule } from '@angular/common';
|
||||||
|
import { RouterTestingModule } from '@angular/router/testing';
|
||||||
|
import { CollectionDataService } from '../../../core/data/collection-data.service';
|
||||||
|
import { ActivatedRoute } from '@angular/router';
|
||||||
|
import { of as observableOf } from 'rxjs/internal/observable/of';
|
||||||
|
import { NO_ERRORS_SCHEMA } from '@angular/core';
|
||||||
|
import { CollectionMetadataComponent } from './collection-metadata.component';
|
||||||
|
|
||||||
|
describe('CollectionMetadataComponent', () => {
|
||||||
|
let comp: CollectionMetadataComponent;
|
||||||
|
let fixture: ComponentFixture<CollectionMetadataComponent>;
|
||||||
|
|
||||||
|
beforeEach(async(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
imports: [TranslateModule.forRoot(), SharedModule, CommonModule, RouterTestingModule],
|
||||||
|
declarations: [CollectionMetadataComponent],
|
||||||
|
providers: [
|
||||||
|
{ provide: CollectionDataService, useValue: {} },
|
||||||
|
{ provide: ActivatedRoute, useValue: { parent: { data: observableOf({ dso: { payload: {} } }) } } },
|
||||||
|
],
|
||||||
|
schemas: [NO_ERRORS_SCHEMA]
|
||||||
|
}).compileComponents();
|
||||||
|
}));
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
fixture = TestBed.createComponent(CollectionMetadataComponent);
|
||||||
|
comp = fixture.componentInstance;
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('frontendURL', () => {
|
||||||
|
it('should have the right frontendURL set', () => {
|
||||||
|
expect((comp as any).frontendURL).toEqual('/collections/');
|
||||||
|
})
|
||||||
|
});
|
||||||
|
});
|
@@ -13,13 +13,29 @@ describe('EditCollectionPageComponent', () => {
|
|||||||
let comp: EditCollectionPageComponent;
|
let comp: EditCollectionPageComponent;
|
||||||
let fixture: ComponentFixture<EditCollectionPageComponent>;
|
let fixture: ComponentFixture<EditCollectionPageComponent>;
|
||||||
|
|
||||||
|
const routeStub = {
|
||||||
|
data: observableOf({
|
||||||
|
dso: { payload: {} }
|
||||||
|
}),
|
||||||
|
routeConfig: {
|
||||||
|
children: []
|
||||||
|
},
|
||||||
|
snapshot: {
|
||||||
|
firstChild: {
|
||||||
|
routeConfig: {
|
||||||
|
path: 'mockUrl'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
beforeEach(async(() => {
|
beforeEach(async(() => {
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
imports: [TranslateModule.forRoot(), SharedModule, CommonModule, RouterTestingModule],
|
imports: [TranslateModule.forRoot(), SharedModule, CommonModule, RouterTestingModule],
|
||||||
declarations: [EditCollectionPageComponent],
|
declarations: [EditCollectionPageComponent],
|
||||||
providers: [
|
providers: [
|
||||||
{ provide: CollectionDataService, useValue: {} },
|
{ provide: CollectionDataService, useValue: {} },
|
||||||
{ provide: ActivatedRoute, useValue: { data: observableOf({ dso: { payload: {} } }) } },
|
{ provide: ActivatedRoute, useValue: routeStub },
|
||||||
],
|
],
|
||||||
schemas: [NO_ERRORS_SCHEMA]
|
schemas: [NO_ERRORS_SCHEMA]
|
||||||
}).compileComponents();
|
}).compileComponents();
|
||||||
@@ -31,9 +47,9 @@ describe('EditCollectionPageComponent', () => {
|
|||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('frontendURL', () => {
|
describe('type', () => {
|
||||||
it('should have the right frontendURL set', () => {
|
it('should have the right type set', () => {
|
||||||
expect((comp as any).frontendURL).toEqual('/collections/');
|
expect((comp as any).type).toEqual('collection');
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -0,0 +1,39 @@
|
|||||||
|
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
import { TranslateModule } from '@ngx-translate/core';
|
||||||
|
import { SharedModule } from '../../../shared/shared.module';
|
||||||
|
import { CommonModule } from '@angular/common';
|
||||||
|
import { RouterTestingModule } from '@angular/router/testing';
|
||||||
|
import { ActivatedRoute } from '@angular/router';
|
||||||
|
import { of as observableOf } from 'rxjs/internal/observable/of';
|
||||||
|
import { NO_ERRORS_SCHEMA } from '@angular/core';
|
||||||
|
import { CommunityMetadataComponent } from './community-metadata.component';
|
||||||
|
import { CommunityDataService } from '../../../core/data/community-data.service';
|
||||||
|
|
||||||
|
describe('CommunityMetadataComponent', () => {
|
||||||
|
let comp: CommunityMetadataComponent;
|
||||||
|
let fixture: ComponentFixture<CommunityMetadataComponent>;
|
||||||
|
|
||||||
|
beforeEach(async(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
imports: [TranslateModule.forRoot(), SharedModule, CommonModule, RouterTestingModule],
|
||||||
|
declarations: [CommunityMetadataComponent],
|
||||||
|
providers: [
|
||||||
|
{ provide: CommunityDataService, useValue: {} },
|
||||||
|
{ provide: ActivatedRoute, useValue: { parent: { data: observableOf({ dso: { payload: {} } }) } } },
|
||||||
|
],
|
||||||
|
schemas: [NO_ERRORS_SCHEMA]
|
||||||
|
}).compileComponents();
|
||||||
|
}));
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
fixture = TestBed.createComponent(CommunityMetadataComponent);
|
||||||
|
comp = fixture.componentInstance;
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('frontendURL', () => {
|
||||||
|
it('should have the right frontendURL set', () => {
|
||||||
|
expect((comp as any).frontendURL).toEqual('/communities/');
|
||||||
|
})
|
||||||
|
});
|
||||||
|
});
|
@@ -13,13 +13,29 @@ describe('EditCommunityPageComponent', () => {
|
|||||||
let comp: EditCommunityPageComponent;
|
let comp: EditCommunityPageComponent;
|
||||||
let fixture: ComponentFixture<EditCommunityPageComponent>;
|
let fixture: ComponentFixture<EditCommunityPageComponent>;
|
||||||
|
|
||||||
|
const routeStub = {
|
||||||
|
data: observableOf({
|
||||||
|
dso: { payload: {} }
|
||||||
|
}),
|
||||||
|
routeConfig: {
|
||||||
|
children: []
|
||||||
|
},
|
||||||
|
snapshot: {
|
||||||
|
firstChild: {
|
||||||
|
routeConfig: {
|
||||||
|
path: 'mockUrl'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
beforeEach(async(() => {
|
beforeEach(async(() => {
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
imports: [TranslateModule.forRoot(), SharedModule, CommonModule, RouterTestingModule],
|
imports: [TranslateModule.forRoot(), SharedModule, CommonModule, RouterTestingModule],
|
||||||
declarations: [EditCommunityPageComponent],
|
declarations: [EditCommunityPageComponent],
|
||||||
providers: [
|
providers: [
|
||||||
{ provide: CommunityDataService, useValue: {} },
|
{ provide: CommunityDataService, useValue: {} },
|
||||||
{ provide: ActivatedRoute, useValue: { data: observableOf({ dso: { payload: {} } }) } },
|
{ provide: ActivatedRoute, useValue: routeStub },
|
||||||
],
|
],
|
||||||
schemas: [NO_ERRORS_SCHEMA]
|
schemas: [NO_ERRORS_SCHEMA]
|
||||||
}).compileComponents();
|
}).compileComponents();
|
||||||
@@ -31,9 +47,9 @@ describe('EditCommunityPageComponent', () => {
|
|||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('frontendURL', () => {
|
describe('type', () => {
|
||||||
it('should have the right frontendURL set', () => {
|
it('should have the right type set', () => {
|
||||||
expect((comp as any).frontendURL).toEqual('/communities/');
|
expect((comp as any).type).toEqual('community');
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -0,0 +1,108 @@
|
|||||||
|
import { DSpaceObject } from '../../../../core/shared/dspace-object.model';
|
||||||
|
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
import { CommunityDataService } from '../../../../core/data/community-data.service';
|
||||||
|
import { ActivatedRoute, Router } from '@angular/router';
|
||||||
|
import { Community } from '../../../../core/shared/community.model';
|
||||||
|
import { of as observableOf } from 'rxjs/internal/observable/of';
|
||||||
|
import { RemoteData } from '../../../../core/data/remote-data';
|
||||||
|
import { TranslateModule } from '@ngx-translate/core';
|
||||||
|
import { SharedModule } from '../../../shared.module';
|
||||||
|
import { CommonModule } from '@angular/common';
|
||||||
|
import { RouterTestingModule } from '@angular/router/testing';
|
||||||
|
import { DataService } from '../../../../core/data/data.service';
|
||||||
|
import { NO_ERRORS_SCHEMA } from '@angular/core';
|
||||||
|
import { ComcolMetadataComponent } from './comcol-metadata.component';
|
||||||
|
|
||||||
|
describe('ComColMetadataComponent', () => {
|
||||||
|
let comp: ComcolMetadataComponent<DSpaceObject>;
|
||||||
|
let fixture: ComponentFixture<ComcolMetadataComponent<DSpaceObject>>;
|
||||||
|
let dsoDataService: CommunityDataService;
|
||||||
|
let router: Router;
|
||||||
|
|
||||||
|
let community;
|
||||||
|
let newCommunity;
|
||||||
|
let communityDataServiceStub;
|
||||||
|
let routerStub;
|
||||||
|
let routeStub;
|
||||||
|
|
||||||
|
function initializeVars() {
|
||||||
|
community = Object.assign(new Community(), {
|
||||||
|
uuid: 'a20da287-e174-466a-9926-f66b9300d347',
|
||||||
|
metadata: [{
|
||||||
|
key: 'dc.title',
|
||||||
|
value: 'test community'
|
||||||
|
}]
|
||||||
|
});
|
||||||
|
|
||||||
|
newCommunity = Object.assign(new Community(), {
|
||||||
|
uuid: '1ff59938-a69a-4e62-b9a4-718569c55d48',
|
||||||
|
metadata: [{
|
||||||
|
key: 'dc.title',
|
||||||
|
value: 'new community'
|
||||||
|
}]
|
||||||
|
});
|
||||||
|
|
||||||
|
communityDataServiceStub = {
|
||||||
|
update: (com, uuid?) => observableOf(new RemoteData(false, false, true, undefined, newCommunity))
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
routerStub = {
|
||||||
|
navigate: (commands) => commands
|
||||||
|
};
|
||||||
|
|
||||||
|
routeStub = {
|
||||||
|
parent: {
|
||||||
|
data: observableOf(community)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
beforeEach(async(() => {
|
||||||
|
initializeVars();
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
imports: [TranslateModule.forRoot(), SharedModule, CommonModule, RouterTestingModule],
|
||||||
|
providers: [
|
||||||
|
{ provide: DataService, useValue: communityDataServiceStub },
|
||||||
|
{ provide: Router, useValue: routerStub },
|
||||||
|
{ provide: ActivatedRoute, useValue: routeStub },
|
||||||
|
],
|
||||||
|
schemas: [NO_ERRORS_SCHEMA]
|
||||||
|
}).compileComponents();
|
||||||
|
}));
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
fixture = TestBed.createComponent(ComcolMetadataComponent);
|
||||||
|
comp = fixture.componentInstance;
|
||||||
|
fixture.detectChanges();
|
||||||
|
dsoDataService = (comp as any).dsoDataService;
|
||||||
|
router = (comp as any).router;
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('onSubmit', () => {
|
||||||
|
let data;
|
||||||
|
beforeEach(() => {
|
||||||
|
data = Object.assign(new Community(), {
|
||||||
|
metadata: [{
|
||||||
|
key: 'dc.title',
|
||||||
|
value: 'test'
|
||||||
|
}]
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('should navigate when successful', () => {
|
||||||
|
spyOn(router, 'navigate');
|
||||||
|
comp.onSubmit(data);
|
||||||
|
fixture.detectChanges();
|
||||||
|
expect(router.navigate).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not navigate on failure', () => {
|
||||||
|
spyOn(router, 'navigate');
|
||||||
|
spyOn(dsoDataService, 'update').and.returnValue(observableOf(new RemoteData(true, true, false, undefined, newCommunity)));
|
||||||
|
comp.onSubmit(data);
|
||||||
|
fixture.detectChanges();
|
||||||
|
expect(router.navigate).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
@@ -1,9 +1,7 @@
|
|||||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
import { CommunityDataService } from '../../../core/data/community-data.service';
|
|
||||||
import { ActivatedRoute, Router } from '@angular/router';
|
import { ActivatedRoute, Router } from '@angular/router';
|
||||||
import { TranslateModule } from '@ngx-translate/core';
|
import { TranslateModule } from '@ngx-translate/core';
|
||||||
import { of as observableOf } from 'rxjs';
|
import { of as observableOf } from 'rxjs';
|
||||||
import { RemoteData } from '../../../core/data/remote-data';
|
|
||||||
import { Community } from '../../../core/shared/community.model';
|
import { Community } from '../../../core/shared/community.model';
|
||||||
import { SharedModule } from '../../shared.module';
|
import { SharedModule } from '../../shared.module';
|
||||||
import { CommonModule } from '@angular/common';
|
import { CommonModule } from '@angular/common';
|
||||||
@@ -11,17 +9,13 @@ import { RouterTestingModule } from '@angular/router/testing';
|
|||||||
import { NO_ERRORS_SCHEMA } from '@angular/core';
|
import { NO_ERRORS_SCHEMA } from '@angular/core';
|
||||||
import { DSpaceObject } from '../../../core/shared/dspace-object.model';
|
import { DSpaceObject } from '../../../core/shared/dspace-object.model';
|
||||||
import { EditComColPageComponent } from './edit-comcol-page.component';
|
import { EditComColPageComponent } from './edit-comcol-page.component';
|
||||||
import { DataService } from '../../../core/data/data.service';
|
|
||||||
|
|
||||||
describe('EditComColPageComponent', () => {
|
describe('EditComColPageComponent', () => {
|
||||||
let comp: EditComColPageComponent<DSpaceObject>;
|
let comp: EditComColPageComponent<DSpaceObject>;
|
||||||
let fixture: ComponentFixture<EditComColPageComponent<DSpaceObject>>;
|
let fixture: ComponentFixture<EditComColPageComponent<DSpaceObject>>;
|
||||||
let dsoDataService: CommunityDataService;
|
|
||||||
let router: Router;
|
let router: Router;
|
||||||
|
|
||||||
let community;
|
let community;
|
||||||
let newCommunity;
|
|
||||||
let communityDataServiceStub;
|
|
||||||
let routerStub;
|
let routerStub;
|
||||||
let routeStub;
|
let routeStub;
|
||||||
|
|
||||||
@@ -34,25 +28,26 @@ describe('EditComColPageComponent', () => {
|
|||||||
}]
|
}]
|
||||||
});
|
});
|
||||||
|
|
||||||
newCommunity = Object.assign(new Community(), {
|
|
||||||
uuid: '1ff59938-a69a-4e62-b9a4-718569c55d48',
|
|
||||||
metadata: [{
|
|
||||||
key: 'dc.title',
|
|
||||||
value: 'new community'
|
|
||||||
}]
|
|
||||||
});
|
|
||||||
|
|
||||||
communityDataServiceStub = {
|
|
||||||
update: (com, uuid?) => observableOf(new RemoteData(false, false, true, undefined, newCommunity))
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
routerStub = {
|
routerStub = {
|
||||||
navigate: (commands) => commands
|
navigate: (commands) => commands,
|
||||||
|
events: observableOf({}),
|
||||||
|
url: 'mockUrl'
|
||||||
};
|
};
|
||||||
|
|
||||||
routeStub = {
|
routeStub = {
|
||||||
data: observableOf(community)
|
data: observableOf({
|
||||||
|
dso: community
|
||||||
|
}),
|
||||||
|
routeConfig: {
|
||||||
|
children: []
|
||||||
|
},
|
||||||
|
snapshot: {
|
||||||
|
firstChild: {
|
||||||
|
routeConfig: {
|
||||||
|
path: 'mockUrl'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -62,7 +57,6 @@ describe('EditComColPageComponent', () => {
|
|||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
imports: [TranslateModule.forRoot(), SharedModule, CommonModule, RouterTestingModule],
|
imports: [TranslateModule.forRoot(), SharedModule, CommonModule, RouterTestingModule],
|
||||||
providers: [
|
providers: [
|
||||||
{ provide: DataService, useValue: communityDataServiceStub },
|
|
||||||
{ provide: Router, useValue: routerStub },
|
{ provide: Router, useValue: routerStub },
|
||||||
{ provide: ActivatedRoute, useValue: routeStub },
|
{ provide: ActivatedRoute, useValue: routeStub },
|
||||||
],
|
],
|
||||||
@@ -74,33 +68,16 @@ describe('EditComColPageComponent', () => {
|
|||||||
fixture = TestBed.createComponent(EditComColPageComponent);
|
fixture = TestBed.createComponent(EditComColPageComponent);
|
||||||
comp = fixture.componentInstance;
|
comp = fixture.componentInstance;
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
dsoDataService = (comp as any).dsoDataService;
|
|
||||||
router = (comp as any).router;
|
router = (comp as any).router;
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('onSubmit', () => {
|
describe('getPageUrl', () => {
|
||||||
let data;
|
let url;
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
data = Object.assign(new Community(), {
|
url = comp.getPageUrl(community);
|
||||||
metadata: [{
|
|
||||||
key: 'dc.title',
|
|
||||||
value: 'test'
|
|
||||||
}]
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
it('should navigate when successful', () => {
|
it('should return the current url as a fallback', () => {
|
||||||
spyOn(router, 'navigate');
|
expect(url).toEqual(routerStub.url);
|
||||||
comp.onSubmit(data);
|
|
||||||
fixture.detectChanges();
|
|
||||||
expect(router.navigate).toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should not navigate on failure', () => {
|
|
||||||
spyOn(router, 'navigate');
|
|
||||||
spyOn(dsoDataService, 'update').and.returnValue(observableOf(new RemoteData(true, true, false, undefined, newCommunity)));
|
|
||||||
comp.onSubmit(data);
|
|
||||||
fixture.detectChanges();
|
|
||||||
expect(router.navigate).not.toHaveBeenCalled();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -13,7 +13,7 @@ import { DSpaceObject } from '../../../core/shared/dspace-object.model';
|
|||||||
*/
|
*/
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'ds-edit-comcol',
|
selector: 'ds-edit-comcol',
|
||||||
templateUrl: './edit-comcol-page.component.html'
|
template: ''
|
||||||
})
|
})
|
||||||
export class EditComColPageComponent<TDomain extends DSpaceObject> implements OnInit {
|
export class EditComColPageComponent<TDomain extends DSpaceObject> implements OnInit {
|
||||||
/**
|
/**
|
||||||
@@ -31,6 +31,9 @@ export class EditComColPageComponent<TDomain extends DSpaceObject> implements On
|
|||||||
*/
|
*/
|
||||||
public pages: string[];
|
public pages: string[];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The DSO to render the edit page for
|
||||||
|
*/
|
||||||
public dsoRD$: Observable<RemoteData<TDomain>>;
|
public dsoRD$: Observable<RemoteData<TDomain>>;
|
||||||
|
|
||||||
public constructor(
|
public constructor(
|
||||||
|
Reference in New Issue
Block a user