-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvitest.setup.ts
More file actions
142 lines (135 loc) · 3.22 KB
/
vitest.setup.ts
File metadata and controls
142 lines (135 loc) · 3.22 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import "@testing-library/jest-dom";
import { cleanup } from "@testing-library/react";
import { afterEach, vi } from "vitest";
// Cleanup after each test
afterEach(() => {
cleanup();
});
// Mock window.matchMedia
Object.defineProperty(window, "matchMedia", {
writable: true,
value: (query: string) => ({
matches: false,
media: query,
onchange: null,
addListener: () => {},
removeListener: () => {},
addEventListener: () => {},
removeEventListener: () => {},
dispatchEvent: () => true,
}),
});
// Mock localStorage
const localStorageMock = {
getItem: () => null,
setItem: () => {},
removeItem: () => {},
clear: () => {},
};
global.localStorage = localStorageMock as any;
// Mock HTMLCanvasElement and CanvasRenderingContext2D
HTMLCanvasElement.prototype.getContext = vi.fn(() => ({
fillStyle: "",
fillRect: vi.fn(),
clearRect: vi.fn(),
getImageData: vi.fn(),
putImageData: vi.fn(),
createImageData: vi.fn(),
setTransform: vi.fn(),
drawImage: vi.fn(),
save: vi.fn(),
restore: vi.fn(),
beginPath: vi.fn(),
moveTo: vi.fn(),
lineTo: vi.fn(),
closePath: vi.fn(),
stroke: vi.fn(),
translate: vi.fn(),
scale: vi.fn(),
rotate: vi.fn(),
arc: vi.fn(),
fill: vi.fn(),
measureText: vi.fn(() => ({ width: 0 })),
transform: vi.fn(),
rect: vi.fn(),
clip: vi.fn(),
})) as any;
// Mock ResizeObserver
global.ResizeObserver = vi.fn().mockImplementation(() => ({
observe: vi.fn(),
unobserve: vi.fn(),
disconnect: vi.fn(),
}));
// Mock Lightweight Charts
vi.mock("lightweight-charts", () => {
const mockSeries = () => ({
setData: vi.fn(),
applyOptions: vi.fn(),
setMarkers: vi.fn(),
priceScale: vi.fn(() => ({
applyOptions: vi.fn(),
})),
});
return {
createChart: vi.fn(() => ({
addSeries: vi.fn(mockSeries), // Generic addSeries method
addAreaSeries: vi.fn(mockSeries),
addLineSeries: vi.fn(mockSeries),
addCandlestickSeries: vi.fn(mockSeries),
addHistogramSeries: vi.fn(mockSeries),
addBaselineSeries: vi.fn(mockSeries),
timeScale: vi.fn(() => ({
fitContent: vi.fn(),
scrollToPosition: vi.fn(),
applyOptions: vi.fn(),
scrollToRealTime: vi.fn(),
getVisibleRange: vi.fn(),
setVisibleRange: vi.fn(),
})),
priceScale: vi.fn(() => ({
applyOptions: vi.fn(),
})),
applyOptions: vi.fn(),
resize: vi.fn(),
remove: vi.fn(),
subscribeCrosshairMove: vi.fn(),
unsubscribeCrosshairMove: vi.fn(),
subscribeClick: vi.fn(),
unsubscribeClick: vi.fn(),
takeScreenshot: vi.fn(),
})),
ColorType: {
Solid: 0,
VerticalGradient: 1,
},
CrosshairMode: {
Normal: 0,
Magnet: 1,
Hidden: 2,
},
LineStyle: {
Solid: 0,
Dotted: 1,
Dashed: 2,
LargeDashed: 3,
SparseDotted: 4,
},
LineType: {
Simple: 0,
WithSteps: 1,
Curved: 2,
},
PriceScaleMode: {
Normal: 0,
Logarithmic: 1,
Percentage: 2,
IndexedTo100: 3,
},
// Export series constructors
LineSeries: vi.fn(),
AreaSeries: vi.fn(),
CandlestickSeries: vi.fn(),
HistogramSeries: vi.fn(),
BaselineSeries: vi.fn(),
};
});