From 23459947922d1a6276ae02311a89f5b10be66d29 Mon Sep 17 00:00:00 2001 From: shaed-parkar <41630528+shaed-parkar@users.noreply.github.com> Date: Fri, 27 Oct 2023 15:34:59 +0100 Subject: [PATCH] VIH-10234 disable hearing type required when ref data toggle is on (#1293) --- .../create-hearing.component.spec.ts | 54 +++++++++++++++++++ .../create-hearing.component.ts | 17 +++++- 2 files changed, 69 insertions(+), 2 deletions(-) diff --git a/AdminWebsite/AdminWebsite/ClientApp/src/app/booking/create-hearing/create-hearing.component.spec.ts b/AdminWebsite/AdminWebsite/ClientApp/src/app/booking/create-hearing/create-hearing.component.spec.ts index 181db3e50..82b2a95a5 100644 --- a/AdminWebsite/AdminWebsite/ClientApp/src/app/booking/create-hearing/create-hearing.component.spec.ts +++ b/AdminWebsite/AdminWebsite/ClientApp/src/app/booking/create-hearing/create-hearing.component.spec.ts @@ -55,6 +55,7 @@ describe('CreateHearingComponent with multiple case types', () => { beforeEach(() => { launchDarklyServiceSpy = jasmine.createSpyObj('LaunchDarklyService', ['getFlag']); launchDarklyServiceSpy.getFlag.withArgs(FeatureFlags.eJudFeature).and.returnValue(of(true)); + launchDarklyServiceSpy.getFlag.withArgs(FeatureFlags.referenceData).and.returnValue(of(false)); videoHearingsServiceSpy = jasmine.createSpyObj('VideoHearingsService', [ 'getHearingTypes', @@ -187,6 +188,7 @@ describe('CreateHearingComponent with single case type', () => { beforeEach(() => { launchDarklyServiceSpy = jasmine.createSpyObj('LaunchDarklyService', ['getFlag']); launchDarklyServiceSpy.getFlag.withArgs(FeatureFlags.eJudFeature).and.returnValue(of(true)); + launchDarklyServiceSpy.getFlag.withArgs(FeatureFlags.referenceData).and.returnValue(of(false)); videoHearingsServiceSpy = jasmine.createSpyObj('VideoHearingsService', [ 'getHearingTypes', @@ -237,6 +239,57 @@ describe('CreateHearingComponent with single case type', () => { }); }); +describe('CreateHearingComponent with ref data toggle on', () => { + let component: CreateHearingComponent; + let fixture: ComponentFixture; + let hearingTypeControl: AbstractControl; + const newHearing = initHearingRequest(); + + beforeEach(() => { + launchDarklyServiceSpy = jasmine.createSpyObj('LaunchDarklyService', ['getFlag']); + launchDarklyServiceSpy.getFlag.withArgs(FeatureFlags.eJudFeature).and.returnValue(of(true)); + launchDarklyServiceSpy.getFlag.withArgs(FeatureFlags.referenceData).and.returnValue(of(true)); + + videoHearingsServiceSpy = jasmine.createSpyObj('VideoHearingsService', [ + 'getHearingTypes', + 'getCurrentRequest', + 'updateHearingRequest', + 'cancelRequest', + 'setBookingHasChanged' + ]); + routerSpy = jasmine.createSpyObj('Router', ['navigate']); + bookingServiceSpy = jasmine.createSpyObj('BookingSErvice', ['isEditMode', 'resetEditMode', 'removeEditMode']); + videoHearingsServiceSpy.getCurrentRequest.and.returnValue(newHearing); + videoHearingsServiceSpy.getHearingTypes.and.returnValue(of(MockValues.HearingTypesSingle)); + + TestBed.configureTestingModule({ + imports: [HttpClientModule, ReactiveFormsModule, RouterTestingModule], + providers: [ + { provide: VideoHearingsService, useValue: videoHearingsServiceSpy }, + { provide: Router, useValue: routerSpy }, + { provide: ErrorService, useValue: errorService }, + { provide: BookingService, useValue: bookingServiceSpy }, + { provide: Logger, useValue: loggerSpy }, + { provide: LaunchDarklyService, useValue: launchDarklyServiceSpy } + ], + declarations: [CreateHearingComponent, BreadcrumbComponent, CancelPopupComponent, DiscardConfirmPopupComponent] + }).compileComponents(); + + fixture = TestBed.createComponent(CreateHearingComponent); + component = fixture.componentInstance; + component.ngOnInit(); + fixture.detectChanges(); + + hearingTypeControl = component.form.controls['hearingType']; + }); + + it('should pass validation when no hearing type is not set', () => { + expect(hearingTypeControl.valid).toBeTruthy(); + hearingTypeControl.setValue(2); + expect(hearingTypeControl.valid).toBeTruthy(); + }); +}); + describe('CreateHearingComponent with existing request in session', () => { let component: CreateHearingComponent; let fixture: ComponentFixture; @@ -246,6 +299,7 @@ describe('CreateHearingComponent with existing request in session', () => { beforeEach(() => { launchDarklyServiceSpy = jasmine.createSpyObj('LaunchDarklyService', ['getFlag']); launchDarklyServiceSpy.getFlag.withArgs(FeatureFlags.eJudFeature).and.returnValue(of(true)); + launchDarklyServiceSpy.getFlag.withArgs(FeatureFlags.referenceData).and.returnValue(of(false)); videoHearingsServiceSpy = jasmine.createSpyObj('VideoHearingsService', [ 'getHearingTypes', diff --git a/AdminWebsite/AdminWebsite/ClientApp/src/app/booking/create-hearing/create-hearing.component.ts b/AdminWebsite/AdminWebsite/ClientApp/src/app/booking/create-hearing/create-hearing.component.ts index 37cb0f09c..d323fd51d 100644 --- a/AdminWebsite/AdminWebsite/ClientApp/src/app/booking/create-hearing/create-hearing.component.ts +++ b/AdminWebsite/AdminWebsite/ClientApp/src/app/booking/create-hearing/create-hearing.component.ts @@ -12,6 +12,9 @@ import { PageUrls } from 'src/app/shared/page-url.constants'; import { Constants } from 'src/app/common/constants'; import { SanitizeInputText } from '../../common/formatters/sanitize-input-text'; import { Logger } from 'src/app/services/logger'; +import { FeatureFlags, LaunchDarklyService } from '../../services/launch-darkly.service'; +import { takeUntil } from 'rxjs/operators'; +import { Subject } from 'rxjs'; @Component({ selector: 'app-create-hearing', @@ -30,6 +33,9 @@ export class CreateHearingComponent extends BookingBaseComponent implements OnIn filteredHearingTypes: HearingTypeResponse[] = []; hasSaved: boolean; isExistingHearing: boolean; + destroyed$ = new Subject(); + + private refDataEnabled: boolean; constructor( protected hearingService: VideoHearingsService, @@ -37,7 +43,8 @@ export class CreateHearingComponent extends BookingBaseComponent implements OnIn protected router: Router, protected bookingService: BookingService, protected logger: Logger, - private errorService: ErrorService + private errorService: ErrorService, + private launchDarklyService: LaunchDarklyService ) { super(bookingService, router, hearingService, logger); this.attemptingCancellation = false; @@ -45,6 +52,10 @@ export class CreateHearingComponent extends BookingBaseComponent implements OnIn } ngOnInit() { + this.launchDarklyService + .getFlag(FeatureFlags.referenceData) + .pipe(takeUntil(this.destroyed$)) + .subscribe(flag => (this.refDataEnabled = flag)); this.failedSubmission = false; this.checkForExistingRequestOrCreateNew(); this.initForm(); @@ -93,7 +104,7 @@ export class CreateHearingComponent extends BookingBaseComponent implements OnIn [Validators.required, Validators.pattern(Constants.TextInputPattern), Validators.maxLength(255)] ], caseType: [this.selectedCaseType, [Validators.required, Validators.pattern('^((?!Please select).)*$')]], - hearingType: [this.hearing.hearing_type_id, [Validators.required, Validators.min(1)]] + hearingType: [this.hearing.hearing_type_id, this.refDataEnabled ? [] : [Validators.required, Validators.min(1)]] }); if (this.isExistingHearingOrParticipantsAdded()) { @@ -305,5 +316,7 @@ export class CreateHearingComponent extends BookingBaseComponent implements OnIn ngOnDestroy() { this.bookingService.removeEditMode(); + this.destroyed$.next(); + this.destroyed$.complete(); } }