mirror of
https://github.com/Alfresco/alfresco-content-app.git
synced 2026-09-09 18:02:54 +00:00
[ACS-9374] Add validator to aca-shared
This commit is contained in:
-50
@@ -1,50 +0,0 @@
|
||||
/*!
|
||||
* Copyright © 2005-2025 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Alfresco Example Content Application
|
||||
*
|
||||
* This file is part of the Alfresco Example Content Application.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* The Alfresco Example Content Application is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* The Alfresco Example Content Application is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* from Hyland Software. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { FormControl } from '@angular/forms';
|
||||
import { noWhitespaceValidator } from './no-whitespace.validator';
|
||||
|
||||
describe('noWhitespaceValidator', () => {
|
||||
const validatorFn = noWhitespaceValidator();
|
||||
|
||||
it('should return null for valid non-whitespace input', () => {
|
||||
const control = new FormControl('valid input');
|
||||
expect(validatorFn(control)).toBeNull();
|
||||
});
|
||||
|
||||
it('should return error for input with only spaces', () => {
|
||||
const control = new FormControl(' ');
|
||||
expect(validatorFn(control)).toEqual({ whitespace: true });
|
||||
});
|
||||
|
||||
it('should return error for empty string', () => {
|
||||
const control = new FormControl('');
|
||||
expect(validatorFn(control)).toBeNull();
|
||||
});
|
||||
|
||||
it('should return null for input with leading and trailing spaces but valid content inside', () => {
|
||||
const control = new FormControl(' valid ');
|
||||
expect(validatorFn(control)).toBeNull();
|
||||
});
|
||||
});
|
||||
-37
@@ -1,37 +0,0 @@
|
||||
/*!
|
||||
* Copyright © 2005-2025 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Alfresco Example Content Application
|
||||
*
|
||||
* This file is part of the Alfresco Example Content Application.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* The Alfresco Example Content Application is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* The Alfresco Example Content Application is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* from Hyland Software. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { AbstractControl, ValidationErrors, ValidatorFn } from '@angular/forms';
|
||||
|
||||
export const noWhitespaceValidator = (): ValidatorFn => {
|
||||
return (control: AbstractControl): ValidationErrors | null => {
|
||||
const rawValue = control.value;
|
||||
if (rawValue === null || rawValue === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
const trimmedValue = rawValue.toString().trim();
|
||||
return trimmedValue.length === 0 ? { whitespace: true } : null;
|
||||
};
|
||||
};
|
||||
+2
-2
@@ -31,7 +31,7 @@ import { MatFormFieldModule } from '@angular/material/form-field';
|
||||
import { MatInputModule } from '@angular/material/input';
|
||||
import { FormControl, FormsModule, ReactiveFormsModule, Validators } from '@angular/forms';
|
||||
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
||||
import { noWhitespaceValidator } from 'projects/aca-content/folder-rules/src/rule-details/validators/no-whitespace.validator';
|
||||
import { noWhitespaceValidator } from 'projects/aca-shared/src/lib/validators/no-whitespace.validator';
|
||||
|
||||
@Component({
|
||||
imports: [CommonModule, TranslatePipe, MatButtonModule, MatIconModule, MatFormFieldModule, MatInputModule, FormsModule, ReactiveFormsModule],
|
||||
@@ -106,6 +106,6 @@ export class SearchInputControlComponent implements OnInit {
|
||||
}
|
||||
|
||||
isTermTooShort() {
|
||||
return !!(this.searchTerm.trim() && this.searchTerm.trim().length < 2);
|
||||
return this.searchTerm.trim()?.length < 2;
|
||||
}
|
||||
}
|
||||
|
||||
+14
-10
@@ -36,17 +36,21 @@
|
||||
(submit)="onSearchSubmit($event)"
|
||||
(searchChange)="onSearchChange($event)"
|
||||
/>
|
||||
<mat-error *ngIf="hasLibrariesConstraint" class="app-search-error">
|
||||
{{ 'SEARCH.INPUT.HINT' | translate }}
|
||||
<mat-error *ngIf="searchInputControl.searchFieldFormControl.touched" class="app-search-error">
|
||||
<ng-container *ngIf="hasLibrariesConstraint; else checkRequired">
|
||||
{{ 'SEARCH.INPUT.HINT' | translate }}
|
||||
</ng-container>
|
||||
<ng-template #checkRequired>
|
||||
<ng-container *ngIf="searchInputControl.searchFieldFormControl.errors?.required; else checkWhitespace">
|
||||
{{ 'SEARCH.INPUT.REQUIRED' | translate }}
|
||||
</ng-container>
|
||||
</ng-template>
|
||||
<ng-template #checkWhitespace>
|
||||
<ng-container *ngIf="searchInputControl.searchFieldFormControl.errors?.whitespace">
|
||||
{{ 'SEARCH.INPUT.WHITESPACE' | translate }}
|
||||
</ng-container>
|
||||
</ng-template>
|
||||
</mat-error>
|
||||
<mat-error
|
||||
*ngIf="searchInputControl.searchFieldFormControl.errors?.required && searchInputControl.searchFieldFormControl.touched" class="app-search-error">
|
||||
{{ 'SEARCH.INPUT.REQUIRED' | translate }}
|
||||
</mat-error>
|
||||
<mat-error *ngIf="searchInputControl.searchFieldFormControl.errors?.whitespace && searchInputControl.searchFieldFormControl.touched" class="app-search-error">
|
||||
{{ 'SEARCH.INPUT.WHITESPACE' | translate }}
|
||||
</mat-error>
|
||||
|
||||
<div id="search-options" class="app-search-options">
|
||||
<mat-checkbox *ngFor="let option of searchOptions"
|
||||
id="{{ option.id }}"
|
||||
|
||||
+2
-2
@@ -47,13 +47,13 @@ describe('SearchInputComponent', () => {
|
||||
return error?.nativeElement.textContent.trim();
|
||||
}
|
||||
|
||||
async function openMenu() {
|
||||
async function openMenu(): Promise<MatMenuHarness> {
|
||||
const menu = await loader.getHarness(MatMenuHarness);
|
||||
await menu.open();
|
||||
return menu;
|
||||
}
|
||||
|
||||
async function getCheckbox(id: string) {
|
||||
function getCheckbox(id: string): Promise<MatCheckboxHarness> {
|
||||
const overlayLoader = TestbedHarnessEnvironment.documentRootLoader(fixture);
|
||||
return overlayLoader.getHarness(MatCheckboxHarness.with({ selector: `#${id}` }));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user