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

feat: copy support async #48123

Merged
merged 16 commits into from Mar 29, 2024
Merged

feat: copy support async #48123

merged 16 commits into from Mar 29, 2024

Conversation

crazyair
Copy link
Member

@crazyair crazyair commented Mar 27, 2024

[中文版模板 / Chinese template]

🤔 This is a ...

  • New feature
  • Bug fix
  • Site / documentation update
  • Demo update
  • Component style update
  • TypeScript definition update
  • Bundle size optimization
  • Performance optimization
  • Enhancement feature
  • Internationalization
  • Refactoring
  • Code style optimization
  • Test Case
  • Branch merge
  • Workflow
  • Other (about what?)

🔗 Related issue link

#47860

💡 Background and solution

📝 Changelog

Language Changelog
🇺🇸 English Copy support async
🇨🇳 Chinese 支持异步复制

☑️ Self-Check before Merge

⚠️ Please check all items below before requesting a reviewing. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • TypeScript definition is updated/provided or not needed
  • Changelog is provided or not needed

Copy link

stackblitz bot commented Mar 27, 2024

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

Copy link
Contributor

github-actions bot commented Mar 27, 2024

👁 Visual Regression Report for PR #48123 Failed ❌

🎯 Target branch: feature (595e600)
📖 View Full Report ↗︎

Image name Expected Actual Diff
typography-copyable.compact.png feature: 595e600813ab1b1ef4540af16c6378e80554557f current: pr-48123 diff
typography-copyable.compact.css-var.png feature: 595e600813ab1b1ef4540af16c6378e80554557f current: pr-48123 diff
typography-copyable.dark.png feature: 595e600813ab1b1ef4540af16c6378e80554557f current: pr-48123 diff
typography-copyable.dark.css-var.png feature: 595e600813ab1b1ef4540af16c6378e80554557f current: pr-48123 diff
typography-copyable.default.png feature: 595e600813ab1b1ef4540af16c6378e80554557f current: pr-48123 diff
typography-copyable.default.css-var.png feature: 595e600813ab1b1ef4540af16c6378e80554557f current: pr-48123 diff

Check Full Report for details

Copy link
Contributor

github-actions bot commented Mar 27, 2024

Preview is ready

Copy link
Contributor

github-actions bot commented Mar 27, 2024

size-limit report 📦

Path Size
./dist/antd.min.js 336.12 KB (+108 B 🔺)
./dist/antd-with-locales.min.js 383.26 KB (+114 B 🔺)

Copy link

codesandbox-ci bot commented Mar 27, 2024

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

afc163
afc163 previously approved these changes Mar 27, 2024
Copy link

codecov bot commented Mar 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (100fa29) to head (230280d).
Report is 1 commits behind head on feature.

Additional details and impacted files
@@            Coverage Diff            @@
##           feature    #48123   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          742       743    +1     
  Lines        12817     12828   +11     
  Branches      3363      3364    +1     
=========================================
+ Hits         12817     12828   +11     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

afc163
afc163 previously approved these changes Mar 27, 2024
@afc163
Copy link
Member

afc163 commented Mar 27, 2024

测试用例需要补一下。

@crazyair
Copy link
Member Author

测试用例需要补一下。

catch 的吗?

@afc163
Copy link
Member

afc163 commented Mar 27, 2024

图片

看下哪里没覆盖到。

@li-jia-nan
Copy link
Member

image

@crazyair
Copy link
Member Author

测试用例需要补一下。

async function fetchData() {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      reject('Fetch error');
    }, 1000);
  });
}

test('fetchData should throw an error', async () => {
  expect.assertions(1);
  try {
    await fetchData();
  } catch (error) {
    expect(error).toEqual('Fetch error');
  }
});

这个能测异常,但是组件怎么写都报错。

@crazyair
Copy link
Member Author

throw 这玩意单测怎么写啊,单独 throw 可以,Demo 的 onClick 里 throw 就报错

const Demo = () => {
    return (
        <div
            onClick={() => {
                throw new Error('aaa');
            }}
        >
            11
        </div>
    );
};

