From 808b9a6dbb67606258bf695db9909935b2ef9b15 Mon Sep 17 00:00:00 2001 From: MadCcc <1075746765@qq.com> Date: Thu, 27 Apr 2023 17:22:16 +0800 Subject: [PATCH] chore: bump rc-dropdown to 4.1.0 (#661) * chore: bump rc-dropdown to 4.1.0 * test: update --- package.json | 3 ++- tests/common/util.tsx | 21 ++++++++++++++++++++ tests/overflow.test.tsx | 43 ++++++++++++++++++++++++----------------- 3 files changed, 48 insertions(+), 19 deletions(-) diff --git a/package.json b/package.json index 1ecaca8b..e0bff250 100644 --- a/package.json +++ b/package.json @@ -41,6 +41,7 @@ }, "devDependencies": { "@rc-component/father-plugin": "^1.0.0", + "@rc-component/trigger": "^1.10.0", "@testing-library/jest-dom": "^5.16.4", "@testing-library/react": "^13.0.0", "@types/classnames": "^2.2.10", @@ -74,7 +75,7 @@ "dependencies": { "@babel/runtime": "^7.11.2", "classnames": "2.x", - "rc-dropdown": "~4.0.0", + "rc-dropdown": "~4.1.0", "rc-menu": "~9.8.0", "rc-motion": "^2.6.2", "rc-resize-observer": "^1.0.0", diff --git a/tests/common/util.tsx b/tests/common/util.tsx index 80d122b3..d41ac8e9 100644 --- a/tests/common/util.tsx +++ b/tests/common/util.tsx @@ -158,3 +158,24 @@ export const triggerResize = (container: Element) => { onEsResize([{ target } as ResizeObserverEntry]); }); }; + +/** + * Wait for a time delay. Will wait `advanceTime * times` ms. + * + * @param advanceTime Default 1000 + * @param times Default 20 + */ +export async function waitFakeTimer(advanceTime = 1000, times = 20) { + for (let i = 0; i < times; i += 1) { + // eslint-disable-next-line no-await-in-loop + await act(async () => { + await Promise.resolve(); + + if (advanceTime > 0) { + jest.advanceTimersByTime(advanceTime); + } else { + jest.runAllTimers(); + } + }); + } +} diff --git a/tests/overflow.test.tsx b/tests/overflow.test.tsx index 3a1c9727..718e4ae6 100644 --- a/tests/overflow.test.tsx +++ b/tests/overflow.test.tsx @@ -11,7 +11,7 @@ import { getTabs, getTransformX, getTransformY, - triggerResize, + triggerResize, waitFakeTimer, } from './common/util'; describe('Tabs.Overflow', () => { @@ -25,7 +25,7 @@ describe('Tabs.Overflow', () => { }); }); - beforeAll(() => { + beforeEach(() => { domSpy = spyElementPrototypes(HTMLElement, { scrollIntoView: () => {}, offsetWidth: { @@ -43,7 +43,7 @@ describe('Tabs.Overflow', () => { }); }); - afterAll(() => { + afterEach(() => { domSpy.mockRestore(); }); @@ -363,10 +363,26 @@ describe('Tabs.Overflow', () => { }); }); - it('auto hidden Dropdown', () => { + it('auto hidden Dropdown', async () => { jest.useFakeTimers(); - const originItems: TabsProps['items'] = new Array(8).fill(0).map((_, index) => ({ + domSpy = spyElementPrototypes(HTMLElement, { + scrollIntoView: () => {}, + offsetWidth: { + get: getOffsetSizeFunc({ ...hackOffsetInfo, container: 45 }), + }, + offsetHeight: { + get: getOffsetSizeFunc(hackOffsetInfo), + }, + offsetLeft: { + get: btnOffsetPosition, + }, + offsetTop: { + get: btnOffsetPosition, + }, + }); + + const originItems: TabsProps['items'] = new Array(2).fill(0).map((_, index) => ({ key: `${index}`, label: `Tab ${index + 1}`, children: `Tab Content${index + 1}`, @@ -406,20 +422,11 @@ describe('Tabs.Overflow', () => { jest.runAllTimers(); }); - while (true) { - const remove = document.querySelector('.rc-tabs-dropdown-menu-item-remove'); - if (!remove) { - break; - } - - act(() => { - fireEvent.click(remove); - }); + const remove = document.querySelector('.rc-tabs-dropdown-menu-item-remove'); - act(() => { - jest.runAllTimers(); - }); - } + act(() => { + fireEvent.click(remove); + }); expect(document.querySelector('.rc-tabs-dropdown-hidden')).toBeTruthy();