-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Support duplicating * Add tests
- Loading branch information
Showing
2 changed files
with
71 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { cleanup, fireEvent, render } from '@testing-library/react'; | ||
import { ReactMultiEmail } from '../react-multi-email'; | ||
import React from 'react'; | ||
|
||
afterEach(cleanup); | ||
|
||
function createReactMultiEmail(allowDuplicate?: boolean) { | ||
return ( | ||
<ReactMultiEmail | ||
allowDuplicate={allowDuplicate} | ||
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> | ||
); | ||
}} | ||
/> | ||
); | ||
} | ||
it('allowDuplicate = true', async () => { | ||
const { getByRole } = render(createReactMultiEmail(true)); | ||
const textbox = getByRole('textbox'); | ||
|
||
const num = 3; | ||
for (let i = 0; i < num; i++) { | ||
fireEvent.change(textbox, { target: { value: `test@example.com` } }); | ||
fireEvent.keyUp(textbox, { key: 'Enter', code: 'Enter' }); | ||
} | ||
|
||
const emailsWrapper = document.querySelector('.data-labels'); | ||
expect(emailsWrapper?.childElementCount)?.toBe(num); | ||
}); | ||
|
||
it('allowDuplicate = false', async () => { | ||
const { getByRole } = render(createReactMultiEmail(false)); | ||
const textbox = getByRole('textbox'); | ||
|
||
const num = 3; | ||
for (let i = 0; i < num; i++) { | ||
fireEvent.change(textbox, { target: { value: `test@example.com` } }); | ||
fireEvent.keyUp(textbox, { key: 'Enter', code: 'Enter' }); | ||
} | ||
|
||
const emailsWrapper = document.querySelector('.data-labels'); | ||
expect(emailsWrapper?.childElementCount)?.toBe(1); | ||
}); | ||
|
||
it('allowDuplicate = undefined', async () => { | ||
const { getByRole } = render(createReactMultiEmail()); | ||
const textbox = getByRole('textbox'); | ||
|
||
const num = 3; | ||
for (let i = 0; i < num; i++) { | ||
fireEvent.change(textbox, { target: { value: `test@example.com` } }); | ||
fireEvent.keyUp(textbox, { key: 'Enter', code: 'Enter' }); | ||
} | ||
|
||
const emailsWrapper = document.querySelector('.data-labels'); | ||
expect(emailsWrapper?.childElementCount)?.toBe(1); | ||
}); |
1ca3287
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-axframe.vercel.app
react-multi-email-git-master-axframe.vercel.app
react-multi-email.vercel.app