-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feat/config-provider
- Loading branch information
Showing
4 changed files
with
104 additions
and
1 deletion.
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,5 @@ | ||
--- | ||
'@ant-design/web3': patch | ||
--- | ||
|
||
test:Increase ConnectButton test coverage |
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,5 @@ | ||
--- | ||
'@ant-design/web3': patch | ||
--- | ||
|
||
fix: fix intl for connect-button |
93 changes: 93 additions & 0 deletions
93
packages/web3/src/connect-button/__tests__/connect.test.tsx
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,93 @@ | ||
import React from 'react'; | ||
import { useProvider } from '@ant-design/web3'; | ||
import { fireEvent, render } from '@testing-library/react'; | ||
import { describe, expect, it, vi } from 'vitest'; | ||
|
||
import { ConnectButton, Web3ConfigProvider, type Account } from '../../../../web3/src'; | ||
|
||
describe('ConnectButton connect', async () => { | ||
it('connect', async () => { | ||
const CustomConnector = () => { | ||
const { connect, account, disconnect } = useProvider(); | ||
|
||
return ( | ||
<ConnectButton | ||
className="custom-btn" | ||
account={account} | ||
onConnectClick={() => { | ||
if (account) { | ||
disconnect?.(); | ||
return; | ||
} | ||
connect?.(); | ||
}} | ||
onDisconnectClick={() => { | ||
disconnect?.(); | ||
}} | ||
/> | ||
); | ||
}; | ||
|
||
const App = () => { | ||
const [account, setAccount] = React.useState<Account | undefined>(); | ||
return ( | ||
<Web3ConfigProvider | ||
availableWallets={[ | ||
{ | ||
name: 'MetaMask', | ||
remark: 'Easy-to-use browser extension.', | ||
extensions: [ | ||
{ | ||
key: 'Chrome', | ||
browserIcon: | ||
'https://github.com/ant-design/ant-design/assets/10286961/0d4e4ac7-8f89-4147-a06a-de72c02e85cb', | ||
browserName: 'Chrome', | ||
link: 'https://chrome.google.com/webstore/detail/metamask/nkbihfbeogaeaoehlefnkodbefgpgknn', | ||
description: 'Access your wallet right from your favorite web browser.', | ||
}, | ||
], | ||
}, | ||
]} | ||
connect={async () => { | ||
const newAccount = { | ||
address: '0x1234567890123456789012345678901234567890', | ||
}; | ||
setAccount(newAccount); | ||
}} | ||
disconnect={async () => { | ||
setAccount(undefined); | ||
}} | ||
account={account} | ||
> | ||
<CustomConnector /> | ||
</Web3ConfigProvider> | ||
); | ||
}; | ||
const { baseElement } = render(<App />); | ||
|
||
fireEvent.click(baseElement.querySelector('.custom-btn')!); | ||
await vi.waitFor(() => { | ||
expect(baseElement.querySelector('.ant-web3-address-text')?.textContent).toBe( | ||
'0x1234...7890', | ||
); | ||
}); | ||
|
||
fireEvent.click(baseElement.querySelector('.custom-btn')!); | ||
|
||
const btns = baseElement.querySelectorAll('.ant-btn'); | ||
fireEvent.click(baseElement.querySelector('.ant-modal-close')!); | ||
|
||
await vi.waitFor(() => { | ||
expect( | ||
baseElement.querySelector('.ant-web3-connect-button-profile-modal')?.className, | ||
).toContain('ant-zoom-leave'); | ||
}); | ||
|
||
fireEvent.click(btns[2]); | ||
await vi.waitFor(() => { | ||
expect(baseElement.querySelector('.ant-web3-connect-button-text')?.textContent).toBe( | ||
'Connect Wallet', | ||
); | ||
}); | ||
}); | ||
}); |
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