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

163 lines
7.0 KiB
Lua

-- Exercise the secondary card through the page lifecycle and real click handler.
local events, loadHook, refreshHook, playerSkill, opened, current, displayed, errorMessage
local professionInfo
local acceptsRecipePage = true
local combat = false
local cardsCreated = 0
function InCombatLockdown() return combat end
C_SkillInfo = { GetSkillLineInfoByID = function(id)
assert(id == 142)
return playerSkill
end }
function ProfessionsFrame_LoadUI() return true end
function ShowUIPanel(panel) displayed = panel end
function UpdateUIPanelPositions() error("Sizing the profession window must stay local to the window") end
C_TradeSkillUI = {
GetBaseProfessionInfo = function() return current end,
GetProfessionInfoBySkillLineID = function(id) assert(id == 142); return professionInfo end,
OpenTradeSkill = function(id) opened = id; return acceptsRecipePage end,
}
UIErrorsFrame = {AddMessage = function(self, text) errorMessage = text end}
local region = {}
region.__index = region
function region:SetWidth(w) self.width = w end
function region:GetWidth() return self.width end
function region:ClearAllPoints() self.point = nil end
function region:Show() self.shown = true end
function region:SetDesaturated(value) self.desaturated = value end
function region:SetVertexColor(...) self.vertexColor = {...} end
function region:HookScript(key, func) self[key] = func end
function region:SetSize(w, h) self.width, self.height = w, h end
function region:SetAllPoints(parent) self.anchor = parent end
function region:SetPoint(...) self.point = {...} end
function region:SetText(s) self.text = s end
function region:SetFormattedText(...) self.text = string.format(...) end
function region:SetShown(value) self.shown = value end
function region:Hide() self.shown = false end
function region:SetAtlas(atlas) self.atlas = atlas end
function region:SetColorTexture(...) self.color = {...} end
function region:SetScript(key, f) self[key] = f end
function region:RegisterEvent() end
function region:UnregisterEvent() end
function region:GetMaskWidth(ratio) return self.width * ratio - 5 end
local function newRegion() return setmetatable({}, region) end
local function secondary()
local card = newRegion()
card.width = 225
card.Background, card.missingText = newRegion(), newRegion()
card.missingHeader, card.ProfessionName = newRegion(), newRegion()
card.spellButtons = {newRegion(), newRegion(), newRegion(), newRegion()}
local bar = newRegion()
bar.Background, bar.Border, bar.Mask = newRegion(), newRegion(), newRegion()
bar.Fill, bar.Flare, bar.Rank = newRegion(), newRegion(), {Text = newRegion()}
function bar:Update(info) self.professionInfo = info end
card.StatusBar = bar
return card
end
function CreateFrame(kind, name, parent, template)
if template == "SecondaryProfessionTemplate" then
assert(not combat)
cardsCreated = cardsCreated + 1
return secondary()
elseif template == "UIPanelButtonTemplate" then
assert(kind == "Button" and not combat)
return newRegion()
end
assert(kind == "Frame" and not template)
events = newRegion()
return events
end
function hooksecurefunc(target, method, callback)
if method == "OnLoad" then loadHook = callback
elseif method == "Update" then
assert(not refreshHook)
refreshHook = callback
else
assert(method == "SetTab")
end
end
ProfessionsBookFrameMixin = {OnLoad = function() end}
local content = {SecondaryProfession1=secondary(), SecondaryProfession2=secondary(), SecondaryProfession3=secondary()}
content.PrimaryProfession1, content.PrimaryProfession2 = newRegion(), newRegion()
local book = setmetatable({ProfessionsContentFrame=content}, region)
ProfessionsFrame = setmetatable({BookPage=book, width=782, recipesTabID=6, SetTab=function(self, id) self.currentTab = id end}, region)
combat = true
dofile(arg[1])
assert(not content.SecondaryProfession4 and WoWHybridUI.professionBookPending)
combat = false
events.OnEvent(nil, "PLAYER_REGEN_ENABLED")
local fourth = assert(content.SecondaryProfession4)
assert(fourth.point[1] == "TOPLEFT" and fourth.point[2] == content.SecondaryProfession3)
assert(fourth.point[3] == "TOPRIGHT" and fourth.point[4] == -6)
for i = 1,4 do
local c = content["SecondaryProfession"..i]
assert(c.width == 225 and not c.Background.anchor)
end
assert(4*fourth.width + 3*fourth.point[4] == 882 and ProfessionsFrame.width == 900)
loadHook(book)
assert(cardsCreated == 1 and fourth == content.SecondaryProfession4)
for _, action in ipairs(fourth.spellButtons) do assert(action.shown == false) end
assert(fourth.missingHeader.shown and not fourth.StatusBar.shown and not fourth.RecipeButton.shown)
fourth.RecipeButton:OnClick()
assert(not opened)
playerSkill = {skillID=142, name="Survival", rank=37, maxRank=75, modifier=5}
refreshHook(book)
assert(not fourth.missingHeader.shown and fourth.ProfessionName.text == "Survival")
assert(fourth.StatusBar.shown)
local function assertRank(rank, maximum, modifier)
local info = fourth.StatusBar.professionInfo
assert(info.skillLevel == rank and info.maxSkillLevel == maximum and info.skillModifier == modifier,
"incorrect Survival rank data delivered to the native bar")
end
assertRank(37, 75, 5)
for _, partial in ipairs({
{skillLevel = 0, maxSkillLevel = 75},
{skillLevel = 37, maxSkillLevel = 0},
{skillLevel = 37},
}) do
professionInfo = partial
refreshHook(book)
assertRank(37, 75, 5)
end
professionInfo = {skillLevel = 42, maxSkillLevel = 150, skillModifier = 3}
refreshHook(book)
assertRank(42, 150, 3)
professionInfo = nil
assert(fourth.RecipeButton.shown and fourth.RecipeButton.text == "Recipes")
fourth.RecipeButton:OnClick()
assert(opened == 142 and displayed == ProfessionsFrame and displayed.currentTab == 6)
acceptsRecipePage, displayed, ProfessionsFrame.currentTab = false, nil, nil
current = {professionID = 185}
fourth.RecipeButton:OnClick()
assert(errorMessage and not displayed and not ProfessionsFrame.currentTab)
current, opened = {professionID = 142}, nil
fourth.RecipeButton:OnClick()
assert(displayed == ProfessionsFrame and not opened)
playerSkill.rank, playerSkill.maxRank, playerSkill.modifier = 75, 150, 0
refreshHook(book)
assertRank(75, 150, 0)
opened = nil
-- Between drawing and clicking, the account changed or the skill was lost.
playerSkill = nil
fourth.RecipeButton:OnClick()
assert(not opened)
for _, invalid in ipairs({
{skillID=51, name="Survival", rank=75, maxRank=75},
{skillID=142, isHeader=true, rank=75, maxRank=75},
{skillID=142, rank=0, maxRank=75},
{skillID=142, rank=1, maxRank=0},
}) do
playerSkill = invalid
refreshHook(book)
assert(not fourth.StatusBar.shown and not fourth.RecipeButton.shown and fourth.missingText.shown)
fourth.RecipeButton:OnClick()
assert(not opened)
end
-- Leave a future native fourth card and its existing layout in native hands.
local original = secondary()
loadHook({ProfessionsContentFrame={SecondaryProfession3=secondary(), SecondaryProfession4=original}})
assert(cardsCreated == 1 and original.width == 225)