ruen-ui/tests/check-profiles.lua

101 lines
5.9 KiB
Lua

local root=assert(arg[1], 'Pass addon directory with trailing slash')
local base,saves,combat,class,role,spec={},0,false,'HUNTER','NONE',nil
local frames={}
UIParent={}
function CreateFrame(_,name)
local frame={events={},scripts={}}
function frame:RegisterEvent(e)self.events[e]=true end
function frame:SetScript(k,v)self.scripts[k]=v end
function frame:HookScript(k,v)self.scripts[k]=v end
frames[#frames+1]=frame
if name then _G[name]=frame end
return frame
end
function InCombatLockdown()return combat end
function UnitClass()return class,class end
function UnitName()return 'Test' end
function UnitGUID()return 'player-'..class end
function UnitGroupRolesAssigned()return role end
function GetSpecialization()return spec end
function GetSpecializationRole()return role end
function GetCurrentBindingSet()return 1 end
function GetBindingAction(key)return base[key] or '' end
function GetBindingKey(action)for k,v in pairs(base)do if v==action then return k end end end
function GetBindingText(key)return key end
function SaveBindings()saves=saves+1 end
function hooksecurefunc(object,key,fn)local old=object[key];object[key]=function(...)old(...);fn(...)end end
C_Timer={After=function(_,fn)fn()end}
PetActionBar={IsShown=function()return false end}
function UnitExists(unit)return unit=='pet' and PetActionBar:IsShown()end
local fixture=dofile('tests/secure-binding-fixture.lua')
local P={Localized=function(en)return en end}
assert(loadfile(root..'CharacterProfiles.lua'))('RuenUI',P)
RuenUIDB={petBindingsVersion=2,cooldownsMode='off',damageMeterMode='auto'}
local numbers={'1','2','3','4','5','6','7','8','9','0','-','='}
for i,key in ipairs(numbers)do
base[key]=i<=10 and 'BONUSACTIONBUTTON'..i or 'CLICK RuenPetExtraButton'..i..':LeftButton'
base['CTRL-'..key]='MULTIACTIONBAR4BUTTON'..i
end
base.Q='ACTIONBUTTON1';base.F1='TARGETSELF'
local function font()return {SetText=function(self,s)self.text=s end,Show=function(self)self.shown=true end,Hide=function(self)self.shown=false end}end
PetActionButton1={HotKey=font(),SetHotkeys=function()end}
MultiBarLeftButton1={HotKey=font(),UpdateHotkeys=function()end}
RuenPetExtraButton11={HotKey=font()}
local chars={}
for _,value in ipairs({'HUNTER','WARLOCK','ROGUE','WARRIOR','MAGE','DRUID','PALADIN','SHAMAN','PRIEST'})do
class=value;RuenUICharacter={version=5};chars[class]=RuenUICharacter
P.InitializeCharacterProfiles();P.ApplyCharacterBindings(false)
local pet=class=='HUNTER' or class=='WARLOCK'
for i,key in ipairs(numbers)do
local action=i<=10 and 'BONUSACTIONBUTTON'..i or 'CLICK RuenPetExtraButton'..i..':LeftButton'
assert(GetBindingAction(key,true)==(pet and action or 'MULTIACTIONBAR4BUTTON'..i))
assert(GetBindingAction('CTRL-'..key,true)==(pet and 'MULTIACTIONBAR4BUTTON'..i or action))
end
assert(PetActionButton1.HotKey.text==(pet and '1' or 'CTRL-1'))
assert(MultiBarLeftButton1.HotKey.text==(pet and 'CTRL-1' or '1'))
assert(RuenPetExtraButton11.HotKey.text==(pet and '-' or 'CTRL--'))
assert(base['1']=='BONUSACTIONBUTTON1' and base['CTRL-1']=='MULTIACTIONBAR4BUTTON1' and saves==0,'profile rewrote shared bindings')
assert(RuenUICharacter.cooldownsMode=='off' and RuenUICharacter.damageMeterMode=='auto')
end
-- Manual changes after a profile was applied immediately supersede it.
base['1']='CUSTOM';P.ApplyCharacterBindings(false)
assert(GetBindingAction('1',true)=='CUSTOM' and RuenUICharacter.numberBindingConflicts[1]=='1')
base['1']='BONUSACTIONBUTTON1';P.ApplyCharacterBindings(false)
assert(GetBindingAction('1',true)=='BONUSACTIONBUTTON1','reclaimed a customized key automatically')
P.ApplyCharacterBindings(true);assert(GetBindingAction('1',true)=='MULTIACTIONBAR4BUTTON1')
-- Config changes defer in combat; native handoff still executes its secure
-- snippet immediately, without an insecure SetAttribute call.
combat=true
P.CharacterProfileCommand('keys','pet')
assert(GetBindingAction('1',true)=='MULTIACTIONBAR4BUTTON1')
fixture.transition(true);assert(next(fixture.active())==nil,'native control handoff retained overrides')
fixture.transition(false);assert(GetBindingAction('1',true)=='MULTIACTIONBAR4BUTTON1')
combat=false;P.ApplyCharacterBindings(false);assert(GetBindingAction('1',true)=='BONUSACTIONBUTTON1')
-- Mage capability: no unconditional empty pet shelf, but no disappearing row
-- after a temporary pet dies during the same session.
class='MAGE';RuenUICharacter=chars.MAGE;P.ApplyCharacterBindings(false)
assert(not P.NeedsPetRow())
PetActionBar.IsShown=function()return true end;assert(P.NeedsPetRow())
PetActionBar.IsShown=function()return false end;assert(P.NeedsPetRow())
spec=2;assert(not P.NeedsPetRow());spec=nil
-- Roles do not follow forms or class guesses, and manual choices win.
RuenUICharacter={};P.EnsureCharacterProfile();assert(P.CharacterRole()=='UNKNOWN' and RuenUICharacter.cooldownsMode=='off')
role='HEALER';assert(P.CharacterRole()=='HEALER')
P.CharacterProfileCommand('role','damage');assert(P.CharacterRole()=='DAMAGER' and RuenUICharacter.mouseoverMode=='auto')
role='TANK';assert(P.CharacterRole()=='DAMAGER')
P.CharacterProfileCommand('role','auto');assert(P.CharacterRole()=='TANK')
-- Assigned roles can change without a specialization change on this client.
local roleSeen
P.ApplyMouseover=function()roleSeen=P.CharacterRole()end
role='HEALER'
for _,frame in ipairs(frames)do
if frame.events.PLAYER_ROLES_ASSIGNED then frame.scripts.OnEvent(frame,'PLAYER_ROLES_ASSIGNED')end
end
assert(roleSeen=='HEALER','assigned role changes must refresh the auto input preference')
RuenUIDB.disabled=true;P.ApplyCharacterBindings(false)
assert(next(fixture.active())==nil and GetBindingAction('1',true)==base['1'])
RuenUIDB.disabled=nil;P.ApplyCharacterBindings(false)
assert(next(fixture.active())~=nil)
P.ClearCharacterBindings();assert(next(fixture.active())==nil and saves==0)
print('PASS: nine-class 24-key profiles, no account writes, actual secure snippet combat handoff, manual key preservation, effective hotkeys, deferred changes, role/capability defaults, migration and restore')