From 7fb650f76ebe47d22c2bde3e00090f0454b14737 Mon Sep 17 00:00:00 2001 From: mashina-moj Date: Wed, 29 Jul 2026 19:27:26 +0100 Subject: [PATCH] CHD-2305 & CHD-2306: add disable property to hearing-type autosuggest component and scheduling-slots component --- .../hearing-type.autosuggest.spec.ts.snap | 12 +++ .../hearing-type.autosuggest.spec.ts | 101 ++++++++++++++++++ .../components/hearing-type.autosuggest.ts | 6 ++ .../scheduling-slots.component.spec.ts.snap | 1 + .../scheduling-slots.component.html | 1 + .../scheduling-slots.component.spec.ts | 46 ++++++++ .../scheduling-slots.component.ts | 1 + 7 files changed, 168 insertions(+) create mode 100644 projects/reference-data/src/components/__tests__/__snapshots__/hearing-type.autosuggest.spec.ts.snap create mode 100644 projects/reference-data/src/components/__tests__/hearing-type.autosuggest.spec.ts diff --git a/projects/reference-data/src/components/__tests__/__snapshots__/hearing-type.autosuggest.spec.ts.snap b/projects/reference-data/src/components/__tests__/__snapshots__/hearing-type.autosuggest.spec.ts.snap new file mode 100644 index 0000000..d4a6d14 --- /dev/null +++ b/projects/reference-data/src/components/__tests__/__snapshots__/hearing-type.autosuggest.spec.ts.snap @@ -0,0 +1,12 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`HearingTypeAutosuggestComponent should render 1`] = ` + + + + + +`; diff --git a/projects/reference-data/src/components/__tests__/hearing-type.autosuggest.spec.ts b/projects/reference-data/src/components/__tests__/hearing-type.autosuggest.spec.ts new file mode 100644 index 0000000..0732b08 --- /dev/null +++ b/projects/reference-data/src/components/__tests__/hearing-type.autosuggest.spec.ts @@ -0,0 +1,101 @@ +import { CommonModule } from '@angular/common'; +import { Component, EventEmitter, Input, Output } from '@angular/core'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { By } from '@angular/platform-browser'; +import { StoreModule } from '@ngrx/store'; +import { referenceDataReducer } from '../../reducers'; +import { HearingTypeAutosuggestComponent } from '../hearing-type.autosuggest'; +import { PdkAutosuggestLiteComponent } from '@cpp/pdk'; + +describe('HearingTypeAutosuggestComponent', () => { + let fixture: ComponentFixture; + + beforeEach(() => { + TestBed.configureTestingModule({ + imports: [ + CommonModule, + StoreModule.forRoot(() => null, { + runtimeChecks: {} + }), + StoreModule.forFeature('referenceData', referenceDataReducer), + HearingTypeAutosuggestComponent + ], + declarations: [HearingTypeAutosuggestTestComponent] + }); + + TestBed.overrideComponent(HearingTypeAutosuggestComponent, { + remove: { + imports: [PdkAutosuggestLiteComponent] + }, + add: { + imports: [AutosuggestLiteMockComponent] + } + }); + + fixture = TestBed.createComponent(HearingTypeAutosuggestTestComponent); + fixture.detectChanges(); + }); + + it('should render', () => { + expect(fixture).toMatchSnapshot(); + }); + + describe('disabled', () => { + const autosuggestLiteInstance = () => + fixture.debugElement.query(By.directive(AutosuggestLiteMockComponent)).componentInstance; + + it('should default to enabled', () => { + expect(autosuggestLiteInstance().disabled).toBe(false); + }); + + it('should forward disabled to the inner autosuggest', () => { + fixture.componentInstance.disabled = true; + fixture.detectChanges(); + + expect(autosuggestLiteInstance().disabled).toBe(true); + }); + + it('should honour setDisabledState from the forms API', () => { + const hearingTypeAutosuggest = fixture.debugElement.query( + By.directive(HearingTypeAutosuggestComponent) + ).componentInstance as HearingTypeAutosuggestComponent; + + hearingTypeAutosuggest.setDisabledState(true); + fixture.detectChanges(); + + expect(autosuggestLiteInstance().disabled).toBe(true); + }); + }); +}); + +@Component({ + selector: 'cpp-hearing-type-autosuggest-test', + template: ` + + `, + standalone: false +}) +class HearingTypeAutosuggestTestComponent { + disabled = false; + id = 'id'; +} + +@Component({ + selector: 'pdk-autosuggest-lite', + template: `` +}) +class AutosuggestLiteMockComponent { + @Input() ariaDescribedBy?: string; + @Input() ariaLabel?: string; + @Input() ariaLabelledBy?: string; + @Input() disabled?: boolean; + @Input() hasError?: boolean; + @Input() highlightFirstSuggestion?: boolean; + @Input() highlightMatchedText?: boolean; + @Input() id?: string; + @Input() inputWidth?: number; + @Input() suggestions?: any[]; + @Input() suggestionKey?: string; + @Input() suggestionTitle?: string; + @Output() inputText = new EventEmitter(); +} diff --git a/projects/reference-data/src/components/hearing-type.autosuggest.ts b/projects/reference-data/src/components/hearing-type.autosuggest.ts index 0f01b0e..1a0c32a 100644 --- a/projects/reference-data/src/components/hearing-type.autosuggest.ts +++ b/projects/reference-data/src/components/hearing-type.autosuggest.ts @@ -24,6 +24,7 @@ import { AsyncPipe } from '@angular/common'; [ariaDescribedBy]="ariaDescribedBy" [ariaLabel]="ariaLabel" [ariaLabelledBy]="ariaLabelledBy" + [disabled]="disabled" [hasError]="hasError" [highlightFirstSuggestion]="highlightFirstSuggestion" [highlightMatchedText]="highlightMatchedText" @@ -55,6 +56,7 @@ export class HearingTypeAutosuggestComponent @Input() ariaDescribedBy: string | null = null; @Input() ariaLabel: string | null = null; @Input() ariaLabelledBy: string | null = null; + @Input() disabled = false; @Input() fetchOptionsOnMount = false; @Input() hasError = false; @Input() highlightFirstSuggestion?: boolean; @@ -136,6 +138,10 @@ export class HearingTypeAutosuggestComponent this.autosuggestLiteRef.writeValue(value); } + setDisabledState(isDisabled: boolean): void { + this.disabled = isDisabled; + } + // FormFieldControl forwarding get controlType() { diff --git a/projects/scheduling/src/components/scheduling-slots/__snapshots__/scheduling-slots.component.spec.ts.snap b/projects/scheduling/src/components/scheduling-slots/__snapshots__/scheduling-slots.component.spec.ts.snap index a16b578..78cdd69 100644 --- a/projects/scheduling/src/components/scheduling-slots/__snapshots__/scheduling-slots.component.spec.ts.snap +++ b/projects/scheduling/src/components/scheduling-slots/__snapshots__/scheduling-slots.component.spec.ts.snap @@ -10,6 +10,7 @@ exports[`SchedulingSlotsComponent should render 1`] = ` hearingSlotAllocations={[Function EventEmitter_]} hearingSlotMinutes="0" hearingSlots={[Function Array]} + hearingTypeDisabled="false" hearingTypesOptions={[Function Array]} maxPages={[Function Number]} pageChange={[Function EventEmitter_]} diff --git a/projects/scheduling/src/components/scheduling-slots/scheduling-slots.component.html b/projects/scheduling/src/components/scheduling-slots/scheduling-slots.component.html index 6c3f28c..a5aaeba 100644 --- a/projects/scheduling/src/components/scheduling-slots/scheduling-slots.component.html +++ b/projects/scheduling/src/components/scheduling-slots/scheduling-slots.component.html @@ -56,6 +56,7 @@ { ]); }); + describe('hearingTypeDisabled', () => { + beforeEach(() => { + component.totalResults = 1; + component.formConfig = { formFields: ['hearingType'] }; + component.hearingTypes = [ + { id: '1', hearingDescription: 'Trial' } + ] as unknown as HearingType[]; + component.hearingType = { id: '1', hearingDescription: 'Trial' } as HearingType; + }); + + it('should default to enabled', () => { + fixture.detectChanges(); + + const select = fixture.nativeElement.querySelector('pdk-select select'); + expect(component.hearingTypeDisabled).toBe(false); + expect(select.disabled).toBe(false); + }); + + it('should disable the hearing type select when set', () => { + component.hearingTypeDisabled = true; + fixture.detectChanges(); + + const select = fixture.nativeElement.querySelector('pdk-select select'); + expect(select.disabled).toBe(true); + }); + + it('should keep the preselected hearing type in the submit payload when disabled', () => { + component.hearingTypeDisabled = true; + component.allocations = [ + { + hearingSlot: { courtScheduleId: '1', slotBased: true, sessionDate: '2025-04-09' }, + hearingSlotTime: '2025-04-09T09:00:00.000Z' + } + ] as unknown as HearingSlotAllocation[]; + jest.spyOn(component.hearingSlotAllocations, 'emit'); + + component.handleSubmitAllocations(); + + expect(component.hearingSlotAllocations.emit).toHaveBeenCalledWith( + expect.objectContaining({ + hearingType: expect.objectContaining({ id: '1' }) + }) + ); + }); + }); + it('should emit pageChange event when triggered', () => { jest.spyOn(component.pageChange, 'emit'); component.pageChange.emit(2); diff --git a/projects/scheduling/src/components/scheduling-slots/scheduling-slots.component.ts b/projects/scheduling/src/components/scheduling-slots/scheduling-slots.component.ts index f84cc31..a11c57f 100644 --- a/projects/scheduling/src/components/scheduling-slots/scheduling-slots.component.ts +++ b/projects/scheduling/src/components/scheduling-slots/scheduling-slots.component.ts @@ -46,6 +46,7 @@ export class SchedulingSlotsComponent { @Input() currentPage = 1; @Input() hearingSlots: HearingSlot[] = []; @Input() hearingSlotMinutes?: number = 0; + @Input() hearingTypeDisabled = false; @Input() maxPages = 9; @Input() pageSize = 10; @Input() totalResults = 0;