Skip to content

Commit a08173a

Browse files
[DURACOM-415] fix status update for cc license
(cherry picked from commit cc56fd5)
1 parent 0e0806f commit a08173a

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
@@ -16,6 +16,7 @@ import {
1616
import { TranslateModule } from '@ngx-translate/core';
1717
import { InfiniteScrollModule } from 'ngx-infinite-scroll';
1818
import {
19+
BehaviorSubject,
1920
Observable,
2021
of,
2122
Subscription,
@@ -154,6 +155,11 @@ export class SubmissionSectionCcLicensesComponent extends SectionModelComponent
154155

155156
ccLicenseLink$: Observable<string>;
156157

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

183190
ngOnChanges(changes: SimpleChanges): void {
@@ -310,7 +317,10 @@ export class SubmissionSectionCcLicensesComponent extends SectionModelComponent
310317
* the section status
311318
*/
312319
getSectionStatus(): Observable<boolean> {
313-
return of(this.accepted);
320+
return this.required$.pipe(
321+
map((required) => !required || this.accepted),
322+
distinctUntilChanged(),
323+
);
314324
}
315325

316326
/**

0 commit comments

Comments
 (0)