Files
WoW-Hybrid-gateway/tests/source_creation_challenges_test.lua

60 lines
2.9 KiB
Lua

local frames={}
local function frame()
local f={scripts={},shown=true,checked=false}
function f:SetScript(k,v)self.scripts[k]=v end
function f:HookScript(k,v)self.scripts[k]=v end
function f:SetShown(v)self.shown=v end
function f:IsShown()return self.shown end
function f:Hide()self.shown=false end
function f:SetChecked(v)self.checked=v end
function f:GetChecked()return self.checked end
function f:CreateFontString()return frame()end
for _,k in ipairs({'SetPoint','SetSize','SetText','SetTextColor','SetFrameStrata','SetBackdrop','SetBackdropColor','SetWidth','SetJustifyH','SetToplevel','EnableMouseWheel'})do f[k]=function()end end
function f:EnableMouse(v)self.mouse=v end
frames[#frames+1]=f;return f
end
function CreateFrame()return frame()end
local pending=0
local classID, realmType = 1, 0
C_CharacterCreation={GetSelectedClass=function()return {classID=classID}end}
C_Login={GetTurtleRealmSnapshot=function(q,v)
if q==0 then return 0 end
if q==1 then return realmType end
if q==22 then pending=v;return v end
if q==23 then return pending end
error('unexpected query')
end}
dofile(arg[1])
local parent=frame();parent.BackButton=frame()
GW_SourceChallengeAttach(parent,true)
local buttons={}
for _,f in ipairs(frames)do if f.index then buttons[f.index]=f end end
assert(#buttons==12)
assert(frames[3].mouse==true,'challenge panel must take its own clicks')
local function click(i)buttons[i]:SetChecked(true);buttons[i].scripts.OnClick(buttons[i])end
click(1);assert(GW_SourceChallengeStage() and pending==2)
click(3);assert(GW_SourceChallengeStage() and pending==10)
click(10);assert(GW_SourceChallengeStage() and pending==1034)
classID=5;assert(GW_SourceChallengeStage() and pending==10)
GW_SourceChallengeReset()
for _,class in ipairs({1,2,3,4})do
classID=class;click(10);assert(GW_SourceChallengeStage() and pending==1024)
GW_SourceChallengeReset()
end
classID=9;click(10);assert(not buttons[10]:GetChecked())
click(5);click(11);assert(not buttons[11]:GetChecked())
assert(GW_SourceChallengeStage() and pending==32)
GW_SourceChallengeReset();click(11);click(5);assert(not buttons[5]:GetChecked())
assert(GW_SourceChallengeStage() and pending==2048)
click(12);assert(not buttons[12]:GetChecked())
realmType=6;click(12);assert(GW_SourceChallengeStage() and pending==6144)
realmType=0;assert(GW_SourceChallengeStage() and pending==2048)
GW_SourceChallengeReset();realmType=8;click(12);assert(GW_SourceChallengeStage() and pending==4096)
realmType=0
parent.BackButton.scripts.OnClick();assert(pending==0 and GW_SourceChallengeStage() and pending==0)
click(2);parent.scripts.OnHide();assert(GW_SourceChallengeStage() and pending==0)
click(1);GW_SourceChallengeReset();assert(GW_SourceChallengeStage() and pending==0)
C_Login.GetTurtleRealmSnapshot=function()return -4005 end
click(1);assert(not buttons[1]:GetChecked() and not GW_SourceChallengeStage())
print('chooser class/realm/exclusivity/reset/unavailable checks PASS')