mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-14 05:23:06 +00:00
Added tests/type doc
This commit is contained in:
@@ -7,7 +7,7 @@ import { CreateCollectionPageComponent } from './create-collection-page/create-c
|
|||||||
import { AuthenticatedGuard } from '../core/auth/authenticated.guard';
|
import { AuthenticatedGuard } from '../core/auth/authenticated.guard';
|
||||||
import { EditCollectionPageComponent } from './edit-collection-page/edit-collection-page.component';
|
import { EditCollectionPageComponent } from './edit-collection-page/edit-collection-page.component';
|
||||||
import { CreateCollectionPageGuard } from './create-collection-page/create-collection-page.guard';
|
import { CreateCollectionPageGuard } from './create-collection-page/create-collection-page.guard';
|
||||||
import { DeleteCollectionPageComponent } from './delete-collection-page/delete-community-page.component';
|
import { DeleteCollectionPageComponent } from './delete-collection-page/delete-collection-page.component';
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
imports: [
|
imports: [
|
||||||
|
@@ -9,7 +9,7 @@ import { CreateCollectionPageComponent } from './create-collection-page/create-c
|
|||||||
import { CollectionFormComponent } from './collection-form/collection-form.component';
|
import { CollectionFormComponent } from './collection-form/collection-form.component';
|
||||||
import { SearchPageModule } from '../+search-page/search-page.module';
|
import { SearchPageModule } from '../+search-page/search-page.module';
|
||||||
import { EditCollectionPageComponent } from './edit-collection-page/edit-collection-page.component';
|
import { EditCollectionPageComponent } from './edit-collection-page/edit-collection-page.component';
|
||||||
import { DeleteCollectionPageComponent } from './delete-collection-page/delete-community-page.component';
|
import { DeleteCollectionPageComponent } from './delete-collection-page/delete-collection-page.component';
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
imports: [
|
imports: [
|
||||||
|
@@ -11,7 +11,7 @@ import { Collection } from '../../core/shared/collection.model';
|
|||||||
import { TranslateService } from '@ngx-translate/core';
|
import { TranslateService } from '@ngx-translate/core';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Component that represents the page where a user can edit an existing Community
|
* Component that represents the page where a user can delete an existing Collection
|
||||||
*/
|
*/
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'ds-delete-collection',
|
selector: 'ds-delete-collection',
|
@@ -8,7 +8,7 @@ import { NotificationsService } from '../../shared/notifications/notifications.s
|
|||||||
import { TranslateService } from '@ngx-translate/core';
|
import { TranslateService } from '@ngx-translate/core';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Component that represents the page where a user can edit an existing Community
|
* Component that represents the page where a user can delete an existing Community
|
||||||
*/
|
*/
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'ds-delete-community',
|
selector: 'ds-delete-community',
|
||||||
|
@@ -21,7 +21,7 @@ import { NormalizedDSpaceObject } from '../../../core/cache/models/normalized-ds
|
|||||||
})
|
})
|
||||||
export class CreateComColPageComponent<TDomain extends DSpaceObject, TNormalized extends NormalizedDSpaceObject> implements OnInit {
|
export class CreateComColPageComponent<TDomain extends DSpaceObject, TNormalized extends NormalizedDSpaceObject> implements OnInit {
|
||||||
/**
|
/**
|
||||||
* Frontend endpoint where for this type of DSP
|
* Frontend endpoint for this type of DSO
|
||||||
*/
|
*/
|
||||||
protected frontendURL: string;
|
protected frontendURL: string;
|
||||||
|
|
||||||
|
@@ -0,0 +1,154 @@
|
|||||||
|
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
import { CommunityDataService } from '../../../core/data/community-data.service';
|
||||||
|
import { ActivatedRoute, Router } from '@angular/router';
|
||||||
|
import { TranslateModule } from '@ngx-translate/core';
|
||||||
|
import { of as observableOf } from 'rxjs';
|
||||||
|
import { Community } from '../../../core/shared/community.model';
|
||||||
|
import { SharedModule } from '../../shared.module';
|
||||||
|
import { CommonModule } from '@angular/common';
|
||||||
|
import { RouterTestingModule } from '@angular/router/testing';
|
||||||
|
import { NO_ERRORS_SCHEMA } from '@angular/core';
|
||||||
|
import { DSpaceObject } from '../../../core/shared/dspace-object.model';
|
||||||
|
import { NormalizedDSpaceObject } from '../../../core/cache/models/normalized-dspace-object.model';
|
||||||
|
import { DataService } from '../../../core/data/data.service';
|
||||||
|
import { DeleteComColPageComponent } from './delete-comcol-page.component';
|
||||||
|
import { NotificationsService } from '../../notifications/notifications.service';
|
||||||
|
import { NotificationsServiceStub } from '../../testing/notifications-service-stub';
|
||||||
|
|
||||||
|
describe('DeleteComColPageComponent', () => {
|
||||||
|
let comp: DeleteComColPageComponent<DSpaceObject, NormalizedDSpaceObject>;
|
||||||
|
let fixture: ComponentFixture<DeleteComColPageComponent<DSpaceObject, NormalizedDSpaceObject>>;
|
||||||
|
let dsoDataService: CommunityDataService;
|
||||||
|
let router: Router;
|
||||||
|
|
||||||
|
let community;
|
||||||
|
let newCommunity;
|
||||||
|
let routerStub;
|
||||||
|
let routeStub;
|
||||||
|
let notificationsService;
|
||||||
|
const validUUID = 'valid-uuid';
|
||||||
|
const invalidUUID = 'invalid-uuid';
|
||||||
|
|
||||||
|
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'
|
||||||
|
}]
|
||||||
|
});
|
||||||
|
|
||||||
|
dsoDataService = jasmine.createSpyObj(
|
||||||
|
'dsoDataService',
|
||||||
|
{
|
||||||
|
delete: observableOf(true)
|
||||||
|
});
|
||||||
|
|
||||||
|
routerStub = {
|
||||||
|
navigate: (commands) => commands
|
||||||
|
};
|
||||||
|
|
||||||
|
routeStub = {
|
||||||
|
data: observableOf(community)
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
beforeEach(async(() => {
|
||||||
|
initializeVars();
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
imports: [TranslateModule.forRoot(), SharedModule, CommonModule, RouterTestingModule],
|
||||||
|
providers: [
|
||||||
|
{ provide: DataService, useValue: dsoDataService },
|
||||||
|
{ provide: Router, useValue: routerStub },
|
||||||
|
{ provide: ActivatedRoute, useValue: routeStub },
|
||||||
|
{ provide: NotificationsService, useValue: new NotificationsServiceStub() },
|
||||||
|
],
|
||||||
|
schemas: [NO_ERRORS_SCHEMA]
|
||||||
|
}).compileComponents();
|
||||||
|
}));
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
fixture = TestBed.createComponent(DeleteComColPageComponent);
|
||||||
|
comp = fixture.componentInstance;
|
||||||
|
fixture.detectChanges();
|
||||||
|
notificationsService = (comp as any).notifications;
|
||||||
|
router = (comp as any).router;
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('onConfirm', () => {
|
||||||
|
let data1;
|
||||||
|
let data2;
|
||||||
|
beforeEach(() => {
|
||||||
|
data1 = Object.assign(new Community(), {
|
||||||
|
uuid: validUUID,
|
||||||
|
metadata: [{
|
||||||
|
key: 'dc.title',
|
||||||
|
value: 'test'
|
||||||
|
}]
|
||||||
|
});
|
||||||
|
|
||||||
|
data2 = Object.assign(new Community(), {
|
||||||
|
uuid: invalidUUID,
|
||||||
|
metadata: [{
|
||||||
|
key: 'dc.title',
|
||||||
|
value: 'test'
|
||||||
|
}]
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should show an error notification on failure', () => {
|
||||||
|
(dsoDataService.delete as any).and.returnValue(observableOf(false));
|
||||||
|
spyOn(notificationsService, 'error');
|
||||||
|
spyOn(router, 'navigate');
|
||||||
|
comp.onConfirm(data2);
|
||||||
|
fixture.detectChanges();
|
||||||
|
expect(notificationsService.error).toHaveBeenCalled();
|
||||||
|
expect(router.navigate).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should show a success notification on success and navigate', () => {
|
||||||
|
spyOn(notificationsService, 'success');
|
||||||
|
spyOn(router, 'navigate');
|
||||||
|
comp.onConfirm(data1);
|
||||||
|
fixture.detectChanges();
|
||||||
|
expect(notificationsService.success).toHaveBeenCalled();
|
||||||
|
expect(router.navigate).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should call delete on the data service', () => {
|
||||||
|
comp.onConfirm(data1);
|
||||||
|
fixture.detectChanges();
|
||||||
|
expect(dsoDataService.delete).toHaveBeenCalledWith(data1);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('onCancel', () => {
|
||||||
|
let data1;
|
||||||
|
beforeEach(() => {
|
||||||
|
data1 = Object.assign(new Community(), {
|
||||||
|
uuid: validUUID,
|
||||||
|
metadata: [{
|
||||||
|
key: 'dc.title',
|
||||||
|
value: 'test'
|
||||||
|
}]
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should redirect to the edit page', () => {
|
||||||
|
const redirectURL = 'communities/edit/' + validUUID;
|
||||||
|
spyOn(router, 'navigate');
|
||||||
|
comp.onCancel(data1);
|
||||||
|
fixture.detectChanges();
|
||||||
|
expect(router.navigate).toHaveBeenCalledWith([redirectURL]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
@@ -13,7 +13,7 @@ import { NotificationsService } from '../../notifications/notifications.service'
|
|||||||
import { TranslateService } from '@ngx-translate/core';
|
import { TranslateService } from '@ngx-translate/core';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Component representing the edit page for communities and collections
|
* Component representing the delete page for communities and collections
|
||||||
*/
|
*/
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'ds-delete-comcol',
|
selector: 'ds-delete-comcol',
|
||||||
@@ -21,7 +21,7 @@ import { TranslateService } from '@ngx-translate/core';
|
|||||||
})
|
})
|
||||||
export class DeleteComColPageComponent<TDomain extends DSpaceObject, TNormalized extends NormalizedDSpaceObject> implements OnInit {
|
export class DeleteComColPageComponent<TDomain extends DSpaceObject, TNormalized extends NormalizedDSpaceObject> implements OnInit {
|
||||||
/**
|
/**
|
||||||
* Frontend endpoint where for this type of DSP
|
* Frontend endpoint for this type of DSO
|
||||||
*/
|
*/
|
||||||
protected frontendURL: string;
|
protected frontendURL: string;
|
||||||
/**
|
/**
|
||||||
@@ -44,7 +44,7 @@ export class DeleteComColPageComponent<TDomain extends DSpaceObject, TNormalized
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {TDomain} dso The DSO to delete
|
* @param {TDomain} dso The DSO to delete
|
||||||
* Deletes an existing DSO and redirects to the home page afterwards
|
* Deletes an existing DSO and redirects to the home page afterwards, showing a notification that states whether or not the deletion was successful
|
||||||
*/
|
*/
|
||||||
onConfirm(dso: TDomain) {
|
onConfirm(dso: TDomain) {
|
||||||
this.dsoDataService.delete(dso)
|
this.dsoDataService.delete(dso)
|
||||||
|
@@ -17,7 +17,6 @@ import { DataService } from '../../../core/data/data.service';
|
|||||||
describe('EditComColPageComponent', () => {
|
describe('EditComColPageComponent', () => {
|
||||||
let comp: EditComColPageComponent<DSpaceObject, NormalizedDSpaceObject>;
|
let comp: EditComColPageComponent<DSpaceObject, NormalizedDSpaceObject>;
|
||||||
let fixture: ComponentFixture<EditComColPageComponent<DSpaceObject, NormalizedDSpaceObject>>;
|
let fixture: ComponentFixture<EditComColPageComponent<DSpaceObject, NormalizedDSpaceObject>>;
|
||||||
let communityDataService: CommunityDataService;
|
|
||||||
let dsoDataService: CommunityDataService;
|
let dsoDataService: CommunityDataService;
|
||||||
let router: Router;
|
let router: Router;
|
||||||
|
|
||||||
@@ -45,13 +44,6 @@ describe('EditComColPageComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
communityDataServiceStub = {
|
communityDataServiceStub = {
|
||||||
findById: (uuid) => observableOf(new RemoteData(false, false, true, null, Object.assign(new Community(), {
|
|
||||||
uuid: uuid,
|
|
||||||
metadata: [{
|
|
||||||
key: 'dc.title',
|
|
||||||
value: community.name
|
|
||||||
}]
|
|
||||||
}))),
|
|
||||||
update: (com, uuid?) => observableOf(new RemoteData(false, false, true, undefined, newCommunity))
|
update: (com, uuid?) => observableOf(new RemoteData(false, false, true, undefined, newCommunity))
|
||||||
|
|
||||||
};
|
};
|
||||||
@@ -84,7 +76,6 @@ describe('EditComColPageComponent', () => {
|
|||||||
comp = fixture.componentInstance;
|
comp = fixture.componentInstance;
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
dsoDataService = (comp as any).dsoDataService;
|
dsoDataService = (comp as any).dsoDataService;
|
||||||
communityDataService = (comp as any).communityDataService;
|
|
||||||
router = (comp as any).router;
|
router = (comp as any).router;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -18,7 +18,7 @@ import { DSpaceObject } from '../../../core/shared/dspace-object.model';
|
|||||||
})
|
})
|
||||||
export class EditComColPageComponent<TDomain extends DSpaceObject, TNormalized extends NormalizedDSpaceObject> implements OnInit {
|
export class EditComColPageComponent<TDomain extends DSpaceObject, TNormalized extends NormalizedDSpaceObject> implements OnInit {
|
||||||
/**
|
/**
|
||||||
* Frontend endpoint where for this type of DSP
|
* Frontend endpoint for this type of DSO
|
||||||
*/
|
*/
|
||||||
protected frontendURL: string;
|
protected frontendURL: string;
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user