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