-
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: delimiter default case * test: delimiter custom case
- Loading branch information
1 parent
25fbc64
commit 6d4c3af
Showing
1 changed file
with
77 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,77 @@ | ||
import { cleanup, fireEvent, getByRole, render } from '@testing-library/react'; | ||
import { ReactMultiEmail } from '../react-multi-email'; | ||
import React from 'react'; | ||
|
||
afterEach(cleanup); | ||
|
||
describe('ReactMultiEmail delimiter TEST', () => { | ||
it('Default delimiter test', () => { | ||
const { getByRole } = render( | ||
<ReactMultiEmail | ||
getLabel={(email, index, removeEmail) => ( | ||
<div data-tag key={index}> | ||
<div data-tag-item>{email}</div> | ||
<span data-tag-handle onClick={() => removeEmail(index)}> | ||
× | ||
</span> | ||
</div> | ||
)} | ||
/>, | ||
); | ||
|
||
const inputElem = getByRole('textbox'); | ||
const emailsWrapper = document.querySelector('.data-labels'); | ||
const MAX_TEST_CASE = 3; | ||
|
||
for (let i = 0; i < MAX_TEST_CASE; i++) { | ||
const testValue = i === 0 ? 'test@gmail.com' : i === 1 ? 'test@naver.com' : 'test@tt.com'; | ||
const delimiter = i === 0 ? ' ' : i === 1 ? ',' : ';'; | ||
|
||
fireEvent.change(inputElem, { target: { value: testValue } }); | ||
expect(emailsWrapper?.childElementCount).toEqual(i); | ||
fireEvent.change(inputElem, { target: { value: `${testValue}${delimiter}` } }); | ||
expect(emailsWrapper?.childElementCount).toEqual(i + 1); | ||
} | ||
// 중복 체크 | ||
const duplicationValue = 'test@gmail.com'; | ||
fireEvent.change(inputElem, { target: { value: duplicationValue } }); | ||
expect(emailsWrapper?.childElementCount).toEqual(MAX_TEST_CASE); | ||
fireEvent.change(inputElem, { target: { value: `${duplicationValue};` } }); | ||
expect(emailsWrapper?.childElementCount).toEqual(MAX_TEST_CASE); | ||
}); | ||
|
||
it('Custom delimiter test', () => { | ||
const { getByRole } = render( | ||
<ReactMultiEmail | ||
delimiter='[&/]' | ||
getLabel={(email, index, removeEmail) => ( | ||
<div data-tag key={index}> | ||
<div data-tag-item>{email}</div> | ||
<span data-tag-handle onClick={() => removeEmail(index)}> | ||
× | ||
</span> | ||
</div> | ||
)} | ||
/>, | ||
); | ||
const inputElem = getByRole('textbox'); | ||
const emailsWrapper = document.querySelector('.data-labels'); | ||
const MAX_TEST_CASE = 2; | ||
|
||
for (let i = 0; i < MAX_TEST_CASE; i++) { | ||
const testValue = i === 0 ? 'test@gmail.com' : 'test@naver.com'; | ||
const delimiter = i === 0 ? '&' : '/'; | ||
|
||
fireEvent.change(inputElem, { target: { value: testValue } }); | ||
expect(emailsWrapper?.childElementCount).toEqual(i); | ||
fireEvent.change(inputElem, { target: { value: `${testValue}${delimiter}` } }); | ||
expect(emailsWrapper?.childElementCount).toEqual(i + 1); | ||
} | ||
// 중복 체크 | ||
const duplicationValue = 'test@gmail.com'; | ||
fireEvent.change(inputElem, { target: { value: duplicationValue } }); | ||
expect(emailsWrapper?.childElementCount).toEqual(MAX_TEST_CASE); | ||
fireEvent.change(inputElem, { target: { value: `${duplicationValue}/` } }); | ||
expect(emailsWrapper?.childElementCount).toEqual(MAX_TEST_CASE); | ||
}); | ||
}); |
6d4c3af
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-git-master-axframe.vercel.app
react-multi-email-axframe.vercel.app