-
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.
- Loading branch information
1 parent
68e9041
commit 3a58b58
Showing
6 changed files
with
175 additions
and
137 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
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 |
---|---|---|
|
@@ -7,43 +7,47 @@ import { sleep } from './utils/sleep'; | |
afterEach(cleanup); | ||
|
||
describe('ReactMultEmail emails TEST', () => { | ||
it('Emails validation children node count', () => { | ||
render( | ||
<ReactMultiEmail | ||
emails={['test', 'tt', '[email protected]']} | ||
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('Emails validation children node count', async () => { | ||
await act(async () => { | ||
return render( | ||
<ReactMultiEmail | ||
emails={['test', 'tt', '[email protected]']} | ||
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 emailsWrapper = document.querySelector('.data-labels'); | ||
expect(emailsWrapper?.childElementCount).toEqual(1); | ||
}); | ||
|
||
it('Emails empty', () => { | ||
render( | ||
<ReactMultiEmail | ||
emails={[]} | ||
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('Emails empty', async () => { | ||
await act(async () => { | ||
return render( | ||
<ReactMultiEmail | ||
emails={[]} | ||
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 emptyElement = document.querySelector('.empty'); | ||
const emailsWrapper = document.querySelector('.data-labels'); | ||
|
@@ -52,22 +56,24 @@ describe('ReactMultEmail emails TEST', () => { | |
expect(emptyElement).toBeTruthy(); | ||
}); | ||
|
||
it('Emails with invalid text', () => { | ||
render( | ||
<ReactMultiEmail | ||
emails={['test', 'email']} | ||
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('Emails with invalid text', async () => { | ||
await act(async () => { | ||
return render( | ||
<ReactMultiEmail | ||
emails={['test', 'email']} | ||
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 emptyElement = document.querySelector('.empty'); | ||
const emailsWrapper = document.querySelector('.data-labels'); | ||
|
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 |
---|---|---|
@@ -1,64 +1,68 @@ | ||
import { cleanup, fireEvent, render } from '@testing-library/react'; | ||
import { ReactMultiEmail } from '../react-multi-email'; | ||
import React from 'react'; | ||
import { act } from 'react-dom/test-utils'; | ||
|
||
afterEach(cleanup); | ||
|
||
it('check enable and disabled executed ', () => { | ||
it('check enable and disabled executed ', async () => { | ||
const enableMockFunc = jest.fn().mockImplementation(({ emailCnt }: { emailCnt: number }) => emailCnt < 3); | ||
const disabledMockFunc = jest.fn(); | ||
const emailList = ['[email protected]', '[email protected]', '[email protected]']; | ||
|
||
const { getByRole } = render( | ||
<ReactMultiEmail | ||
enable={enableMockFunc} | ||
onDisabled={disabledMockFunc} | ||
emails={emailList} | ||
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 { getByRole } = await act(async () => { | ||
return render( | ||
<ReactMultiEmail | ||
enable={enableMockFunc} | ||
onDisabled={disabledMockFunc} | ||
emails={emailList} | ||
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 inputElement = getByRole('textbox'); | ||
fireEvent.keyDown(inputElement, { key: 'Enter', code: 'Enter' }); | ||
for (let i = 0; i < 3; i++) { | ||
fireEvent.change(inputElement, { target: { value: `test${i}@test.com` } }); | ||
fireEvent.keyDown(inputElement, { key: 'Enter', code: 'Enter' }); | ||
} | ||
|
||
expect(disabledMockFunc).toHaveBeenCalled(); | ||
}); | ||
|
||
it('check enable function is executed and disabled function is not executed', () => { | ||
it('check enable function is executed and disabled function is not executed', async () => { | ||
const enableMockFunc = jest.fn().mockImplementation(({ emailCnt }: { emailCnt: number }) => emailCnt < 3); | ||
const disabledMockFunc = jest.fn(); | ||
const emailList = ['[email protected]', '[email protected]']; | ||
|
||
const { getByRole } = render( | ||
<ReactMultiEmail | ||
enable={enableMockFunc} | ||
onDisabled={disabledMockFunc} | ||
emails={emailList} | ||
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 { getByRole } = await act(async () => { | ||
return render( | ||
<ReactMultiEmail | ||
enable={enableMockFunc} | ||
onDisabled={disabledMockFunc} | ||
emails={emailList} | ||
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 inputElement = getByRole('textbox'); | ||
fireEvent.keyDown(inputElement, { key: 'Enter', code: 'Enter' }); | ||
|
Oops, something went wrong.