-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestPanel.lua
More file actions
466 lines (399 loc) · 16.8 KB
/
TestPanel.lua
File metadata and controls
466 lines (399 loc) · 16.8 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
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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
local AceAddon = LibStub("AceAddon-3.0")
local addon = AceAddon and AceAddon:GetAddon("SimpleUnitFrames", true)
if not addon then
return
end
local core = addon._core or {}
local addonName = core.addonName or "SimpleUnitFrames"
-- Test output storage
addon.testOutput = addon.testOutput or {}
local testOutput = addon.testOutput
-- Color codes for output
local COLORS = {
SUCCESS = "|cff00ff00", -- Green
ERROR = "|cffff0000", -- Red
INFO = "|cff87ceeb", -- Blue
HEADER = "|cffffaa00", -- Orange
RESET = "|r",
}
local function AddTestOutput(msg)
table.insert(testOutput, msg)
if addon.testPanelRefresh then
addon:testPanelRefresh()
end
end
local function ClearTestOutput()
testOutput = {}
addon.testOutput = testOutput
if addon.testPanelRefresh then
addon:testPanelRefresh()
end
end
-- Test Functions (Phase 1 Validation)
local function TestDiagnostics()
ClearTestOutput()
AddTestOutput(COLORS.HEADER .. "=== Phase 1 Diagnostics ===" .. COLORS.RESET)
AddTestOutput("")
-- Check validator loaded
if addon.ValidateImportTree then
AddTestOutput(COLORS.SUCCESS .. "[OK] Validator loaded" .. COLORS.RESET)
else
AddTestOutput(COLORS.ERROR .. "[FAIL] Validator MISSING" .. COLORS.RESET)
end
-- Check safe helpers exported
if addon.SafeCompare then
AddTestOutput(COLORS.SUCCESS .. "[OK] SafeCompare loaded" .. COLORS.RESET)
else
AddTestOutput(COLORS.ERROR .. "[FAIL] SafeCompare MISSING" .. COLORS.RESET)
end
if addon._core and addon._core.SafeArithmetic then
AddTestOutput(COLORS.SUCCESS .. "[OK] SafeArithmetic loaded" .. COLORS.RESET)
else
AddTestOutput(COLORS.ERROR .. "[FAIL] SafeArithmetic MISSING" .. COLORS.RESET)
end
-- Test simple validation
local ok, err = addon:ValidateImportTree({a = 1, b = 2})
if ok then
AddTestOutput(COLORS.SUCCESS .. "[OK] Validation test passed" .. COLORS.RESET)
else
AddTestOutput(COLORS.ERROR .. "[FAIL] Validation test failed: " .. tostring(err) .. COLORS.RESET)
end
AddTestOutput("")
AddTestOutput(COLORS.INFO .. "Memory Usage: " .. string.format("%.1f MB", collectgarbage("count") / 1024) .. COLORS.RESET)
AddTestOutput(COLORS.INFO .. "Active Frames: " .. #(addon.frames or {}) .. COLORS.RESET)
end
local function TestValidProfileImport()
ClearTestOutput()
AddTestOutput(COLORS.HEADER .. "=== Test 1: Valid Profile Import ===" .. COLORS.RESET)
AddTestOutput("")
AddTestOutput(COLORS.INFO .. "INSTRUCTIONS:" .. COLORS.RESET)
AddTestOutput("1. Export current profile: /suf export")
AddTestOutput("2. Open options → Profiles tab")
AddTestOutput("3. Click 'Import Profile'")
AddTestOutput("4. Paste export string")
AddTestOutput("5. Click 'Import'")
AddTestOutput("")
AddTestOutput(COLORS.HEADER .. "EXPECTED:" .. COLORS.RESET)
AddTestOutput(" • Profile loads successfully")
AddTestOutput(" • Settings apply correctly")
AddTestOutput(" • No validation errors in chat")
AddTestOutput("")
AddTestOutput(COLORS.SUCCESS .. "PASS CRITERIA: Settings applied, no chat errors" .. COLORS.RESET)
end
local function TestMalformedImport()
ClearTestOutput()
AddTestOutput(COLORS.HEADER .. "=== Test 2: Malformed Import ===" .. COLORS.RESET)
AddTestOutput("")
AddTestOutput(COLORS.INFO .. "INSTRUCTIONS:" .. COLORS.RESET)
AddTestOutput("1. Open options → Profiles tab")
AddTestOutput("2. Click 'Import Profile'")
AddTestOutput("3. Paste truncated/invalid string (first 50 chars of export)")
AddTestOutput("4. Click 'Import'")
AddTestOutput("")
AddTestOutput(COLORS.HEADER .. "EXPECTED:" .. COLORS.RESET)
AddTestOutput(" • Clear error message shown")
AddTestOutput(" • Original profile unchanged")
AddTestOutput(" • Addon remains stable")
AddTestOutput("")
AddTestOutput(COLORS.SUCCESS .. "PASS CRITERIA: Error shown, no crash, addon stable" .. COLORS.RESET)
end
local function TestCycleDetection()
ClearTestOutput()
AddTestOutput(COLORS.HEADER .. "=== Test 3: Cycle Detection ===" .. COLORS.RESET)
AddTestOutput("")
AddTestOutput(COLORS.INFO .. "Running automated test..." .. COLORS.RESET)
AddTestOutput("")
-- Create circular reference
local t = {}
t.self = t
local ok, err = addon:ValidateImportTree(t)
if not ok and err and (err:match("cycl") or err:match("repeated")) then
AddTestOutput(COLORS.SUCCESS .. "[PASS] Cycle detected correctly" .. COLORS.RESET)
AddTestOutput(" Error: " .. err)
elseif ok then
AddTestOutput(COLORS.ERROR .. "[FAIL] Cycle NOT detected (returned OK)" .. COLORS.RESET)
else
AddTestOutput(COLORS.ERROR .. "[FAIL] Unexpected error: " .. tostring(err) .. COLORS.RESET)
end
AddTestOutput("")
AddTestOutput(COLORS.SUCCESS .. "PASS: No infinite loop, no crash" .. COLORS.RESET)
end
local function TestNodeLimit()
ClearTestOutput()
AddTestOutput(COLORS.HEADER .. "=== Test 4: Node Limit Validation ===" .. COLORS.RESET)
AddTestOutput("")
AddTestOutput(COLORS.INFO .. "Creating large nested structure (51,000 table nodes)..." .. COLORS.RESET)
local t = {}
for i = 1, 51000 do
t[i] = {} -- Create nested tables, not primitives
end
AddTestOutput(COLORS.INFO .. "Running validation..." .. COLORS.RESET)
local startTime = GetTime()
local ok, err = addon:ValidateImportTree(t)
local elapsed = GetTime() - startTime
AddTestOutput("")
if not ok and err and (err:match("node") or err:match("large")) then
AddTestOutput(COLORS.SUCCESS .. "[PASS] Node limit enforced" .. COLORS.RESET)
AddTestOutput(" Error: " .. err)
elseif ok then
AddTestOutput(COLORS.ERROR .. "[FAIL] Large table accepted (should reject)" .. COLORS.RESET)
else
AddTestOutput(COLORS.ERROR .. "[FAIL] Unexpected error: " .. tostring(err) .. COLORS.RESET)
end
AddTestOutput("")
AddTestOutput(COLORS.INFO .. "Elapsed: " .. string.format("%.3fs", elapsed) .. COLORS.RESET)
if elapsed < 1.0 then
AddTestOutput(COLORS.SUCCESS .. "[PASS] Completes quickly (<1s)" .. COLORS.RESET)
else
AddTestOutput(COLORS.ERROR .. "[FAIL] Too slow (>1s)" .. COLORS.RESET)
end
end
local function TestDepthLimit()
ClearTestOutput()
AddTestOutput(COLORS.HEADER .. "=== Test 5: Depth Limit Validation ===" .. COLORS.RESET)
AddTestOutput("")
AddTestOutput(COLORS.INFO .. "Creating 25-level deep nesting..." .. COLORS.RESET)
local t = {}
local cur = t
for i = 1, 25 do
local new = {}
cur.next = new
cur = new
end
AddTestOutput(COLORS.INFO .. "Running validation..." .. COLORS.RESET)
local ok, err = addon:ValidateImportTree(t)
AddTestOutput("")
if not ok and err and err:match("depth") then
AddTestOutput(COLORS.SUCCESS .. "[PASS] Depth limit enforced" .. COLORS.RESET)
AddTestOutput(" Error: " .. err)
elseif ok then
AddTestOutput(COLORS.ERROR .. "[FAIL] Deep nesting accepted (should reject)" .. COLORS.RESET)
else
AddTestOutput(COLORS.ERROR .. "[FAIL] Unexpected error: " .. tostring(err) .. COLORS.RESET)
end
AddTestOutput("")
AddTestOutput(COLORS.SUCCESS .. "PASS: No crash or hang" .. COLORS.RESET)
end
local function TestProfileReload()
ClearTestOutput()
AddTestOutput(COLORS.HEADER .. "=== Test 6: Profile Reload (SafeReload) ===" .. COLORS.RESET)
AddTestOutput("")
AddTestOutput(COLORS.INFO .. "INSTRUCTIONS:" .. COLORS.RESET)
AddTestOutput("1. Open options window (/suf)")
AddTestOutput("2. Make a setting change (e.g., toggle status bar)")
AddTestOutput("3. Click 'Reload Profile' button OR type: /suf reload")
AddTestOutput("4. Verify settings revert to saved state")
AddTestOutput("")
AddTestOutput(COLORS.HEADER .. "EXPECTED:" .. COLORS.RESET)
AddTestOutput(" • Profile reloads without UI glitches")
AddTestOutput(" • Settings reset to saved values")
AddTestOutput(" • Chat shows confirmation message")
AddTestOutput("")
AddTestOutput(COLORS.SUCCESS .. "PASS CRITERIA: Reload completes, UI stable, settings reset" .. COLORS.RESET)
end
local function TestSafeHelpersInstance()
ClearTestOutput()
AddTestOutput(COLORS.HEADER .. "=== Test 7: Safe Helpers (Instance Test) ===" .. COLORS.RESET)
AddTestOutput("")
-- Check if in instance
local inInstance, instanceType = IsInInstance()
if inInstance then
AddTestOutput(COLORS.INFO .. "Currently in instance: " .. (instanceType or "unknown") .. COLORS.RESET)
else
AddTestOutput(COLORS.ERROR .. "[Note] Not in instance - secret values may not be active" .. COLORS.RESET)
end
AddTestOutput("")
AddTestOutput(COLORS.INFO .. "INSTRUCTIONS:" .. COLORS.RESET)
AddTestOutput("1. Enter a Dungeon/Raid Instance (where secret values active)")
AddTestOutput("2. Open options window (/suf)")
AddTestOutput("3. Toggle 3-4 settings:")
AddTestOutput(" • Health bar color")
AddTestOutput(" • Power bar visibility")
AddTestOutput(" • Nameplate mode")
AddTestOutput("4. Watch for errors in chat")
AddTestOutput("")
AddTestOutput(COLORS.HEADER .. "EXPECTED:" .. COLORS.RESET)
AddTestOutput(" • Settings apply correctly")
AddTestOutput(" • No 'attempt to perform arithmetic' errors")
AddTestOutput(" • No secret value comparison errors")
AddTestOutput("")
AddTestOutput(COLORS.SUCCESS .. "PASS CRITERIA: No secret value errors, settings apply" .. COLORS.RESET)
end
local function TestRoundTrip()
ClearTestOutput()
AddTestOutput(COLORS.HEADER .. "=== Test 8: Export/Import Round-Trip ===" .. COLORS.RESET)
AddTestOutput("")
AddTestOutput(COLORS.INFO .. "INSTRUCTIONS:" .. COLORS.RESET)
AddTestOutput("1. Export current profile: /suf export")
AddTestOutput("2. Create new profile (e.g., 'Test Copy')")
AddTestOutput("3. Import exported string into new profile")
AddTestOutput("4. Compare 5-6 key settings with original:")
AddTestOutput(" • Colors (health, power)")
AddTestOutput(" • Visibility toggles")
AddTestOutput(" • Font settings")
AddTestOutput("5. Delete test profile when done")
AddTestOutput("")
AddTestOutput(COLORS.HEADER .. "EXPECTED:" .. COLORS.RESET)
AddTestOutput(" • Re-imported profile identical to original")
AddTestOutput(" • All settings preserved")
AddTestOutput(" • No data loss")
AddTestOutput("")
AddTestOutput(COLORS.SUCCESS .. "PASS CRITERIA: Round-trip successful, all settings preserved" .. COLORS.RESET)
end
-- Create Test Panel UI
function addon:ShowTestPanel()
if not self.testPanel then
local frame = CreateFrame("Frame", "SUFTestPanel", UIParent, "BasicFrameTemplateWithInset")
frame:SetSize(600, 500)
frame:SetPoint("CENTER")
self:EnableMovableFrame(frame, true, "test_panel", { "CENTER", "UIParent", "CENTER", 0, 0 })
frame:SetFrameStrata("DIALOG")
-- Title
local title = frame:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge")
title:SetPoint("TOP", frame, "TOP", 0, -10)
title:SetText("SUF Test Panel (Phase 1 Validation)")
-- Button Panel (top)
local buttonPanel = CreateFrame("Frame", nil, frame)
buttonPanel:SetSize(580, 135)
buttonPanel:SetPoint("TOPLEFT", frame, "TOPLEFT", 10, -35)
-- Test Buttons (3 columns, 3 rows)
local buttons = {
{ text = "Diagnostics", func = TestDiagnostics, col = 1, row = 1 },
{ text = "1: Valid Import", func = TestValidProfileImport, col = 2, row = 1 },
{ text = "2: Malformed Import", func = TestMalformedImport, col = 3, row = 1 },
{ text = "3: Cycle Detection", func = TestCycleDetection, col = 1, row = 2 },
{ text = "4: Node Limit", func = TestNodeLimit, col = 2, row = 2 },
{ text = "5: Depth Limit", func = TestDepthLimit, col = 3, row = 2 },
{ text = "6: Profile Reload", func = TestProfileReload, col = 1, row = 3 },
{ text = "7: Safe Helpers", func = TestSafeHelpersInstance, col = 2, row = 3 },
{ text = "8: Round-Trip", func = TestRoundTrip, col = 3, row = 3 },
}
for _, btnData in ipairs(buttons) do
local btn = CreateFrame("Button", nil, buttonPanel, "UIPanelButtonTemplate")
btn:SetSize(180, 28)
local col = btnData.col or 1
local row = btnData.row or 1
local xOffset = (col - 1) * 190 + 5
local yOffset = (row - 1) * 35 + 5
btn:SetPoint("TOPLEFT", buttonPanel, "TOPLEFT", xOffset, -yOffset)
-- Improve text visibility
btn:SetText(btnData.text)
btn:GetFontString():SetTextColor(1, 0.82, 0, 1) -- Gold color for visibility
btn:GetFontString():SetFont(GameFontNormal:GetFont(), 11, "OUTLINE")
btn:SetScript("OnClick", function()
btnData.func()
self:testPanelRefresh()
end)
end
-- Control buttons
local clearBtn = CreateFrame("Button", nil, buttonPanel, "UIPanelButtonTemplate")
clearBtn:SetSize(70, 28)
clearBtn:SetPoint("BOTTOMRIGHT", buttonPanel, "BOTTOMRIGHT", -5, 0)
clearBtn:SetText("Clear")
clearBtn:GetFontString():SetFont(GameFontNormal:GetFont(), 11, "OUTLINE")
clearBtn:SetScript("OnClick", function()
ClearTestOutput()
self:testPanelRefresh()
end)
local exportBtn = CreateFrame("Button", nil, buttonPanel, "UIPanelButtonTemplate")
exportBtn:SetSize(70, 28)
exportBtn:SetPoint("RIGHT", clearBtn, "LEFT", -5, 0)
exportBtn:SetText("Export")
exportBtn:GetFontString():SetFont(GameFontNormal:GetFont(), 11, "OUTLINE")
exportBtn:SetScript("OnClick", function()
self:ShowTestExportDialog()
end)
-- Output Text with ScrollFrame
local scroll = CreateFrame("ScrollFrame", nil, frame, "UIPanelScrollFrameTemplate")
scroll:SetPoint("TOPLEFT", frame, "TOPLEFT", 10, -170)
scroll:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -30, 10)
local textFrame = CreateFrame("Frame", nil, scroll)
textFrame:SetSize(560, 1) -- Height will be adjusted dynamically
scroll:SetScrollChild(textFrame)
local messagesText = textFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
messagesText:SetPoint("TOPLEFT", textFrame, "TOPLEFT", 0, 0)
messagesText:SetWidth(550)
messagesText:SetJustifyH("LEFT")
messagesText:SetJustifyV("TOP")
messagesText:SetText("Welcome to SUF Phase 1 Test Panel!\n\nClick 'Diagnostics' to verify components, then run tests 1-8.\n\nAutomated tests (3-5) run immediately.\nManual tests (1,2,6-8) show instructions.")
messagesText:SetNonSpaceWrap(true) -- Enable word wrapping
frame.messagesText = messagesText
frame.textFrame = textFrame
frame.scrollFrame = scroll
self.testPanel = frame
-- Apply theming
if self.ApplySUFBackdropColors then
self:ApplySUFBackdropColors(frame, "window")
end
end
self:PrepareWindowForDisplay(self.testPanel)
self.testPanel:Show()
self:PlayWindowOpenAnimation(self.testPanel)
end
function addon:testPanelRefresh()
if not self.testPanel or not self.testPanel.messagesText then
return
end
local text = table.concat(testOutput, "\n")
self.testPanel.messagesText:SetText(text)
-- Wait for text to render, then update height
C_Timer.After(0.01, function()
if not self.testPanel or not self.testPanel.messagesText or not self.testPanel.textFrame then
return
end
local height = self.testPanel.messagesText:GetStringHeight()
local scrollHeight = self.testPanel.scrollFrame:GetHeight()
-- Set textFrame height to content height (minimum is scroll frame height)
self.testPanel.textFrame:SetHeight(math.max(height + 20, scrollHeight))
-- Scroll to bottom if content is long
if height > scrollHeight - 20 then
self.testPanel.scrollFrame:SetVerticalScroll(height - scrollHeight + 40)
end
end)
end
function addon:ShowTestExportDialog()
if not self.testExportFrame then
local frame = CreateFrame("Frame", "SUFTestExportFrame", UIParent, "BasicFrameTemplateWithInset")
frame:SetSize(520, 420)
frame:SetPoint("CENTER")
self:EnableMovableFrame(frame, true, "test_export", { "CENTER", "UIParent", "CENTER", 0, 0 })
frame:SetFrameStrata("DIALOG")
local title = frame:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge")
title:SetPoint("TOP", frame, "TOP", 0, -10)
title:SetText("Export Test Results")
local note = frame:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
note:SetPoint("TOPLEFT", frame, "TOPLEFT", 12, -34)
note:SetText("Ctrl+A to select all, Ctrl+C to copy")
local scroll = CreateFrame("ScrollFrame", nil, frame, "UIPanelScrollFrameTemplate")
scroll:SetPoint("TOPLEFT", frame, "TOPLEFT", 10, -56)
scroll:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -30, 10)
local editBox = CreateFrame("EditBox", nil, scroll)
editBox:SetMultiLine(true)
editBox:SetFontObject(GameFontHighlightSmall)
editBox:SetWidth(470)
editBox:SetAutoFocus(false)
editBox:SetScript("OnEscapePressed", function() frame:Hide() end)
scroll:SetScrollChild(editBox)
frame.editBox = editBox
if self.ApplySUFBackdropColors then
self:ApplySUFBackdropColors(frame, "window")
end
self.testExportFrame = frame
end
local title = self.testExportFrame:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge")
if self.testExportFrame.TitleText then
title = self.testExportFrame.TitleText
end
title:SetText("Export Test Results")
local exportText = table.concat(testOutput, "\n")
self.testExportFrame.editBox:SetText(exportText)
self.testExportFrame.editBox:SetCursorPosition(0)
self.testExportFrame.editBox:HighlightText()
self:PrepareWindowForDisplay(self.testExportFrame)
self.testExportFrame:Show()
self:PlayWindowOpenAnimation(self.testExportFrame)
end
-- Register test panel slash command
addon:RegisterChatCommand("suftest", function()
addon:ShowTestPanel()
end)