Skip to content

Commit 85100e2

Browse files
committed
fix e2e
1 parent df17af3 commit 85100e2

File tree

4 files changed

+10
-17
lines changed

4 files changed

+10
-17
lines changed

packages/react-image-focal-point/e2e/basic.spec.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,20 +63,21 @@ test.describe('basic with scroll', () => {
6363
await expect(focalPointButton).toHaveAttribute('style', 'left: 50%; top: 50%; cursor: grab;');
6464
});
6565

66+
const REAL_FIREROX_SCROLL_Y = 686; // Weird firefox scroll Y
67+
6668
test('should place the focal point button on X=60% and Y=40% when it moves X=1180px and Y=1120px because page has 1000px of margin', async ({
6769
page,
70+
browserName,
6871
}) => {
6972
const focalPointButton = page.getByRole('button', { name: 'Focal Point' });
70-
const x = 1180;
71-
const y = 1120;
72-
const rect = await focalPointButton.boundingBox();
73+
const scrollY = 800;
74+
await page.mouse.wheel(0, scrollY);
7375

74-
await page.mouse.wheel(0, rect?.y! - 300);
75-
// await focalPointButton.focus();
7676
await focalPointButton.dispatchEvent('mousedown');
7777
await expect(focalPointButton).toHaveAttribute('style', 'left: 50%; top: 50%; cursor: grabbing;');
78-
// const x2 = rect?.x! + 180;
79-
// const y2 = rect?.y! + 180;
78+
79+
const x = 1180;
80+
const y = 1120 - (browserName === 'firefox' ? REAL_FIREROX_SCROLL_Y : scrollY);
8081
await page.mouse.move(x, y);
8182
await expect(focalPointButton).toHaveAttribute('style', 'left: 60%; top: 40%; cursor: grabbing;');
8283
await focalPointButton.dispatchEvent('mouseup');

packages/react-image-focal-point/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"clean": "rimraf dist",
2727
"test": "jest -c ./config/test/jest.js",
2828
"test:watch": "npm run test -- --watchAll -i",
29-
"test:e2e-dev": "playwright test --debug --project=chromium"
29+
"test:e2e": "playwright test"
3030
},
3131
"repository": {
3232
"type": "git",

packages/react-image-focal-point/src/image-focal-point.helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ export const onMove = (props: Props) => e => {
1616
if (props.canMove) {
1717
const event = e as MouseEvent;
1818
const containerBoundingRectangle = props.container.getBoundingClientRect();
19-
const currentTarget = event.currentTarget as HTMLDivElement;
2019
const xPixels = event.clientX - containerBoundingRectangle.left;
2120
const yPixels = event.clientY - containerBoundingRectangle.top;
21+
const currentTarget = event.currentTarget as HTMLDivElement;
2222
const x = parseToPercentage(xPixels, currentTarget.clientWidth);
2323
const y = parseToPercentage(yPixels, currentTarget.clientHeight);
2424
props.setX(x);

packages/react-image-focal-point/src/image-focal-point.hooks.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,10 @@ const DEFAULT_PERCENTAGE = 50;
1111

1212
export const useFocalPoint = (props: Props) => {
1313
const ref = React.useRef<HTMLDivElement>(null);
14-
const boundingRectangle = React.useRef<DOMRect | null>(null);
1514
const [x, setX] = React.useState<number>(props.focalPoint?.x ?? DEFAULT_PERCENTAGE);
1615
const [y, setY] = React.useState<number>(props.focalPoint?.y ?? DEFAULT_PERCENTAGE);
1716
const [canMove, setCanMove] = React.useState(false);
1817

19-
// React.useEffect(() => {
20-
// if (ref.current) {
21-
// boundingRectangle.current = ref.current.getBoundingClientRect();
22-
// }
23-
// }, [ref, window.scrollX, window.scrollY]);
24-
2518
return {
2619
ref,
2720
x,
@@ -30,7 +23,6 @@ export const useFocalPoint = (props: Props) => {
3023
setX,
3124
setY,
3225
container: ref.current!,
33-
// boundingRectangle: boundingRectangle.current!,
3426
onChange: (x, y) => props.onChange({ x, y }),
3527
canMove,
3628
}),

0 commit comments

Comments
 (0)