Merge pull request #53697 from rhcs-dashboard/mds-number-validator-fix

mgr/dashboard: fix cephfs form validator

Reviewed-by: Pedro Gonzalez Gomez <pegonzal@redhat.com>
Reviewed-by: Aashish Sharma <aasharma@redhat.com>
Reviewed-by: Ankush Behl <cloudbehl@gmail.com>
This commit is contained in:
Nizamudeen A 2023-10-03 13:20:39 +05:30 committed by GitHub
commit b95fc36066
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 4 deletions

View File

@ -35,7 +35,7 @@
i18n>This field is required!</span>
<span *ngIf="form.showError('name', formDir, 'pattern')"
class="invalid-feedback"
i18n>File System name can only contain letters, numbers, '.', '-' or '_'</span>
i18n>File System name should start with a letter and can only contain letters, numbers, '.', '-' or '_'</span>
</div>
</div>

View File

@ -1,15 +1,17 @@
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ComponentFixture, TestBed, fakeAsync, tick } from '@angular/core/testing';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { RouterTestingModule } from '@angular/router/testing';
import { CephfsVolumeFormComponent } from './cephfs-form.component';
import { configureTestBed } from '~/testing/unit-test-helper';
import { FormHelper, configureTestBed } from '~/testing/unit-test-helper';
import { SharedModule } from '~/app/shared/shared.module';
import { ToastrModule } from 'ngx-toastr';
import { ReactiveFormsModule } from '@angular/forms';
describe('CephfsVolumeFormComponent', () => {
let component: CephfsVolumeFormComponent;
let fixture: ComponentFixture<CephfsVolumeFormComponent>;
let formHelper: FormHelper;
configureTestBed({
imports: [
BrowserAnimationsModule,
@ -24,9 +26,28 @@ describe('CephfsVolumeFormComponent', () => {
beforeEach(() => {
fixture = TestBed.createComponent(CephfsVolumeFormComponent);
component = fixture.componentInstance;
formHelper = new FormHelper(component.form);
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
it('should validate proper names', fakeAsync(() => {
const validNames = ['test', 'test1234', 'test_1234', 'test-1234', 'test.1234', 'test12test'];
const invalidNames = ['1234', 'test@', 'test)'];
for (const validName of validNames) {
formHelper.setValue('name', validName, true);
tick();
formHelper.expectValid('name');
}
for (const invalidName of invalidNames) {
formHelper.setValue('name', invalidName, true);
tick();
formHelper.expectError('name', 'pattern');
}
}));
});

View File

@ -82,7 +82,7 @@ export class CephfsVolumeFormComponent extends CdForm implements OnInit {
});
this.form = this.formBuilder.group({
name: new FormControl('', {
validators: [Validators.pattern(/^[.A-Za-z0-9_-]+$/), Validators.required]
validators: [Validators.pattern(/^[a-zA-Z][.A-Za-z0-9_-]+$/), Validators.required]
}),
placement: ['hosts'],
hosts: [[]],