Skip to content

Commit

Permalink
test: foreach all placement
Browse files Browse the repository at this point in the history
  • Loading branch information
zpc7 committed May 7, 2022
1 parent 55f9e29 commit 22b89ee
Showing 1 changed file with 39 additions and 19 deletions.
58 changes: 39 additions & 19 deletions components/tooltip/__tests__/tooltip.test.js
Expand Up @@ -314,27 +314,47 @@ describe('Tooltip', () => {
}).not.toThrow();
});

it('other placement when mouse enter', async () => {
const { container } = render(
<Tooltip
title="xxxxx"
placement="topRight"
transitionName=""
popupTransitionName=""
mouseEnterDelay={0}
>
<span>Hello world!</span>
</Tooltip>,
);
describe('support other placement when mouse enter', () => {
const placementList = [
'top',
'left',
'right',
'bottom',
'topLeft',
'topRight',
'bottomLeft',
'bottomRight',
'leftTop',
'leftBottom',
'rightTop',
'rightBottom',
];
const testPlacement = (name, placement) => {
it(name, async () => {
const { container } = render(
<Tooltip
title="xxxxx"
transitionName=""
popupTransitionName=""
mouseEnterDelay={0}
placement={placement}
>
<span>Hello world!</span>
</Tooltip>,
);

expect(container.getElementsByTagName('span')).toHaveLength(1);
const element = container.getElementsByTagName('span')[0];
fireEvent.mouseEnter(element);
await sleep(500);
expect(container.getElementsByTagName('span')).toHaveLength(1);
const element = container.getElementsByTagName('span')[0];
fireEvent.mouseEnter(element);
await sleep(500);

await waitFor(() => {
expect(document.querySelector('.ant-tooltip-placement-topRight')).not.toBeNull();
});
await waitFor(() => {
expect(document.querySelector(`.ant-tooltip-placement-${placement}`)).not.toBeNull();
});
});
};

placementList.forEach(placement => testPlacement(`Placement ${placement}`, placement));
});

it('should works for mismatch placement', async () => {
Expand Down

0 comments on commit 22b89ee

Please sign in to comment.