test('demo', () => {
    expect.assertions(1);

    try {
        // const { getByText } = render(<Demo />);
        // fireEvent.click(getByText(/11/));
        throw new Error('aaa');
    } catch (error) {
        // console.log('222', error);
        // expect(error.message).toBe('aaa');
        expect('aaa').toBe('aaa');
    }
});

@arvinxx
Copy link
Contributor

arvinxx commented Mar 28, 2024

为了编写针对上述 React 组件的单元测试,我们将使用 Vitest 和 React 测试库。这个测试的目标是验证当 Demo 组件被点击时,是否会抛出预期的错误。由于这个错误是在一个事件处理器中抛出的,我们需要确保能够捕获这个错误并验证其内容。

首先,你需要安装相关的依赖:

npm install vitest react@latest react-dom@latest @testing-library/react

接下来,编写测试代码:

// Demo.test.tsx
import { describe, it, expect } from 'vitest';
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { Demo } from './Demo'; // 确保正确引入你的组件

describe('Demo Component', () => {
    it('should throw an error when clicked', async () => {
        render(<Demo />);
        
        // 捕获组件内部抛出的错误
        const errorHandler = vi.fn(); // 使用 Vitest 的 spy 功能
        window.addEventListener('error', errorHandler);

        // 模拟用户点击
        const divElement = screen.getByText('11');
        await userEvent.click(divElement);

        // 验证错误是否被正确捕获
        expect(errorHandler).toHaveBeenCalled();
        expect(errorHandler.mock.calls[0][0].error.message).toBe('aaa');

        // 清理
        window.removeEventListener('error', errorHandler);
    });
});

这个测试用例首先渲染 Demo 组件,然后模拟用户点击该组件。由于组件被点击时会抛出错误,我们通过添加一个全局的错误处理器来捕获这个错误,并验证错误信息是否符合预期。

注意,由于这个错误是通过事件处理器抛出的,它会被封装在一个 ErrorEvent 对象中,因此我们需要通过 errorHandler.mock.calls[0][0].error.message 来访问实际的错误信息。

另外,记得在测试完成后移除全局的错误处理器,以避免对其他测试造成影响。

这个测试案例展示了如何在组件内部事件处理器中抛出错误的情况下进行测试,确保你的组件在遇到错误时能够按预期行为运行。

