Skip to content

Commit

Permalink
VIH-10234 disable hearing type required when ref data toggle is on (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
shaed-parkar authored Oct 27, 2023
1 parent 3e3bd32 commit 2345994
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ describe('CreateHearingComponent with multiple case types', () => {
beforeEach(() => {
launchDarklyServiceSpy = jasmine.createSpyObj<LaunchDarklyService>('LaunchDarklyService', ['getFlag']);
launchDarklyServiceSpy.getFlag.withArgs(FeatureFlags.eJudFeature).and.returnValue(of(true));
launchDarklyServiceSpy.getFlag.withArgs(FeatureFlags.referenceData).and.returnValue(of(false));

videoHearingsServiceSpy = jasmine.createSpyObj<VideoHearingsService>('VideoHearingsService', [
'getHearingTypes',
Expand Down Expand Up @@ -187,6 +188,7 @@ describe('CreateHearingComponent with single case type', () => {
beforeEach(() => {
launchDarklyServiceSpy = jasmine.createSpyObj<LaunchDarklyService>('LaunchDarklyService', ['getFlag']);
launchDarklyServiceSpy.getFlag.withArgs(FeatureFlags.eJudFeature).and.returnValue(of(true));
launchDarklyServiceSpy.getFlag.withArgs(FeatureFlags.referenceData).and.returnValue(of(false));

videoHearingsServiceSpy = jasmine.createSpyObj<VideoHearingsService>('VideoHearingsService', [
'getHearingTypes',
Expand Down Expand Up @@ -237,6 +239,57 @@ describe('CreateHearingComponent with single case type', () => {
});
});

describe('CreateHearingComponent with ref data toggle on', () => {
let component: CreateHearingComponent;
let fixture: ComponentFixture<CreateHearingComponent>;
let hearingTypeControl: AbstractControl;
const newHearing = initHearingRequest();

beforeEach(() => {
launchDarklyServiceSpy = jasmine.createSpyObj<LaunchDarklyService>('LaunchDarklyService', ['getFlag']);
launchDarklyServiceSpy.getFlag.withArgs(FeatureFlags.eJudFeature).and.returnValue(of(true));
launchDarklyServiceSpy.getFlag.withArgs(FeatureFlags.referenceData).and.returnValue(of(true));

videoHearingsServiceSpy = jasmine.createSpyObj<VideoHearingsService>('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<CreateHearingComponent>;
Expand All @@ -246,6 +299,7 @@ describe('CreateHearingComponent with existing request in session', () => {
beforeEach(() => {
launchDarklyServiceSpy = jasmine.createSpyObj<LaunchDarklyService>('LaunchDarklyService', ['getFlag']);
launchDarklyServiceSpy.getFlag.withArgs(FeatureFlags.eJudFeature).and.returnValue(of(true));
launchDarklyServiceSpy.getFlag.withArgs(FeatureFlags.referenceData).and.returnValue(of(false));

videoHearingsServiceSpy = jasmine.createSpyObj<VideoHearingsService>('VideoHearingsService', [
'getHearingTypes',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -30,21 +33,29 @@ export class CreateHearingComponent extends BookingBaseComponent implements OnIn
filteredHearingTypes: HearingTypeResponse[] = [];
hasSaved: boolean;
isExistingHearing: boolean;
destroyed$ = new Subject<void>();

private refDataEnabled: boolean;

constructor(
protected hearingService: VideoHearingsService,
private fb: FormBuilder,
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;
this.availableCaseTypes = [];
}

ngOnInit() {
this.launchDarklyService
.getFlag<boolean>(FeatureFlags.referenceData)
.pipe(takeUntil(this.destroyed$))
.subscribe(flag => (this.refDataEnabled = flag));
this.failedSubmission = false;
this.checkForExistingRequestOrCreateNew();
this.initForm();
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -305,5 +316,7 @@ export class CreateHearingComponent extends BookingBaseComponent implements OnIn

ngOnDestroy() {
this.bookingService.removeEditMode();
this.destroyed$.next();
this.destroyed$.complete();
}
}

0 comments on commit 2345994

Please sign in to comment.