[ACS-9252] Create Button Not Enabled After Resolving Duplicate Folder Name Warning (#10635)

This commit is contained in:
dominikiwanekhyland 2025-02-12 10:59:10 +01:00 committed by GitHub
parent ddd81d8806
commit 287519ee24
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 2 deletions

View File

@ -15,7 +15,7 @@
* limitations under the License.
*/
import { TestBed, ComponentFixture } from '@angular/core/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { MatDialogRef } from '@angular/material/dialog';
import { NodesApiService } from '../../common/services/nodes-api.service';
@ -316,6 +316,17 @@ describe('FolderDialogComponent', () => {
component.submit();
});
it('should enable submit button after changing name field when previous value caused error', () => {
createFolderNode$.error(throwError('error'));
spyOn(component, 'handleError').and.callFake((val) => val);
component.form.controls['name'].setValue('');
component.submit();
expect(component.disableSubmitButton).toBeTrue();
component.form.controls['name'].setValue('testName');
expect(component.disableSubmitButton).toBeFalse();
});
});
});

View File

@ -16,7 +16,7 @@
*/
import { Observable } from 'rxjs';
import { Component, Inject, OnInit, Optional, EventEmitter, Output, ViewEncapsulation } from '@angular/core';
import { Component, DestroyRef, EventEmitter, inject, Inject, OnInit, Optional, Output, ViewEncapsulation } from '@angular/core';
import { ReactiveFormsModule, UntypedFormBuilder, UntypedFormGroup, Validators } from '@angular/forms';
import { MAT_DIALOG_DATA, MatDialogModule, MatDialogRef } from '@angular/material/dialog';
import { Node } from '@alfresco/js-api';
@ -29,6 +29,7 @@ import { MatFormFieldModule } from '@angular/material/form-field';
import { MatInputModule } from '@angular/material/input';
import { AutoFocusDirective } from '../../directives';
import { MatButtonModule } from '@angular/material/button';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
@Component({
selector: 'adf-folder-dialog',
@ -93,6 +94,8 @@ export class FolderDialogComponent implements OnInit {
};
}
private readonly destroyRef = inject(DestroyRef);
constructor(
private formBuilder: UntypedFormBuilder,
private dialog: MatDialogRef<FolderDialogComponent>,
@ -132,6 +135,8 @@ export class FolderDialogComponent implements OnInit {
title: [title],
description: [description]
});
this.form.controls['name'].valueChanges.pipe(takeUntilDestroyed(this.destroyRef)).subscribe(() => (this.disableSubmitButton = false));
}
submit() {