-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* test : validateEmail props * test : email test logic 수정
- Loading branch information
Showing
1 changed file
with
94 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import { cleanup, fireEvent, render, waitFor } from '@testing-library/react'; | ||
import { ReactMultiEmail } from '../react-multi-email'; | ||
import React from 'react'; | ||
|
||
afterEach(cleanup); | ||
|
||
it('ReactMultiEmail validateEmail function works test', async () => { | ||
const mockValidateEmailFunc = jest.fn(); | ||
|
||
const { getByRole } = render( | ||
<ReactMultiEmail | ||
validateEmail={mockValidateEmailFunc} | ||
getLabel={(email, index, removeEmail) => { | ||
return ( | ||
<div data-tag key={index}> | ||
<div data-tag-item>{email}</div> | ||
<span data-tag-handle onClick={() => removeEmail(index)}> | ||
× | ||
</span> | ||
</div> | ||
); | ||
}} | ||
/>, | ||
); | ||
|
||
const input = getByRole('textbox') as HTMLElement; | ||
|
||
fireEvent.change(input, { target: { value: 'abc@gmail.com' } }); | ||
fireEvent.keyUp(input, { key: 'Enter', code: 'Enter' }); | ||
|
||
await waitFor(() => { | ||
expect(mockValidateEmailFunc).toHaveBeenCalled(); | ||
}); | ||
}); | ||
|
||
it('validateEmail = true , test code ending in .com', async () => { | ||
const regex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.(com)$/; | ||
const mockValidateEmailFunc = jest.fn().mockImplementation(email => regex.test(email)); | ||
|
||
const { getByRole } = render( | ||
<ReactMultiEmail | ||
validateEmail={mockValidateEmailFunc} | ||
getLabel={(email, index, removeEmail) => { | ||
return ( | ||
<div data-tag key={index}> | ||
<div data-tag-item>{email}</div> | ||
<span data-tag-handle onClick={() => removeEmail(index)}> | ||
× | ||
</span> | ||
</div> | ||
); | ||
}} | ||
/>, | ||
); | ||
|
||
const input = getByRole('textbox') as HTMLInputElement; | ||
|
||
fireEvent.change(input, { target: { value: 'abc@gmail.com' } }); | ||
|
||
await waitFor(() => { | ||
expect(mockValidateEmailFunc(input.value)).toBe(true); | ||
}); | ||
}); | ||
|
||
it('validateEmail = false', async () => { | ||
const regex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.(com)$/; | ||
const mockValidateEmailFunc = jest.fn().mockImplementation(email => regex.test(email)); | ||
|
||
const { getByRole } = render( | ||
<ReactMultiEmail | ||
validateEmail={mockValidateEmailFunc} | ||
getLabel={(email, index, removeEmail) => { | ||
return ( | ||
<div data-tag key={index}> | ||
<div data-tag-item>{email}</div> | ||
<span data-tag-handle onClick={() => removeEmail(index)}> | ||
× | ||
</span> | ||
</div> | ||
); | ||
}} | ||
/>, | ||
); | ||
|
||
const input = getByRole('textbox') as HTMLInputElement; | ||
|
||
fireEvent.change(input, { target: { value: 'abc@gmail.kr' } }); | ||
|
||
await waitFor(() => { | ||
expect(mockValidateEmailFunc(input.value)).toBe(false); | ||
}); | ||
}); | ||
|
||
export {}; |
25fbc64
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
react-multi-email – ./
react-multi-email.vercel.app
react-multi-email-axframe.vercel.app
react-multi-email-git-master-axframe.vercel.app