-
-
Notifications
You must be signed in to change notification settings - Fork 322
Expand file tree
/
Copy pathsetup.js
More file actions
118 lines (104 loc) · 2.95 KB
/
setup.js
File metadata and controls
118 lines (104 loc) · 2.95 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
import { vi } from "vitest"
import jQuery from "jquery"
// Make jQuery available globally
globalThis.$ = jQuery
globalThis.jQuery = jQuery
// Mock select2 to avoid network requests in jsdom environment
globalThis.jQuery.fn.select2 = function (options) {
// Mock select2 initialization
const $element = this
// Add basic select2 classes and structure for tests
if (!$element.next(".select2-container").length) {
const container = jQuery(
'<div class="select2-container alchemy_selectbox"></div>'
)
// Add clear button if allowClear is enabled
if (options?.allowClear) {
container.append('<span class="select2-search-choice-close"></span>')
}
$element.after(container)
}
return $element
}
// Mock select2 static methods if needed
globalThis.jQuery.fn.select2.defaults = {}
// Mock TinyMCE to avoid network requests in jsdom environment
globalThis.tinymce = {
init: vi.fn().mockResolvedValue([]),
get: vi.fn().mockReturnValue({
remove: vi.fn(),
show: vi.fn(),
on: vi.fn()
}),
remove: vi.fn()
}
// Mock select2 module to avoid network requests
vi.mock("select2", () => ({}))
// Mock dynamic imports to avoid network requests
vi.mock("flatpickr/en.js", () => ({}))
vi.mock("flatpickr/de.js", () => ({}))
vi.mock("flatpickr/es.js", () => ({}))
vi.mock("flatpickr/fr.js", () => ({}))
vi.mock("flatpickr/it.js", () => ({}))
vi.mock("flatpickr/nl.js", () => ({}))
vi.mock("flatpickr/pt.js", () => ({}))
vi.mock("flatpickr/ru.js", () => ({}))
vi.mock("flatpickr/zh.js", () => ({}))
// Mock fetch to avoid network requests
globalThis.fetch = vi.fn().mockResolvedValue({
ok: true,
status: 200,
json: vi.fn().mockResolvedValue({}),
text: vi.fn().mockResolvedValue(""),
headers: {
get: vi.fn().mockReturnValue("application/json")
}
})
// Mock XMLHttpRequest to avoid network requests
globalThis.XMLHttpRequest = vi.fn(function () {
this.open = vi.fn()
this.send = vi.fn()
this.setRequestHeader = vi.fn()
this.abort = vi.fn()
this.status = 200
this.readyState = 4
this.responseText = ""
this.response = ""
this.upload = {
addEventListener: vi.fn(),
removeEventListener: vi.fn(),
onprogress: vi.fn()
}
this.addEventListener = vi.fn()
this.removeEventListener = vi.fn()
})
// Mock matchMedia for components that use it
Object.defineProperty(window, "matchMedia", {
writable: true,
value: vi.fn().mockImplementation((query) => ({
matches: false,
media: query,
onchange: null,
addListener: vi.fn(), // deprecated
removeListener: vi.fn(), // deprecated
addEventListener: vi.fn(),
removeEventListener: vi.fn(),
dispatchEvent: vi.fn()
}))
})
// Set up global Alchemy object that many tests expect
globalThis.Alchemy = {
translations: {},
locale: "en",
growl: vi.fn(),
routes: {},
LinkDialog: vi.fn(function () {
this.open = vi.fn()
}),
currentDialog: vi.fn(),
uploader_defaults: {},
PreviewWindow: {
postMessage: vi.fn(),
refresh: vi.fn()
}
}