From 9edd18f2896f4e1944e7a5c637284aa01cbf9933 Mon Sep 17 00:00:00 2001 From: Giuseppe Digilio Date: Thu, 10 Jan 2019 19:13:40 +0100 Subject: [PATCH] Added tests --- src/app/shared/mocks/mock-submission.ts | 454 +++++++++++++++++- .../submission-form-collection.component.html | 8 +- ...bmission-form-collection.component.spec.ts | 353 ++++++++++++++ .../submission-form-collection.component.ts | 17 +- .../submission-form-footer.component.spec.ts | 195 ++++++++ ...mission-form-section-add.component.spec.ts | 168 +++++++ .../form/submission-form.component.spec.ts | 164 +++++++ .../submission-upload-files.component.spec.ts | 164 +++++++ .../submission-objects.effects.spec.ts | 32 +- src/app/submission/submission.service.spec.ts | 8 +- 10 files changed, 1516 insertions(+), 47 deletions(-) create mode 100644 src/app/submission/form/collection/submission-form-collection.component.spec.ts create mode 100644 src/app/submission/form/footer/submission-form-footer.component.spec.ts create mode 100644 src/app/submission/form/section-add/submission-form-section-add.component.spec.ts create mode 100644 src/app/submission/form/submission-form.component.spec.ts create mode 100644 src/app/submission/form/submission-upload-files/submission-upload-files.component.spec.ts diff --git a/src/app/shared/mocks/mock-submission.ts b/src/app/shared/mocks/mock-submission.ts index a83f536858..fd1ee27253 100644 --- a/src/app/shared/mocks/mock-submission.ts +++ b/src/app/shared/mocks/mock-submission.ts @@ -55,7 +55,54 @@ export const mockSectionsErrors = [ } ]; -export const submissionRestResponse = [ +export const mockUploadResponse1Errors = { + errors: [ + { + message: 'error.validation.required', + paths: [ + '/sections/traditionalpageone/dc.title', + '/sections/traditionalpageone/dc.date.issued' + ] + } + ] +}; + +export const mockUploadResponse1ParsedErrors: any = { + traditionalpageone: [ + { path: '/sections/traditionalpageone/dc.title', message: 'error.validation.required' }, + { path: '/sections/traditionalpageone/dc.date.issued', message: 'error.validation.required' } + ] +}; + +export const mockUploadResponse2Errors = { + errors: [ + { + message: 'error.validation.required', + paths: [ + '/sections/traditionalpageone/dc.title', + '/sections/traditionalpageone/dc.date.issued' + ] + }, + { + message: 'error.upload', + paths: [ + '/sections/upload' + ] + } + ] +}; + +export const mockUploadResponse2ParsedErrors = { + traditionalpageone: [ + { path: '/sections/traditionalpageone/dc.title', message: 'error.validation.required' }, + { path: '/sections/traditionalpageone/dc.date.issued', message: 'error.validation.required' } + ], + upload: [ + { path: '/sections/upload', message: 'error.upload' } + ] +}; + +export const mockSubmissionRestResponse = [ { id: 826, lastModified: '2018-08-03T12:49:45.268+0000', @@ -257,6 +304,7 @@ export const submissionRestResponse = [ } } ]; + export const mockSubmissionObject = { collection: { handle: '10673/2', @@ -476,9 +524,9 @@ export const mockSubmissionObject = { 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', + self: 'https://rest.api/dspace-spring-rest/api/eperson/epersons/99423c27-b642-5tg6-a9cd-6d910e68dca5', + id: '99423c27-b642-5tg6-a9cd-6d910e68dca5', + uuid: '99423c27-b642-5tg6-a9cd-6d910e68dca5', type: 'eperson', name: 'dspacedemo+submit@gmail.com', metadata: [ @@ -494,7 +542,7 @@ export const mockSubmissionObject = { } ], _links: { - self: 'https://rest.api/dspace-spring-rest/api/eperson/epersons/99423c27-b642-4bb9-a9cd-6d910e68dca5' + self: 'https://rest.api/dspace-spring-rest/api/eperson/epersons/99423c27-b642-5tg6-a9cd-6d910e68dca5' } }, id: 826, @@ -518,18 +566,276 @@ export const mockSubmissionObject = { ] } ], - self: 'https://rest.api/dspace-spring-rest/api/submission/workspaceitems/269', + self: 'https://rest.api/dspace-spring-rest/api/submission/workspaceitems/826', 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' + collection: 'https://rest.api/dspace-spring-rest/api/submission/workspaceitems/826/collection', + item: 'https://rest.api/dspace-spring-rest/api/submission/workspaceitems/826/item', + submissionDefinition: 'https://rest.api/dspace-spring-rest/api/submission/workspaceitems/826/submissionDefinition', + submitter: 'https://rest.api/dspace-spring-rest/api/submission/workspaceitems/826/submitter', + self: 'https://rest.api/dspace-spring-rest/api/submission/workspaceitems/826' } -} +}; + +export const mockSubmissionObjectNew = { + collection: { + handle: '10673/2', + license: 'https://rest.api/dspace-spring-rest/api/core/collections/45f2f3f1-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/45f2f3f1-ba1f-4f36-908a-3f1ea9a557eb', + id: '45f2f3f1-ba1f-4f36-908a-3f1ea9a557eb', + uuid: '45f2f3f1-ba1f-4f36-908a-3f1ea9a557eb', + type: 'collection', + name: 'Another 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: '

This is a DSpace Collection which contains sample DSpace Items.

\r\n

Collections in DSpace may only contain Items.

\r\n

This particular Collection has its own logo (the Open Source Initiative logo).

\r\n

This introductory text is editable by System Administrators, Community Administrators (of a parent Community) or Collection Administrators (of this Collection).

' + }, + { + key: 'dc.description.abstract', + language: null, + value: 'This collection contains sample items.' + }, + { + key: 'dc.description.tableofcontents', + language: null, + value: '

This is the news section for this Collection. System Administrators, Community Administrators (of a parent Community) or Collection Administrators (of this Collection) can edit this News field.

' + }, + { + key: 'dc.rights', + language: null, + value: '

If this collection had a specific copyright statement, it would be placed here.

' + }, + { + key: 'dc.title', + language: null, + value: 'Collection of Sample Items' + } + ], + _links: { + license: 'https://rest.api/dspace-spring-rest/api/core/collections/45f2f3f1-ba1f-4f36-908a-3f1ea9a557eb/license', + defaultAccessConditions: 'https://rest.api/dspace-spring-rest/api/core/collections/45f2f3f1-ba1f-4f36-908a-3f1ea9a557eb/defaultAccessConditions', + logo: 'https://rest.api/dspace-spring-rest/api/core/collections/45f2f3f1-ba1f-4f36-908a-3f1ea9a557eb/logo', + self: 'https://rest.api/dspace-spring-rest/api/core/collections/45f2f3f1-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: 'traditionaltwo', + 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-45gh23e68dca5', + id: '99423c27-b642-4bb9-a9cd-45gh23e68dca5', + uuid: '99423c27-b642-4bb9-a9cd-45gh23e68dca5', + 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-45gh23e68dca5' + } + }, + id: 826, + lastModified: '2019-01-09T10:17:33.738+0000', + sections: {}, + errors: [], + self: 'https://rest.api/dspace-spring-rest/api/submission/workspaceitems/826', + type: 'workspaceitem', + _links: { + collection: 'https://rest.api/dspace-spring-rest/api/submission/workspaceitems/826/collection', + item: 'https://rest.api/dspace-spring-rest/api/submission/workspaceitems/826/item', + submissionDefinition: 'https://rest.api/dspace-spring-rest/api/submission/workspaceitems/826/submissionDefinition', + submitter: 'https://rest.api/dspace-spring-rest/api/submission/workspaceitems/826/submitter', + self: 'https://rest.api/dspace-spring-rest/api/submission/workspaceitems/826' + } +}; + export const mockSubmissionCollectionId = '1c11f3f1-ba1f-4f36-908a-3f1ea9a557eb'; + export const mockSubmissionId = '826'; + export const mockSubmissionSelfUrl = 'https://rest.api/dspace-spring-rest/api/submission/workspaceitems/826'; export const mockSubmissionDefinitionResponse = { @@ -801,3 +1107,127 @@ export const mockSubmissionState: SubmissionObjectState = { depositPending: false } }; + +export const mockSectionsState = { + extraction: { + config: '', + mandatory: true, + sectionType: 'utils', + visibility: { + main: 'HIDDEN', + other: 'HIDDEN' + }, + collapsed: false, + enabled: true, + data: {}, + errors: [], + isLoading: false, + isValid: false + } as any, + collection: { + config: '', + mandatory: true, + sectionType: 'collection', + visibility: { + main: 'HIDDEN', + other: 'HIDDEN' + }, + collapsed: false, + enabled: true, + data: {}, + errors: [], + isLoading: false, + isValid: false + } as any, + traditionalpageone: { + header: 'submit.progressbar.describe.stepone', + config: 'https://rest.api/dspace-spring-rest/api/config/submissionforms/traditionalpageone', + mandatory: true, + sectionType: 'submission-form', + collapsed: false, + enabled: true, + data: {}, + errors: [], + isLoading: false, + isValid: false + } as any, + traditionalpagetwo: { + header: 'submit.progressbar.describe.steptwo', + config: 'https://rest.api/dspace-spring-rest/api/config/submissionforms/traditionalpagetwo', + mandatory: false, + sectionType: 'submission-form', + collapsed: false, + enabled: false, + data: {}, + errors: [], + isLoading: false, + isValid: false + } as any, + upload: { + header: 'submit.progressbar.upload', + config: 'https://rest.api/dspace-spring-rest/api/config/submissionuploads/upload', + mandatory: true, + sectionType: 'upload', + collapsed: false, + enabled: true, + data: {}, + errors: [], + isLoading: false, + isValid: false + } as any, + license: { + header: 'submit.progressbar.license', + config: '', + mandatory: true, + sectionType: 'license', + visibility: { + main: null, + other: 'READONLY' + }, + collapsed: false, + enabled: true, + data: {}, + errors: [], + isLoading: false, + isValid: false + } as any +}; + +export const mockSectionsList = [ + { + config: 'https://rest.api/dspace-spring-rest/api/config/submissionforms/traditionalpageone', + mandatory: true, + data: {}, + errors: [], + header: 'submit.progressbar.describe.stepone', + id: 'traditionalpageone', + sectionType: 'submission-form' + }, + { + config: 'https://rest.api/dspace-spring-rest/api/config/submissionforms/traditionalpagetwo', + mandatory: true, + data: {}, + errors: [], + header: 'submit.progressbar.describe.steptwo', + id: 'traditionalpagetwo', + sectionType: 'submission-form' + }, + { + config: 'https://rest.api/dspace-spring-rest/api/config/submissionuploads/upload', + mandatory: true, + data: {}, + errors: [], + header: 'submit.progressbar.upload', + id: 'upload', + sectionType: 'upload' + }, + { + config: '', + mandatory: true, + data: {}, + errors: [], + header: 'submit.progressbar.license', + id: 'license', + sectionType: 'license' + } +]; diff --git a/src/app/submission/form/collection/submission-form-collection.component.html b/src/app/submission/form/collection/submission-form-collection.component.html index 2e5294ac7e..4ed14051f4 100644 --- a/src/app/submission/form/collection/submission-form-collection.component.html +++ b/src/app/submission/form/collection/submission-form-collection.component.html @@ -10,10 +10,10 @@ class="btn btn-outline-primary" (blur)="onClose()" (click)="onClose()" - [disabled]="disabled" + [disabled]="(disabled$ | async)" ngbDropdownToggle> - - {{ (selectedCollectionName) ? selectedCollectionName : '' }} + + {{ (selectedCollectionName) ? selectedCollectionName : '' }}
-