Skip to content

Commit cc56fd5

Browse files
[DURACOM-415] fix status update for cc license
1 parent d39bfaf commit cc56fd5

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

src/app/submission/sections/cc-license/submission-section-cc-licenses.component.spec.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,8 @@ describe('SubmissionSectionCcLicensesComponent', () => {
241241
});
242242

243243
it('should have section status incomplete', () => {
244-
expect(component.getSectionStatus()).toBeObservable(cold('(a|)', { a: false }));
244+
component.required$.next(true);
245+
expect(component.getSectionStatus()).toBeObservable(cold('(a)', { a: false }));
245246
});
246247

247248
describe('when all options have a value selected', () => {
@@ -271,7 +272,13 @@ describe('SubmissionSectionCcLicensesComponent', () => {
271272
});
272273

273274
it('should have section status incomplete', () => {
274-
expect(component.getSectionStatus()).toBeObservable(cold('(a|)', { a: false }));
275+
component.required$.next(true);
276+
expect(component.getSectionStatus()).toBeObservable(cold('(a)', { a: false }));
277+
});
278+
279+
it('should have section status complete if not required', () => {
280+
component.required$.next(false);
281+
expect(component.getSectionStatus()).toBeObservable(cold('(a)', { a: true }));
275282
});
276283

277284
describe('when the cc license is accepted', () => {
@@ -282,7 +289,8 @@ describe('SubmissionSectionCcLicensesComponent', () => {
282289
});
283290

284291
it('should have section status complete', () => {
285-
expect(component.getSectionStatus()).toBeObservable(cold('(a|)', { a: true }));
292+
component.required$.next(false);
293+
expect(component.getSectionStatus()).toBeObservable(cold('(a)', { a: true })); // first true is because the section is not required
286294
});
287295
});
288296
});

src/app/submission/sections/cc-license/submission-section-cc-licenses.component.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import {
3939
import { TranslateModule } from '@ngx-translate/core';
4040
import { InfiniteScrollModule } from 'ngx-infinite-scroll';
4141
import {
42+
BehaviorSubject,
4243
Observable,
4344
of,
4445
Subscription,
@@ -155,6 +156,11 @@ export class SubmissionSectionCcLicensesComponent extends SectionModelComponent
155156

156157
ccLicenseLink$: Observable<string>;
157158

159+
/**
160+
* Is the section required
161+
*/
162+
public required$ = new BehaviorSubject<boolean>(false);
163+
158164
constructor(
159165
protected modalService: NgbModal,
160166
protected sectionService: SectionsService,
@@ -179,6 +185,7 @@ export class SubmissionSectionCcLicensesComponent extends SectionModelComponent
179185
if (hasNoValue(this.ccLicenseLink$)) {
180186
this.ccLicenseLink$ = this.getCcLicenseLink$();
181187
}
188+
this.required$.next(this.sectionData.mandatory);
182189
}
183190

184191
ngOnChanges(changes: SimpleChanges): void {
@@ -311,7 +318,10 @@ export class SubmissionSectionCcLicensesComponent extends SectionModelComponent
311318
* the section status
312319
*/
313320
getSectionStatus(): Observable<boolean> {
314-
return of(this.accepted);
321+
return this.required$.pipe(
322+
map((required) => !required || this.accepted),
323+
distinctUntilChanged(),
324+
);
315325
}
316326

317327
/**

0 commit comments

Comments
 (0)