Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: ConnectModal components test coverage #483

Merged
merged 3 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/angry-years-explode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@ant-design/web3': patch
---

test:ConnectModal components test coverage
41 changes: 40 additions & 1 deletion packages/web3/src/connect-modal/__tests__/basic.test.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { useEffect, useState } from 'react';
import React, { useEffect, useState } from 'react';
import type { DefaultGuide } from '@ant-design/web3';
import { ConnectModal } from '@ant-design/web3';
import { BitcoinCircleColorful } from '@ant-design/web3-icons';
import { fireEvent, render } from '@testing-library/react';
import { theme as antTheme, ConfigProvider, Grid } from 'antd';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';

import { mockBrowser } from '../../utils/test-utils';
import DefaultGuidePanel from '../components/DefaultGuidePanel';
import { groupOrder, guide, walletList } from './mock';

describe('ConnectModal with guide', () => {
Expand Down Expand Up @@ -163,4 +166,40 @@ describe('ConnectModal with guide', () => {
it('ModalPanel', async () => {
expect(ConnectModal.ModalPanel).not.toBeUndefined();
});

it('when DefaultGuidePanel guide is null', async () => {
const App = () => <DefaultGuidePanel guide={null as unknown as DefaultGuide} />;
const { baseElement } = render(<App />);
expect(baseElement.querySelector('.ant-web3-connect-modal-guide-panel')).toBeNull();
});

it('when DefaultGuidePanel guide is a valid React element', async () => {
const ValidReactElement: React.FC = () => <div className="custom">valid</div>;
const App = () => (
<DefaultGuidePanel
guide={React.createElement(ValidReactElement) as unknown as DefaultGuide}
/>
);
const { baseElement } = render(<App />);
expect(baseElement.querySelector('.custom')).toBeTruthy();
expect(baseElement.querySelector('.custom')?.textContent).toBe('valid');
});

it('when DefaultGuidePanel guide element icon is not string', async () => {
const Guide = {
title: 'title',
infos: [
{
icon: <BitcoinCircleColorful />,
title: 'title',
description: 'desc',
},
],
};
const App = () => <DefaultGuidePanel guide={Guide as unknown as DefaultGuide} />;
const { baseElement } = render(<App />);
// Show `ant-web3-connect-modal-guide-item-icon` classname only if icon is string
expect(baseElement.querySelector('.ant-web3-connect-modal-guide-item-icon')).toBeNull();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

icon 是 ReactNode 的时候应该也要能展示,比如是一个 svg 的时候。

Copy link
Collaborator Author

@thinkasany thinkasany Jan 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是会显示,但是这边组件内部的逻辑是ant-web3-connect-modal-guide-item-icon 这个classname只有在是icon是url的时候才显示。
image

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

想了想原来的数字确实不太合适,现在换成了web3-icons

expect(baseElement.querySelector('.ant-web3-icon-bitcoin-circle-colorful')).toBeTruthy();
});
});