-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
88 additions
and
4 deletions.
There are no files selected for viewing
78 changes: 78 additions & 0 deletions
78
x-pack/plugins/cases/public/components/observables/fields_config.test.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,78 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import type { ValidationFunc } from '@kbn/es-ui-shared-plugin/static/forms/hook_form_lib/types'; | ||
import { emailValidator, genericValidator } from './fields_config'; | ||
|
||
describe('emailValidator', () => { | ||
it('should return an error if the value is not a string', () => { | ||
const result = emailValidator({ | ||
value: undefined, | ||
path: 'email', | ||
} as Parameters<ValidationFunc>[0]); | ||
|
||
expect(result).toEqual({ | ||
code: 'ERR_NOT_STRING', | ||
message: 'Value should be a string', | ||
path: 'email', | ||
}); | ||
}); | ||
|
||
it('should return an error if the value is not a valid email', () => { | ||
const result = emailValidator({ | ||
value: 'invalid-email', | ||
path: 'email', | ||
} as Parameters<ValidationFunc>[0]); | ||
expect(result).toEqual({ | ||
code: 'ERR_NOT_EMAIL', | ||
message: 'Value should be an email', | ||
path: 'email', | ||
}); | ||
}); | ||
|
||
it('should return undefined if the value is a valid email', () => { | ||
const result = emailValidator({ | ||
value: '[email protected]', | ||
path: 'email', | ||
} as Parameters<ValidationFunc>[0]); | ||
expect(result).toBeUndefined(); | ||
}); | ||
}); | ||
|
||
describe('genericValidator', () => { | ||
it('should return an error if the value is not a string', () => { | ||
const result = genericValidator({ | ||
value: 123, | ||
path: 'generic', | ||
} as Parameters<ValidationFunc>[0]); | ||
expect(result).toEqual({ | ||
code: 'ERR_NOT_STRING', | ||
message: 'Value should be a string', | ||
path: 'generic', | ||
}); | ||
}); | ||
|
||
it('should return an error if the value is not valid', () => { | ||
const result = genericValidator({ | ||
value: 'invalid value!', | ||
path: 'generic', | ||
} as Parameters<ValidationFunc>[0]); | ||
expect(result).toEqual({ | ||
code: 'ERR_NOT_VALID', | ||
message: 'Value is invalid', | ||
path: 'generic', | ||
}); | ||
}); | ||
|
||
it('should return undefined if the value is valid', () => { | ||
const result = genericValidator({ | ||
value: 'valid_value', | ||
path: 'generic', | ||
} as Parameters<ValidationFunc>[0]); | ||
expect(result).toBeUndefined(); | ||
}); | ||
}); |
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