162 lines
7.2 KiB
Lua
162 lines
7.2 KiB
Lua
-- Run from the repository root with lua5.1 tests/octo_transmog_confirm_send_test.lua.
|
|
local __frames, __timers, __preview = {}, {}, {}
|
|
local __weapon16 = 58214
|
|
local methods = {}
|
|
function methods:SetScript(name, callback) self.scripts[name] = callback end
|
|
function methods:Show() self.shown = true; if self.scripts.OnShow then self.scripts.OnShow(self) end end
|
|
function methods:Hide() self.shown = false; if self.scripts.OnHide then self.scripts.OnHide(self) end end
|
|
function methods:IsShown() return self.shown end
|
|
function methods:SetText(value) self.text = value end
|
|
function methods:SetShown(value) self.shown = value end
|
|
function methods:SetPropagateKeyboardInput(value) assert(not InCombatLockdown()); self.propagate = value end
|
|
function methods:GetPropagateKeyboardInput() return self.propagate == true end
|
|
function methods:Enable() self.enabled = true end
|
|
function methods:Disable() self.enabled = false end
|
|
function methods:CreateTexture() return CreateFrame("Texture") end
|
|
function methods:CreateFontString() return CreateFrame("FontString") end
|
|
function methods:SetUnit(unit) self.unit = unit end
|
|
function methods:TryOn(link, hand)
|
|
__preview[#__preview+1] = {link=link, hand=hand}
|
|
return Enum.ItemTryOnReason.Success
|
|
end
|
|
setmetatable(methods, {__index = function(_, key) return function() end end})
|
|
function CreateFrame(kind, name, parent, template)
|
|
local value = setmetatable({kind=kind, name=name, parent=parent, propagate=template=="InsecureKeyboardInputPropagatorTemplate", shown=true, scripts={}}, {__index=methods})
|
|
__frames[#__frames+1] = value
|
|
return value
|
|
end
|
|
UIParent = CreateFrame("Frame")
|
|
local combat, modal, focus = false, false, nil
|
|
function InCombatLockdown() return combat end
|
|
function GetBindingFromClick(key) return key == "F11" and "TOGGLEGAMEMENU" or "" end
|
|
function StaticPopup_IsAnyDialogShown() return modal end
|
|
function SpellIsTargeting() return false end
|
|
function GetCurrentKeyBoardFocus() return focus end
|
|
function RegisterGameMenuEscHandler() error("Addon registered in the stock Escape dispatcher") end
|
|
UISpecialFrames, StaticPopupDialogs, SlashCmdList = {}, {}, {}
|
|
Enum = {ItemTryOnReason={Success=0}}
|
|
YES, NO = "Yes", "No"
|
|
GameTooltip = CreateFrame("Frame")
|
|
function StaticPopup_Hide() end
|
|
function UnitName() return "Fixture" end
|
|
function UnitGUID() return "Creature-0-0-0-51291-0" end
|
|
function GetItemCount() return 2 end
|
|
function GetInventoryItemLink(_, slot)
|
|
if slot == 16 then return "|Hitem:"..__weapon16..":0:0:0|h[Test Weapon]|h" end
|
|
if slot == 17 then return "|Hitem:58215:0:0:0|h[Test Offhand]|h" end
|
|
end
|
|
C_Item = {
|
|
GetItemInfo = function(id)
|
|
return "Item "..id, nil,nil,nil,nil,nil,nil,nil,nil,"Icon"
|
|
end,
|
|
GetItemInfoInstant = function(id) return id,nil,nil,"INVTYPE_WEAPON" end,
|
|
GetItemIconByID = function() return "Icon" end,
|
|
RequestLoadItemDataByID = function() end,
|
|
}
|
|
C_ChatInfo = {
|
|
RegisterAddonMessagePrefix = function() return true end,
|
|
}
|
|
C_Timer = {After = function(_, callback) __timers[#__timers+1] = callback end}
|
|
|
|
local instances = {[16] = "item-A", [17] = "item-B"}
|
|
ItemLocation = {CreateFromEquipmentSlot=function(_,slot) return slot end}
|
|
C_Item.GetItemGUID = function(location) return instances[location] end
|
|
local result = 0
|
|
local attempted, accepted, popup = {}, {}, nil
|
|
function C_ChatInfo.SendAddonMessage(_,payload)
|
|
attempted[#attempted+1] = payload
|
|
if result == 0 then accepted[#accepted+1] = payload end
|
|
return result
|
|
end
|
|
function StaticPopup_Show(_,_,_,data) popup = data end
|
|
local addon = arg[1] or "client_addons/OctoTransmog"
|
|
dofile(addon .. "/OctoTransmogData.lua")
|
|
dofile(addon .. "/OctoTransmogUI.lua")
|
|
local T = OctoTransmog
|
|
for code=1,12 do
|
|
result = code
|
|
assert(T.Send("GetTransmogStatus") == false, "numeric rejection counted as successful")
|
|
end
|
|
result = 3
|
|
T.frame:Show()
|
|
assert(T.state.statusOutstanding == 0, "throttle left a phantom status request")
|
|
assert(T.state.listFlight == nil and not T.state.loading, "throttle locked the list")
|
|
local buttons, events = {}, nil
|
|
for _,frame in ipairs(__frames) do
|
|
if frame.kind == "Button" then buttons[frame.text] = frame end
|
|
if frame.scripts.OnEvent then events = frame end
|
|
end
|
|
local function reply(message)
|
|
events.scripts.OnEvent(events, "CHAT_MSG_ADDON", T.prefix, message, "GUILD", "Fixture")
|
|
end
|
|
local function click(name) buttons[name].scripts.OnClick(buttons[name]) end
|
|
local function selectLook(slot)
|
|
T.SelectSlot(slot)
|
|
reply("AvailableTransmogs:"..slot..":679:start")
|
|
reply("AvailableTransmogs:"..slot..":679:109")
|
|
reply("AvailableTransmogs:"..slot..":679:end")
|
|
assert(T.state.complete)
|
|
T.state.selected = 109
|
|
T.Refresh()
|
|
assert(buttons["Apply appearance"].enabled)
|
|
end
|
|
local function accept() StaticPopupDialogs.OCTO_TRANSMOG_CONFIRM.OnAccept(nil,popup) end
|
|
result = 0
|
|
click("Refresh")
|
|
assert(T.state.listFlight and T.state.statusOutstanding == 1)
|
|
reply("TransmogStatus:16:109,17:109")
|
|
local first = T.state.slot
|
|
reply("AvailableTransmogs:"..first..":679:start")
|
|
reply("AvailableTransmogs:"..first..":679:end")
|
|
selectLook(16)
|
|
click("Apply appearance")
|
|
selectLook(17)
|
|
local before = #attempted
|
|
accept()
|
|
assert(#attempted == before, "old popup spent on another slot")
|
|
selectLook(16)
|
|
click("Apply appearance")
|
|
instances[16] = "another-copy-of-the-same-weapon"
|
|
before = #attempted
|
|
accept()
|
|
assert(#attempted == before, "old popup spent on a different item instance")
|
|
click("Apply appearance")
|
|
result = 8
|
|
accept()
|
|
assert(T.state.pending == nil and buttons["Apply appearance"].enabled, "rejected apply locked subsequent actions")
|
|
result = 9
|
|
click("Reset")
|
|
assert(T.state.pending == nil and buttons["Reset"].enabled, "rejected reset locked subsequent actions")
|
|
result = 0
|
|
click("Apply appearance")
|
|
accept()
|
|
assert(T.state.pending and accepted[#accepted] == "DoTransmog:15:109:16")
|
|
reply("TransmogResult:15:16:0")
|
|
assert(not T.state.pending)
|
|
local keys, combatKeys
|
|
for _, child in ipairs(__frames) do
|
|
if child.parent == T.frame and child.scripts.OnKeyDown then
|
|
if child.scripts.OnEvent then keys = child else combatKeys = child end
|
|
end
|
|
end
|
|
assert(keys and combatKeys and keys:IsShown() and not combatKeys:IsShown() and T.frame:IsShown() and #UISpecialFrames == 0)
|
|
local function press(key)
|
|
local active = keys:IsShown() and keys or combatKeys
|
|
active.scripts.OnKeyDown(active, key)
|
|
end
|
|
press("W"); assert(keys.propagate and T.frame:IsShown())
|
|
modal = true; press("ESCAPE"); assert(keys.propagate and T.frame:IsShown())
|
|
modal, focus = false, {}; press("ESCAPE"); assert(keys.propagate and T.frame:IsShown())
|
|
focus = nil
|
|
EditModeManagerFrame = CreateFrame("Frame")
|
|
press("ESCAPE"); assert(keys.propagate and T.frame:IsShown())
|
|
EditModeManagerFrame:Hide()
|
|
press("F11"); assert(not keys.propagate and not T.frame:IsShown())
|
|
combat = true; T.frame:Show(); assert(not keys:IsShown() and combatKeys:IsShown() and combatKeys.propagate)
|
|
press("W"); assert(combatKeys.propagate and T.frame:IsShown())
|
|
press("ESCAPE"); assert(combatKeys.propagate and not T.frame:IsShown())
|
|
T.frame:Show(); combat = false; keys.scripts.OnEvent(keys,"PLAYER_REGEN_ENABLED")
|
|
assert(keys:IsShown() and keys.propagate and not combatKeys:IsShown())
|
|
press("ESCAPE"); assert(not keys.propagate and not T.frame:IsShown())
|
|
print("PASS numeric send outcomes, retry, slot and item-instance confirmation")
|