Skip to content

Commit 74b13aa

Browse files
committed
try to add a test case for a visible popup without any mouse events
1 parent 0938784 commit 74b13aa

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

src/hooks/useAlign.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ export default function useAlign(
212212
};
213213
} else {
214214
const rect = target.getBoundingClientRect();
215+
console.log("target.getBoundingClientRect()", target.getBoundingClientRect());
215216
targetRect = {
216217
x: rect.x,
217218
y: rect.y,
@@ -301,6 +302,8 @@ export default function useAlign(
301302
scaleY === 0 ||
302303
(isDOM(target) && !isVisible(target))
303304
) {
305+
console.warn("isDOM(target)", isDOM(target))
306+
console.warn("!isVisible(target)", !isVisible(target))
304307
return;
305308
}
306309

@@ -704,6 +707,7 @@ export default function useAlign(
704707

705708
// Reset ready status when placement & open changed
706709
const resetReady = () => {
710+
console.log("RESET");
707711
setOffsetInfo((ori) => ({
708712
...ori,
709713
ready: false,

src/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@ export function generateTrigger(
381381
) => {
382382
setMousePos([event.clientX, event.clientY]);
383383
};
384+
console.log("mousePos != null", mousePos != null, alignPoint);
384385

385386
const [
386387
ready,
@@ -403,6 +404,7 @@ export function generateTrigger(
403404
popupAlign,
404405
onPopupAlign,
405406
);
407+
console.log("info", { ready, offsetX, alignInfo });
406408

407409
const [showActions, hideActions] = useAction(
408410
mobile,

tests/point.test.jsx

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ describe('Trigger.Point', () => {
2525
<div
2626
className="scroll"
2727
// Jest can not get calculated style in jsdom. So we need to set it manually
28-
style={{ overflowX: 'hidden', overflowY: 'hidden' }}
28+
style={{ overflowX: 'hidden', overflowY: 'hidden', width: 500, height: 500 }}
2929
>
3030
<Trigger
3131
ref={this.props.triggerRef}
@@ -34,7 +34,7 @@ describe('Trigger.Point', () => {
3434
alignPoint
3535
{...this.props}
3636
>
37-
<div className="point-region" />
37+
<div className="point-region" style={{ width: 100, height: 200 }} />
3838
</Trigger>
3939
</div>
4040
);
@@ -141,6 +141,27 @@ describe('Trigger.Point', () => {
141141

142142
expect(document.querySelector('.rc-trigger-popup-hidden')).toBeTruthy();
143143
});
144+
145+
it('should default to targets position when shown in controlled manner', async () => {
146+
// TODO:
147+
// This test does not work at all at the moment, because useAlign calls
148+
// isVisible on the trigger's target (div with class "point-region").
149+
// For that div, getBoundingClientRect() always returns a width and height
150+
// of zero. Therefore, it is interpreted as not visible and useAlign
151+
// returns ready==false.
152+
const { container } = render(<Demo popupVisible action={[]} />);
153+
await trigger(container, 'click', { clientX: 11, clientY: 28 });
154+
await trigger(container, 'mouseenter', { clientX: 10, clientY: 20 });
155+
await trigger(container, 'mouseover', { clientX: 9, clientY: 3 });
156+
157+
const popup = document.querySelector('.rc-trigger-popup');
158+
console.log("popup.style.left", popup.style.left);
159+
console.log("popup.style.top", popup.style.top);
160+
161+
162+
// todo: compare with proper value
163+
expect(popup.style.left).toEqual(0);
164+
});
144165
});
145166

146167
describe('placement', () => {

0 commit comments

Comments
 (0)