-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(onTokenSelectorClick): add onTokenSelectorClick event handler (#129
) * feat(onTokenSelectorClick): add event handler and optional handler setting hook * style(lint): lint action with ESLint * use handler * style(lint): lint action with ESLint * tests * style(lint): lint action with ESLint * tests! * style(lint): lint action with ESLint * add missing useCallback dep * test: expand test utils * update some test util stuff * style(lint): lint action with ESLint * useSyncEventHandlers * drop assert (node.js core lib not available in frontend env) * test cleanup * style(lint): lint action with ESLint * add Field arg to handler * style(lint): lint action with ESLint * add field hook dep Co-authored-by: Lint Action <lint-action@uniswap.org> Co-authored-by: Zach Pomerantz <zzmp@uniswap.org>
- Loading branch information
1 parent
1094e01
commit d88541b
Showing
15 changed files
with
272 additions
and
103 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
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 |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/** | ||
* @jest-environment hardhat/dist/jsdom | ||
*/ | ||
|
||
import '@ethersproject/providers' | ||
import 'jest-environment-hardhat' | ||
|
||
import { Field, onTokenSelectorClickAtom } from '../../state/swap' | ||
import { renderWidget, userEvent } from '../../test' | ||
import TokenSelect from './' | ||
|
||
describe('TokenSelect.tsx', () => { | ||
describe('onTokenSelectorClick', () => { | ||
it('should fire the onTokenSelectorClick handler when it exists', async () => { | ||
const user = userEvent.setup() | ||
const onTokenSelectorClick = jest.fn() | ||
|
||
const component = renderWidget( | ||
<TokenSelect field={Field.INPUT} value={undefined} collapsed disabled={false} onSelect={jest.fn()} />, | ||
{ | ||
initialAtomValues: [[onTokenSelectorClickAtom, onTokenSelectorClick]], | ||
} | ||
) | ||
|
||
await user.click(component.getByRole('button')) | ||
expect(onTokenSelectorClick).toHaveBeenCalledWith(Field.INPUT) | ||
}) | ||
it('should continue if the handler promise resolves to true', async () => { | ||
const user = userEvent.setup() | ||
|
||
const onTokenSelectorClick = jest.fn().mockResolvedValueOnce(true) | ||
|
||
const component = renderWidget( | ||
<TokenSelect field={Field.INPUT} value={undefined} collapsed={false} disabled={false} onSelect={jest.fn()} />, | ||
{ | ||
initialAtomValues: [[onTokenSelectorClickAtom, onTokenSelectorClick]], | ||
} | ||
) | ||
|
||
await user.click(component.getByRole('button')) | ||
expect(component.getByTestId('dialog-header').textContent).toBe('Select a token') | ||
}) | ||
it('should halt if the handler promise resolves to false', async () => { | ||
const user = userEvent.setup() | ||
|
||
const onTokenSelectorClick = jest.fn().mockResolvedValueOnce(false) | ||
|
||
const component = renderWidget( | ||
<TokenSelect field={Field.INPUT} value={undefined} collapsed={false} disabled={false} onSelect={jest.fn()} />, | ||
{ | ||
initialAtomValues: [[onTokenSelectorClickAtom, onTokenSelectorClick]], | ||
} | ||
) | ||
|
||
await user.click(component.getByRole('button')) | ||
expect(() => component.getByTestId('dialog-header')).toThrow() | ||
}) | ||
it('should halt if the handler promise rejects', async () => { | ||
const user = userEvent.setup() | ||
|
||
const onTokenSelectorClick = jest.fn().mockRejectedValueOnce(false) | ||
|
||
const component = renderWidget( | ||
<TokenSelect field={Field.INPUT} value={undefined} collapsed={false} disabled={false} onSelect={jest.fn()} />, | ||
{ | ||
initialAtomValues: [[onTokenSelectorClickAtom, onTokenSelectorClick]], | ||
} | ||
) | ||
|
||
await user.click(component.getByRole('button')) | ||
expect(() => component.getByTestId('dialog-header')).toThrow() | ||
}) | ||
}) | ||
}) |
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
Oops, something went wrong.
d88541b
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:
widgets – ./
widgets-uniswap.vercel.app
widgets-seven-tau.vercel.app
widgets-git-main-uniswap.vercel.app