Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`HearingTypeAutosuggestComponent should render 1`] = `
<cpp-hearing-type-autosuggest-test
disabled="false"
id={[Function String]}
>
<cpp-hearing-type-autosuggest>
<pdk-autosuggest-lite />
</cpp-hearing-type-autosuggest>
</cpp-hearing-type-autosuggest-test>
`;
Original file line number Diff line number Diff line change
@@ -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<HearingTypeAutosuggestTestComponent>;

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<never>;

hearingTypeAutosuggest.setDisabledState(true);
fixture.detectChanges();

expect(autosuggestLiteInstance().disabled).toBe(true);
});
});
});

@Component({
selector: 'cpp-hearing-type-autosuggest-test',
template: `
<cpp-hearing-type-autosuggest [id]="id" [disabled]="disabled"> </cpp-hearing-type-autosuggest>
`,
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<string>();
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { AsyncPipe } from '@angular/common';
[ariaDescribedBy]="ariaDescribedBy"
[ariaLabel]="ariaLabel"
[ariaLabelledBy]="ariaLabelledBy"
[disabled]="disabled"
[hasError]="hasError"
[highlightFirstSuggestion]="highlightFirstSuggestion"
[highlightMatchedText]="highlightMatchedText"
Expand Down Expand Up @@ -55,6 +56,7 @@ export class HearingTypeAutosuggestComponent<T extends HearingType>
@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;
Expand Down Expand Up @@ -136,6 +138,10 @@ export class HearingTypeAutosuggestComponent<T extends HearingType>
this.autosuggestLiteRef.writeValue(value);
}

setDisabledState(isDisabled: boolean): void {
this.disabled = isDisabled;
}

// FormFieldControl forwarding

get controlType() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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_]}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
<pdk-select
[(ngModel)]="selectedHearingTypeId"
[name]="'hearingTypeId'"
[disabled]="hearingTypeDisabled"
justified
[options]="hearingTypesOptions"
required
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,52 @@ describe('SchedulingSlotsComponent', () => {
]);
});

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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading