Files
WoW-Hybrid-gateway/tests/item_tooltip_dependencies_test.lua
praxisandClaude Fable 5.2 7f2139d8d0 Offline test fixtures
883 files, from working commit b1a079a.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-19 01:32:48 +02:00

57 lines
4.2 KiB
Lua

-- Shared dependency loading only; no native rendering or gameplay claim.
local source=assert(arg[1])
GWItemDependencyData={sets={[511]={10,11,12},[641]={20,21}},itemSets={[10]=511,[11]=511,[20]=641}}
local cached={[10]=true};local requested={};local timers={};local callback;local event
issecretvalue=function(v)return v=='SECRET'end
C_Item={GetItemInfo=function(id)if cached[id]then return 'item'..id end end,
RequestLoadItemDataByID=function(id)requested[#requested+1]=id end}
local original=C_Item.GetItemInfo
TooltipDataProcessor={AddTooltipPostCall=function(kind,cb)assert(kind==0);callback=cb end}
Enum={TooltipDataType={Item=0}};C_Timer={After=function(delay,fn)assert(delay==0.15);timers[#timers+1]=fn end}
CreateFrame=function()return{RegisterEvent=function()end,SetScript=function(_,kind,cb)assert(kind=='OnEvent');event=cb end}end
local function tooltip(id)
return {id=id,rebuilds=0,IsShown=function(self)return self.shown~=false end,
GetTooltipData=function(self)return{id=self.id}end,
RebuildFromTooltipInfo=function(self)self.rebuilds=self.rebuilds+1;callback(self,{id=self.id})end}
end
local function tick()local q=timers;timers={};for _,fn in ipairs(q)do fn()end end
dofile(source)
assert(#requested==0 and #timers==0) -- Never eagerly warm during login.
local t=tooltip(10);GameTooltip=t;callback(t,{id=10});assert(#requested==2 and requested[1]==11 and requested[2]==12 and #timers==1)
callback(t,{id=10});assert(#requested==2 and #timers==1) -- Shared requests deduplicate.
t.id=99;tick();assert(t.rebuilds==0) -- Do not replace a changed tooltip.
callback(t,{id='SECRET'});callback(t,{id=true});assert(#requested==2)
local u=tooltip(11);ItemRefTooltip=u;callback(u,{id=11});cached[11]=true;cached[12]=true;event(nil,'ITEM_DATA_LOAD_RESULT',11,true);tick()
assert(u.rebuilds==1 and #timers==0 and #requested==2)
callback(u,{id=11});assert(#timers==0 and #requested==2)
local v=tooltip(20);GameTooltip=v;callback(v,{id=20});assert(#requested==4);v.shown=false;tick();assert(v.rebuilds==0)
local comparison=tooltip(20);ShoppingTooltip1=comparison;GameTooltip=tooltip(99);cached[20]=nil;cached[21]=nil
callback(comparison,{id=20});event(nil,'ITEM_DATA_LOAD_RESULT',20,true);tick();assert(comparison.rebuilds==0 and GameTooltip.rebuilds==1)
assert(C_Item.GetItemInfo==original and GWItemDependencyDiagnostics.errors==0)
print('Lazy shared-set requests, no login work, secret guards, stable APIs, stale-tooltip rejection and original-context rebuild pass.')
GWItemDependencyData.itemSpells={[10]={50,51},[99]={52}}
GWItemDependencyData.setSpells={[511]={51,53}}
local spellCached={[51]=true};local spellRequests={}
C_Spell={IsSpellDataCached=function(id)return spellCached[id]or false end,RequestLoadSpellData=function(id)spellRequests[#spellRequests+1]=id end}
local spellOriginal=C_Spell.RequestLoadSpellData
cached[10]=true;cached[11]=true;cached[12]=true;timers={}
dofile(source)
assert(#spellRequests==0 and GWItemDependencyDiagnostics.spellRequests==0)
GameTooltip=tooltip(10);callback(GameTooltip,{id=10})
assert(#spellRequests==2 and spellRequests[1]==50 and spellRequests[2]==53)
callback(GameTooltip,{id=10});assert(#spellRequests==2 and #timers==1)
tick();assert(GameTooltip.rebuilds==1 and #timers==0) -- Keep pending asynchronous dependencies.
spellCached[50]=true;event(nil,'SPELL_DATA_LOAD_RESULT',50,true);tick()
assert(GameTooltip.rebuilds==2 and #spellRequests==2)
event(nil,'SPELL_DATA_LOAD_RESULT',53,false);assert(#timers==0)
spellCached[53]=true;event(nil,'SPELL_DATA_LOAD_RESULT',53,true);tick()
assert(GameTooltip.rebuilds==3 and #timers==0)
callback(GameTooltip,{id=10});assert(#spellRequests==2 and #timers==0)
spellCached[52]='SECRET';GameTooltip=tooltip(99);callback(GameTooltip,{id=99});assert(#spellRequests==2)
spellCached[52]=nil;callback(GameTooltip,{id=99});assert(#spellRequests==3)
GameTooltip.id=100;spellCached[52]=true;event(nil,'SPELL_DATA_LOAD_RESULT',52,true);tick()
assert(GameTooltip.rebuilds==0) -- A delayed spell response cannot overwrite a changed tooltip.
assert(C_Spell.RequestLoadSpellData==spellOriginal and C_Item.GetItemInfo==original and GWItemDependencyDiagnostics.errors==0)
print('Item and set-bonus spell dependencies load on hover only, deduplicate, wait for real cache events, preserve stale contexts and keep native APIs.')