mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
Add isSectionTypeAvailable method and use it to check if upload section is available
This commit is contained in:
@@ -1101,6 +1101,91 @@ export const mockSubmissionState: SubmissionObjectState = Object.assign({}, {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const mockSubmissionStateWithoutUpload: SubmissionObjectState = Object.assign({}, {
|
||||||
|
826: {
|
||||||
|
collection: mockSubmissionCollectionId,
|
||||||
|
definition: 'traditional',
|
||||||
|
selfUrl: mockSubmissionSelfUrl,
|
||||||
|
activeSection: null,
|
||||||
|
sections: {
|
||||||
|
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: [],
|
||||||
|
formId: '2_traditionalpageone',
|
||||||
|
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,
|
||||||
|
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
|
||||||
|
},
|
||||||
|
isLoading: false,
|
||||||
|
savePending: false,
|
||||||
|
depositPending: false
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
export const mockSectionsState = Object.assign({}, {
|
export const mockSectionsState = Object.assign({}, {
|
||||||
extraction: {
|
extraction: {
|
||||||
config: '',
|
config: '',
|
||||||
|
@@ -55,7 +55,7 @@ describe('SubmissionFormComponent Component', () => {
|
|||||||
{ provide: AuthService, useClass: AuthServiceStub },
|
{ provide: AuthService, useClass: AuthServiceStub },
|
||||||
{ provide: HALEndpointService, useValue: new HALEndpointServiceStub('workspaceitems') },
|
{ provide: HALEndpointService, useValue: new HALEndpointServiceStub('workspaceitems') },
|
||||||
{ provide: SubmissionService, useValue: submissionServiceStub },
|
{ provide: SubmissionService, useValue: submissionServiceStub },
|
||||||
{ provide: SectionsService, useValue: { isSectionAvailable: () => observableOf(true) } },
|
{ provide: SectionsService, useValue: { isSectionTypeAvailable: () => observableOf(true) } },
|
||||||
ChangeDetectorRef,
|
ChangeDetectorRef,
|
||||||
SubmissionFormComponent
|
SubmissionFormComponent
|
||||||
],
|
],
|
||||||
|
@@ -138,7 +138,7 @@ export class SubmissionFormComponent implements OnChanges, OnDestroy {
|
|||||||
return observableOf([]);
|
return observableOf([]);
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
this.uploadEnabled$ = this.sectionsService.isSectionAvailable(this.submissionId, SectionsType.Upload);
|
this.uploadEnabled$ = this.sectionsService.isSectionTypeAvailable(this.submissionId, SectionsType.Upload);
|
||||||
|
|
||||||
// check if is submission loading
|
// check if is submission loading
|
||||||
this.loading = this.submissionService.getSubmissionObject(this.submissionId).pipe(
|
this.loading = this.submissionService.getSubmissionObject(this.submissionId).pipe(
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
import { waitForAsync, TestBed } from '@angular/core/testing';
|
import { TestBed, waitForAsync } from '@angular/core/testing';
|
||||||
|
|
||||||
import { cold, getTestScheduler } from 'jasmine-marbles';
|
import { cold, getTestScheduler } from 'jasmine-marbles';
|
||||||
import { of as observableOf } from 'rxjs';
|
import { of as observableOf } from 'rxjs';
|
||||||
@@ -17,7 +17,8 @@ import { SectionsService } from './sections.service';
|
|||||||
import {
|
import {
|
||||||
mockSectionsData,
|
mockSectionsData,
|
||||||
mockSectionsErrors,
|
mockSectionsErrors,
|
||||||
mockSubmissionState
|
mockSubmissionState,
|
||||||
|
mockSubmissionStateWithoutUpload
|
||||||
} from '../../shared/mocks/submission.mock';
|
} from '../../shared/mocks/submission.mock';
|
||||||
import {
|
import {
|
||||||
DisableSectionAction,
|
DisableSectionAction,
|
||||||
@@ -27,11 +28,7 @@ import {
|
|||||||
SectionStatusChangeAction,
|
SectionStatusChangeAction,
|
||||||
UpdateSectionDataAction
|
UpdateSectionDataAction
|
||||||
} from '../objects/submission-objects.actions';
|
} from '../objects/submission-objects.actions';
|
||||||
import {
|
import { FormAddError, FormClearErrorsAction, FormRemoveErrorAction } from '../../shared/form/form.actions';
|
||||||
FormAddError,
|
|
||||||
FormClearErrorsAction,
|
|
||||||
FormRemoveErrorAction
|
|
||||||
} from '../../shared/form/form.actions';
|
|
||||||
import parseSectionErrors from '../utils/parseSectionErrors';
|
import parseSectionErrors from '../utils/parseSectionErrors';
|
||||||
import { SubmissionScopeType } from '../../core/submission/submission-scope-type';
|
import { SubmissionScopeType } from '../../core/submission/submission-scope-type';
|
||||||
import { SubmissionSectionError } from '../objects/submission-objects.reducer';
|
import { SubmissionSectionError } from '../objects/submission-objects.reducer';
|
||||||
@@ -52,6 +49,7 @@ describe('SectionsService test suite', () => {
|
|||||||
const sectionErrors: any = parseSectionErrors(mockSectionsErrors);
|
const sectionErrors: any = parseSectionErrors(mockSectionsErrors);
|
||||||
const sectionData: any = mockSectionsData;
|
const sectionData: any = mockSectionsData;
|
||||||
const submissionState: any = Object.assign({}, mockSubmissionState[submissionId]);
|
const submissionState: any = Object.assign({}, mockSubmissionState[submissionId]);
|
||||||
|
const submissionStateWithoutUpload: any = Object.assign({}, mockSubmissionStateWithoutUpload[submissionId]);
|
||||||
const sectionState: any = Object.assign({}, mockSubmissionState['826'].sections[sectionId]);
|
const sectionState: any = Object.assign({}, mockSubmissionState['826'].sections[sectionId]);
|
||||||
|
|
||||||
const store: any = jasmine.createSpyObj('store', {
|
const store: any = jasmine.createSpyObj('store', {
|
||||||
@@ -314,6 +312,28 @@ describe('SectionsService test suite', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('isSectionTypeAvailable', () => {
|
||||||
|
it('should return an observable of true when section is available', () => {
|
||||||
|
store.select.and.returnValue(observableOf(submissionState));
|
||||||
|
|
||||||
|
const expected = cold('(b|)', {
|
||||||
|
b: true
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(service.isSectionTypeAvailable(submissionId, SectionsType.Upload)).toBeObservable(expected);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return an observable of false when section is not available', () => {
|
||||||
|
store.select.and.returnValue(observableOf(submissionStateWithoutUpload));
|
||||||
|
|
||||||
|
const expected = cold('(b|)', {
|
||||||
|
b: false
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(service.isSectionAvailable(submissionId, SectionsType.Upload)).toBeObservable(expected);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('addSection', () => {
|
describe('addSection', () => {
|
||||||
it('should dispatch a new EnableSectionAction a move target to new section', () => {
|
it('should dispatch a new EnableSectionAction a move target to new section', () => {
|
||||||
|
|
||||||
|
@@ -5,7 +5,7 @@ import { distinctUntilChanged, filter, map, take } from 'rxjs/operators';
|
|||||||
import { Store } from '@ngrx/store';
|
import { Store } from '@ngrx/store';
|
||||||
import { TranslateService } from '@ngx-translate/core';
|
import { TranslateService } from '@ngx-translate/core';
|
||||||
import { ScrollToConfigOptions, ScrollToService } from '@nicky-lenaers/ngx-scroll-to';
|
import { ScrollToConfigOptions, ScrollToService } from '@nicky-lenaers/ngx-scroll-to';
|
||||||
import { isEqual } from 'lodash';
|
import { findKey, isEqual } from 'lodash';
|
||||||
|
|
||||||
import { SubmissionState } from '../submission.reducers';
|
import { SubmissionState } from '../submission.reducers';
|
||||||
import { hasValue, isEmpty, isNotEmpty, isNotUndefined } from '../../shared/empty.util';
|
import { hasValue, isEmpty, isNotEmpty, isNotUndefined } from '../../shared/empty.util';
|
||||||
@@ -291,14 +291,14 @@ export class SectionsService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if a given section is a read only available
|
* Check if a given section id is present in the list of sections
|
||||||
*
|
*
|
||||||
* @param submissionId
|
* @param submissionId
|
||||||
* The submission id
|
* The submission id
|
||||||
* @param sectionId
|
* @param sectionId
|
||||||
* The section id
|
* The section id
|
||||||
* @return Observable<boolean>
|
* @return Observable<boolean>
|
||||||
* Emits true whenever a given section should be available
|
* Emits true whenever a given section id should be available
|
||||||
*/
|
*/
|
||||||
public isSectionAvailable(submissionId: string, sectionId: string): Observable<boolean> {
|
public isSectionAvailable(submissionId: string, sectionId: string): Observable<boolean> {
|
||||||
return this.store.select(submissionObjectFromIdSelector(submissionId)).pipe(
|
return this.store.select(submissionObjectFromIdSelector(submissionId)).pipe(
|
||||||
@@ -309,6 +309,25 @@ export class SectionsService {
|
|||||||
distinctUntilChanged());
|
distinctUntilChanged());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a given section type is present in the list of sections
|
||||||
|
*
|
||||||
|
* @param submissionId
|
||||||
|
* The submission id
|
||||||
|
* @param sectionType
|
||||||
|
* The section type
|
||||||
|
* @return Observable<boolean>
|
||||||
|
* Emits true whenever a given section type should be available
|
||||||
|
*/
|
||||||
|
public isSectionTypeAvailable(submissionId: string, sectionType: SectionsType): Observable<boolean> {
|
||||||
|
return this.store.select(submissionObjectFromIdSelector(submissionId)).pipe(
|
||||||
|
filter((submissionState: SubmissionObjectEntry) => isNotUndefined(submissionState)),
|
||||||
|
map((submissionState: SubmissionObjectEntry) => {
|
||||||
|
return isNotUndefined(submissionState.sections) && isNotUndefined(findKey(submissionState.sections, {sectionType: sectionType}));
|
||||||
|
}),
|
||||||
|
distinctUntilChanged());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dispatch a new [EnableSectionAction] to add a new section and move page target to it
|
* Dispatch a new [EnableSectionAction] to add a new section and move page target to it
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user