Close the window when Escape is pressed
Register the main frame ("AmibisMainFrame") in UISpecialFrames so Escape
hides it and suppresses the game menu while it is open, matching the
default UI panels.
Move the stats-retry timer cleanup into the frame's OnHide script so the
close button, Escape, and /amibis all stop the timer.
Tests: the mock now registers named frames in _G and runs OnHide scripts.
The UI suite simulates FrameXML's CloseSpecialWindows() and asserts the
frame hides and the retry timer is cleared. 108 passing.
This commit is contained in:
1 parent
cc3971fe93
commit
d8fefc947e
6 files changed
+77
-9
No files matched your search
@@ -27,7 +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) |
|
||||
| `test_ui.lua` | UI smoke tests 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), and the main frame is registered in `UISpecialFrames` so Escape closes it |
|
||||
|
||||
## Layout
|
||||
|
||||
|
||||
@@ -53,4 +53,30 @@ describe("UI stat panel", function()
|
||||
expect(holyTexts["+Healing"]).toBeTruthy()
|
||||
expect(holyTexts["+Spell Damage"]).toBeFalsy()
|
||||
end)
|
||||
|
||||
it("closes the window when Escape is pressed", function()
|
||||
ns.UI.Initialize()
|
||||
if not ns.UI.IsShown() then
|
||||
ns.UI.ToggleFrame()
|
||||
end
|
||||
expect(ns.UI.IsShown()).toBeTruthy()
|
||||
|
||||
local registered = false
|
||||
for _, name in ipairs(UISpecialFrames) do
|
||||
if name == "AmibisMainFrame" then registered = true end
|
||||
end
|
||||
expect(registered).toBeTruthy()
|
||||
|
||||
-- Simulate an in-flight stats retry so the OnHide cleanup is exercised.
|
||||
ns.Amibis._statsRetryTimer = CreateFrame("Frame")
|
||||
|
||||
-- Mirrors FrameXML's CloseSpecialWindows(): hide every shown special frame.
|
||||
for _, name in ipairs(UISpecialFrames) do
|
||||
local frame = _G[name]
|
||||
if frame and frame:IsShown() then frame:Hide() end
|
||||
end
|
||||
|
||||
expect(ns.UI.IsShown()).toBeFalsy()
|
||||
expect(ns.Amibis._statsRetryTimer).toBeNil()
|
||||
end)
|
||||
end)
|
||||
@@ -71,7 +71,7 @@ local function makeChild()
|
||||
end
|
||||
|
||||
local function makeFrame()
|
||||
local frame = { fonts = {}, textures = {}, shown = true, width = 0, height = 0 }
|
||||
local frame = { fonts = {}, textures = {}, shown = true, width = 0, height = 0, scripts = {} }
|
||||
return setmetatable(frame, {
|
||||
__index = function(self, key)
|
||||
if key == "CreateFontString" then
|
||||
@@ -86,10 +86,28 @@ local function makeFrame()
|
||||
table.insert(self.textures, tx)
|
||||
return tx
|
||||
end
|
||||
elseif key == "SetScript" then
|
||||
return function(_, event, handler)
|
||||
self.scripts[event] = handler
|
||||
return self
|
||||
end
|
||||
elseif key == "GetScript" then
|
||||
return function(_, event)
|
||||
return self.scripts[event]
|
||||
end
|
||||
elseif key == "Show" then
|
||||
return function() self.shown = true; return self end
|
||||
return function()
|
||||
self.shown = true
|
||||
return self
|
||||
end
|
||||
elseif key == "Hide" then
|
||||
return function() self.shown = false; return self end
|
||||
return function()
|
||||
local wasShown = self.shown
|
||||
self.shown = false
|
||||
local handler = self.scripts["OnHide"]
|
||||
if wasShown and handler then handler(self) end
|
||||
return self
|
||||
end
|
||||
elseif key == "IsShown" then
|
||||
return function() return self.shown end
|
||||
elseif key == "SetSize" then
|
||||
@@ -112,11 +130,15 @@ local function makeFrame()
|
||||
end
|
||||
|
||||
_G.MockFrames = {}
|
||||
function CreateFrame()
|
||||
function CreateFrame(frameType, name, parent, template)
|
||||
local f = makeFrame()
|
||||
if name then
|
||||
_G[name] = f
|
||||
end
|
||||
table.insert(_G.MockFrames, f)
|
||||
return f
|
||||
end
|
||||
|
||||
_G.GameTooltip = makeFrame()
|
||||
_G.SlashCmdList = {}
|
||||
_G.UISpecialFrames = { "GameMenuFrame", "StaticPopup1" }
|
||||
@@ -52,6 +52,27 @@ local function CreateMainFrame()
|
||||
self:StopMovingOrSizing()
|
||||
Amibis:SaveFramePosition(self)
|
||||
end)
|
||||
frame:SetScript("OnHide", function()
|
||||
if Amibis._statsRetryTimer then
|
||||
Amibis._statsRetryTimer:Hide()
|
||||
Amibis._statsRetryTimer = nil
|
||||
end
|
||||
end)
|
||||
|
||||
-- Registering with UISpecialFrames makes the Escape key close the window
|
||||
-- (and suppresses the game menu, like the default UI panels).
|
||||
if UISpecialFrames then
|
||||
local registered = false
|
||||
for _, name in ipairs(UISpecialFrames) do
|
||||
if name == "AmibisMainFrame" then
|
||||
registered = true
|
||||
break
|
||||
end
|
||||
end
|
||||
if not registered then
|
||||
table.insert(UISpecialFrames, "AmibisMainFrame")
|
||||
end
|
||||
end
|
||||
|
||||
frame:SetPoint("CENTER", UIParent, "CENTER", 0, 0)
|
||||
return frame
|
||||
@@ -584,11 +605,8 @@ function ns.UI.ToggleFrame()
|
||||
end
|
||||
|
||||
if MainFrame:IsShown() then
|
||||
-- Hiding runs the frame's OnHide script, which stops the stats retry timer.
|
||||
MainFrame:Hide()
|
||||
if Amibis._statsRetryTimer then
|
||||
Amibis._statsRetryTimer:Hide()
|
||||
Amibis._statsRetryTimer = nil
|
||||
end
|
||||
else
|
||||
MainFrame:Show()
|
||||
Amibis._statsRetryAttempts = nil
|
||||
|
||||
Reference in new issue
Block a user