forked from Questie/Questie
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetupTests.lua
251 lines (238 loc) · 6.94 KB
/
setupTests.lua
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
dofile("Modules/Libs/QuestieLoader.lua")
dofile("Database/itemDB.lua")
dofile("Database/Zones/zoneTables.lua")
dofile("Database/Corrections/ContentPhases/ContentPhases.lua")
local EMTPY_FUNC = function() end
local bit = require("bit32")
_G.bit = bit
_G.table.getn = function(table)
local count = 0
for _ in pairs(table) do count = count + 1 end
return count
end
_G.tContains = function(tab, val)
for _, value in ipairs(tab) do
if value == val then
return true
end
end
return false
end
_G.strsplit = function(delimiter, str)
local results = {}
for match in (str .. delimiter):gmatch("(.-)" .. delimiter) do
table.insert(results, match)
end
return unpack(results)
end
_G.date = os.date
_G.string.trim = function(str)
return str:gsub("^%s*(.-)%s*$", "%1")
end
_G.strlen = string.len
_G.hooksecurefunc = EMTPY_FUNC
_G.GetTime = function() return 0 end
_G.GetCurrentRegion = function() return 3 end
_G.Enum = {ItemQuality = {Poor = 0, Standard = 1}}
_G.QUEST_MONSTERS_KILLED = ""
_G.QUEST_ITEMS_NEEDED = ""
_G.QUEST_OBJECTS_FOUND = ""
_G.UIParent = {GetEffectiveScale = function() return 1 end}
_G.C_QuestLog = {IsQuestFlaggedCompleted = {}}
setmetatable(_G.C_QuestLog.IsQuestFlaggedCompleted, {
mockedReturnValue = false,
__call = function(_, ...) return _.mockedReturnValue end}
)
_G.DurabilityFrame = {
GetPoint = function() return nil end
}
_G.QuestLogListScrollFrame = {
ScrollBar = {}
}
_G.GetItemCount = function() return 0 end
_G.GetNumQuestWatches = function() return 0 end
_G.GetQuestLogTitle = function() return "Test Quest" end
_G.GetQuestLogIndexByID = function() return 1 end
_G.ExpandFactionHeader = EMTPY_FUNC
_G.IsEquippableItem = function() return false end
_G.IsInGroup = function() return false end
_G.UnitInParty = function() return false end
_G.UnitInRaid = function() return false end
_G.UnitFactionGroup = function() return "Horde" end
_G.UnitName = function() return "Testi" end
_G.QUEST_MONSTERS_KILLED = "%s slain: %d/%d"
_G.QUEST_ITEMS_NEEDED = "%s: %d/%d"
_G.QUEST_OBJECTS_FOUND = "%s: %d/%d"
local mockedFrames = {}
_G.CreateFrame = {
mockedFrames = mockedFrames,
resetMockedFrames = function()
for k in pairs(mockedFrames) do
mockedFrames[k] = nil
end
end
}
setmetatable(_G.CreateFrame, {
__call = function(_, frameType, frameName)
local alpha = 1
local width, height
local point
local normalTexture
local pushedTexture
local highlightTexture
local scripts = {}
local attributes = {}
local isShown = true
local mockFrame = {
ClearAllPoints = EMTPY_FUNC,
SetScript = function(_, name, callback)
scripts[name] = callback
end,
SetHeight = function(_, value)
height = value
end,
GetHeight = function()
return height
end,
SetWidth = function(_, value)
width = value
end,
GetWidth = function()
return width
end,
SetSize = function(_, w, h)
width = w
height = h
end,
GetSize = function()
return width, height
end,
SetAlpha = function(_, value)
alpha = value
end,
GetAlpha = function()
return alpha
end,
SetBackdrop = EMTPY_FUNC,
SetBackdropColor = EMTPY_FUNC,
SetBackdropBorderColor = EMTPY_FUNC,
SetPoint = function(_, l, x, y)
point = {l, nil, nil, x, y}
end,
GetPoint = function()
return unpack(point)
end,
SetParent = EMTPY_FUNC,
CreateFontString = function()
return {
SetText = EMTPY_FUNC,
SetPoint = EMTPY_FUNC,
SetFont = EMTPY_FUNC,
Hide = EMTPY_FUNC,
Show = EMTPY_FUNC,
}
end,
CreateTexture = function()
return {
SetTexture = EMTPY_FUNC,
SetSize = EMTPY_FUNC,
SetPoint = EMTPY_FUNC
}
end,
SetNormalTexture = function(_, texture)
normalTexture = {
GetTexture = function()
return texture
end
}
end,
GetNormalTexture = function()
return normalTexture
end,
SetPushedTexture = function(_, texture)
pushedTexture = {
GetTexture = function()
return texture
end
}
end,
GetPushedTexture = function()
return pushedTexture
end,
SetHighlightTexture = function(_, texture)
highlightTexture = {
GetTexture = function()
return texture
end
}
end,
GetHighlightTexture = function()
return highlightTexture
end,
GetName = function()
return frameName
end,
GetObjectType = function()
return frameType
end,
RegisterForClicks = EMTPY_FUNC,
SetAttribute = function(_, key, value)
attributes[key] = value
end,
Show = function()
isShown = true
end,
Hide = function()
isShown = false
end,
IsVisible = function()
return isShown
end,
RegisterEvent = EMTPY_FUNC,
HookScript = EMTPY_FUNC,
scripts = scripts,
attributes = attributes,
}
table.insert(mockedFrames, mockFrame)
return mockFrame
end
})
_G.LibStub = {
GetLibrary = function() return {} end
}
setmetatable(_G.LibStub, {
__call = function()
return {
Fetch = function() return "Font" end
}
end
})
local registeredEvents = {}
_G["Questie"] = {
db = {
char = {},
profile = {},
global = {},
},
Debug = EMTPY_FUNC,
Warning = function(_, text)
print("|cffffff00[WARNING]|r", text)
end,
icons = {},
RegisterEvent = function(_, eventName, callback)
registeredEvents[eventName] = callback
end,
SendMessage = EMTPY_FUNC,
}
---@class TestUtils
local TestUtils = {
resetEvents = function()
registeredEvents = {}
end,
triggerMockEvent = function(eventName, ...)
if registeredEvents[eventName] then
registeredEvents[eventName](eventName, ...)
end
end
}
return TestUtils