@crazyair crazyair requested a review from afc163 March 29, 2024 02:00
@afc163 afc163 merged commit 8cc1d30 into feature Mar 29, 2024
104 of 105 checks passed
@afc163 afc163 deleted the copy-support-async branch March 29, 2024 05:20
MadCcc added a commit that referenced this pull request Mar 31, 2024
* fix: consistent with the tag component, the processing state uses colorInfo token. (#47695)

Signed-off-by: pfdgithub <pfdgithub@users.noreply.github.com>

* feat: Notification support aria-* in closable (#47710)

* feat: Notification support aria-* in closable

* feat: optimize code

* Cascader support option render (#47727)

* feat: done

* feat: doc

* feat: improve Transfer `key` type (#47879)

* feat: add Transfer's key type

* docs: update prop

* fix: key type

* fix: cycle dependency

* chore: update size limit (#47903)

Signed-off-by: Amumu <yoyo837@hotmail.com>

* chore: update size limit (#47904)

* feat: add Uzbek(latn) locale (#47899)

* feat: add Uzbek(latn) locale

* size-limit

* Update docs/react/i18n.zh-CN.md

Co-authored-by: afc163 <afc163@gmail.com>
Signed-off-by: Amumu <yoyo837@hotmail.com>

---------

Signed-off-by: Amumu <yoyo837@hotmail.com>
Co-authored-by: afc163 <afc163@gmail.com>
Co-authored-by: lijianan <574980606@qq.com>

* feat: support `showSorterTooltip.target` for Table sorters (#47409)

* Added `sorterTooltipTarget` prop for table sorters

* demo updated

* updated snapshot

* updated snapshot

* moved table tooltip target to `showSorterTooltip`

* fix

* updated docs

* empty commit

* updated version in docs

---------

Co-authored-by: Alina Andrieieva <Alina_Andrieieva@epam.com>

* feat: CP support FloatButton.Group closeIcon (#47953)

* Typography support collapse (#47264)

* feat: typograohy support collapse

* feat: snap

* feat: test

* feat: 单测不符合预期

* feat: test

* feat: 恢复

* feat: test

* feat: test

* feat: 修改命名

* feat: 代码优化

* feat: 添加控制台提示

* feat: snap

* feat: symbol support function

* feat: snap

* fix: text

* feat: snap

* feat: api 修改

* feat: key 修改

* feat: 去掉参数

* feat: lint

* feat: snap

* feat: test

* feat: use 2

* feat: review

* feat: test

* chore: part of it

* chore: fix auto collapse logic

* feat: 修改 doc 单测

* feat: doc

* test: update testcase

* docs: add more

---------

Co-authored-by: 二货机器人 <smith3816@gmail.com>

* feat: Table support onScroll event (#47986)

* feat: Popover can be closed by ESC when trigger is focus or click (#47928)

* feat:Add keydown event to handle escape

* fix

* fix:use exact same logic with popconfirm

* fix:move same logic from popconfirm to popover

* fix

* fix

* add test

* fix

* fix

* fix

* test size-limit

* fix

* fix popconfirm test

* fix

* fix

---------

Co-authored-by: afc163 <afc163@gmail.com>

* chore: update size-limit (#48014)

* feat: steps support for circular progress bar (#47940)

* feat: steps support for circular progress bar

* Update components/progress/index.zh-CN.md

Co-authored-by: afc163 <afc163@gmail.com>
Signed-off-by: lijianan <574980606@qq.com>

* Update components/progress/index.en-US.md

Signed-off-by: lijianan <574980606@qq.com>

* Update components/progress/index.en-US.md

Signed-off-by: lijianan <574980606@qq.com>

* Update components/progress/index.zh-CN.md

Signed-off-by: lijianan <574980606@qq.com>

* Update components/progress/index.zh-CN.md

Signed-off-by: lijianan <574980606@qq.com>

* Update components/progress/index.en-US.md

Signed-off-by: lijianan <574980606@qq.com>

* Update components/progress/progress.tsx

Signed-off-by: lijianan <574980606@qq.com>

* Update components/progress/__tests__/index.test.tsx

Signed-off-by: lijianan <574980606@qq.com>

* Update components/progress/demo/circle-steps.tsx

Signed-off-by: lijianan <574980606@qq.com>

* Update components/progress/index.en-US.md

Signed-off-by: lijianan <574980606@qq.com>

* Update components/progress/index.en-US.md

Signed-off-by: lijianan <574980606@qq.com>

* Update components/progress/index.zh-CN.md

Signed-off-by: lijianan <574980606@qq.com>

* Update components/progress/index.zh-CN.md

Signed-off-by: lijianan <574980606@qq.com>

* Update circle-steps.tsx

* Update components/progress/progress.tsx

Signed-off-by: lijianan <574980606@qq.com>

* Update components/progress/index.zh-CN.md

Signed-off-by: lijianan <574980606@qq.com>

* Update components/progress/index.zh-CN.md

Signed-off-by: lijianan <574980606@qq.com>

* Update components/progress/index.en-US.md

Signed-off-by: lijianan <574980606@qq.com>

* Update components/progress/index.en-US.md

Signed-off-by: lijianan <574980606@qq.com>

* Update package.json

* Update components/progress/demo/circle-steps.md

Co-authored-by: afc163 <afc163@gmail.com>
Signed-off-by: lijianan <574980606@qq.com>

---------

Signed-off-by: lijianan <574980606@qq.com>
Co-authored-by: lijianan <574980606@qq.com>
Co-authored-by: afc163 <afc163@gmail.com>

* demo: update Progress demo (#48052)

* demo: update Progress demo

* fix: fix

* fix: fix

* fix: fix

* fix: update snap

* chore: update size-limit (#48098)

* feat: add Scrollbar css token (#48109)

* feat: add Scrollbar css token

* docs: update docs

* feat: upgrade react-slick (#48093)

* feat: upgrade react-slick

* test: update snapshots

* test: update snapshots

---------

Co-authored-by: lijianan <574980606@qq.com>

* Revert "feat: add Scrollbar css token (#48109)" (#48115)

This reverts commit d0cc93b.

* feat: Input.OTP component support (#48076)

* chore: basic control

* chore: input instad

* docs: update demo

* chore: adjust operation interactive

* chore: lock selection

* chore: fix patch logic

* chore: merge logic

* chore: patch autoFocus

* test: update snapshot

* test: add test case

* test: coverage

* chore: update size limit

* docs: update docs

* test: fix test case

* chore: update comment

* refactor: change to length

* chore: blur all

* chore: size limit

* fix: Upload remove margin using flex display (#48091)

* fix: remove upload margin with flex

* fix

* use support not

* fix

* feat: copy support async (#48123)

* feat: copy support async

* feat: add test

* feat: doc

* feat: snap

* feat: add loading

* feat: 恢复 try

* feat: 判断是否是 Error

* feat: throw error

* feat: 为了醋包了饺子

* feat: remove code

* feat: add loading test

* fix: test

* fix: icon import way

* chore: improve test case code

* chore: improve test case code

---------

Co-authored-by: afc163 <afc163@gmail.com>

* feat: Table add `rowHoverable` to disable hover interaction (#48112)

* feat: Tag support aria-* in closable (#47678)

* feat: Tag support aria-* in closable

* feat: optimize code

* feat: optimize code

* feat: optimize code

* feat: optimize code

* feat: optimize code

* feat: optimize code

* feat: optimize code

* feat: optimize code

* feat: optimize code

* feat: optimize code

* feat: optimize code

* feat: optimize code

* feat: optimize code

* feat: optimize code

* feat: optimize code

* feat: optimize code

* feat: optimize code

* feat: optimize code

* feat: optimize code

* feat: optimize code

* feat: optimize code

* feat: optimize code

* feat: optimize code

* feat: optimize code

* feat: optimize code

* feat: optimize code

* feat: optimize code

* refactor: useClosable

* chore: modal

* fix: check logic

* chore: clean up

* feat: optimize code

* feat: optimize code

---------

Signed-off-by: kiner-tang <1127031143@qq.com>
Co-authored-by: 二货机器人 <smith3816@gmail.com>

---------

Signed-off-by: pfdgithub <pfdgithub@users.noreply.github.com>
Signed-off-by: Amumu <yoyo837@hotmail.com>
Signed-off-by: lijianan <574980606@qq.com>
Signed-off-by: kiner-tang <1127031143@qq.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: pfdgithub <pfdgithub@users.noreply.github.com>
Co-authored-by: kiner-tang <1127031143@qq.com>
Co-authored-by: 叶枫 <7971419+crazyair@users.noreply.github.com>
Co-authored-by: lijianan <574980606@qq.com>
Co-authored-by: 章鱼怪 <hi.madocto@gmail.com>
Co-authored-by: Amumu <yoyo837@hotmail.com>
Co-authored-by: afc163 <afc163@gmail.com>
Co-authored-by: Alina Andrieieva <emilialina@list.ru>
Co-authored-by: Alina Andrieieva <Alina_Andrieieva@epam.com>
Co-authored-by: 二货机器人 <smith3816@gmail.com>
Co-authored-by: Cooper <73218815+CooperHash@users.noreply.github.com>
Co-authored-by: yykoypj <601924094@qq.com>
@MadCcc MadCcc mentioned this pull request Mar 31, 2024
CooperHash pushed a commit to CooperHash/ant-design that referenced this pull request Apr 10, 2024
* feat: copy support async

* feat: add test

* feat: doc

* feat: snap

* feat: add loading

* feat: 恢复 try

* feat: 判断是否是 Error

* feat: throw error

* feat: 为了醋包了饺子

* feat: remove code

* feat: add loading test

* fix: test

* fix: icon import way

* chore: improve test case code

* chore: improve test case code

---------

Co-authored-by: afc163 <afc163@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants