Skip to content

Commit

Permalink
chore: bump rc-dropdown to 4.1.0 (#661)
Browse files Browse the repository at this point in the history
* chore: bump rc-dropdown to 4.1.0

* test: update
  • Loading branch information
MadCcc authored Apr 27, 2023
1 parent 10c39cd commit 808b9a6
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 19 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
21 changes: 21 additions & 0 deletions tests/common/util.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
});
}
}
43 changes: 25 additions & 18 deletions tests/overflow.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
getTabs,
getTransformX,
getTransformY,
triggerResize,
triggerResize, waitFakeTimer,
} from './common/util';

describe('Tabs.Overflow', () => {
Expand All @@ -25,7 +25,7 @@ describe('Tabs.Overflow', () => {
});
});

beforeAll(() => {
beforeEach(() => {
domSpy = spyElementPrototypes(HTMLElement, {
scrollIntoView: () => {},
offsetWidth: {
Expand All @@ -43,7 +43,7 @@ describe('Tabs.Overflow', () => {
});
});

afterAll(() => {
afterEach(() => {
domSpy.mockRestore();
});

Expand Down Expand Up @@ -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}`,
Expand Down Expand Up @@ -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();

Expand Down

1 comment on commit 808b9a6

@vercel
Copy link

@vercel vercel bot commented on 808b9a6 Apr 27, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

tabs – ./

tabs-git-master-react-component.vercel.app
tabs-react-component.vercel.app

Please sign in to comment.