129 lines
5.5 KiB
Python
129 lines
5.5 KiB
Python
"""Offline realm-confirmation behavior for the native appearance settings canvas."""
|
|
from pathlib import Path
|
|
import subprocess
|
|
import unittest
|
|
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
LUA = ROOT / "client_addons/WoWHybridUI/NativeEquipmentVisibility.lua"
|
|
|
|
|
|
class NativeEquipmentVisibilityOptionsTest(unittest.TestCase):
|
|
def test_checkbox_waits_for_server_confirmation(self):
|
|
script = r'''
|
|
local sent, buttons, timers = {}, {}, {}
|
|
local eventFrame, panel, lastLabel
|
|
local visible = true
|
|
local sendResult = 0
|
|
UIParent = {}
|
|
local function noop() end
|
|
local function font()
|
|
return {SetPoint=noop, SetText=function(self, value) self.text=value; lastLabel=value end}
|
|
end
|
|
function CreateFrame(kind, name, parent)
|
|
local frame = {
|
|
SetSize=noop, SetPoint=noop, RegisterEvent=noop,
|
|
CreateFontString=function() return font() end,
|
|
SetScript=function(self, event, callback) self[event]=callback end,
|
|
SetText=noop, IsShown=function() return true end, IsVisible=function() return visible end,
|
|
SetChecked=function(self, value) self.checked=value end,
|
|
SetEnabled=function(self, value) self.enabled=value end,
|
|
}
|
|
if kind == 'CheckButton' then table.insert(buttons, frame)
|
|
elseif parent == UIParent then panel = frame
|
|
else eventFrame = frame end
|
|
return frame
|
|
end
|
|
GameFontNormalLarge, GameFontHighlight, GameFontDisableSmall = {}, {}, {}
|
|
UnitName = function(unit) assert(unit == 'player'); return 'Fixture' end
|
|
C_ChatInfo = {SendAddonMessage=function(prefix, message, channel, target)
|
|
assert(prefix == 'GWTURTLE' and channel == 'WHISPER' and target == 'Fixture')
|
|
table.insert(sent, message)
|
|
return sendResult
|
|
end}
|
|
C_Timer = {After=function(delay, callback) table.insert(timers, callback) end}
|
|
Settings = {
|
|
INTERFACE_CATEGORY_ID=4,
|
|
GetCategory=function(id) assert(id == 4); return {} end,
|
|
RegisterCanvasLayoutSubcategory=function(parent, frame, name)
|
|
assert(frame == panel and name == 'Equipment appearance'); return {}
|
|
end,
|
|
RegisterCategory=function() end,
|
|
}
|
|
SettingsRegistrar = {AddRegistrant=function(self, fn) fn() end}
|
|
EventUtil = {ContinueOnAddOnLoaded=function(name, fn)
|
|
assert(name == 'Blizzard_SettingsDefinitions_Frame'); fn()
|
|
end}
|
|
dofile(arg[1])
|
|
assert(panel and eventFrame and #buttons == 2)
|
|
sendResult=3
|
|
panel.OnShow()
|
|
assert(#timers==0 and not buttons[1].enabled and lastLabel:match('retry'))
|
|
sendResult=0
|
|
panel.OnShow()
|
|
assert(#sent == 2 and sent[2] == 'visibility helm status')
|
|
assert(not buttons[1].enabled and not buttons[2].enabled)
|
|
eventFrame.OnEvent(eventFrame, 'CHAT_MSG_SYSTEM', 'GWTURTLE1 VISIBILITY helm on confirmed')
|
|
eventFrame.OnEvent(eventFrame, 'CHAT_MSG_SYSTEM', 'GWTURTLE1 VISIBILITY cloak off confirmed')
|
|
assert(buttons[1].checked and buttons[1].enabled)
|
|
assert(not buttons[2].checked and buttons[2].enabled)
|
|
sendResult=8
|
|
local previousTimers=#timers
|
|
buttons[1].OnClick()
|
|
assert(buttons[1].checked and buttons[1].enabled and lastLabel:match('retry'))
|
|
assert(#timers==previousTimers)
|
|
sendResult=0
|
|
buttons[1].OnClick()
|
|
assert(sent[#sent] == 'visibility helm off')
|
|
assert(buttons[1].checked and not buttons[1].enabled)
|
|
sendResult=3
|
|
timers[#timers-1]() -- read-only follow-up failed; the original change still awaits confirmation
|
|
assert(sent[#sent]=='visibility helm status' and lastLabel:match('retry'))
|
|
assert(buttons[1].checked and not buttons[1].enabled)
|
|
sendResult=0
|
|
eventFrame.OnEvent(eventFrame, 'CHAT_MSG_SYSTEM', 'GWTURTLE1 VISIBILITY helm off pending')
|
|
assert(buttons[1].checked and not buttons[1].enabled)
|
|
eventFrame.OnEvent(eventFrame, 'CHAT_MSG_SYSTEM', 'GWTURTLE1 VISIBILITY helm off confirmed')
|
|
assert(not buttons[1].checked and buttons[1].enabled)
|
|
assert(#sent == 5)
|
|
local oldStatus, oldTimeout = timers[#timers-1], timers[#timers]
|
|
buttons[1].OnClick() -- show helm again while the previous hide timers still exist
|
|
buttons[2].OnClick() -- cloak changes have independent lifetimes
|
|
assert(sent[6]=='visibility helm on' and sent[7]=='visibility cloak on')
|
|
local helmStatus, cloakTimeout = timers[#timers-3], timers[#timers]
|
|
oldStatus()
|
|
oldTimeout()
|
|
assert(#sent==7, "an expired request sent another status query")
|
|
helmStatus()
|
|
assert(sent[8]=='visibility helm status', "old timeout cancelled the new helm request")
|
|
cloakTimeout()
|
|
assert(not buttons[2].enabled and not buttons[1].enabled)
|
|
eventFrame.OnEvent(eventFrame, 'CHAT_MSG_SYSTEM', 'GWTURTLE1 VISIBILITY helm on confirmed')
|
|
assert(buttons[1].checked and buttons[1].enabled)
|
|
eventFrame.OnEvent(eventFrame, 'PLAYER_LEAVING_WORLD')
|
|
assert(not buttons[1].enabled and not buttons[2].enabled)
|
|
assert(#sent == 8)
|
|
-- A queued confirmation between worlds belongs to the character that just left.
|
|
eventFrame.OnEvent(eventFrame, 'CHAT_MSG_SYSTEM', 'GWTURTLE1 VISIBILITY helm on confirmed')
|
|
assert(not buttons[1].enabled, "old character confirmed helm after world exit")
|
|
panel.OnShow()
|
|
assert(#sent==8, "panel queried during world exit")
|
|
eventFrame.OnEvent(eventFrame,'PLAYER_ENTERING_WORLD')
|
|
assert(#sent==9 and sent[9]=='visibility helm status')
|
|
issecretvalue=function(message) return message=='GWTURTLE1 VISIBILITY helm on confirmed' end
|
|
eventFrame.OnEvent(eventFrame,'CHAT_MSG_SYSTEM','GWTURTLE1 VISIBILITY helm on confirmed')
|
|
assert(not buttons[1].enabled and not buttons[2].enabled)
|
|
eventFrame.OnEvent(eventFrame,'CHAT_MSG_SYSTEM','GWTURTLE1 VISIBILITY helm off confirmed')
|
|
assert(buttons[1].enabled and not buttons[1].checked)
|
|
visible=false
|
|
eventFrame.OnEvent(eventFrame,'PLAYER_LEAVING_WORLD')
|
|
eventFrame.OnEvent(eventFrame,'PLAYER_ENTERING_WORLD')
|
|
assert(#sent==9 and not buttons[1].enabled)
|
|
|
|
'''
|
|
subprocess.run(["lua", "-", str(LUA)], input=script, text=True, check=True)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|