mirror of
https://github.com/ceph/ceph
synced 2026-08-02 07:03:18 +00:00
Merge pull request #70604 from rhcs-dashboard/service-form-text-label-fix
mgr/dashboard: fix cd-text-label-list string writeValue Reviewed-by: Nizamudeen A <nia@redhat.com>
This commit is contained in:
commit
0bb0d59a85
@ -41,6 +41,34 @@ describe('TextLabelListComponent', () => {
|
||||
expect(inputs[0].nativeElement.value).toBe('');
|
||||
});
|
||||
|
||||
it('should treat a string value as a single item', () => {
|
||||
component.writeValue('openid profile email');
|
||||
fixture.detectChanges();
|
||||
|
||||
const inputs = fixture.debugElement.queryAll(By.css('cds-text-label input'));
|
||||
expect(inputs.length).toBe(2);
|
||||
expect(inputs[0].nativeElement.value).toBe('openid profile email');
|
||||
expect(inputs[1].nativeElement.value).toBe('');
|
||||
});
|
||||
|
||||
it('should not spread a string into individual characters', () => {
|
||||
component.writeValue('openid');
|
||||
fixture.detectChanges();
|
||||
|
||||
const inputs = fixture.debugElement.queryAll(By.css('cds-text-label input'));
|
||||
expect(inputs.length).toBe(2);
|
||||
expect(inputs[0].nativeElement.value).toBe('openid');
|
||||
});
|
||||
|
||||
it('should treat null like an empty list', () => {
|
||||
component.writeValue(null);
|
||||
fixture.detectChanges();
|
||||
|
||||
const inputs = fixture.debugElement.queryAll(By.css('cds-text-label input'));
|
||||
expect(inputs.length).toBe(1);
|
||||
expect(inputs[0].nativeElement.value).toBe('');
|
||||
});
|
||||
|
||||
it('should call onTouch on input changes', () => {
|
||||
spyOn(component as any, 'onTouched');
|
||||
|
||||
|
||||
@ -44,8 +44,14 @@ export class TextLabelListComponent implements ControlValueAccessor {
|
||||
return originalValue.slice(0, -1) === value;
|
||||
}
|
||||
|
||||
writeValue(value: string[]): void {
|
||||
this.values = value?.length ? [...value, ''] : [''];
|
||||
writeValue(value: string[] | string | null): void {
|
||||
let items: string[] = [];
|
||||
if (typeof value === 'string') {
|
||||
items = value ? [value] : [];
|
||||
} else if (Array.isArray(value)) {
|
||||
items = [...value];
|
||||
}
|
||||
this.values = items.length ? [...items, ''] : [''];
|
||||
}
|
||||
|
||||
registerOnChange(onChange: (value: string[]) => void): void {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user