diff --git a/src/app/submission/sections/cc-license/submission-section-cc-licenses.component.spec.ts b/src/app/submission/sections/cc-license/submission-section-cc-licenses.component.spec.ts index b30d1fd758a..bcef6df20a2 100644 --- a/src/app/submission/sections/cc-license/submission-section-cc-licenses.component.spec.ts +++ b/src/app/submission/sections/cc-license/submission-section-cc-licenses.component.spec.ts @@ -241,7 +241,8 @@ describe('SubmissionSectionCcLicensesComponent', () => { }); it('should have section status incomplete', () => { - expect(component.getSectionStatus()).toBeObservable(cold('(a|)', { a: false })); + component.required$.next(true); + expect(component.getSectionStatus()).toBeObservable(cold('(a)', { a: false })); }); describe('when all options have a value selected', () => { @@ -271,7 +272,13 @@ describe('SubmissionSectionCcLicensesComponent', () => { }); it('should have section status incomplete', () => { - expect(component.getSectionStatus()).toBeObservable(cold('(a|)', { a: false })); + component.required$.next(true); + expect(component.getSectionStatus()).toBeObservable(cold('(a)', { a: false })); + }); + + it('should have section status complete if not required', () => { + component.required$.next(false); + expect(component.getSectionStatus()).toBeObservable(cold('(a)', { a: true })); }); describe('when the cc license is accepted', () => { @@ -282,7 +289,8 @@ describe('SubmissionSectionCcLicensesComponent', () => { }); it('should have section status complete', () => { - expect(component.getSectionStatus()).toBeObservable(cold('(a|)', { a: true })); + component.required$.next(false); + expect(component.getSectionStatus()).toBeObservable(cold('(a)', { a: true })); // first true is because the section is not required }); }); }); diff --git a/src/app/submission/sections/cc-license/submission-section-cc-licenses.component.ts b/src/app/submission/sections/cc-license/submission-section-cc-licenses.component.ts index bc1a2f347a0..6ffa50b4f1e 100644 --- a/src/app/submission/sections/cc-license/submission-section-cc-licenses.component.ts +++ b/src/app/submission/sections/cc-license/submission-section-cc-licenses.component.ts @@ -39,6 +39,7 @@ import { import { TranslateModule } from '@ngx-translate/core'; import { InfiniteScrollModule } from 'ngx-infinite-scroll'; import { + BehaviorSubject, Observable, of, Subscription, @@ -155,6 +156,11 @@ export class SubmissionSectionCcLicensesComponent extends SectionModelComponent ccLicenseLink$: Observable; + /** + * Is the section required + */ + public required$ = new BehaviorSubject(false); + constructor( protected modalService: NgbModal, protected sectionService: SectionsService, @@ -179,6 +185,7 @@ export class SubmissionSectionCcLicensesComponent extends SectionModelComponent if (hasNoValue(this.ccLicenseLink$)) { this.ccLicenseLink$ = this.getCcLicenseLink$(); } + this.required$.next(this.sectionData.mandatory); } ngOnChanges(changes: SimpleChanges): void { @@ -311,7 +318,10 @@ export class SubmissionSectionCcLicensesComponent extends SectionModelComponent * the section status */ getSectionStatus(): Observable { - return of(this.accepted); + return this.required$.pipe( + map((required) => !required || this.accepted), + distinctUntilChanged(), + ); } /**