-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[AC-1609] Update domain name validation regex to support single lette…
…r name (#9336)
- Loading branch information
Showing
2 changed files
with
51 additions
and
16 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
...anage/domain-verification/domain-add-edit-dialog/validators/domain-name.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,37 @@ | ||
import { AbstractControl, ValidationErrors } from "@angular/forms"; | ||
|
||
import { domainNameValidator } from "./domain-name.validator"; | ||
|
||
describe("domainNameValidator", () => { | ||
let validatorFn: (control: AbstractControl) => ValidationErrors | null; | ||
const errorMessage = "Invalid domain name"; | ||
|
||
beforeEach(() => { | ||
validatorFn = domainNameValidator(errorMessage); | ||
}); | ||
|
||
const testCases = [ | ||
{ value: "e.com", expected: null }, | ||
{ value: "example.com", expected: null }, | ||
{ value: "sub.example.com", expected: null }, | ||
{ value: "sub.sub.example.com", expected: null }, | ||
{ value: "example.co.uk", expected: null }, | ||
{ value: "example", expected: { invalidDomainName: { message: errorMessage } } }, | ||
{ value: "-example.com", expected: { invalidDomainName: { message: errorMessage } } }, | ||
{ value: "example-.com", expected: { invalidDomainName: { message: errorMessage } } }, | ||
{ value: "example..com", expected: { invalidDomainName: { message: errorMessage } } }, | ||
{ value: "http://example.com", expected: { invalidDomainName: { message: errorMessage } } }, | ||
{ value: "www.example.com", expected: { invalidDomainName: { message: errorMessage } } }, | ||
{ value: "", expected: null }, | ||
{ value: "x".repeat(64) + ".com", expected: { invalidDomainName: { message: errorMessage } } }, | ||
]; | ||
|
||
describe("run test cases", () => { | ||
testCases.forEach(({ value, expected }) => { | ||
test(`should return ${JSON.stringify(expected)} for value "${value}"`, () => { | ||
const control = { value } as AbstractControl; | ||
expect(validatorFn(control)).toEqual(expected); | ||
}); | ||
}); | ||
}); | ||
}); |
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