-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsetup.ts
More file actions
89 lines (79 loc) · 2.56 KB
/
Copy pathsetup.ts
File metadata and controls
89 lines (79 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// Test setup file for Vitest
// Add any global test configuration here
import { afterEach, vi } from "vitest";
import { cleanup } from "@testing-library/react";
import React from "react";
// Mock ResizeObserver which is not available in jsdom
global.ResizeObserver = class ResizeObserver {
constructor(callback: ResizeObserverCallback) {
// Store callback for potential future use
this.callback = callback;
}
callback: ResizeObserverCallback;
observe() {}
unobserve() {}
disconnect() {}
};
// Mock scrollIntoView which is not available in jsdom
HTMLElement.prototype.scrollIntoView = vi.fn();
// Ensure we cleanup between tests to avoid lingering handles
afterEach(() => {
cleanup();
});
// Mock canvas getContext used by audio recorder during tests
HTMLCanvasElement.prototype.getContext = function(contextId: any) {
if (contextId === '2d') {
return {
fillRect: () => {},
clearRect: () => {},
getImageData: () => ({ data: [] }),
putImageData: () => {},
createImageData: () => ({ data: [] }),
setTransform: () => {},
drawImage: () => {},
save: () => {},
restore: () => {},
beginPath: () => {},
closePath: () => {},
moveTo: () => {},
lineTo: () => {},
stroke: () => {},
translate: () => {},
scale: () => {},
rotate: () => {},
arc: () => {},
fill: () => {},
measureText: (text: string) => ({ width: text.length * 8 }),
transform: () => {},
rect: () => {},
clip: () => {},
} as unknown as CanvasRenderingContext2D;
}
return null;
} as any;
// Simplify Radix tooltip behavior to avoid act() noise in jsdom
vi.mock("@radix-ui/react-tooltip", async () => {
const forward = (
renderFn: React.ForwardRefRenderFunction<HTMLElement, any>
) => React.forwardRef(renderFn);
const SimpleProvider: React.FC<{ children?: React.ReactNode }> = ({ children }) =>
React.createElement(React.Fragment, null, children);
const SimplePortal: React.FC<{ children?: React.ReactNode }> = ({ children }) =>
React.createElement(React.Fragment, null, children);
const createWrapper = () =>
forward(({ children, asChild, sideOffset: _sideOffset, ...rest }: any, ref) => {
if (asChild && React.isValidElement(children)) {
return React.cloneElement(children, { ref, ...rest });
}
return React.createElement("div", { ref, ...rest }, children);
});
const passthrough = createWrapper();
return {
Provider: SimpleProvider,
Root: passthrough,
Trigger: passthrough,
Content: passthrough,
Portal: SimplePortal,
Arrow: () => null,
};
});