-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add test and refactor
getFormattedEmailOptions
Signed-off-by: Oyelola Victoria <[email protected]>
- Loading branch information
Showing
2 changed files
with
62 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ import { useKibana } from '@kbn/kibana-react-plugin/public'; | |
import { triggersActionsUiMock } from '@kbn/triggers-actions-ui-plugin/public/mocks'; | ||
import EmailParamsFields from './email_params'; | ||
import { getIsExperimentalFeatureEnabled } from '../../common/get_experimental_features'; | ||
import { getFormattedEmailOptions } from './email_params'; | ||
|
||
jest.mock('@kbn/kibana-react-plugin/public', () => ({ | ||
useKibana: jest.fn(), | ||
|
@@ -234,3 +235,48 @@ describe('EmailParamsFields renders', () => { | |
expect(editAction).not.toHaveBeenCalled(); | ||
}); | ||
}); | ||
|
||
describe('getFormattedEmailOptions', () => { | ||
test('should return new options added to previous options', () => { | ||
const searchValue = '[email protected], [email protected]'; | ||
const previousOptions = [{ label: '[email protected]' }]; | ||
const newOptions = getFormattedEmailOptions(searchValue, previousOptions); | ||
|
||
expect(newOptions).toEqual([ | ||
{ label: '[email protected]' }, | ||
{ label: '[email protected]' }, | ||
{ label: '[email protected]' }, | ||
]); | ||
}); | ||
|
||
test('should trim extra spaces in search value', () => { | ||
const searchValue = ' [email protected] , [email protected] , '; | ||
const previousOptions: Array<{ label: string }> = []; | ||
const newOptions = getFormattedEmailOptions(searchValue, previousOptions); | ||
|
||
expect(newOptions).toEqual([{ label: '[email protected]' }, { label: '[email protected]' }]); | ||
}); | ||
|
||
test('should prevent duplicate email addresses', () => { | ||
const searchValue = '[email protected], [email protected]'; | ||
const previousOptions = [{ label: '[email protected]' }, { label: '[email protected]' }]; | ||
const newOptions = getFormattedEmailOptions(searchValue, previousOptions); | ||
|
||
expect(newOptions).toEqual([{ label: '[email protected]' }, { label: '[email protected]' }]); | ||
}); | ||
|
||
test('should return previous options if search value is empty', () => { | ||
const searchValue = ''; | ||
const previousOptions = [{ label: '[email protected]' }]; | ||
const newOptions = getFormattedEmailOptions(searchValue, previousOptions); | ||
expect(newOptions).toEqual([{ label: '[email protected]' }]); | ||
}); | ||
|
||
test('should handle single email without comma', () => { | ||
const searchValue = '[email protected]'; | ||
const previousOptions = [{ label: '[email protected]' }]; | ||
const newOptions = getFormattedEmailOptions(searchValue, previousOptions); | ||
|
||
expect(newOptions).toEqual([{ label: '[email protected]' }, { label: '[email protected]' }]); | ||
}); | ||
}); |
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