fix value update for match detections (#11417)

This commit is contained in:
Nick Krantz 2024-10-04 13:16:21 -05:00 committed by GitHub
parent 935ae9d238
commit e6ff647343
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 2 deletions

View File

@ -96,6 +96,17 @@ describe("UriOptionComponent", () => {
expect(component["uriForm"].enabled).toBe(false); expect(component["uriForm"].enabled).toBe(false);
}); });
it("should update form when `writeValue` is invoked", () => {
expect(component["uriForm"].value).toEqual({ uri: null, matchDetection: null });
component.writeValue({ uri: "example.com", matchDetection: UriMatchStrategy.Exact });
expect(component["uriForm"].value).toEqual({
uri: "example.com",
matchDetection: UriMatchStrategy.Exact,
});
});
describe("match detection", () => { describe("match detection", () => {
it("should hide the match detection select by default", () => { it("should hide the match detection select by default", () => {
fixture.detectChanges(); fixture.detectChanges();

View File

@ -149,12 +149,12 @@ export class UriOptionComponent implements ControlValueAccessor {
} }
// NG_VALUE_ACCESSOR implementation // NG_VALUE_ACCESSOR implementation
writeValue(value: any): void { writeValue(value: { uri: string; matchDetection: UriMatchStrategySetting | null }): void {
if (value) { if (value) {
this.uriForm.setValue( this.uriForm.setValue(
{ {
uri: value.uri ?? "", uri: value.uri ?? "",
matchDetection: value.match ?? null, matchDetection: value.matchDetection ?? null,
}, },
{ emitEvent: false }, { emitEvent: false },
); );