Files
WoW-Hybrid-gateway/tests/fixtures/character_addon_panel_contract.lua
2026-11-23 03:28:32 +02:00

172 lines
7.5 KiB
Lua

-- Offline contract for the separate Octo panel. This does not emulate WoW taint.
local created, events, watched = {}, {}, {}
local secret, identity, now = {}, "paladin", 120
function issecretvalue(value) return value == secret end
function UnitGUID() return identity end
function GetTime() return now end
local Frame = {}; Frame.__index = Frame
function Frame:RegisterEvent(event) watched[event] = true end
function Frame:RegisterUnitEvent(event, unit) watched[event] = unit end
function Frame:SetScript(event, fn) self.scripts[event] = fn end
function Frame:SetSize() end
function Frame:SetPoint(...)
self.points = self.points or {}
table.insert(self.points, {...})
end
function Frame:ClearAllPoints() end
function Frame:SetHeight() end
function Frame:SetWidth(width) self.width = width end
function Frame:GetWidth() return self.width or 240 end
function Frame:GetFrameLevel() return 1 end
function Frame:SetFrameLevel() end
function Frame:CreateTexture() return setmetatable({scripts={}}, Frame) end
function Frame:CreateFontString() return setmetatable({scripts={}}, Frame) end
function Frame:SetAllPoints() end
function Frame:SetColorTexture() end
function Frame:SetScrollChild(child) self.child = child end
function Frame:SetJustifyH() end
function Frame:SetWordWrap() end
function Frame:SetMaxLines() end
function Frame:EnableMouse() end
function Frame:SetText(value) self.text = value end
function Frame:GetStringWidth() return #(self.text or "") * 5 end
function Frame:GetRight() return 200 end
function Frame:Show()
self.shown = true
if self.scripts.OnShow then self.scripts.OnShow(self) end
end
function Frame:Hide()
self.shown = false
if self.scripts.OnHide then self.scripts.OnHide(self) end
end
function Frame:IsShown()
return self.shown == true and (not self.parent or self.parent:IsShown())
end
Frame.IsVisible = Frame.IsShown
function Frame:SetShown(shown)
if self.shown == shown then return end
if shown then self:Show() else self:Hide() end
end
function CreateFrame(kind, _, parent)
local frame = setmetatable({kind=kind,parent=parent,scripts={}}, Frame)
created[#created+1] = frame
if not parent then events[#events+1] = frame end
return frame
end
local host = CreateFrame("Frame")
CharacterFrame = {RightPaneHost=host}
PaperDollFrame = CreateFrame("Frame"); PaperDollFrame.shown = true
local nativeUpdate = function() return 31 end
local nativeStat = {stat="NATIVE"}
local nativeCategory = {unit="player",stats={nativeStat}}
PAPERDOLL_STATINFO = {NATIVE={updateFunc=nativeUpdate}}
PAPERDOLL_STATCATEGORIES = {nativeCategory}
local nativeInfo,nativeCategories=PAPERDOLL_STATINFO,PAPERDOLL_STATCATEGORIES
local weaponRow = {label="Main Hand",read=function() return "Fixture sword" end}
WoWHybridUI = {weaponSkill={GetStandaloneRows=function() return {weaponRow} end,
FitWeaponName=function(_,value) return value end},
characterStats={ReadAvoidanceChance=function(stat) return stat=="PARRY" and 10 or 5 end}}
Enum={PowerType={Mana=0}}; CR_HIT_SPELL=8
BreakUpLargeNumbers=tostring
local schools={0,8,19,8,8,8,8}
function GetSpellBonusDamage(school) return schools[school] end
local spellCrit,healing=12.75,12
function GetSpellCritChance() return spellCrit end
function GetSpellBonusHealing() return healing end
function GetCombatRatingBonus() return 2.25 end
function GetSpellHitModifier() return 0.5 end
function UnitSpellHaste() return 0 end
function GetSpellPenetration() return 0 end
function UnitPowerMax() return 100 end
function GetManaRegen() return 9,3 end
local ticker
C_Timer={NewTicker=function(_,fn)
ticker={tick=fn,Cancel=function(self) self.cancelled=true end};return ticker
end}
GameTooltip={}
function GameTooltip:SetOwner() end
function GameTooltip:SetText() end
function GameTooltip:AddLine() end
function GameTooltip:AddDoubleLine() end
function GameTooltip:Show() end
function GameTooltip:Hide() end
dofile(arg[1])
local function fire(event,arg2)
for _,frame in ipairs(events) do
if frame.scripts.OnEvent then frame.scripts.OnEvent(frame,event,arg2) end
end
end
local function modeTab()
local tab = {shown=true, hooks=0}
function tab:HookScript(event, callback)
assert(event == "OnShow")
self.hooks = self.hooks + 1
self.onShow = callback
end
function tab:Hide() self.shown = false end
function tab:Show()
self.shown = true
if self.onShow then self.onShow(self) end
end
return tab
end
local modes = {CharacterTab=modeTab(), StatisticsTab=modeTab(), SkillsTab=modeTab(),
ReputationTab=modeTab(), PvPTab=modeTab(), CurrencyTab=modeTab()}
CharacterFrame.ModeTabs = modes
local ordered = {modes.CharacterTab, modes.ReputationTab, modes.SkillsTab, modes.PvPTab, modes.CurrencyTab, modes.StatisticsTab}
local indicators = {visibleTabs=ordered, updates=0}
function indicators:IsVisible() return true end
function indicators:UpdateTabVisibility()
self.updates = self.updates + 1
self.visibleTabs = {}
for _, tab in ipairs(ordered) do
if tab.shown then table.insert(self.visibleTabs, tab) end
end
end
CharacterFrame.TabIndicators = indicators
local layouts = 0
function CharacterFrame:UpdateTabLayout() layouts = layouts + 1 end
fire("ADDON_LOADED", "Blizzard_UIPanels_Game")
fire("ADDON_LOADED", "Blizzard_TokenUI")
assert(layouts == 1 and not modes.PvPTab.shown and not modes.CurrencyTab.shown)
assert(#indicators.visibleTabs == 4 and indicators.visibleTabs[4] == modes.StatisticsTab)
assert(indicators.updates == 1)
modes.PvPTab:Show()
modes.CurrencyTab:Show()
assert(indicators.updates == 1)
assert(layouts == 3 and not modes.PvPTab.shown and not modes.CurrencyTab.shown)
assert(modes.PvPTab.hooks == 1 and modes.CurrencyTab.hooks == 1)
for _, button in ipairs({modes.CharacterTab, modes.StatisticsTab, modes.SkillsTab, modes.ReputationTab}) do
assert(button.shown and button.hooks == 0)
end
fire("ADDON_LOADED","WoWHybridUI")
fire("PLAYER_ENTERING_WORLD")
-- The separate "Octo stats" box is retired (Octo stats are native Stats-pane categories, OctoStatsPane.lua).
for _,frame in ipairs(created) do assert(frame.text~="Octo stats") end
local function rendered()
local values={}
for _,row in ipairs(WoWHybridUI.GetRecordedCharacterTotals() or {}) do values[row[1]]=row[2] end
return values
end
assert(watched.UNIT_SPELLCAST_SUCCEEDED=="player" and watched.PLAYER_LOGOUT)
fire("QUEST_TURNED_IN");fire("PLAYER_DEAD");fire("UNIT_SPELLCAST_SUCCEEDED")
now=242
local values=rendered()
assert(values["Time (min)"]=="2" and values.Spellcasts=="1")
assert(values.Quests=="1" and values.Deaths=="1")
assert(PAPERDOLL_STATINFO==nativeInfo and PAPERDOLL_STATCATEGORIES==nativeCategories)
assert(#nativeCategories==1 and nativeCategories[1]==nativeCategory)
assert(#nativeCategory.stats==1 and nativeCategory.stats[1]==nativeStat)
assert(nativeInfo.NATIVE.updateFunc==nativeUpdate and not next(PaperDollFrame.scripts))
fire("PLAYER_LOGOUT");local paladin=WoWHybridCharacterStatistics
assert(paladin.seconds==122 and paladin.casts==1 and paladin.quests==1 and paladin.deaths==1)
identity="warrior";now=600;fire("PLAYER_ENTERING_WORLD")
local warrior=WoWHybridCharacterStatistics
assert(warrior~=paladin and warrior.seconds==0 and warrior.casts==0)
fire("PLAYER_DEAD");now=630;fire("PLAYER_LOGOUT")
assert(warrior.seconds==30 and warrior.deaths==1 and paladin.deaths==1)
print("Retired stats box absent, recorded totals, native stat isolation and character-specific counters PASS.")
-- The Statistics-tab counters box is retired too: "This Character" is a native Stats-pane category.
assert(not StatisticsFrame)