Files
ShaguTweaks-ClassicAPI/tests/test_options_search.lua
T

87 lines
5.2 KiB
Lua

local root=(arg[1] or '.') .. '/'
local function noop() end
local methods={}
function methods:SetScript(k,v) self.scripts[k]=v end
function methods:SetText(v) self.text=v; if self.scripts.OnTextChanged then local old=this; this=self; self.scripts.OnTextChanged(); this=old end end
function methods:GetText() return self.text or '' end
function methods:Show() self.visible=true end
function methods:Hide() self.visible=false end
function methods:IsShown() return self.visible end
function methods:SetWidth(v) self.width=v end
function methods:SetHeight(v) self.height=v end
function methods:GetWidth() return self.width or 500 end
function methods:GetHeight() return self.height or 900 end
function methods:GetScale() return 1 end
function methods:SetChecked(v) self.checked=v end
function methods:GetChecked() return self.checked end
function methods:Enable() self.enabled=true end
function methods:Disable() self.enabled=false end
function methods:SetValue(v) self.value=v; if self.scripts.OnValueChanged then local old=this; this=self; self.scripts.OnValueChanged(); this=old end end
function methods:GetValue() return self.value end
function methods:CreateFontString() return CreateFrame() end
function methods:CreateTexture() return CreateFrame() end
local made=0
function CreateFrame(kind,name,parent,template)
made=made+1
local f=setmetatable({scripts={},visible=true},{__index=function(t,k) if methods[k] then return methods[k] elseif string.find(k,'^[A-Z]') then return noop end end})
if name then _G[name]=f end
if name and template=='OptionsCheckButtonTemplate' then _G[name..'Text']=CreateFrame() end
return f
end
UIParent=CreateFrame(); GameMenuFrame=CreateFrame(); GameMenuButtonUIOptions=CreateFrame(); GameMenuButtonKeybindings=CreateFrame(); GameTooltip=CreateFrame()
UISpecialFrames={}; DEFAULTS='Defaults'; OKAY='Okay'; CANCEL='Cancel'
ShowUIPanel=noop; HideUIPanel=noop; UpdateMicroButtons=noop
local reloaded=false
function ReloadUI() reloaded=true end
Minimap=CreateFrame()
ShaguTweaks={T=setmetatable({},{__index=function(t,k) return k end}),mods={}}
function ShaguTweaks.GetGlobalEnv() return _G end
function ShaguTweaks:GetExpansion() return 'vanilla' end
function ShaguTweaks.spairs(t,comp)
local keys={}; for k in pairs(t) do table.insert(keys,k) end; table.sort(keys,comp)
local i=0; return function() i=i+1; if keys[i] then return keys[i],t[keys[i]] end end
end
local function add(title,category,description,sliders)
ShaguTweaks.mods[title]={title=title,category=category,description=description,sliders=sliders,expansions={vanilla=true}}
end
add('Golden UI','Interface','Colors borders gold')
add('Hide Player Frame Resources','Unit Frames','Hides native resources')
add('Hide Player Name','Unit Frames','Hides native name')
ShaguTweaks.mods['Hide Player Name'].requires={'Hide Player Frame Resources'}
add('Item Rarity Borders','Tooltip & Items','Colors mail and trade items')
add('Range Color','Action Bar','Shows distance',{{key='range.delay',label='Update interval',min=1,max=10,default=3}})
for i=1,40 do add('Other '..i,'Other','Another feature') end
ShaguTweaks_config={overwrites={}}
dofile(root..'config.lua')
local gui=AdvancedSettingsGUI
this=gui; gui.scripts.OnShow(); this=nil
assert(gui.scrollframe.visible)
local hideName=gui.entries['Hide Player Name']
local hideResources=gui.entries['Hide Player Frame Resources']
assert(not hideName.enabled)
hideName:SetChecked(true);this=hideName;hideName.scripts.OnClick();assert(not hideName.checked)
hideResources:SetChecked(true);this=hideResources;hideResources.scripts.OnClick();assert(hideName.enabled)
hideName:SetChecked(true);this=hideName;hideName.scripts.OnClick()
gui.search:SetText('Hide Player Name');assert(hideName.enabled and hideName.checked)
gui.search:SetText('')
hideResources:SetChecked(false);this=hideResources;hideResources.scripts.OnClick()
assert(not hideName.enabled and hideName.checked) -- retain dependent choice while dormant
local firstCount=made
local checkbox=gui.entries['Golden UI']; checkbox:SetChecked(true); this=checkbox; checkbox.scripts.OnClick(); this=nil
-- Collapse a category before searching: matches must still be visible.
local collapse=gui.category.Interface.button; this=collapse; collapse.scripts.OnClick(); this=nil
assert(not checkbox.visible)
gui.search:SetText(' GOLDEN ')
assert(checkbox.visible and checkbox.checked and not gui.entries['Range Color'].visible)
assert(not gui.scrollframe.visible and not gui.empty.visible)
assert(not ShaguTweaks_config['Golden UI'])
gui.search:SetText('mail'); assert(gui.entries['Item Rarity Borders'].visible and not checkbox.visible)
gui.search:SetText('update interval'); assert(gui.entries['Range Color'].visible and gui.entries['slider:range.delay'].visible)
gui.search:SetText('[.*'); assert(gui.empty.visible) -- literal, not Lua pattern matching
this=gui.searchClear; gui.searchClear.scripts.OnClick(); this=nil
assert(not gui.empty.visible and checkbox.visible and checkbox.checked and gui.scrollframe.visible)
assert(made==firstCount) -- subsequent searches reuse all widgets
this=gui.okay; gui.okay.scripts.OnClick(); this=nil
assert(ShaguTweaks_config['Golden UI']==1 and reloaded)
print('Search: literal/case-insensitive matching, descriptions/sliders, collapsed categories, empty/clear, widget reuse, scroll layouts and unsaved settings passed')