Skip to content

Commit 349e06c

Browse files
feat: expose thumb layers in ThumbPage component for testing
1 parent a13ff37 commit 349e06c

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

src/pods/thumb-pages/components/thumb-page.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import classes from './thumb-page.module.css';
1212

1313
import React from 'react';
1414
import { useDragDropThumb } from './drag-drop-thumb.hook';
15+
import Konva from 'konva';
16+
import { ENV } from '@/core/constants';
1517

1618
interface Props {
1719
pageIndex: number;
@@ -35,6 +37,7 @@ export const ThumbPage: React.FunctionComponent<Props> = props => {
3537
});
3638

3739
const divRef = useRef<HTMLDivElement>(null);
40+
const layerRef = useRef<Konva.Layer>(null);
3841
const [key, setKey] = React.useState(0);
3942

4043
const { dragging, isDraggedOver } = useDragDropThumb(divRef, pageIndex);
@@ -52,6 +55,15 @@ export const ThumbPage: React.FunctionComponent<Props> = props => {
5255
}, 100);
5356
};
5457

58+
// Exposing thumb layer for testing
59+
60+
if (typeof window !== 'undefined' && ENV.IS_TEST_ENV && layerRef.current) {
61+
if (!window.__TESTING_KONVA_THUMB_LAYERS__) {
62+
window.__TESTING_KONVA_THUMB_LAYERS__ = [];
63+
}
64+
window.__TESTING_KONVA_THUMB_LAYERS__[pageIndex] = layerRef.current;
65+
}
66+
5567
React.useLayoutEffect(() => {
5668
handleResizeAndForceRedraw();
5769
}, []);
@@ -105,7 +117,7 @@ export const ThumbPage: React.FunctionComponent<Props> = props => {
105117
scaleX={finalScale}
106118
scaleY={finalScale}
107119
>
108-
<Layer>
120+
<Layer ref={layerRef}>
109121
{shapes.map(shape => {
110122
if (!fakeShapeRefs.current[shape.id]) {
111123
fakeShapeRefs.current[shape.id] = createRef();

0 commit comments

Comments
 (0)