mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
Started fixing tests
This commit is contained in:
@@ -44,18 +44,20 @@
|
||||
"sub-community-list": {
|
||||
"head": "Communities of this Community"
|
||||
},
|
||||
"edit": {
|
||||
"head": "Edit collction",
|
||||
"name": "Name",
|
||||
"description": "Short Description",
|
||||
"introductory": "Introductory text (HTML)",
|
||||
"copyright": "Copyright text (HTML)",
|
||||
"news": "News (HTML)",
|
||||
"submit": "Submit",
|
||||
"cancel": "Cancel",
|
||||
"required": {
|
||||
"name": "Please enter a community name"
|
||||
"form": {
|
||||
"title": "Name",
|
||||
"description": "Introductory text (HTML)",
|
||||
"abstract": "Short Description",
|
||||
"rights": "Copyright text (HTML)",
|
||||
"tableofcontents": "News (HTML)",
|
||||
"errors": {
|
||||
"title": {
|
||||
"required": "Please enter a community name"
|
||||
}
|
||||
}
|
||||
},
|
||||
"edit": {
|
||||
"head": "Edit collection"
|
||||
},
|
||||
"create": {
|
||||
"head": "Create a Community",
|
||||
|
@@ -4,9 +4,10 @@ import { TranslateModule } from '@ngx-translate/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { RouterTestingModule } from '@angular/router/testing';
|
||||
import { By } from '@angular/platform-browser';
|
||||
import { DebugElement } from '@angular/core';
|
||||
import { DebugElement, NO_ERRORS_SCHEMA } from '@angular/core';
|
||||
import { CollectionFormComponent } from './collection-form.component';
|
||||
import { Location } from '@angular/common';
|
||||
import { DynamicFormService } from '@ng-dynamic-forms/core';
|
||||
|
||||
describe('CommunityFormComponent', () => {
|
||||
let comp: CollectionFormComponent;
|
||||
@@ -24,8 +25,9 @@ describe('CommunityFormComponent', () => {
|
||||
imports: [TranslateModule.forRoot(), SharedModule, CommonModule, RouterTestingModule],
|
||||
declarations: [CollectionFormComponent],
|
||||
providers: [
|
||||
{ provide: Location, useValue: locationStub }
|
||||
]
|
||||
{ provide: Location, useValue: locationStub },
|
||||
],
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
}).compileComponents();
|
||||
}));
|
||||
|
||||
|
@@ -1,15 +1,11 @@
|
||||
import { SharedModule } from '../../shared/shared.module';
|
||||
import { Community } from '../../core/shared/community.model';
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { DSOSuccessResponse, ErrorResponse } from '../../core/cache/response-cache.models';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { CreateCommunityPageComponent } from '../../+community-page/create-community-page/create-community-page.component';
|
||||
import { CommonModule, Location } from '@angular/common';
|
||||
import { Router } from '@angular/router';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { CommunityFormComponent } from '../../+community-page/community-form/community-form.component';
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
import { Observable } from 'rxjs';
|
||||
import { CommunityDataService } from '../../core/data/community-data.service';
|
||||
import { RequestError } from '../../core/data/request.models';
|
||||
import { RouteService } from '../../shared/services/route.service';
|
||||
import { RemoteData } from '../../core/data/remote-data';
|
||||
import { CreateCollectionPageComponent } from './create-collection-page.component';
|
||||
@@ -17,6 +13,8 @@ import { CollectionDataService } from '../../core/data/collection-data.service';
|
||||
import { Collection } from '../../core/shared/collection.model';
|
||||
import { RouterTestingModule } from '@angular/router/testing';
|
||||
import { CollectionFormComponent } from '../collection-form/collection-form.component';
|
||||
import { of as observableOf } from 'rxjs';
|
||||
import { NO_ERRORS_SCHEMA } from '@angular/core';
|
||||
|
||||
describe('CreateCollectionPageComponent', () => {
|
||||
let comp: CreateCollectionPageComponent;
|
||||
@@ -28,25 +26,33 @@ describe('CreateCollectionPageComponent', () => {
|
||||
|
||||
const community = Object.assign(new Community(), {
|
||||
uuid: 'a20da287-e174-466a-9926-f66b9300d347',
|
||||
name: 'test community'
|
||||
metadata: [{
|
||||
key: 'dc.title',
|
||||
value: 'test collection'
|
||||
}]
|
||||
});
|
||||
|
||||
const collection = Object.assign(new Collection(), {
|
||||
uuid: 'ce41d451-97ed-4a9c-94a1-7de34f16a9f4',
|
||||
name: 'new collection'
|
||||
});
|
||||
metadata: [{
|
||||
key: 'dc.title',
|
||||
value: 'new collection'
|
||||
}] });
|
||||
|
||||
const collectionDataServiceStub = {
|
||||
create: (col, uuid?) => Observable.of(new RemoteData(false, false, true, undefined, collection))
|
||||
create: (col, uuid?) => observableOf(new RemoteData(false, false, true, undefined, collection))
|
||||
};
|
||||
const communityDataServiceStub = {
|
||||
findById: (uuid) => Observable.of(new RemoteData(false, false, true, null, Object.assign(new Community(), {
|
||||
findById: (uuid) => observableOf(new RemoteData(false, false, true, null, Object.assign(new Community(), {
|
||||
uuid: uuid,
|
||||
name: community.name
|
||||
metadata: [{
|
||||
key: 'dc.title',
|
||||
value: community.name
|
||||
}]
|
||||
})))
|
||||
};
|
||||
const routeServiceStub = {
|
||||
getQueryParameterValue: (param) => Observable.of(community.uuid)
|
||||
getQueryParameterValue: (param) => observableOf(community.uuid)
|
||||
};
|
||||
const routerStub = {
|
||||
navigate: (commands) => commands
|
||||
@@ -55,13 +61,14 @@ describe('CreateCollectionPageComponent', () => {
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [TranslateModule.forRoot(), SharedModule, CommonModule, RouterTestingModule],
|
||||
declarations: [CreateCollectionPageComponent, CollectionFormComponent],
|
||||
declarations: [CreateCollectionPageComponent],
|
||||
providers: [
|
||||
{ provide: CollectionDataService, useValue: collectionDataServiceStub },
|
||||
{ provide: CommunityDataService, useValue: communityDataServiceStub },
|
||||
{ provide: RouteService, useValue: routeServiceStub },
|
||||
{ provide: Router, useValue: routerStub }
|
||||
]
|
||||
],
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
}).compileComponents();
|
||||
}));
|
||||
|
||||
@@ -77,7 +84,10 @@ describe('CreateCollectionPageComponent', () => {
|
||||
|
||||
describe('onSubmit', () => {
|
||||
const data = {
|
||||
name: 'test'
|
||||
metadata: [{
|
||||
key: 'dc.title',
|
||||
value:'test'
|
||||
}]
|
||||
};
|
||||
|
||||
it('should navigate when successful', () => {
|
||||
@@ -89,7 +99,7 @@ describe('CreateCollectionPageComponent', () => {
|
||||
|
||||
it('should not navigate on failure', () => {
|
||||
spyOn(router, 'navigate');
|
||||
spyOn(collectionDataService, 'create').and.returnValue(Observable.of(new RemoteData(true, true, false, undefined, collection)));
|
||||
spyOn(collectionDataService, 'create').and.returnValue(observableOf(new RemoteData(true, true, false, undefined, collection)));
|
||||
comp.onSubmit(data);
|
||||
fixture.detectChanges();
|
||||
expect(router.navigate).not.toHaveBeenCalled();
|
||||
|
@@ -9,7 +9,6 @@ import { Observable } from 'rxjs';
|
||||
import { take } from 'rxjs/operators';
|
||||
import { RemoteData } from '../../core/data/remote-data';
|
||||
import { isNotEmpty } from '../../shared/empty.util';
|
||||
import { NormalizedCollection } from '../../core/cache/models/normalized-collection.model';
|
||||
import { ResourceType } from '../../core/shared/resource-type';
|
||||
|
||||
@Component({
|
||||
|
@@ -1,4 +1,3 @@
|
||||
<ds-form *ngIf="formModel" #formRef="formComponent"
|
||||
<ds-form *ngIf="formModel"
|
||||
[formId]="'community-form-id'"
|
||||
[formModel]="formModel" (submit)="onSubmit($event)"></ds-form>
|
||||
|
||||
[formModel]="formModel" (submitForm)="onSubmit()"></ds-form>
|
@@ -1,31 +1,65 @@
|
||||
import { CommunityFormComponent } from './community-form.component';
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { SharedModule } from '../../shared/shared.module';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { RouterTestingModule } from '@angular/router/testing';
|
||||
import { By } from '@angular/platform-browser';
|
||||
import { DebugElement } from '@angular/core';
|
||||
import { Location } from '@angular/common';
|
||||
import { RouterTestingModule } from '@angular/router/testing';
|
||||
import { NO_ERRORS_SCHEMA } from '@angular/core';
|
||||
import {
|
||||
DynamicFormService,
|
||||
DynamicInputControlModel,
|
||||
DynamicInputModel
|
||||
} from '@ng-dynamic-forms/core';
|
||||
import { FormControl, FormGroup } from '@angular/forms';
|
||||
import { DynamicFormControlModel } from '@ng-dynamic-forms/core/src/model/dynamic-form-control.model';
|
||||
import { Community } from '../../core/shared/community.model';
|
||||
import { ResourceType } from '../../core/shared/resource-type';
|
||||
|
||||
describe('CommunityFormComponent', () => {
|
||||
fdescribe('CommunityFormComponent', () => {
|
||||
let comp: CommunityFormComponent;
|
||||
let fixture: ComponentFixture<CommunityFormComponent>;
|
||||
let location: Location;
|
||||
const formServiceStub: any = {
|
||||
createFormGroup: (formModel: DynamicFormControlModel[]) => {
|
||||
const controls = {};
|
||||
formModel.forEach((controlModel) => {
|
||||
controls[controlModel.id] = new FormControl((controlModel as any).value);
|
||||
});
|
||||
return new FormGroup(controls);
|
||||
}
|
||||
};
|
||||
const titleMD = { key: 'dc.title', value: 'Community Title' };
|
||||
const randomMD = { key: 'dc.random', value: 'Random metadata excluded from form' };
|
||||
const abstractMD = { key: 'dc.description.abstract', value: 'Community description' };
|
||||
const newTitleMD = { key: 'dc.title', value: 'New Community Title' };
|
||||
const formModel = [
|
||||
new DynamicInputModel({
|
||||
id: 'title',
|
||||
name: newTitleMD.key,
|
||||
value: newTitleMD.value
|
||||
}),
|
||||
new DynamicInputModel({
|
||||
id: 'abstract',
|
||||
name: abstractMD.key,
|
||||
value: abstractMD.value
|
||||
})
|
||||
];
|
||||
|
||||
/* tslint:disable:no-empty */
|
||||
const locationStub = {
|
||||
back: () => {}
|
||||
back: () => {
|
||||
}
|
||||
};
|
||||
/* tslint:enable:no-empty */
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [TranslateModule.forRoot(), SharedModule, CommonModule, RouterTestingModule],
|
||||
imports: [TranslateModule.forRoot(), RouterTestingModule],
|
||||
declarations: [CommunityFormComponent],
|
||||
providers: [
|
||||
{ provide: Location, useValue: locationStub }
|
||||
]
|
||||
{ provide: Location, useValue: locationStub },
|
||||
{ provide: DynamicFormService, useValue: formServiceStub }
|
||||
],
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
}).compileComponents();
|
||||
}));
|
||||
|
||||
@@ -34,38 +68,41 @@ describe('CommunityFormComponent', () => {
|
||||
comp = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
location = (comp as any).location;
|
||||
comp.formModel = formModel;
|
||||
});
|
||||
|
||||
describe('when submitting', () => {
|
||||
let input: DebugElement;
|
||||
let submit: DebugElement;
|
||||
let cancel: DebugElement;
|
||||
let error: DebugElement;
|
||||
|
||||
describe('onSubmit', () => {
|
||||
beforeEach(() => {
|
||||
input = fixture.debugElement.query(By.css('input#community-name'));
|
||||
submit = fixture.debugElement.query(By.css('button#community-submit'));
|
||||
cancel = fixture.debugElement.query(By.css('button#community-cancel'));
|
||||
error = fixture.debugElement.query(By.css('div.invalid-feedback'));
|
||||
spyOn(comp.submitForm, 'emit');
|
||||
});
|
||||
|
||||
it('should display an error when leaving name empty', () => {
|
||||
const el = input.nativeElement;
|
||||
it('should update emit the new version of the community', () => {
|
||||
comp.community = Object.assign(
|
||||
new Community(),
|
||||
{
|
||||
metadata: [
|
||||
titleMD,
|
||||
randomMD
|
||||
]
|
||||
}
|
||||
);
|
||||
|
||||
el.value = '';
|
||||
el.dispatchEvent(new Event('input'));
|
||||
submit.nativeElement.click();
|
||||
fixture.detectChanges();
|
||||
comp.onSubmit();
|
||||
|
||||
expect(error.nativeElement.style.display).not.toEqual('none');
|
||||
});
|
||||
|
||||
it('should navigate back when pressing cancel', () => {
|
||||
spyOn(location, 'back');
|
||||
cancel.nativeElement.click();
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(location.back).toHaveBeenCalled();
|
||||
});
|
||||
expect(comp.submitForm.emit).toHaveBeenCalledWith(
|
||||
Object.assign(
|
||||
{},
|
||||
new Community(),
|
||||
{
|
||||
metadata: [
|
||||
randomMD,
|
||||
newTitleMD,
|
||||
abstractMD
|
||||
],
|
||||
type: ResourceType.Community
|
||||
},
|
||||
)
|
||||
);
|
||||
})
|
||||
});
|
||||
});
|
||||
|
@@ -9,7 +9,11 @@ import { FormGroup } from '@angular/forms';
|
||||
import { DynamicFormControlModel } from '@ng-dynamic-forms/core/src/model/dynamic-form-control.model';
|
||||
import { Community } from '../../core/shared/community.model';
|
||||
import { ResourceType } from '../../core/shared/resource-type';
|
||||
import { hasValue, isNotEmpty } from '../../shared/empty.util';
|
||||
import { isNotEmpty } from '../../shared/empty.util';
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
|
||||
const LABEL_KEY_PREFIX = 'community.form.';
|
||||
const ERROR_KEY_PREFIX = 'community.form.errors.';
|
||||
|
||||
@Component({
|
||||
selector: 'ds-community-form',
|
||||
@@ -17,40 +21,34 @@ import { hasValue, isNotEmpty } from '../../shared/empty.util';
|
||||
templateUrl: './community-form.component.html'
|
||||
})
|
||||
export class CommunityFormComponent implements OnInit {
|
||||
|
||||
@Input() community: Community = new Community();
|
||||
formModel: DynamicFormControlModel[] = [
|
||||
new DynamicInputModel({
|
||||
id: 'title',
|
||||
name: 'dc.title',
|
||||
label: 'Name',
|
||||
required: true,
|
||||
validators: {
|
||||
required: null
|
||||
},
|
||||
errorMessages: {
|
||||
required: 'Please enter a name for this title'
|
||||
}
|
||||
},
|
||||
}),
|
||||
new DynamicTextAreaModel({
|
||||
id: 'description',
|
||||
name: 'dc.description',
|
||||
label: 'Introductory text (HTML)',
|
||||
}),
|
||||
new DynamicTextAreaModel({
|
||||
id: 'abstract',
|
||||
name: 'dc.description.abstract',
|
||||
label: 'Short Description',
|
||||
}),
|
||||
new DynamicTextAreaModel({
|
||||
id: 'rights',
|
||||
name: 'dc.rights',
|
||||
label: 'Copyright text (HTML)',
|
||||
}),
|
||||
new DynamicTextAreaModel({
|
||||
id: 'tableofcontents',
|
||||
name: 'dc.description.tableofcontents',
|
||||
label: 'News (HTML)',
|
||||
}),
|
||||
];
|
||||
|
||||
@@ -58,7 +56,9 @@ export class CommunityFormComponent implements OnInit {
|
||||
|
||||
@Output() submitForm: EventEmitter<any> = new EventEmitter();
|
||||
|
||||
public constructor(private location: Location, private formService: DynamicFormService) {
|
||||
public constructor(private location: Location,
|
||||
private formService: DynamicFormService,
|
||||
private translate: TranslateService) {
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
@@ -68,10 +68,14 @@ export class CommunityFormComponent implements OnInit {
|
||||
}
|
||||
);
|
||||
this.formGroup = this.formService.createFormGroup(this.formModel);
|
||||
this.updateFieldTranslations();
|
||||
this.translate.onLangChange
|
||||
.subscribe(() => {
|
||||
this.updateFieldTranslations();
|
||||
});
|
||||
}
|
||||
|
||||
onSubmit(event: Event) {
|
||||
event.stopPropagation();
|
||||
onSubmit() {
|
||||
const metadata = this.formModel.map(
|
||||
(fieldModel: DynamicInputModel) => {
|
||||
return { key: fieldModel.name, value: fieldModel.value }
|
||||
@@ -87,7 +91,17 @@ export class CommunityFormComponent implements OnInit {
|
||||
this.submitForm.emit(updatedCommunity);
|
||||
}
|
||||
|
||||
cancel() {
|
||||
this.location.back();
|
||||
private updateFieldTranslations() {
|
||||
this.formModel.forEach(
|
||||
(fieldModel: DynamicInputModel) => {
|
||||
fieldModel.label = this.translate.instant(LABEL_KEY_PREFIX + fieldModel.id);
|
||||
if (isNotEmpty(fieldModel.validators)) {
|
||||
fieldModel.errorMessages = {};
|
||||
Object.keys(fieldModel.validators).forEach((key) => {
|
||||
fieldModel.errorMessages[key] = this.translate.instant(ERROR_KEY_PREFIX + fieldModel.id + '.' + key);
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@@ -1,9 +1,9 @@
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-12 pb-4">
|
||||
<ng-container *ngVar="(communityRDObs | async)?.payload as community">
|
||||
<h2 *ngIf="!community" id="header" class="border-bottom pb-2">{{ 'community.create.head' | translate }}</h2>
|
||||
<h2 *ngIf="community" id="sub-header" class="border-bottom pb-2">{{ 'community.create.sub-head' | translate:{ parent: community.name } }}</h2>
|
||||
<ng-container *ngVar="(parentUUID$ | async)?.payload as parent">
|
||||
<h2 *ngIf="!parent" id="header" class="border-bottom pb-2">{{ 'community.create.head' | translate }}</h2>
|
||||
<h2 *ngIf="parent" id="sub-header" class="border-bottom pb-2">{{ 'community.create.sub-head' | translate:{ parent: parent.name } }}</h2>
|
||||
</ng-container>
|
||||
</div>
|
||||
</div>
|
||||
|
@@ -4,55 +4,76 @@ import { CommunityDataService } from '../../core/data/community-data.service';
|
||||
import { RouteService } from '../../shared/services/route.service';
|
||||
import { Router } from '@angular/router';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
import { of as observableOf } from 'rxjs';
|
||||
import { RemoteData } from '../../core/data/remote-data';
|
||||
import { Community } from '../../core/shared/community.model';
|
||||
import { DSOSuccessResponse, ErrorResponse } from '../../core/cache/response-cache.models';
|
||||
import { SharedModule } from '../../shared/shared.module';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { CommunityFormComponent } from '../community-form/community-form.component';
|
||||
import { RouterTestingModule } from '@angular/router/testing';
|
||||
import { NO_ERRORS_SCHEMA } from '@angular/core';
|
||||
|
||||
describe('CreateCommunityPageComponent', () => {
|
||||
fdescribe('CreateCommunityPageComponent', () => {
|
||||
let comp: CreateCommunityPageComponent;
|
||||
let fixture: ComponentFixture<CreateCommunityPageComponent>;
|
||||
let communityDataService: CommunityDataService;
|
||||
let routeService: RouteService;
|
||||
let router: Router;
|
||||
|
||||
const community = Object.assign(new Community(), {
|
||||
let community;
|
||||
let newCommunity;
|
||||
let communityDataServiceStub;
|
||||
let routeServiceStub;
|
||||
let routerStub;
|
||||
|
||||
function initializeVars() {
|
||||
community = Object.assign(new Community(), {
|
||||
uuid: 'a20da287-e174-466a-9926-f66b9300d347',
|
||||
name: 'test community'
|
||||
metadata: [{
|
||||
key: 'dc.title',
|
||||
value: 'test community'
|
||||
}]
|
||||
});
|
||||
|
||||
const newCommunity = Object.assign(new Community(), {
|
||||
newCommunity = Object.assign(new Community(), {
|
||||
uuid: '1ff59938-a69a-4e62-b9a4-718569c55d48',
|
||||
name: 'new community'
|
||||
metadata: [{
|
||||
key: 'dc.title',
|
||||
value: 'new community'
|
||||
}]
|
||||
});
|
||||
|
||||
const communityDataServiceStub = {
|
||||
findById: (uuid) => Observable.of(new RemoteData(false, false, true, null, Object.assign(new Community(), {
|
||||
communityDataServiceStub = {
|
||||
findById: (uuid) => observableOf(new RemoteData(false, false, true, null, Object.assign(new Community(), {
|
||||
uuid: uuid,
|
||||
name: community.name
|
||||
metadata: [{
|
||||
key: 'dc.title',
|
||||
value: community.name
|
||||
}]
|
||||
}))),
|
||||
create: (com, uuid?) => Observable.of(new RemoteData(false, false, true, undefined, newCommunity))
|
||||
create: (com, uuid?) => observableOf(new RemoteData(false, false, true, undefined, newCommunity))
|
||||
|
||||
};
|
||||
const routeServiceStub = {
|
||||
getQueryParameterValue: (param) => Observable.of(community.uuid)
|
||||
|
||||
routeServiceStub = {
|
||||
getQueryParameterValue: (param) => observableOf(community.uuid)
|
||||
};
|
||||
const routerStub = {
|
||||
routerStub = {
|
||||
navigate: (commands) => commands
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
beforeEach(async(() => {
|
||||
initializeVars();
|
||||
TestBed.configureTestingModule({
|
||||
imports: [TranslateModule.forRoot(), SharedModule, CommonModule, RouterTestingModule],
|
||||
declarations: [CreateCommunityPageComponent, CommunityFormComponent],
|
||||
declarations: [CreateCommunityPageComponent],
|
||||
providers: [
|
||||
{ provide: CommunityDataService, useValue: communityDataServiceStub },
|
||||
{ provide: RouteService, useValue: routeServiceStub },
|
||||
{ provide: Router, useValue: routerStub }
|
||||
]
|
||||
{ provide: Router, useValue: routerStub },
|
||||
],
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
}).compileComponents();
|
||||
}));
|
||||
|
||||
@@ -66,10 +87,15 @@ describe('CreateCommunityPageComponent', () => {
|
||||
});
|
||||
|
||||
describe('onSubmit', () => {
|
||||
const data = {
|
||||
name: 'test'
|
||||
};
|
||||
|
||||
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);
|
||||
@@ -79,7 +105,7 @@ describe('CreateCommunityPageComponent', () => {
|
||||
|
||||
it('should not navigate on failure', () => {
|
||||
spyOn(router, 'navigate');
|
||||
spyOn(communityDataService, 'create').and.returnValue(Observable.of(new RemoteData(true, true, false, undefined, newCommunity)));
|
||||
spyOn(communityDataService, 'create').and.returnValue(observableOf(new RemoteData(true, true, false, undefined, newCommunity)));
|
||||
comp.onSubmit(data);
|
||||
fixture.detectChanges();
|
||||
expect(router.navigate).not.toHaveBeenCalled();
|
||||
|
@@ -5,7 +5,7 @@ import { Observable } from 'rxjs';
|
||||
import { RouteService } from '../../shared/services/route.service';
|
||||
import { Router } from '@angular/router';
|
||||
import { RemoteData } from '../../core/data/remote-data';
|
||||
import { isNotEmpty } from '../../shared/empty.util';
|
||||
import { isNotEmpty, isNotUndefined } from '../../shared/empty.util';
|
||||
import { DSpaceObject } from '../../core/shared/dspace-object.model';
|
||||
import { map, take } from 'rxjs/operators';
|
||||
import { getSucceededRemoteData } from '../../core/shared/operators';
|
||||
@@ -42,8 +42,10 @@ export class CreateCommunityPageComponent implements OnInit {
|
||||
this.communityDataService.create(community, uuid)
|
||||
.pipe(getSucceededRemoteData())
|
||||
.subscribe((communityRD: RemoteData<Community>) => {
|
||||
if (isNotUndefined(communityRD)) {
|
||||
const newUUID = communityRD.payload.uuid;
|
||||
this.router.navigate(['/communities/' + newUUID]);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@@ -1,10 +1,7 @@
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-12 pb-4">
|
||||
<ng-container *ngVar="(parentUUID$ | async)?.payload as parent">
|
||||
<h2 *ngIf="!parent" id="header" class="border-bottom pb-2">{{ 'community.edit.head' | translate }}</h2>
|
||||
<h2 *ngIf="parent" id="sub-header" class="border-bottom pb-2">{{ 'community.edit.sub-head' | translate:{ parent: parent.name } }}</h2>
|
||||
</ng-container>
|
||||
<h2 id="header" class="border-bottom pb-2">{{ 'community.edit.head' | translate }}</h2>
|
||||
</div>
|
||||
</div>
|
||||
<ds-community-form (submitForm)="onSubmit($event)" [community]="(communityRD$ | async)?.payload"></ds-community-form>
|
||||
|
@@ -1,65 +1,91 @@
|
||||
import { CreateCommunityPageComponent } from './create-community-page.component';
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { CommunityDataService } from '../../core/data/community-data.service';
|
||||
import { RouteService } from '../../shared/services/route.service';
|
||||
import { Router } from '@angular/router';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
import { of as observableOf } from 'rxjs';
|
||||
import { RemoteData } from '../../core/data/remote-data';
|
||||
import { Community } from '../../core/shared/community.model';
|
||||
import { DSOSuccessResponse, ErrorResponse } from '../../core/cache/response-cache.models';
|
||||
import { BrowserModule } from '@angular/platform-browser';
|
||||
import { SharedModule } from '../../shared/shared.module';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { CommunityFormComponent } from '../community-form/community-form.component';
|
||||
import { RouterTestingModule } from '@angular/router/testing';
|
||||
import { RequestError } from '../../core/data/request.models';
|
||||
import { NO_ERRORS_SCHEMA } from '@angular/core';
|
||||
import { EditCommunityPageComponent } from './edit-community-page.component';
|
||||
import { ActivatedRouteStub } from '../../shared/testing/active-router-stub';
|
||||
|
||||
describe('CreateCommunityPageComponent', () => {
|
||||
let comp: CreateCommunityPageComponent;
|
||||
let fixture: ComponentFixture<CreateCommunityPageComponent>;
|
||||
fdescribe('EditCommunityPageComponent', () => {
|
||||
let comp: EditCommunityPageComponent;
|
||||
let fixture: ComponentFixture<EditCommunityPageComponent>;
|
||||
let communityDataService: CommunityDataService;
|
||||
let routeService: RouteService;
|
||||
let router: Router;
|
||||
|
||||
const community = Object.assign(new Community(), {
|
||||
let community;
|
||||
let newCommunity;
|
||||
let communityDataServiceStub;
|
||||
let routeServiceStub;
|
||||
let routerStub;
|
||||
let routeStub;
|
||||
|
||||
function initializeVars() {
|
||||
community = Object.assign(new Community(), {
|
||||
uuid: 'a20da287-e174-466a-9926-f66b9300d347',
|
||||
name: 'test community'
|
||||
metadata: [{
|
||||
key: 'dc.title',
|
||||
value: 'test community'
|
||||
}]
|
||||
});
|
||||
|
||||
const newCommunity = Object.assign(new Community(), {
|
||||
newCommunity = Object.assign(new Community(), {
|
||||
uuid: '1ff59938-a69a-4e62-b9a4-718569c55d48',
|
||||
name: 'new community'
|
||||
metadata: [{
|
||||
key: 'dc.title',
|
||||
value: 'new community'
|
||||
}]
|
||||
});
|
||||
|
||||
const communityDataServiceStub = {
|
||||
findById: (uuid) => Observable.of(new RemoteData(false, false, true, null, Object.assign(new Community(), {
|
||||
communityDataServiceStub = {
|
||||
findById: (uuid) => observableOf(new RemoteData(false, false, true, null, Object.assign(new Community(), {
|
||||
uuid: uuid,
|
||||
name: community.name
|
||||
metadata: [{
|
||||
key: 'dc.title',
|
||||
value: community.name
|
||||
}]
|
||||
}))),
|
||||
create: (com, uuid?) => Observable.of(new RemoteData(false, false, true, undefined, newCommunity))
|
||||
update: (com, uuid?) => observableOf(new RemoteData(false, false, true, undefined, newCommunity))
|
||||
|
||||
};
|
||||
const routeServiceStub = {
|
||||
getQueryParameterValue: (param) => Observable.of(community.uuid)
|
||||
|
||||
routeServiceStub = {
|
||||
getQueryParameterValue: (param) => observableOf(community.uuid)
|
||||
};
|
||||
const routerStub = {
|
||||
routerStub = {
|
||||
navigate: (commands) => commands
|
||||
};
|
||||
|
||||
routeStub = {
|
||||
data: observableOf(community)
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
beforeEach(async(() => {
|
||||
initializeVars();
|
||||
TestBed.configureTestingModule({
|
||||
imports: [TranslateModule.forRoot(), SharedModule, CommonModule, RouterTestingModule],
|
||||
declarations: [CreateCommunityPageComponent, CommunityFormComponent],
|
||||
declarations: [EditCommunityPageComponent],
|
||||
providers: [
|
||||
{ provide: CommunityDataService, useValue: communityDataServiceStub },
|
||||
{ provide: RouteService, useValue: routeServiceStub },
|
||||
{ provide: Router, useValue: routerStub }
|
||||
]
|
||||
{ provide: Router, useValue: routerStub },
|
||||
{ provide: ActivatedRoute, useValue: routeStub },
|
||||
],
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
}).compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(CreateCommunityPageComponent);
|
||||
fixture = TestBed.createComponent(EditCommunityPageComponent);
|
||||
comp = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
communityDataService = (comp as any).communityDataService;
|
||||
@@ -68,10 +94,15 @@ describe('CreateCommunityPageComponent', () => {
|
||||
});
|
||||
|
||||
describe('onSubmit', () => {
|
||||
const data = {
|
||||
name: 'test'
|
||||
};
|
||||
|
||||
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);
|
||||
@@ -81,7 +112,7 @@ describe('CreateCommunityPageComponent', () => {
|
||||
|
||||
it('should not navigate on failure', () => {
|
||||
spyOn(router, 'navigate');
|
||||
spyOn(communityDataService, 'create').and.returnValue(Observable.of(new RemoteData(true, true, false, undefined, newCommunity)));
|
||||
spyOn(communityDataService, 'update').and.returnValue(observableOf(new RemoteData(true, true, false, undefined, newCommunity)));
|
||||
comp.onSubmit(data);
|
||||
fixture.detectChanges();
|
||||
expect(router.navigate).not.toHaveBeenCalled();
|
||||
|
@@ -5,11 +5,8 @@ import { Observable } from 'rxjs';
|
||||
import { RouteService } from '../../shared/services/route.service';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { RemoteData } from '../../core/data/remote-data';
|
||||
import { isNotEmpty } from '../../shared/empty.util';
|
||||
import { DSpaceObject } from '../../core/shared/dspace-object.model';
|
||||
import { first, map, take, tap } from 'rxjs/operators';
|
||||
import { ResourceType } from '../../core/shared/resource-type';
|
||||
import { NormalizedCommunity } from '../../core/cache/models/normalized-community.model';
|
||||
import { isNotUndefined } from '../../shared/empty.util';
|
||||
import { first, map } from 'rxjs/operators';
|
||||
import { getSucceededRemoteData } from '../../core/shared/operators';
|
||||
|
||||
@Component({
|
||||
@@ -39,8 +36,10 @@ export class EditCommunityPageComponent {
|
||||
this.communityDataService.update(community)
|
||||
.pipe(getSucceededRemoteData())
|
||||
.subscribe((communityRD: RemoteData<Community>) => {
|
||||
if (isNotUndefined(communityRD)) {
|
||||
const newUUID = communityRD.payload.uuid;
|
||||
this.router.navigate(['/communities/' + newUUID]);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@@ -17,7 +17,6 @@ describe('SubCommunityList Component', () => {
|
||||
let fixture: ComponentFixture<CommunityPageSubCommunityListComponent>;
|
||||
|
||||
const subcommunities = [Object.assign(new Community(), {
|
||||
name: 'SubCommunity 1',
|
||||
id: '123456789-1',
|
||||
metadata: [
|
||||
{
|
||||
@@ -27,7 +26,6 @@ describe('SubCommunityList Component', () => {
|
||||
}]
|
||||
}),
|
||||
Object.assign(new Community(), {
|
||||
name: 'SubCommunity 2',
|
||||
id: '123456789-2',
|
||||
metadata: [
|
||||
{
|
||||
|
@@ -111,7 +111,6 @@ export const objects = [
|
||||
id: '7669c72a-3f2a-451f-a3b9-9210e7a4c02f',
|
||||
uuid: '7669c72a-3f2a-451f-a3b9-9210e7a4c02f',
|
||||
type: ResourceType.Community,
|
||||
name: 'OR2017 - Demonstration',
|
||||
metadata: [
|
||||
{
|
||||
key: 'dc.description',
|
||||
@@ -161,7 +160,6 @@ export const objects = [
|
||||
id: '9076bd16-e69a-48d6-9e41-0238cb40d863',
|
||||
uuid: '9076bd16-e69a-48d6-9e41-0238cb40d863',
|
||||
type: ResourceType.Community,
|
||||
name: 'Sample Community',
|
||||
metadata: [
|
||||
{
|
||||
key: 'dc.description',
|
||||
|
@@ -36,7 +36,6 @@ describe('ConfigService', () => {
|
||||
const scopedEndpoint = `${serviceEndpoint}/${scopeName}`;
|
||||
const searchEndpoint = `${serviceEndpoint}/${BROWSE}?uuid=${scopeID}`;
|
||||
|
||||
|
||||
function initTestService(): TestService {
|
||||
return new TestService(
|
||||
requestService,
|
||||
|
@@ -9,7 +9,6 @@ import { ComColDataService } from './comcol-data.service';
|
||||
import { CommunityDataService } from './community-data.service';
|
||||
import { RequestService } from './request.service';
|
||||
import { HALEndpointService } from '../shared/hal-endpoint.service';
|
||||
import { AuthService } from '../auth/auth.service';
|
||||
import { NotificationsService } from '../../shared/notifications/notifications.service';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { DataBuildService } from '../cache/builders/data-build.service';
|
||||
@@ -27,7 +26,6 @@ export class CollectionDataService extends ComColDataService<NormalizedCollectio
|
||||
protected cds: CommunityDataService,
|
||||
protected objectCache: ObjectCacheService,
|
||||
protected halService: HALEndpointService,
|
||||
protected authService: AuthService,
|
||||
protected notificationsService: NotificationsService,
|
||||
protected http: HttpClient,
|
||||
protected comparator: DSOUpdateComparator
|
||||
|
@@ -14,12 +14,10 @@ import { NormalizedObject } from '../cache/models/normalized-object.model';
|
||||
import { HALEndpointService } from '../shared/hal-endpoint.service';
|
||||
import { RequestEntry } from './request.reducer';
|
||||
import { of as observableOf } from 'rxjs';
|
||||
import { AuthService } from '../auth/auth.service';
|
||||
import { NotificationsService } from '../../shared/notifications/notifications.service';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { DataBuildService } from '../cache/builders/data-build.service';
|
||||
import { DSOUpdateComparator } from './dso-update-comparator';
|
||||
import { UpdateComparator } from './update-comparator';
|
||||
|
||||
const LINK_NAME = 'test';
|
||||
|
||||
@@ -38,7 +36,6 @@ class TestService extends ComColDataService<NormalizedTestObject, any> {
|
||||
protected cds: CommunityDataService,
|
||||
protected objectCache: ObjectCacheService,
|
||||
protected halService: HALEndpointService,
|
||||
protected authService: AuthService,
|
||||
protected notificationsService: NotificationsService,
|
||||
protected http: HttpClient,
|
||||
protected comparator: DSOUpdateComparator,
|
||||
@@ -56,7 +53,6 @@ describe('ComColDataService', () => {
|
||||
let requestService: RequestService;
|
||||
let cds: CommunityDataService;
|
||||
let objectCache: ObjectCacheService;
|
||||
let authService: AuthService;
|
||||
let halService: any = {};
|
||||
|
||||
const rdbService = {} as RemoteDataBuildService;
|
||||
@@ -106,14 +102,6 @@ describe('ComColDataService', () => {
|
||||
});
|
||||
}
|
||||
|
||||
function initMockAuthService(): AuthService {
|
||||
return jasmine.createSpyObj('authService', {
|
||||
buildAuthHeader: cold('c-', {
|
||||
c: authHeader
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
function initTestService(): TestService {
|
||||
return new TestService(
|
||||
requestService,
|
||||
@@ -124,7 +112,6 @@ describe('ComColDataService', () => {
|
||||
cds,
|
||||
objectCache,
|
||||
halService,
|
||||
authService,
|
||||
notificationsService,
|
||||
http,
|
||||
comparator,
|
||||
@@ -137,7 +124,6 @@ describe('ComColDataService', () => {
|
||||
requestService = getMockRequestService();
|
||||
objectCache = initMockObjectCacheService();
|
||||
halService = mockHalService;
|
||||
authService = initMockAuthService();
|
||||
service = initTestService();
|
||||
});
|
||||
|
||||
|
@@ -10,7 +10,6 @@ import { Community } from '../shared/community.model';
|
||||
import { ComColDataService } from './comcol-data.service';
|
||||
import { RequestService } from './request.service';
|
||||
import { HALEndpointService } from '../shared/hal-endpoint.service';
|
||||
import { AuthService } from '../auth/auth.service';
|
||||
import { FindAllOptions, FindAllRequest } from './request.models';
|
||||
import { RemoteData } from './remote-data';
|
||||
import { hasValue, isNotEmpty } from '../../shared/empty.util';
|
||||
@@ -34,7 +33,6 @@ export class CommunityDataService extends ComColDataService<NormalizedCommunity,
|
||||
protected store: Store<CoreState>,
|
||||
protected objectCache: ObjectCacheService,
|
||||
protected halService: HALEndpointService,
|
||||
protected authService: AuthService,
|
||||
protected notificationsService: NotificationsService,
|
||||
protected http: HttpClient,
|
||||
protected comparator: DSOUpdateComparator
|
||||
|
@@ -177,7 +177,7 @@ describe('ConfigResponseParsingService', () => {
|
||||
'https://rest.api/config/submissionsections/traditionalpagetwo',
|
||||
'https://rest.api/config/submissionsections/upload',
|
||||
'https://rest.api/config/submissionsections/license'
|
||||
], 'https://rest.api/config/submissiondefinitions/traditional/sections')
|
||||
])
|
||||
});
|
||||
|
||||
it('should return a ConfigSuccessResponse if data contains a valid config endpoint response', () => {
|
||||
|
@@ -12,6 +12,11 @@ import { of as observableOf } from 'rxjs';
|
||||
import { ObjectCacheService } from '../cache/object-cache.service';
|
||||
import { Operation } from '../../../../node_modules/fast-json-patch';
|
||||
import { DSpaceObject } from '../shared/dspace-object.model';
|
||||
import { AuthService } from '../auth/auth.service';
|
||||
import { UpdateComparator } from './update-comparator';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { DataBuildService } from '../cache/builders/data-build.service';
|
||||
import { NotificationsService } from '../../shared/notifications/notifications.service';
|
||||
|
||||
const endpoint = 'https://rest.api/core';
|
||||
|
||||
@@ -23,10 +28,14 @@ class TestService extends DataService<NormalizedTestObject, any> {
|
||||
constructor(
|
||||
protected requestService: RequestService,
|
||||
protected rdbService: RemoteDataBuildService,
|
||||
protected dataBuildService: DataBuildService,
|
||||
protected store: Store<CoreState>,
|
||||
protected linkPath: string,
|
||||
protected halService: HALEndpointService,
|
||||
protected objectCache: ObjectCacheService
|
||||
protected objectCache: ObjectCacheService,
|
||||
protected notificationsService: NotificationsService,
|
||||
protected http: HttpClient,
|
||||
protected comparator: UpdateComparator<NormalizedTestObject>
|
||||
) {
|
||||
super();
|
||||
}
|
||||
@@ -42,6 +51,10 @@ describe('DataService', () => {
|
||||
const requestService = {} as RequestService;
|
||||
const halService = {} as HALEndpointService;
|
||||
const rdbService = {} as RemoteDataBuildService;
|
||||
const notificationsService = {} as NotificationsService;
|
||||
const http = {} as HttpClient;
|
||||
const comparator = {} as any;
|
||||
const dataBuildService = {} as DataBuildService;
|
||||
const objectCache = {
|
||||
addPatch: () => {
|
||||
/* empty */
|
||||
@@ -56,13 +69,16 @@ describe('DataService', () => {
|
||||
return new TestService(
|
||||
requestService,
|
||||
rdbService,
|
||||
dataBuildService,
|
||||
store,
|
||||
endpoint,
|
||||
halService,
|
||||
objectCache
|
||||
objectCache,
|
||||
notificationsService,
|
||||
http,
|
||||
comparator,
|
||||
);
|
||||
}
|
||||
|
||||
service = initTestService();
|
||||
|
||||
describe('getFindAllHref', () => {
|
||||
@@ -134,7 +150,7 @@ describe('DataService', () => {
|
||||
let selfLink;
|
||||
|
||||
beforeEach(() => {
|
||||
operations = [{ op: 'replace', path: '/name', value: 'random string' } as Operation];
|
||||
operations = [{ op: 'replace', path: '/metadata/dc.title', value: 'random string' } as Operation];
|
||||
selfLink = 'https://rest.api/endpoint/1698f1d3-be98-4c51-9fd8-6bfedcbd59b7';
|
||||
spyOn(objectCache, 'addPatch');
|
||||
});
|
||||
@@ -153,16 +169,16 @@ describe('DataService', () => {
|
||||
const name1 = 'random string';
|
||||
const name2 = 'another random string';
|
||||
beforeEach(() => {
|
||||
operations = [{ op: 'replace', path: '/name', value: name2 } as Operation];
|
||||
operations = [{ op: 'replace', path: '/metadata/dc.title', value: name2 } as Operation];
|
||||
selfLink = 'https://rest.api/endpoint/1698f1d3-be98-4c51-9fd8-6bfedcbd59b7';
|
||||
|
||||
dso = new DSpaceObject();
|
||||
dso.self = selfLink;
|
||||
dso.name = name1;
|
||||
dso.metadata = [{ key: 'dc.title', value: name1 }];
|
||||
|
||||
dso2 = new DSpaceObject();
|
||||
dso2.self = selfLink;
|
||||
dso2.name = name2;
|
||||
dso2.metadata = [{ key: 'dc.title', value: name2 }];
|
||||
|
||||
spyOn(objectCache, 'getBySelfLink').and.returnValue(dso);
|
||||
spyOn(objectCache, 'addPatch');
|
||||
|
@@ -29,7 +29,6 @@ import { NormalizedObject } from '../cache/models/normalized-object.model';
|
||||
import { compare, Operation } from 'fast-json-patch';
|
||||
import { ObjectCacheService } from '../cache/object-cache.service';
|
||||
import { DSpaceObject } from '../shared/dspace-object.model';
|
||||
import { AuthService } from '../auth/auth.service';
|
||||
import { NotificationsService } from '../../shared/notifications/notifications.service';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import {
|
||||
@@ -53,7 +52,6 @@ export abstract class DataService<TNormalized extends NormalizedObject, TDomain
|
||||
protected abstract linkPath: string;
|
||||
protected abstract halService: HALEndpointService;
|
||||
protected abstract objectCache: ObjectCacheService;
|
||||
protected abstract authService: AuthService;
|
||||
protected abstract notificationsService: NotificationsService;
|
||||
protected abstract http: HttpClient;
|
||||
protected abstract comparator: UpdateComparator<TNormalized>;
|
||||
@@ -155,7 +153,7 @@ export abstract class DataService<TNormalized extends NormalizedObject, TDomain
|
||||
const endpoint$ = this.halService.getEndpoint(this.linkPath).pipe(
|
||||
isNotEmptyOperator(),
|
||||
distinctUntilChanged(),
|
||||
map((endpoint: string) => parentUUID ? `${endpoint}?parent=${parentUUID}` : endpoint)
|
||||
map((endpoint: string) => parentUUID ? `${endpoint}?parentCommunity=${parentUUID}` : endpoint)
|
||||
);
|
||||
|
||||
const normalizedObject: TNormalized = this.dataBuildService.normalize<TDomain, TNormalized>(dso);
|
||||
|
@@ -7,6 +7,9 @@ import { FindByIDRequest } from './request.models';
|
||||
import { RequestService } from './request.service';
|
||||
import { DSpaceObjectDataService } from './dspace-object-data.service';
|
||||
import { ObjectCacheService } from '../cache/object-cache.service';
|
||||
import { NotificationsService } from '../../shared/notifications/notifications.service';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { DataBuildService } from '../cache/builders/data-build.service';
|
||||
|
||||
describe('DSpaceObjectDataService', () => {
|
||||
let scheduler: TestScheduler;
|
||||
@@ -40,12 +43,20 @@ describe('DSpaceObjectDataService', () => {
|
||||
})
|
||||
});
|
||||
objectCache = {} as ObjectCacheService;
|
||||
const notificationsService = {} as NotificationsService;
|
||||
const http = {} as HttpClient;
|
||||
const comparator = {} as any;
|
||||
const dataBuildService = {} as DataBuildService;
|
||||
|
||||
service = new DSpaceObjectDataService(
|
||||
requestService,
|
||||
rdbService,
|
||||
dataBuildService,
|
||||
objectCache,
|
||||
halService,
|
||||
objectCache
|
||||
notificationsService,
|
||||
http,
|
||||
comparator
|
||||
)
|
||||
});
|
||||
|
||||
|
@@ -11,7 +11,6 @@ import { RemoteData } from './remote-data';
|
||||
import { RequestService } from './request.service';
|
||||
import { FindAllOptions } from './request.models';
|
||||
import { ObjectCacheService } from '../cache/object-cache.service';
|
||||
import { AuthService } from '../auth/auth.service';
|
||||
import { NotificationsService } from '../../shared/notifications/notifications.service';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { DataBuildService } from '../cache/builders/data-build.service';
|
||||
@@ -28,7 +27,6 @@ class DataServiceImpl extends DataService<NormalizedDSpaceObject, DSpaceObject>
|
||||
protected store: Store<CoreState>,
|
||||
protected objectCache: ObjectCacheService,
|
||||
protected halService: HALEndpointService,
|
||||
protected authService: AuthService,
|
||||
protected notificationsService: NotificationsService,
|
||||
protected http: HttpClient,
|
||||
protected comparator: DSOUpdateComparator) {
|
||||
@@ -55,11 +53,10 @@ export class DSpaceObjectDataService {
|
||||
protected dataBuildService: DataBuildService,
|
||||
protected objectCache: ObjectCacheService,
|
||||
protected halService: HALEndpointService,
|
||||
protected authService: AuthService,
|
||||
protected notificationsService: NotificationsService,
|
||||
protected http: HttpClient,
|
||||
protected comparator: DSOUpdateComparator) {
|
||||
this.dataService = new DataServiceImpl(requestService, rdbService, dataBuildService, null, objectCache, halService, authService, notificationsService, http, comparator);
|
||||
this.dataService = new DataServiceImpl(requestService, rdbService, dataBuildService, null, objectCache, halService, notificationsService, http, comparator);
|
||||
}
|
||||
|
||||
findById(uuid: string): Observable<RemoteData<DSpaceObject>> {
|
||||
|
@@ -9,6 +9,9 @@ import { RequestService } from './request.service';
|
||||
import { HALEndpointService } from '../shared/hal-endpoint.service';
|
||||
import { ObjectCacheService } from '../cache/object-cache.service';
|
||||
import { FindAllOptions } from './request.models';
|
||||
import { NotificationsService } from '../../shared/notifications/notifications.service';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { DataBuildService } from '../cache/builders/data-build.service';
|
||||
|
||||
describe('ItemDataService', () => {
|
||||
let scheduler: TestScheduler;
|
||||
@@ -34,6 +37,10 @@ describe('ItemDataService', () => {
|
||||
const scopedEndpoint = `${itemBrowseEndpoint}?scope=${scopeID}`;
|
||||
const serviceEndpoint = `https://rest.api/core/items`;
|
||||
const browseError = new Error('getBrowseURL failed');
|
||||
const notificationsService = {} as NotificationsService;
|
||||
const http = {} as HttpClient;
|
||||
const comparator = {} as any;
|
||||
const dataBuildService = {} as DataBuildService;
|
||||
|
||||
function initMockBrowseService(isSuccessful: boolean) {
|
||||
const obs = isSuccessful ?
|
||||
@@ -48,10 +55,14 @@ describe('ItemDataService', () => {
|
||||
return new ItemDataService(
|
||||
requestService,
|
||||
rdbService,
|
||||
dataBuildService,
|
||||
store,
|
||||
bs,
|
||||
objectCache,
|
||||
halEndpointService,
|
||||
objectCache
|
||||
notificationsService,
|
||||
http,
|
||||
comparator
|
||||
);
|
||||
}
|
||||
|
||||
|
@@ -17,7 +17,6 @@ import { HALEndpointService } from '../shared/hal-endpoint.service';
|
||||
import { FindAllOptions } from './request.models';
|
||||
import { ObjectCacheService } from '../cache/object-cache.service';
|
||||
import { NotificationsService } from '../../shared/notifications/notifications.service';
|
||||
import { AuthService } from '../auth/auth.service';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { DataBuildService } from '../cache/builders/data-build.service';
|
||||
import { DSOUpdateComparator } from './dso-update-comparator';
|
||||
@@ -34,7 +33,6 @@ export class ItemDataService extends DataService<NormalizedItem, Item> {
|
||||
private bs: BrowseService,
|
||||
protected objectCache: ObjectCacheService,
|
||||
protected halService: HALEndpointService,
|
||||
protected authService: AuthService,
|
||||
protected notificationsService: NotificationsService,
|
||||
protected http: HttpClient,
|
||||
protected comparator: DSOUpdateComparator) {
|
||||
|
@@ -350,13 +350,13 @@ describe('FormComponent test suite', () => {
|
||||
const control = formComp.formGroup.get(['dc_title']);
|
||||
control.setValue('Test Title');
|
||||
formState.testForm.valid = true;
|
||||
spyOn(formComp.submit, 'emit');
|
||||
spyOn(formComp.submitForm, 'emit');
|
||||
|
||||
form.next(formState.testForm);
|
||||
formFixture.detectChanges();
|
||||
|
||||
formComp.onSubmit();
|
||||
expect(formComp.submit.emit).toHaveBeenCalled();
|
||||
expect(formComp.submitForm.emit).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should not emit submit Event on form submit whether the form is not valid', () => {
|
||||
|
@@ -51,7 +51,6 @@ export const MockItem: Item = Object.assign(new Item(), {
|
||||
id: 'cf9b0c8e-a1eb-4b65-afd0-567366448713',
|
||||
uuid: 'cf9b0c8e-a1eb-4b65-afd0-567366448713',
|
||||
type: 'bitstream',
|
||||
name: 'test_word.docx',
|
||||
metadata: [
|
||||
{
|
||||
key: 'dc.title',
|
||||
@@ -86,7 +85,6 @@ export const MockItem: Item = Object.assign(new Item(), {
|
||||
id: '99b00f3c-1cc6-4689-8158-91965bee6b28',
|
||||
uuid: '99b00f3c-1cc6-4689-8158-91965bee6b28',
|
||||
type: 'bitstream',
|
||||
name: 'test_pdf.pdf',
|
||||
metadata: [
|
||||
{
|
||||
key: 'dc.title',
|
||||
@@ -102,7 +100,6 @@ export const MockItem: Item = Object.assign(new Item(), {
|
||||
id: '0ec7ff22-f211-40ab-a69e-c819b0b1f357',
|
||||
uuid: '0ec7ff22-f211-40ab-a69e-c819b0b1f357',
|
||||
type: 'item',
|
||||
name: 'Test PowerPoint Document',
|
||||
metadata: [
|
||||
{
|
||||
key: 'dc.creator',
|
||||
|
@@ -121,7 +121,6 @@ export const objects: DSpaceObject[] = [
|
||||
id: '7669c72a-3f2a-451f-a3b9-9210e7a4c02f',
|
||||
uuid: '7669c72a-3f2a-451f-a3b9-9210e7a4c02f',
|
||||
type: ResourceType.Community,
|
||||
name: 'OR2017 - Demonstration',
|
||||
metadata: [
|
||||
{
|
||||
key: 'dc.description',
|
||||
@@ -171,7 +170,6 @@ export const objects: DSpaceObject[] = [
|
||||
id: '9076bd16-e69a-48d6-9e41-0238cb40d863',
|
||||
uuid: '9076bd16-e69a-48d6-9e41-0238cb40d863',
|
||||
type: ResourceType.Community,
|
||||
name: 'Sample Community',
|
||||
metadata: [
|
||||
{
|
||||
key: 'dc.description',
|
||||
|
@@ -13,8 +13,12 @@ export const EPersonMock: EPerson = Object.assign(new EPerson(),{
|
||||
id: 'testid',
|
||||
uuid: 'testid',
|
||||
type: 'eperson',
|
||||
name: 'User Test',
|
||||
metadata: [
|
||||
{
|
||||
key: 'dc.title',
|
||||
language: null,
|
||||
value: 'User Test'
|
||||
},
|
||||
{
|
||||
key: 'eperson.firstname',
|
||||
language: null,
|
||||
|
Reference in New Issue
Block a user