Fix stat panel not rebuilding when switching specs
RebuildStatRows hid the previous rows through vals.label, but StatValues never stored the label font string. The first spec change that altered the stat keys raised "attempt to index a nil value (field 'label')", aborting RefreshUI before the new rows were created. The previous spec's panel stayed on screen, so a Holy priest kept seeing Shadow's "+Spell Damage" row instead of "+Healing". Store the label in StatValues so old rows hide correctly and the panel rebuilds with the new spec's profile. Add a UI smoke test using mocked frames (font strings now record text/shown; frames track Show/Hide/IsShown). It switches Shadow -> Holy and asserts the visible rows change; with the bug reverted it fails with the same nil-label error. Also print usage for a bare "/amibis spec" instead of toggling the window, which was a surprising side effect and made tests order-dependent. 107 passing.
This commit is contained in:
1 parent
5fba4ac10c
commit
cc3971fe93
6 files changed
+106
-7
No files matched your search
@@ -641,6 +641,8 @@ SlashCmdList["AMIBIS"] = function(msg)
|
||||
local cmd = (msg:trim():lower():gsub("%s+", " "))
|
||||
if cmd == "" then
|
||||
Amibis:ToggleFrame()
|
||||
elseif cmd == "spec" then
|
||||
print("Amibis: Usage: /amibis spec <SpecName> or /amibis spec clear")
|
||||
elseif cmd == "spec clear" then
|
||||
AmibisCharDB.overrideSpec = nil
|
||||
print("Amibis: Spec override cleared. Using auto-detected spec.")
|
||||
|
||||
@@ -27,6 +27,7 @@ apt-get download lua5.4 && dpkg -x lua5.4_*.deb /tmp/lua && /tmp/lua/usr/bin/lua
|
||||
| `test_stats.lua` | `ScanItemStats`: MAX aggregation across alias keys (spell damage schools, healing, haste/crit/mp5 ratings), single-mapping pass-through, unmapped key filtering, nil handling |
|
||||
| `test_compare.lua` | `CompareGear`: BIS counting, weighted upgrade ranking, positive-diffs-only scoring, per-spec stat profiles (Shadow counts spell damage, Holy counts healing, Warrior counts strength/AP, tank mitigation stats), `GetStatKeysForSpec`, `GetCompletionRatio` |
|
||||
| `test_slash.lua` | `/amibis spec <name>` parsing: override set/clear, case and multi-word normalization, `spec clear` not treated as a spec name |
|
||||
| `test_ui.lua` | UI smoke test with mocked frames: the stats panel rebuilds when switching Shadow → Holy (regression: old rows were hidden via a missing `label` field, which errored and left the Shadow rows on screen) |
|
||||
|
||||
## Layout
|
||||
|
||||
@@ -54,6 +55,6 @@ your dev machine, never in the game client.
|
||||
|
||||
## Not covered
|
||||
|
||||
`UI/ComparisonFrame.lua` — its helpers are file-locals and testing them would
|
||||
require a full frame API mock. The logic worth testing (stat scanning, scoring,
|
||||
phase data) lives in the two suites above.
|
||||
Most of `UI/ComparisonFrame.lua` — layout/anchoring and event wiring still need in-game
|
||||
verification. `test_ui.lua` covers the stats-panel rebuild path using mocked frames
|
||||
(font strings record `text`/`shown`, frames track `Show`/`Hide`/`IsShown`).
|
||||
@@ -18,11 +18,13 @@ _G.AmibisCharDB = {}
|
||||
|
||||
assert(loadfile("Amibis/Amibis.lua"))(ADDON_NAME, ns)
|
||||
assert(loadfile("Amibis/Data/BISLists.lua"))(ADDON_NAME, ns)
|
||||
assert(loadfile("Amibis/UI/ComparisonFrame.lua"))(ADDON_NAME, ns)
|
||||
|
||||
assert(loadfile("Amibis/Tests/test_data.lua"))(ADDON_NAME, ns)
|
||||
assert(loadfile("Amibis/Tests/test_stats.lua"))(ADDON_NAME, ns)
|
||||
assert(loadfile("Amibis/Tests/test_compare.lua"))(ADDON_NAME, ns)
|
||||
assert(loadfile("Amibis/Tests/test_slash.lua"))(ADDON_NAME, ns)
|
||||
assert(loadfile("Amibis/Tests/test_ui.lua"))(ADDON_NAME, ns)
|
||||
|
||||
local success = TestHarness_report()
|
||||
os.exit(success and 0 or 1)
|
||||
@@ -0,0 +1,56 @@
|
||||
-- UI smoke tests: the stats panel must rebuild when the selected spec changes.
|
||||
local _, ns = ...
|
||||
|
||||
local function cacheList(list)
|
||||
for _, entry in pairs(list) do
|
||||
MockItems[entry.itemID] = {
|
||||
name = entry.name,
|
||||
stats = {
|
||||
["ITEM_MOD_INTELLECT_SHORT"] = 50,
|
||||
["ITEM_MOD_SPIRIT_SHORT"] = 30,
|
||||
["ITEM_MOD_SPELL_DAMAGE_DONE_SHORT"] = 40,
|
||||
["ITEM_MOD_SPELL_HEALING_DONE_SHORT"] = 60,
|
||||
},
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
local function visibleTexts()
|
||||
local texts = {}
|
||||
for _, frame in ipairs(MockFrames) do
|
||||
for _, fontString in ipairs(frame.fonts or {}) do
|
||||
if fontString.shown and fontString.text and fontString.text ~= "" then
|
||||
texts[fontString.text] = true
|
||||
end
|
||||
end
|
||||
end
|
||||
return texts
|
||||
end
|
||||
|
||||
describe("UI stat panel", function()
|
||||
it("shows healing after switching from Shadow to Holy", function()
|
||||
MockItems = {}
|
||||
MockEquipped = {}
|
||||
AmibisDB.selectedPhase = "ZA"
|
||||
AmibisCharDB.overrideSpec = "Shadow"
|
||||
|
||||
cacheList(ns.Data.BISLists:GetBISList("PRIEST", "Shadow", "ZA"))
|
||||
cacheList(ns.Data.BISLists:GetBISList("PRIEST", "Holy", "ZA"))
|
||||
|
||||
ns.UI.Initialize()
|
||||
if not ns.UI.IsShown() then
|
||||
ns.UI.ToggleFrame()
|
||||
end
|
||||
|
||||
local shadowTexts = visibleTexts()
|
||||
expect(shadowTexts["+Spell Damage"]).toBeTruthy()
|
||||
expect(shadowTexts["+Healing"]).toBeFalsy()
|
||||
|
||||
AmibisCharDB.overrideSpec = "Holy"
|
||||
ns.UI.RefreshUI()
|
||||
|
||||
local holyTexts = visibleTexts()
|
||||
expect(holyTexts["+Healing"]).toBeTruthy()
|
||||
expect(holyTexts["+Spell Damage"]).toBeFalsy()
|
||||
end)
|
||||
end)
|
||||
@@ -48,15 +48,30 @@ function IsShiftKeyDown() return false end
|
||||
function IsControlKeyDown() return false end
|
||||
|
||||
local function makeChild()
|
||||
return setmetatable({}, {
|
||||
__index = function(_, key)
|
||||
local child = { shown = true, text = "" }
|
||||
return setmetatable(child, {
|
||||
__index = function(self, key)
|
||||
if key == "SetText" then
|
||||
return function(_, value)
|
||||
self.text = value
|
||||
return self
|
||||
end
|
||||
elseif key == "GetText" then
|
||||
return function() return self.text end
|
||||
elseif key == "Show" then
|
||||
return function() self.shown = true; return self end
|
||||
elseif key == "Hide" then
|
||||
return function() self.shown = false; return self end
|
||||
elseif key == "IsShown" then
|
||||
return function() return self.shown end
|
||||
end
|
||||
return function(_, ...) return nil end
|
||||
end
|
||||
})
|
||||
end
|
||||
|
||||
local function makeFrame()
|
||||
local frame = { fonts = {}, textures = {} }
|
||||
local frame = { fonts = {}, textures = {}, shown = true, width = 0, height = 0 }
|
||||
return setmetatable(frame, {
|
||||
__index = function(self, key)
|
||||
if key == "CreateFontString" then
|
||||
@@ -71,6 +86,25 @@ local function makeFrame()
|
||||
table.insert(self.textures, tx)
|
||||
return tx
|
||||
end
|
||||
elseif key == "Show" then
|
||||
return function() self.shown = true; return self end
|
||||
elseif key == "Hide" then
|
||||
return function() self.shown = false; return self end
|
||||
elseif key == "IsShown" then
|
||||
return function() return self.shown end
|
||||
elseif key == "SetSize" then
|
||||
return function(_, width, height)
|
||||
self.width, self.height = width, height
|
||||
return self
|
||||
end
|
||||
elseif key == "GetWidth" then
|
||||
return function() return self.width end
|
||||
elseif key == "GetHeight" then
|
||||
return function() return self.height end
|
||||
elseif key == "SetWidth" then
|
||||
return function(_, width) self.width = width; return self end
|
||||
elseif key == "SetHeight" then
|
||||
return function(_, height) self.height = height; return self end
|
||||
end
|
||||
return function(_, ...) return self end
|
||||
end
|
||||
|
||||
@@ -453,7 +453,7 @@ local function RebuildStatRows(panel, statKeys)
|
||||
diff:SetTextColor(1, 1, 1, 1)
|
||||
|
||||
StatLabels[statKey] = label
|
||||
StatValues[statKey] = { current = current, bis = bis, diff = diff }
|
||||
StatValues[statKey] = { label = label, current = current, bis = bis, diff = diff }
|
||||
end
|
||||
|
||||
panel:SetHeight(#statKeys * 16 + 24)
|
||||
@@ -574,6 +574,10 @@ function ns.UI.Initialize()
|
||||
InitializeUI()
|
||||
end
|
||||
|
||||
function ns.UI.IsShown()
|
||||
return MainFrame ~= nil and MainFrame:IsShown()
|
||||
end
|
||||
|
||||
function ns.UI.ToggleFrame()
|
||||
if not MainFrame then
|
||||
InitializeUI()
|
||||
|
||||
Reference in new issue
Block a user