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.
145 lines
4.7 KiB
Lua
145 lines
4.7 KiB
Lua
-- Minimal WoW API mocks for offline testing.
|
|
-- Fixtures are scriptable: set MockItems / MockEquipped before calling addon code.
|
|
|
|
_G.UIParent = {}
|
|
|
|
_G.CopyTable = function(t)
|
|
if type(t) ~= "table" then return t end
|
|
local out = {}
|
|
for k, v in pairs(t) do
|
|
out[k] = v
|
|
end
|
|
return out
|
|
end
|
|
|
|
_G.MockItems = {} -- itemID -> { name = string, stats = table (WoW API keys) }
|
|
_G.MockEquipped = {} -- inventory slotID -> itemID
|
|
|
|
local function itemLink(itemID)
|
|
local name = _G.MockItems[itemID] and _G.MockItems[itemID].name or ("item" .. itemID)
|
|
return "|Hitem:" .. itemID .. ":0:0:0:0:0:0:0:0|h[" .. name .. "]|h"
|
|
end
|
|
_G.MockItemLink = itemLink
|
|
|
|
function GetItemInfo(itemID)
|
|
local it = _G.MockItems[itemID]
|
|
if not it then return nil end
|
|
return it.name, itemLink(itemID), 4, 100, 70
|
|
end
|
|
|
|
function GetItemStats(link)
|
|
local itemID = tonumber(string.match(link, "item:(%d+)"))
|
|
local it = _G.MockItems[itemID]
|
|
return it and it.stats or nil
|
|
end
|
|
|
|
function GetInventoryItemLink(_, slotID)
|
|
local itemID = _G.MockEquipped[slotID]
|
|
if not itemID then return nil end
|
|
return itemLink(itemID)
|
|
end
|
|
|
|
function UnitClass() return "Priest", "PRIEST" end
|
|
function GetTalentTabInfo() return 0, 0, 0, 0 end
|
|
|
|
function ChatEdit_InsertLink() end
|
|
function DressUpItemLink() end
|
|
function IsShiftKeyDown() return false end
|
|
function IsControlKeyDown() return false end
|
|
|
|
local function makeChild()
|
|
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 = {}, shown = true, width = 0, height = 0, scripts = {} }
|
|
return setmetatable(frame, {
|
|
__index = function(self, key)
|
|
if key == "CreateFontString" then
|
|
return function()
|
|
local fs = makeChild()
|
|
table.insert(self.fonts, fs)
|
|
return fs
|
|
end
|
|
elseif key == "CreateTexture" then
|
|
return function()
|
|
local tx = makeChild()
|
|
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
|
|
elseif key == "Hide" then
|
|
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
|
|
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
|
|
})
|
|
end
|
|
|
|
_G.MockFrames = {}
|
|
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" }
|