From 12f28c38e43edde702ff418d6900c173854054c2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?kiner-tang=28=E6=96=87=E8=BE=89=29?= <1127031143@qq.com>
Date: Sat, 25 Nov 2023 21:42:31 +0800
Subject: [PATCH] feat: optimize code
---
.../__snapshots__/menu.test.tsx.snap | 245 ++++++++++++++++++
.../connect-button/__tests__/menu.test.tsx | 8 +-
.../src/connect-button/connect-button.tsx | 24 +-
3 files changed, 262 insertions(+), 15 deletions(-)
create mode 100644 packages/web3/src/connect-button/__tests__/__snapshots__/menu.test.tsx.snap
diff --git a/packages/web3/src/connect-button/__tests__/__snapshots__/menu.test.tsx.snap b/packages/web3/src/connect-button/__tests__/__snapshots__/menu.test.tsx.snap
new file mode 100644
index 000000000..d1810f92a
--- /dev/null
+++ b/packages/web3/src/connect-button/__tests__/__snapshots__/menu.test.tsx.snap
@@ -0,0 +1,245 @@
+// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
+
+exports[`ConnectButton > Should show menu when hover button 1`] = `
+
+
+
+
+
+
+`;
+
+exports[`ConnectButton > Should show profile modal when click button 1`] = `
+
+
+
+
+`;
diff --git a/packages/web3/src/connect-button/__tests__/menu.test.tsx b/packages/web3/src/connect-button/__tests__/menu.test.tsx
index 3b3e29422..1e861d26f 100644
--- a/packages/web3/src/connect-button/__tests__/menu.test.tsx
+++ b/packages/web3/src/connect-button/__tests__/menu.test.tsx
@@ -64,16 +64,18 @@ describe('ConnectButton', () => {
});
});
it('Should show profile modal when click button', async () => {
- const App = () => ;
+ const App = () => (
+
+ );
const { baseElement } = render();
- fireEvent.click(baseElement.querySelector('.ant-web3-connect-button') as Element);
+ fireEvent.click(baseElement.querySelector('.ant-web3-connect-button-text') as Element);
await vi.waitFor(() => {
expect(baseElement.querySelector('.ant-web3-connect-button-profile-modal')).not.toBeNull();
expect(baseElement).toMatchSnapshot();
});
});
- it.only('Should call action when click menu item with build-in action key', async () => {
+ it('Should call action when click menu item with build-in action key', async () => {
const onDisconnectClick = vi.fn();
const App = () => (
= (props) => {
buttonText = name ?? ;
}
- const onClickButton: React.MouseEventHandler = (e) => {
- const { onClick } = props;
- if (clickActionType !== 'showMenu' && connected && !profileOpen) {
- setProfileOpen(true);
- } else {
- onConnectClick?.();
- }
- onClick?.(e);
- };
-
const buttonProps: ButtonProps = {
style: props.style,
className: classNames(props.className, hashId, prefixCls),
size: props.size,
type: props.type,
ghost: props.ghost,
- onClick: onClickButton,
...restProps,
};
@@ -97,7 +86,18 @@ export const ConnectButton: React.FC = (props) => {
}
}
/>
- {buttonText}
+ {
+ if (clickActionType !== 'showMenu' && connected && !profileOpen) {
+ setProfileOpen(true);
+ } else {
+ onConnectClick?.();
+ }
+ }}
+ >
+ {buttonText}
+
);