-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add error messages directly to validator function return values, to a…
…void dependency in error-hint component
- Loading branch information
Showing
5 changed files
with
121 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/app/core/common-components/entity-form/unique-id-validator/unique-id-validator.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { waitForAsync } from "@angular/core/testing"; | ||
import { uniqueIdValidator } from "./unique-id-validator"; | ||
import { FormControl, ValidatorFn } from "@angular/forms"; | ||
|
||
describe("UniqueIdValidator", () => { | ||
let validator: ValidatorFn; | ||
|
||
let demoIds; | ||
let formControl: FormControl; | ||
|
||
beforeEach(waitForAsync(() => { | ||
demoIds = ["id1", "id2", "id3"]; | ||
formControl = new FormControl(); | ||
validator = uniqueIdValidator(demoIds); | ||
})); | ||
|
||
it("should validate new id", async () => { | ||
formControl.setValue("new id"); | ||
formControl.markAsDirty(); | ||
const validationResult = await validator(formControl); | ||
|
||
expect(validationResult).toBeNull(); | ||
}); | ||
|
||
it("should disallow already existing id", async () => { | ||
formControl.setValue(demoIds[1]); | ||
formControl.markAsDirty(); | ||
const validationResult = await validator(formControl); | ||
|
||
expect(validationResult).toEqual({ uniqueId: jasmine.any(String) }); | ||
}); | ||
|
||
it("should allow to keep unchanged value (to not refuse saving an existing entity with unchanged id)", async () => { | ||
formControl.setValue(demoIds[1]); | ||
formControl.markAsPristine(); | ||
const validationResult = await validator(formControl); | ||
|
||
expect(validationResult).toBeNull(); | ||
}); | ||
}); |
2 changes: 1 addition & 1 deletion
2
src/app/core/common-components/error-hint/error-hint.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
<div *ngFor="let err of form?.errors | keyvalue"> | ||
{{ validatorService.descriptionForValidator(err.key, err.value) }} | ||
{{ err.value["errorMessage"] }} | ||
<ng-content></ng-content> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters