mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-08 10:34:15 +00:00
Added tests
This commit is contained in:
@@ -257,7 +257,277 @@ export const submissionRestResponse = [
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
export const mockSubmissionObject = {
|
||||||
|
collection: {
|
||||||
|
handle: '10673/2',
|
||||||
|
license: 'https://rest.api/dspace-spring-rest/api/core/collections/1c11f3f1-ba1f-4f36-908a-3f1ea9a557eb/license',
|
||||||
|
defaultAccessConditions: {
|
||||||
|
pageInfo: {
|
||||||
|
elementsPerPage: 1,
|
||||||
|
totalElements: 1,
|
||||||
|
totalPages: 1,
|
||||||
|
currentPage: 1
|
||||||
|
},
|
||||||
|
page: [
|
||||||
|
{
|
||||||
|
name: null,
|
||||||
|
groupUUID: '11cc35e5-a11d-4b64-b5b9-0052a5d15509',
|
||||||
|
id: 20,
|
||||||
|
uuid: 'resource-policy-20',
|
||||||
|
self: 'https://rest.api/dspace-spring-rest/api/authz/resourcePolicies/20',
|
||||||
|
type: 'resourcePolicy',
|
||||||
|
_links: {
|
||||||
|
self: 'https://rest.api/dspace-spring-rest/api/authz/resourcePolicies/20'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
logo: {
|
||||||
|
sizeBytes: 7451,
|
||||||
|
content: 'https://rest.api/dspace-spring-rest/api/core/bitstreams/3f859425-ffbd-4b0e-bf91-bfeb458a7425/content',
|
||||||
|
format: 'https://rest.api/dspace-spring-rest/api/core/bitstreams/3f859425-ffbd-4b0e-bf91-bfeb458a7425/format',
|
||||||
|
bundleName: null,
|
||||||
|
self: 'https://rest.api/dspace-spring-rest/api/core/bitstreams/3f859425-ffbd-4b0e-bf91-bfeb458a7425',
|
||||||
|
id: '3f859425-ffbd-4b0e-bf91-bfeb458a7425',
|
||||||
|
uuid: '3f859425-ffbd-4b0e-bf91-bfeb458a7425',
|
||||||
|
type: 'bitstream',
|
||||||
|
name: null,
|
||||||
|
metadata: [],
|
||||||
|
_links: {
|
||||||
|
content: 'https://rest.api/dspace-spring-rest/api/core/bitstreams/3f859425-ffbd-4b0e-bf91-bfeb458a7425/content',
|
||||||
|
format: 'https://rest.api/dspace-spring-rest/api/core/bitstreams/3f859425-ffbd-4b0e-bf91-bfeb458a7425/format',
|
||||||
|
self: 'https://rest.api/dspace-spring-rest/api/core/bitstreams/3f859425-ffbd-4b0e-bf91-bfeb458a7425'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
self: 'https://rest.api/dspace-spring-rest/api/core/collections/1c11f3f1-ba1f-4f36-908a-3f1ea9a557eb',
|
||||||
|
id: '1c11f3f1-ba1f-4f36-908a-3f1ea9a557eb',
|
||||||
|
uuid: '1c11f3f1-ba1f-4f36-908a-3f1ea9a557eb',
|
||||||
|
type: 'collection',
|
||||||
|
name: 'Collection of Sample Items',
|
||||||
|
metadata: [
|
||||||
|
{
|
||||||
|
key: 'dc.provenance',
|
||||||
|
language: null,
|
||||||
|
value: 'This field is for private provenance information. It is only visible to Administrative users and is not displayed in the user interface by default.'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'dc.rights.license',
|
||||||
|
language: null,
|
||||||
|
value: ''
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'dc.description',
|
||||||
|
language: null,
|
||||||
|
value: '<p>This is a <em>DSpace Collection</em> which contains sample DSpace Items.</p>\r\n<p><strong>Collections in DSpace may only contain Items.</strong></p>\r\n<p>This particular Collection has its own logo (the <a href=\'http://www.opensource.org/\'>Open Source Initiative</a> logo).</p>\r\n<p>This introductory text is editable by System Administrators, Community Administrators (of a parent Community) or Collection Administrators (of this Collection).</p>'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'dc.description.abstract',
|
||||||
|
language: null,
|
||||||
|
value: 'This collection contains sample items.'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'dc.description.tableofcontents',
|
||||||
|
language: null,
|
||||||
|
value: '<p>This is the <strong>news</strong> section for this Collection. System Administrators, Community Administrators (of a parent Community) or Collection Administrators (of this Collection) can edit this News field.</p>'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'dc.rights',
|
||||||
|
language: null,
|
||||||
|
value: '<p><em>If this collection had a specific copyright statement, it would be placed here.</em></p>'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'dc.title',
|
||||||
|
language: null,
|
||||||
|
value: 'Collection of Sample Items'
|
||||||
|
}
|
||||||
|
],
|
||||||
|
_links: {
|
||||||
|
license: 'https://rest.api/dspace-spring-rest/api/core/collections/1c11f3f1-ba1f-4f36-908a-3f1ea9a557eb/license',
|
||||||
|
defaultAccessConditions: 'https://rest.api/dspace-spring-rest/api/core/collections/1c11f3f1-ba1f-4f36-908a-3f1ea9a557eb/defaultAccessConditions',
|
||||||
|
logo: 'https://rest.api/dspace-spring-rest/api/core/collections/1c11f3f1-ba1f-4f36-908a-3f1ea9a557eb/logo',
|
||||||
|
self: 'https://rest.api/dspace-spring-rest/api/core/collections/1c11f3f1-ba1f-4f36-908a-3f1ea9a557eb'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
item: {
|
||||||
|
handle: null,
|
||||||
|
lastModified: '2019-01-09T10:17:33.722+0000',
|
||||||
|
isArchived: false,
|
||||||
|
isDiscoverable: true,
|
||||||
|
isWithdrawn: false,
|
||||||
|
owningCollection: 'https://rest.api/dspace-spring-rest/api/core/items/cae8af78-c874-4468-af79-e6c996aa8270/owningCollection',
|
||||||
|
bitstreams: {
|
||||||
|
pageInfo: {
|
||||||
|
elementsPerPage: 0,
|
||||||
|
totalElements: 0,
|
||||||
|
totalPages: 1,
|
||||||
|
currentPage: 1
|
||||||
|
},
|
||||||
|
page: []
|
||||||
|
},
|
||||||
|
self: 'https://rest.api/dspace-spring-rest/api/core/items/cae8af78-c874-4468-af79-e6c996aa8270',
|
||||||
|
id: 'cae8af78-c874-4468-af79-e6c996aa8270',
|
||||||
|
uuid: 'cae8af78-c874-4468-af79-e6c996aa8270',
|
||||||
|
type: 'item',
|
||||||
|
name: null,
|
||||||
|
metadata: [],
|
||||||
|
_links: {
|
||||||
|
bitstreams: 'https://rest.api/dspace-spring-rest/api/core/items/cae8af78-c874-4468-af79-e6c996aa8270/bitstreams',
|
||||||
|
owningCollection: 'https://rest.api/dspace-spring-rest/api/core/items/cae8af78-c874-4468-af79-e6c996aa8270/owningCollection',
|
||||||
|
templateItemOf: 'https://rest.api/dspace-spring-rest/api/core/items/cae8af78-c874-4468-af79-e6c996aa8270/templateItemOf',
|
||||||
|
self: 'https://rest.api/dspace-spring-rest/api/core/items/cae8af78-c874-4468-af79-e6c996aa8270'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
submissionDefinition: {
|
||||||
|
isDefault: true,
|
||||||
|
sections: {
|
||||||
|
pageInfo: {
|
||||||
|
elementsPerPage: 5,
|
||||||
|
totalElements: 5,
|
||||||
|
totalPages: 1,
|
||||||
|
currentPage: 1
|
||||||
|
},
|
||||||
|
page: [
|
||||||
|
{
|
||||||
|
mandatory: true,
|
||||||
|
sectionType: 'collection',
|
||||||
|
visibility: {
|
||||||
|
main: 'HIDDEN',
|
||||||
|
other: 'HIDDEN'
|
||||||
|
},
|
||||||
|
type: 'submissionsection',
|
||||||
|
_links: {
|
||||||
|
self: 'https://rest.api/dspace-spring-rest/api/config/submissionsections/collection'
|
||||||
|
},
|
||||||
|
self: 'https://rest.api/dspace-spring-rest/api/config/submissionsections/collection'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: 'submit.progressbar.describe.stepone',
|
||||||
|
mandatory: true,
|
||||||
|
sectionType: 'submission-form',
|
||||||
|
type: 'submissionsection',
|
||||||
|
_links: {
|
||||||
|
self: 'https://rest.api/dspace-spring-rest/api/config/submissionsections/traditionalpageone',
|
||||||
|
config: 'https://rest.api/dspace-spring-rest/api/config/submissionforms/traditionalpageone'
|
||||||
|
},
|
||||||
|
self: 'https://rest.api/dspace-spring-rest/api/config/submissionsections/traditionalpageone'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: 'submit.progressbar.describe.steptwo',
|
||||||
|
mandatory: true,
|
||||||
|
sectionType: 'submission-form',
|
||||||
|
type: 'submissionsection',
|
||||||
|
_links: {
|
||||||
|
self: 'https://rest.api/dspace-spring-rest/api/config/submissionsections/traditionalpagetwo',
|
||||||
|
config: 'https://rest.api/dspace-spring-rest/api/config/submissionforms/traditionalpagetwo'
|
||||||
|
},
|
||||||
|
self: 'https://rest.api/dspace-spring-rest/api/config/submissionsections/traditionalpagetwo'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: 'submit.progressbar.upload',
|
||||||
|
mandatory: true,
|
||||||
|
sectionType: 'upload',
|
||||||
|
type: 'submissionsection',
|
||||||
|
_links: {
|
||||||
|
self: 'https://rest.api/dspace-spring-rest/api/config/submissionsections/upload',
|
||||||
|
config: 'https://rest.api/dspace-spring-rest/api/config/submissionuploads/upload'
|
||||||
|
},
|
||||||
|
self: 'https://rest.api/dspace-spring-rest/api/config/submissionsections/upload'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: 'submit.progressbar.license',
|
||||||
|
mandatory: true,
|
||||||
|
sectionType: 'license',
|
||||||
|
visibility: {
|
||||||
|
main: null,
|
||||||
|
other: 'READONLY'
|
||||||
|
},
|
||||||
|
type: 'submissionsection',
|
||||||
|
_links: {
|
||||||
|
self: 'https://rest.api/dspace-spring-rest/api/config/submissionsections/license'
|
||||||
|
},
|
||||||
|
self: 'https://rest.api/dspace-spring-rest/api/config/submissionsections/license'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
name: 'traditional',
|
||||||
|
type: 'submissiondefinition',
|
||||||
|
_links: {
|
||||||
|
collections: 'https://rest.api/dspace-spring-rest/api/config/submissiondefinitions/traditional/collections',
|
||||||
|
sections: 'https://rest.api/dspace-spring-rest/api/config/submissiondefinitions/traditional/sections',
|
||||||
|
self: 'https://rest.api/dspace-spring-rest/api/config/submissiondefinitions/traditional'
|
||||||
|
},
|
||||||
|
self: 'https://rest.api/dspace-spring-rest/api/config/submissiondefinitions/traditional',
|
||||||
|
collections: {
|
||||||
|
pageInfo: {
|
||||||
|
elementsPerPage: 0,
|
||||||
|
totalElements: 0,
|
||||||
|
totalPages: 1,
|
||||||
|
currentPage: 1
|
||||||
|
},
|
||||||
|
page: []
|
||||||
|
}
|
||||||
|
},
|
||||||
|
submitter: {
|
||||||
|
handle: null,
|
||||||
|
groups: [],
|
||||||
|
netid: null,
|
||||||
|
lastActive: '2019-01-09T10:17:33.047+0000',
|
||||||
|
canLogIn: true,
|
||||||
|
email: 'dspacedemo+submit@gmail.com',
|
||||||
|
requireCertificate: false,
|
||||||
|
selfRegistered: false,
|
||||||
|
self: 'https://rest.api/dspace-spring-rest/api/eperson/epersons/99423c27-b642-4bb9-a9cd-6d910e68dca5',
|
||||||
|
id: '99423c27-b642-4bb9-a9cd-6d910e68dca5',
|
||||||
|
uuid: '99423c27-b642-4bb9-a9cd-6d910e68dca5',
|
||||||
|
type: 'eperson',
|
||||||
|
name: 'dspacedemo+submit@gmail.com',
|
||||||
|
metadata: [
|
||||||
|
{
|
||||||
|
key: 'eperson.firstname',
|
||||||
|
language: null,
|
||||||
|
value: 'Demo'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'eperson.lastname',
|
||||||
|
language: null,
|
||||||
|
value: 'Submitter'
|
||||||
|
}
|
||||||
|
],
|
||||||
|
_links: {
|
||||||
|
self: 'https://rest.api/dspace-spring-rest/api/eperson/epersons/99423c27-b642-4bb9-a9cd-6d910e68dca5'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
id: 826,
|
||||||
|
lastModified: '2019-01-09T10:17:33.738+0000',
|
||||||
|
sections: {
|
||||||
|
license: {
|
||||||
|
url: null,
|
||||||
|
acceptanceDate: null,
|
||||||
|
granted: false
|
||||||
|
},
|
||||||
|
upload: {
|
||||||
|
files: []
|
||||||
|
}
|
||||||
|
},
|
||||||
|
errors: [
|
||||||
|
{
|
||||||
|
message: 'error.validation.required',
|
||||||
|
paths: [
|
||||||
|
'/sections/traditionalpageone/dc.title',
|
||||||
|
'/sections/traditionalpageone/dc.date.issued'
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
self: 'https://rest.api/dspace-spring-rest/api/submission/workspaceitems/269',
|
||||||
|
type: 'workspaceitem',
|
||||||
|
_links: {
|
||||||
|
collection: 'https://rest.api/dspace-spring-rest/api/submission/workspaceitems/269/collection',
|
||||||
|
item: 'https://rest.api/dspace-spring-rest/api/submission/workspaceitems/269/item',
|
||||||
|
submissionDefinition: 'https://rest.api/dspace-spring-rest/api/submission/workspaceitems/269/submissionDefinition',
|
||||||
|
submitter: 'https://rest.api/dspace-spring-rest/api/submission/workspaceitems/269/submitter',
|
||||||
|
self: 'https://rest.api/dspace-spring-rest/api/submission/workspaceitems/269'
|
||||||
|
}
|
||||||
|
}
|
||||||
export const mockSubmissionCollectionId = '1c11f3f1-ba1f-4f36-908a-3f1ea9a557eb';
|
export const mockSubmissionCollectionId = '1c11f3f1-ba1f-4f36-908a-3f1ea9a557eb';
|
||||||
export const mockSubmissionId = '826';
|
export const mockSubmissionId = '826';
|
||||||
export const mockSubmissionSelfUrl = 'https://rest.api/dspace-spring-rest/api/submission/workspaceitems/826';
|
export const mockSubmissionSelfUrl = 'https://rest.api/dspace-spring-rest/api/submission/workspaceitems/826';
|
||||||
|
@@ -12,6 +12,7 @@ export class ActivatedRouteStub {
|
|||||||
|
|
||||||
params = this.subject.asObservable();
|
params = this.subject.asObservable();
|
||||||
queryParams = this.subject.asObservable();
|
queryParams = this.subject.asObservable();
|
||||||
|
paramMap = this.subject.asObservable().pipe(map((params: Params) => convertToParamMap(params)));;
|
||||||
queryParamMap = this.subject.asObservable().pipe(map((params: Params) => convertToParamMap(params)));
|
queryParamMap = this.subject.asObservable().pipe(map((params: Params) => convertToParamMap(params)));
|
||||||
|
|
||||||
constructor(params?: Params) {
|
constructor(params?: Params) {
|
||||||
|
105
src/app/submission/edit/submission-edit.component.spec.ts
Normal file
105
src/app/submission/edit/submission-edit.component.spec.ts
Normal file
@@ -0,0 +1,105 @@
|
|||||||
|
import { async, ComponentFixture, fakeAsync, TestBed } from '@angular/core/testing';
|
||||||
|
import { RouterTestingModule } from '@angular/router/testing';
|
||||||
|
import { ActivatedRoute, Router } from '@angular/router';
|
||||||
|
import { NO_ERRORS_SCHEMA } from '@angular/core';
|
||||||
|
|
||||||
|
import { of as observableOf } from 'rxjs';
|
||||||
|
import { TranslateModule, TranslateService } from '@ngx-translate/core';
|
||||||
|
|
||||||
|
import { SubmissionEditComponent } from './submission-edit.component';
|
||||||
|
import { NotificationsService } from '../../shared/notifications/notifications.service';
|
||||||
|
import { NotificationsServiceStub } from '../../shared/testing/notifications-service-stub';
|
||||||
|
import { SubmissionService } from '../submission.service';
|
||||||
|
import { SubmissionServiceStub } from '../../shared/testing/submission-service-stub';
|
||||||
|
import { getMockTranslateService } from '../../shared/mocks/mock-translate.service';
|
||||||
|
|
||||||
|
import { RouterStub } from '../../shared/testing/router-stub';
|
||||||
|
import { ActivatedRouteStub } from '../../shared/testing/active-router-stub';
|
||||||
|
import { mockSubmissionObject } from '../../shared/mocks/mock-submission';
|
||||||
|
|
||||||
|
describe('SubmissionEditComponent Component', () => {
|
||||||
|
|
||||||
|
let comp: SubmissionEditComponent;
|
||||||
|
let fixture: ComponentFixture<SubmissionEditComponent>;
|
||||||
|
let submissionServiceStub: SubmissionServiceStub;
|
||||||
|
let router: RouterStub;
|
||||||
|
|
||||||
|
const submissionId = '826';
|
||||||
|
const route: ActivatedRouteStub = new ActivatedRouteStub();
|
||||||
|
const submissionObject: any = mockSubmissionObject;
|
||||||
|
|
||||||
|
beforeEach(async(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
imports: [
|
||||||
|
TranslateModule.forRoot(),
|
||||||
|
RouterTestingModule.withRoutes([
|
||||||
|
{ path: ':id/edit', component: SubmissionEditComponent, pathMatch: 'full' },
|
||||||
|
])
|
||||||
|
],
|
||||||
|
declarations: [SubmissionEditComponent],
|
||||||
|
providers: [
|
||||||
|
{ provide: NotificationsService, useClass: NotificationsServiceStub },
|
||||||
|
{ provide: SubmissionService, useClass: SubmissionServiceStub },
|
||||||
|
{ provide: TranslateService, useValue: getMockTranslateService() },
|
||||||
|
{ provide: Router, useValue: new RouterStub() },
|
||||||
|
{ provide: ActivatedRoute, useValue: route },
|
||||||
|
|
||||||
|
],
|
||||||
|
schemas: [NO_ERRORS_SCHEMA]
|
||||||
|
}).compileComponents();
|
||||||
|
}));
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
fixture = TestBed.createComponent(SubmissionEditComponent);
|
||||||
|
comp = fixture.componentInstance;
|
||||||
|
submissionServiceStub = TestBed.get(SubmissionService);
|
||||||
|
router = TestBed.get(Router);
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
comp = null;
|
||||||
|
fixture = null;
|
||||||
|
router = null;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should init properly when a valid SubmissionObject has been retrieved', fakeAsync(() => {
|
||||||
|
|
||||||
|
route.testParams = { id: submissionId };
|
||||||
|
submissionServiceStub.retrieveSubmission.and.returnValue(observableOf(submissionObject));
|
||||||
|
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
expect(comp.submissionId).toBe(submissionId);
|
||||||
|
expect(comp.collectionId).toBe(submissionObject.collection.id);
|
||||||
|
expect(comp.selfUrl).toBe(submissionObject.self);
|
||||||
|
expect(comp.sections).toBe(submissionObject.sections);
|
||||||
|
expect(comp.submissionDefinition).toBe(submissionObject.submissionDefinition);
|
||||||
|
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should redirect to mydspace when an empty SubmissionObject has been retrieved', fakeAsync(() => {
|
||||||
|
|
||||||
|
route.testParams = { id: submissionId };
|
||||||
|
submissionServiceStub.retrieveSubmission.and.returnValue(observableOf({}));
|
||||||
|
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
expect(router.navigate).toHaveBeenCalled();
|
||||||
|
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should not has effects when an invalid SubmissionObject has been retrieved', fakeAsync(() => {
|
||||||
|
|
||||||
|
route.testParams = { id: submissionId };
|
||||||
|
submissionServiceStub.retrieveSubmission.and.returnValue(observableOf(null));
|
||||||
|
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
expect(router.navigate).not.toHaveBeenCalled();
|
||||||
|
expect(comp.collectionId).toBeUndefined();
|
||||||
|
expect(comp.selfUrl).toBeUndefined();
|
||||||
|
expect(comp.sections).toBeUndefined();
|
||||||
|
expect(comp.submissionDefinition).toBeUndefined();
|
||||||
|
}));
|
||||||
|
|
||||||
|
});
|
@@ -2,16 +2,16 @@ import { ChangeDetectorRef, Component, OnDestroy, OnInit } from '@angular/core';
|
|||||||
import { ActivatedRoute, ParamMap, Router } from '@angular/router';
|
import { ActivatedRoute, ParamMap, Router } from '@angular/router';
|
||||||
|
|
||||||
import { Subscription } from 'rxjs';
|
import { Subscription } from 'rxjs';
|
||||||
|
import { flatMap, tap } from 'rxjs/operators';
|
||||||
|
import { TranslateService } from '@ngx-translate/core';
|
||||||
|
|
||||||
import { WorkspaceitemSectionsObject } from '../../core/submission/models/workspaceitem-sections.model';
|
import { WorkspaceitemSectionsObject } from '../../core/submission/models/workspaceitem-sections.model';
|
||||||
import { hasValue, isEmpty, isNotNull } from '../../shared/empty.util';
|
import { hasValue, isEmpty, isNotNull } from '../../shared/empty.util';
|
||||||
import { SubmissionDefinitionsModel } from '../../core/config/models/config-submission-definitions.model';
|
import { SubmissionDefinitionsModel } from '../../core/config/models/config-submission-definitions.model';
|
||||||
import { SubmissionService } from '../submission.service';
|
import { SubmissionService } from '../submission.service';
|
||||||
import { NotificationsService } from '../../shared/notifications/notifications.service';
|
import { NotificationsService } from '../../shared/notifications/notifications.service';
|
||||||
import { TranslateService } from '@ngx-translate/core';
|
|
||||||
import { SubmissionObject } from '../../core/submission/models/submission-object.model';
|
import { SubmissionObject } from '../../core/submission/models/submission-object.model';
|
||||||
import { Collection } from '../../core/shared/collection.model';
|
import { Collection } from '../../core/shared/collection.model';
|
||||||
import { flatMap, tap } from 'rxjs/operators';
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'ds-submission-edit',
|
selector: 'ds-submission-edit',
|
||||||
|
@@ -0,0 +1,99 @@
|
|||||||
|
import { async, ComponentFixture, fakeAsync, TestBed } from '@angular/core/testing';
|
||||||
|
import { RouterTestingModule } from '@angular/router/testing';
|
||||||
|
import { ActivatedRoute, Router } from '@angular/router';
|
||||||
|
import { NO_ERRORS_SCHEMA, ViewContainerRef } from '@angular/core';
|
||||||
|
|
||||||
|
import { of as observableOf } from 'rxjs';
|
||||||
|
import { TranslateModule, TranslateService } from '@ngx-translate/core';
|
||||||
|
|
||||||
|
import { NotificationsService } from '../../shared/notifications/notifications.service';
|
||||||
|
import { NotificationsServiceStub } from '../../shared/testing/notifications-service-stub';
|
||||||
|
import { SubmissionService } from '../submission.service';
|
||||||
|
import { SubmissionServiceStub } from '../../shared/testing/submission-service-stub';
|
||||||
|
import { getMockTranslateService } from '../../shared/mocks/mock-translate.service';
|
||||||
|
|
||||||
|
import { RouterStub } from '../../shared/testing/router-stub';
|
||||||
|
import { ActivatedRouteStub } from '../../shared/testing/active-router-stub';
|
||||||
|
import { mockSubmissionObject } from '../../shared/mocks/mock-submission';
|
||||||
|
import { SubmissionSubmitComponent } from './submission-submit.component';
|
||||||
|
|
||||||
|
fdescribe('SubmissionSubmitComponent Component', () => {
|
||||||
|
|
||||||
|
let comp: SubmissionSubmitComponent;
|
||||||
|
let fixture: ComponentFixture<SubmissionSubmitComponent>;
|
||||||
|
let submissionServiceStub: SubmissionServiceStub;
|
||||||
|
let router: RouterStub;
|
||||||
|
|
||||||
|
const submissionId = '826';
|
||||||
|
const route: ActivatedRouteStub = new ActivatedRouteStub();
|
||||||
|
const submissionObject: any = mockSubmissionObject;
|
||||||
|
|
||||||
|
beforeEach(async(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
imports: [
|
||||||
|
TranslateModule.forRoot(),
|
||||||
|
RouterTestingModule.withRoutes([
|
||||||
|
{ path: ':id/edit', component: SubmissionSubmitComponent, pathMatch: 'full' },
|
||||||
|
])
|
||||||
|
],
|
||||||
|
declarations: [SubmissionSubmitComponent],
|
||||||
|
providers: [
|
||||||
|
{ provide: NotificationsService, useClass: NotificationsServiceStub },
|
||||||
|
{ provide: SubmissionService, useClass: SubmissionServiceStub },
|
||||||
|
{ provide: TranslateService, useValue: getMockTranslateService() },
|
||||||
|
{ provide: Router, useValue: new RouterStub() },
|
||||||
|
ViewContainerRef
|
||||||
|
],
|
||||||
|
schemas: [NO_ERRORS_SCHEMA]
|
||||||
|
}).compileComponents();
|
||||||
|
}));
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
fixture = TestBed.createComponent(SubmissionSubmitComponent);
|
||||||
|
comp = fixture.componentInstance;
|
||||||
|
submissionServiceStub = TestBed.get(SubmissionService);
|
||||||
|
router = TestBed.get(Router);
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
comp = null;
|
||||||
|
fixture = null;
|
||||||
|
router = null;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should init properly when a valid SubmissionObject has been retrieved', fakeAsync(() => {
|
||||||
|
|
||||||
|
submissionServiceStub.createSubmission.and.returnValue(observableOf(submissionObject));
|
||||||
|
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
expect(comp.submissionId.toString()).toEqual(submissionId);
|
||||||
|
expect(comp.collectionId).toBe(submissionObject.collection.id);
|
||||||
|
expect(comp.selfUrl).toBe(submissionObject.self);
|
||||||
|
expect(comp.submissionDefinition).toBe(submissionObject.submissionDefinition);
|
||||||
|
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should redirect to mydspace when an empty SubmissionObject has been retrieved', fakeAsync(() => {
|
||||||
|
|
||||||
|
submissionServiceStub.createSubmission.and.returnValue(observableOf({}));
|
||||||
|
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
expect(router.navigate).toHaveBeenCalled();
|
||||||
|
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should not has effects when an invalid SubmissionObject has been retrieved', fakeAsync(() => {
|
||||||
|
|
||||||
|
submissionServiceStub.createSubmission.and.returnValue(observableOf(null));
|
||||||
|
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
expect(router.navigate).not.toHaveBeenCalled();
|
||||||
|
expect(comp.collectionId).toBeUndefined();
|
||||||
|
expect(comp.selfUrl).toBeUndefined();
|
||||||
|
expect(comp.submissionDefinition).toBeUndefined();
|
||||||
|
}));
|
||||||
|
|
||||||
|
});
|
Reference in New Issue
Block a user