Initial addons

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rope 2026-11-10 13:02:16 +00:00
commit de17b0006e
17 changed files with 3257 additions and 0 deletions

139
tests/test_dpq.lua Normal file
View file

@ -0,0 +1,139 @@
-- Runs DungeonPreQuest.lua against a mock of the WoW API.
-- arg[1] = addon file
local faction, classID = "Alliance", 1
function UnitFactionGroup() return faction end
function UnitClass() return "x", "X", classID end
local callback
EventRegistry = { RegisterCallback = function(_, _, fn) callback = fn end }
local hooks = {}
function hooksecurefunc(name, fn) hooks[name] = fn end
local function region()
local r = { shown = false }
function r:Show() self.shown = true end
function r:Hide() self.shown = false end
function r:SetPoint() end
function r:SetText(t) self.text = t end
return r
end
local function button(id)
local b = { questID = id, creates = 0 }
function b:CreateFontString() self.creates = self.creates + 1; return region() end
return b
end
local rows = {}
QuestScrollFrame = { titleFramePool = { EnumerateActive = function()
local i = 0
return function() i = i + 1; return rows[i] end
end } }
local onShow
QuestFrameDetailPanel = {
CreateFontString = function() return region() end,
HookScript = function(_, _, fn) onShow = fn end,
}
local banner
do
local make = QuestFrameDetailPanel.CreateFontString
QuestFrameDetailPanel.CreateFontString = function() banner = make(); return banner end
end
QuestFrame = {}
local currentQuest
function GetQuestID() return currentQuest end
local tipLines, tipShown = {}, 0
GameTooltip = { AddLine = function(_, l) tipLines[#tipLines + 1] = l end, Show = function() tipShown = tipShown + 1 end }
local onEvent, registered = nil, {}
CreateFrame = function() return { RegisterEvent = function(_, e) registered[e] = true end, SetScript = function(_, _, fn) onEvent = fn end } end
SlashCmdList = {}
local printed = {}
DEFAULT_CHAT_FRAME = { AddMessage = function(_, m) printed[#printed + 1] = m end }
local failures = 0
local function check(cond, what)
if not cond then failures = failures + 1 end
print((cond and "ok " or "FAIL ") .. what)
end
local ns = {
dungeons = { "The Deadmines", "Stratholme" },
quests = {
[65] = { 1, 3, 0 }, -- everyone
[70] = { 1, 1, 0 }, -- Alliance only
[71] = { 2, 3, 2 }, -- paladins only (class bit 2)
[72] = { 2, 3, 1024 }, -- druids only (class 11)
[73] = { 1, 3, 0, 2, 3, 0, 1, 3, 0 }, -- two dungeons, one repeated
[74] = { 0, 3, 0 }, -- dungeon not known by name
},
}
assert(loadfile(arg[1]))("DungeonPreQuest", ns)
check(hooks.QuestLogQuests_Update == nil, "nothing touches Blizzard frames before login")
onEvent(nil, "QUEST_DETAIL")
onEvent(nil, "PLAYER_LOGIN")
local function text(id)
tipLines = {}
callback(ns, { questID = id }, id)
return tipLines[1]
end
check(text(65) == "Dungeon pre-quest: The Deadmines", "tooltip names the dungeon: " .. tostring(text(65)))
check(text(99) == nil, "unrelated quest gets no tooltip line")
check(text(73) == "Dungeon pre-quest: The Deadmines, Stratholme", "several dungeons, no repeats: " .. tostring(text(73)))
check(text(74) == "Dungeon pre-quest", "unknown dungeon still marks: " .. tostring(text(74)))
check(text(70) ~= nil, "Alliance entry shows for Alliance")
faction = "Horde"
check(text(70) == nil, "Alliance entry hidden for Horde")
faction = "Alliance"
classID = 1
check(text(71) == nil, "paladin chain hidden for a warrior")
classID = 2
check(text(71) ~= nil, "paladin chain shown for a paladin")
classID = 11
check(text(72) ~= nil, "class ID 11 maps to the druid bit")
classID = 1
tipLines = {}
callback(ns, { questID = 65 })
check(tipLines[1] ~= nil, "tooltip falls back to the button's quest ID")
-- Log rows: buttons are pooled and reused.
local a, b = button(65), button(99)
rows = { a, b }
hooks.QuestLogQuests_Update()
check(a.dpqMark and a.dpqMark.shown and a.dpqMark.text:find("D", 1, true), "pre-quest row is marked")
check(b.dpqMark == nil, "other row stays unmarked")
a.questID = 99
hooks.QuestLogQuests_Update()
check(a.dpqMark.shown == false, "reused row drops the mark")
a.questID = 65
hooks.QuestLogQuests_Update()
check(a.dpqMark.shown == true and a.creates == 1, "row mark is reused, not recreated")
-- Offer window.
currentQuest = 65
onShow()
check(banner.shown and banner.text:find("The Deadmines", 1, true), "offer window shows the banner")
currentQuest = 99
check(registered.QUEST_DETAIL, "listens for a new quest being offered")
onEvent()
check(banner.shown == false, "next offer clears the banner")
printed = {}
SlashCmdList.DUNGEONPREQUEST("65")
check(printed[1]:find("The Deadmines", 1, true), "/dpq describes a quest")
SlashCmdList.DUNGEONPREQUEST("nope")
check(printed[2]:find("usage", 1, true), "/dpq explains itself")
print(failures == 0 and "ALL PASSED" or (failures .. " FAILED"))
os.exit(failures == 0 and 0 or 1)

218
tests/test_qch.lua Normal file
View file

@ -0,0 +1,218 @@
-- Runs QuestCraftHighlight.lua against a mock of the WoW API.
-- arg[1] = addon file
local log = {
{ title = "Leather", isHeader = true },
{ title = "Moonglow Vest", questID = 1, level = 18, objs = {
{ type = "item", text = "Embossed Leather Gloves: 0/1", numRequired = 1, numFulfilled = 0 },
} },
{ title = "Bars One", questID = 2, level = 10, objs = {
{ type = "item", text = "Copper Bar: 0/4", numRequired = 4, numFulfilled = 0 },
} },
{ title = "Bars Two", questID = 3, level = 12, objs = {
{ type = "item", text = "Copper Bar: 0/6", numRequired = 6, numFulfilled = 0 },
} },
}
C_QuestLog = {
GetNumQuestLogEntries = function()
local n = 0
for _, e in ipairs(log) do if not e.isHeader then n = n + 1 end end
return #log, n
end,
GetInfo = function(i) return log[i] end,
GetQuestObjectives = function(id)
for _, e in ipairs(log) do if e.questID == id then return e.objs end end
end,
}
function ExpandQuestHeader() end
function CollapseQuestHeader() end
function GetQuestDifficultyColor() return { r = 0.1, g = 0.2, b = 0.3 } end
local outputs = { [100] = 1, [101] = 2, [102] = 3, [103] = 4 }
C_TradeSkillUI = {
GetRecipeSchematic = function(id) return { outputItemID = outputs[id] } end,
}
local names = { [1] = "Embossed Leather Gloves", [2] = "Copper Bar", [3] = "Embossed Leather Cloak" }
local counts = { [1] = 0, [2] = 3, [3] = 0, [4] = 0 }
local requested = {}
C_Item = {
GetItemNameByID = function(id) return names[id] end,
GetItemCount = function(id) return counts[id] end,
RequestLoadItemDataByID = function(id) requested[id] = true end,
}
local queued = {}
C_Timer = { After = function(_, fn) queued[#queued + 1] = fn end }
local function flush() local q = queued; queued = {}; for _, fn in ipairs(q) do fn() end end
function hooksecurefunc(t, name, fn)
local orig = t[name]
t[name] = function(...) orig(...); fn(...) end
end
local function region(extra)
local r = { shown = true }
function r:Show() self.shown = true end
function r:Hide() self.shown = false end
function r:SetShown(v) self.shown = v and true or false end
function r:IsShown() return self.shown end
function r:SetAllPoints() end
function r:ClearAllPoints() end
function r:SetPoint(...) self.point = { ... } end
function r:SetColorTexture() end
function r:SetText(t) self.text = t end
function r:GetStringWidth() return self.textWidth or (#(self.text or "") * 6) end
function r:SetTextColor(a, b, c) self.color = { a, b, c } end
function r:SetWidth(w) self.width = w end
function r:GetWidth() return self.width or 0 end
for k, v in pairs(extra or {}) do r[k] = v end
return r
end
local tipLines, tipOwner = {}, nil
GameTooltip = {
IsOwned = function(_, f) return tipOwner == f end,
SetOwner = function(_, f) tipOwner = f; tipLines = {} end,
AddDoubleLine = function(_, l, r) tipLines[#tipLines + 1] = { l = l, r = r } end,
Show = function() end,
}
local handler
CreateFrame = function()
return { RegisterEvent = function() end, SetScript = function(_, _, fn) handler = fn end }
end
SlashCmdList = {}
local printed = {}
DEFAULT_CHAT_FRAME = { AddMessage = function(_, m) printed[#printed + 1] = m end }
local failures = 0
local function check(cond, what)
if not cond then failures = failures + 1 end
print((cond and "ok " or "FAIL ") .. what)
end
-- The mixin only appears when Blizzard's load-on-demand addon does.
assert(loadfile(arg[1]))("QuestCraftHighlight", {})
ProfessionsRecipeListRecipeMixin = {
Init = function(row, node)
row.Label:SetText(node:GetData().recipeInfo.name)
row.Label:SetWidth(row:GetStringWidthForTest())
end,
OnEnter = function() end,
}
handler(nil, "ADDON_LOADED", "SomethingElse")
local initBefore = ProfessionsRecipeListRecipeMixin.Init
handler(nil, "ADDON_LOADED", "Blizzard_ProfessionsTemplates")
check(ProfessionsRecipeListRecipeMixin.Init ~= initBefore, "hooks installed when Blizzard_ProfessionsTemplates loads")
local initOnce = ProfessionsRecipeListRecipeMixin.Init
handler(nil, "ADDON_LOADED", "Blizzard_ProfessionsTemplates")
check(ProfessionsRecipeListRecipeMixin.Init == initOnce, "hooks are not installed twice")
handler(nil, "PLAYER_ENTERING_WORLD")
flush()
local function newRow()
local row = region({ width = 270, visible = true })
row.Label = region()
row.Count = region({ shown = false })
row.LockedIcon = region({ shown = false, width = 17 })
row.SkillUps = region({ width = 26 })
function row:CreateTexture() return region() end
function row:CreateFontString() return region() end
function row:IsVisible() return self.visible end
function row:GetStringWidthForTest() return self.Label:GetStringWidth() end
return row
end
local function node(id, name) return { GetData = function() return { recipeInfo = { recipeID = id, name = name } } end } end
local function init(row, id, name) ProfessionsRecipeListRecipeMixin.Init(row, node(id, name)) end
local row = newRow()
init(row, 100, "Embossed Leather Gloves")
check(row.qchTint and row.qchTint.shown, "needed recipe is tinted")
check(row.qchText.text == "! 0 / 1", "shows have / need: " .. tostring(row.qchText.text))
check(row.qchText.color[2] == 0.82, "unfinished count is gold")
ProfessionsRecipeListRecipeMixin.OnEnter(row)
check(#tipLines == 1 and tipLines[1].l == "Quest: [18] Moonglow Vest" and tipLines[1].r == "0 / 1", "hover shows quest, level, count")
check(tipOwner == row, "hover takes the tooltip when the row did not")
tipOwner = row.Label; tipLines = { { l = "Full Recipe Name" } }
ProfessionsRecipeListRecipeMixin.OnEnter(row)
check(#tipLines == 2 and tipLines[1].l == "Full Recipe Name", "keeps the truncated-name tooltip and appends")
counts[1] = 1
handler(nil, "BAG_UPDATE_DELAYED")
flush()
check(row.qchText.text == "! 1 / 1" and row.qchText.color[2] == 1, "crafting one updates the row live, count turns green")
check(row.qchTint.shown == false, "tint goes away once you have enough")
local bars = newRow()
init(bars, 101, "Smelt Copper")
check(bars.qchText and bars.qchText.text == "! 3 / 10", "matches output item, not recipe name, and sums quests: " .. tostring(bars.qchText and bars.qchText.text))
ProfessionsRecipeListRecipeMixin.OnEnter(bars)
check(#tipLines == 2 and tipLines[1].r == "3 / 4" and tipLines[2].r == "3 / 6", "tooltip lists each quest")
local other = newRow()
init(other, 102, "Embossed Leather Cloak")
check(other.qchTint == nil, "unrelated recipe is left untouched")
-- Pool reuse: a highlighted row scrolled onto an unrelated recipe.
counts[1] = 0
init(row, 102, "Embossed Leather Cloak")
check(row.qchTint.shown == false and row.qchText.shown == false, "reused row drops its highlight")
ProfessionsRecipeListRecipeMixin.OnEnter(row)
tipLines = {}; ProfessionsRecipeListRecipeMixin.OnEnter(row)
check(#tipLines == 0, "reused row adds no quest line on hover")
-- Label must not run under the count text.
local long = newRow()
names[1] = "Embossed Leather Gloves"
long.Label.textWidth = 500
init(long, 100, "Embossed Leather Gloves")
local avail = 270 - (10 + 26 + long.qchText:GetStringWidth() + 8)
check(long.Label.width == avail, "long name is shortened to clear the count: " .. tostring(long.Label.width) .. " vs " .. avail)
-- Output name not loaded yet.
local uncached = newRow()
log[#log + 1] = { title = "Mystery", questID = 4, level = 5, objs = {
{ type = "item", text = "Late Item: 0/2", numRequired = 2, numFulfilled = 0 },
} }
handler(nil, "QUEST_ACCEPTED")
flush()
init(uncached, 103, "Some Recipe Name")
check(requested[4] == true, "requests the name of an unloaded item")
check(uncached.qchMatch == nil, "no false match while name is loading")
names[4] = "Late Item"
handler(nil, "ITEM_DATA_LOAD_RESULT", 4, true)
flush()
check(uncached.qchText and uncached.qchText.text == "! 0 / 2", "row updates when the name arrives")
local fallback = newRow()
outputs[104] = 5; counts[5] = 0
init(fallback, 104, "Embossed Leather Gloves")
check(fallback.qchText and fallback.qchText.text == "! 0 / 1", "unloaded item falls back to the recipe name")
-- Quest gone: highlight disappears, name gets its width back.
table.remove(log, 2)
long.visible = true
handler(nil, "QUEST_REMOVED")
flush()
check(long.qchMatch == nil and long.qchTint.shown == false, "finished quest removes the highlight")
check(long.Label.width == 270 - 36, "name gets its width back: " .. tostring(long.Label.width))
-- Closed window: nothing to do for hidden rows.
log[#log + 1] = { title = "Again", questID = 9, level = 18, objs = {
{ type = "item", text = "Embossed Leather Gloves: 0/1", numRequired = 1, numFulfilled = 0 },
} }
long.visible = false
handler(nil, "QUEST_ACCEPTED")
flush()
check(long.qchMatch == nil, "hidden rows are not touched")
printed = {}
SlashCmdList.QUESTCRAFTHIGHLIGHT()
check(#printed >= 2 and printed[1]:find("hooked=true", 1, true) ~= nil, "/qch prints state: " .. tostring(printed[1]))
print(failures == 0 and "ALL PASSED" or (failures .. " FAILED"))
os.exit(failures == 0 and 0 or 1)

263
tests/test_qit.lua Normal file
View file

@ -0,0 +1,263 @@
-- Runs QuestItemTip.lua against a mock of the WoW API.
-- arg[1] = addon file
local hideCollapsed -- true: collapsed headers hide their quests (legacy behaviour)
local toggles = 0
local log = {}
local function reset()
toggles = 0
log = {
{ title = "Elwynn", isHeader = true, isCollapsed = false },
{ title = "Linen Quest", questID = 10, level = 12, desc = "Peacebloom grows nearby.", objs = {
{ type = "item", text = "Linen Cloth: 5/5", numRequired = 5, numFulfilled = 5, finished = true },
{ type = "monster", text = "Kobold slain: 1/8", numRequired = 8, numFulfilled = 1 },
} },
{ title = "Second Linen Quest", questID = 11, level = 20, objs = {
{ type = "item", text = "3/10 Linen Cloth (Optional)", numRequired = 10, numFulfilled = 3 },
} },
{ title = "Book Quest", questID = 12, level = 30, objs = {
{ type = "item", text = "Advanced Armorsmithing: Volume II: 0/1", numRequired = 1, numFulfilled = 0 },
} },
{ title = "Westfall", isHeader = true, isCollapsed = true },
{ title = "Collapsed Quest", questID = 20, level = 18, objText = "Bring the Hidden Parcel to Bob.", objs = {
{ type = "item", text = "Red Bandana: 1/15", numRequired = 15, numFulfilled = 1 },
} },
{ title = "Hidden Quest", questID = 30, level = 1, isHidden = true, objs = {
{ type = "item", text = "Secret Thing: 0/1", numRequired = 1, numFulfilled = 0 },
} },
}
end
local function visible()
local out, inCollapsed = {}, false
for _, e in ipairs(log) do
if e.isHeader then
inCollapsed = e.isCollapsed
out[#out + 1] = e
elseif not (hideCollapsed and inCollapsed) then
out[#out + 1] = e
end
end
return out
end
C_QuestLog = {
GetNumQuestLogEntries = function()
local n = 0
for _, e in ipairs(log) do if not e.isHeader then n = n + 1 end end
return #visible(), n
end,
GetInfo = function(i) return visible()[i] end,
GetQuestObjectives = function(id)
for _, e in ipairs(log) do if e.questID == id then return e.objs end end
end,
}
local selectedQuest, abandonQuest = 77, nil
local abandonItems = { [12] = { 500 } }
local completed, popup = {}, false
C_QuestLog.GetSelectedQuest = function() return selectedQuest end
C_QuestLog.SetSelectedQuest = function(id) selectedQuest = id end
C_QuestLog.SetAbandonQuest = function() abandonQuest = selectedQuest end
C_QuestLog.GetAbandonQuestItems = function() return abandonItems[abandonQuest] or {} end
C_QuestLog.IsOnQuest = function(id)
for _, e in ipairs(log) do if e.questID == id then return true end end
return false
end
C_QuestLog.IsQuestFlaggedCompleted = function(id) return completed[id] == true end
function StaticPopup_Visible() return popup end
function GetQuestLogQuestText(i)
local e = visible()[i]
if e.noText then return "", "" end
return e.desc or "Some story.", e.objText or "Do the thing."
end
ITEM_STARTS_QUEST = "This Item Begins a Quest"
function ExpandQuestHeader(i) toggles = toggles + 1; visible()[i].isCollapsed = false end
function CollapseQuestHeader(i) toggles = toggles + 1; visible()[i].isCollapsed = true end
function GetQuestDifficultyColor() return { r = 0.1, g = 0.2, b = 0.3 } end
local names = { [1] = "Linen Cloth", [2] = "Red Bandana", [3] = "Secret Thing", [4] = "Peacebloom", [5] = "Advanced Armorsmithing: Volume II", [500] = "Sealed Letter", [501] = "Old Quest Thing", [502] = "Mystery Thing", [503] = "Odd Starter", [504] = "Abandoned Thing", [506] = "Vial of Purest Water", [507] = "Hidden Parcel" }
local bagCount = { [1] = 7, [2] = 2, [3] = 1, [4] = 9, [5] = 0, [500] = 1, [501] = 1, [502] = 1, [503] = 1, [504] = 1, [505] = 0, [506] = 1, [507] = 1 }
local bankCount = { [1] = 0, [2] = 3 }
C_Item = {
GetItemNameByID = function(id) return names[id] end,
GetItemInfoInstant = function(id) local c = (id >= 501 and id <= 507) and 12 or 7; return id, "", "", "", 0, c end,
GetItemInfo = function() return nil end,
GetItemCount = function(id, incBank) return bagCount[id] + (incBank and (bankCount[id] or 0) or 0) end,
}
local lines = {}
GameTooltip = {
AddDoubleLine = function(_, l, r, _, _, _, rr, rg) lines[#lines + 1] = { l = l, r = r, green = (rr == 0.25 and rg == 1) } end,
AddLine = function(_, l) lines[#lines + 1] = { l = l } end,
Show = function() end,
GetItem = function() return nil end,
}
ItemRefTooltip = GameTooltip
Enum = { TooltipDataType = { Item = 0 } }
local postCall
TooltipDataProcessor = { AddTooltipPostCall = function(_, fn) postCall = fn end }
local handler
local registered = {}
CreateFrame = function()
return {
RegisterEvent = function(_, e) registered[e] = true end,
SetScript = function(_, _, fn) handler = fn end,
}
end
SlashCmdList = {}
local printed = {}
DEFAULT_CHAT_FRAME = { AddMessage = function(_, m) printed[#printed + 1] = m end }
local failures = 0
local function check(cond, what)
if not cond then failures = failures + 1 end
print((cond and "ok " or "FAIL ") .. what)
end
local function tip(id)
lines = {}
postCall(GameTooltip, { id = id })
return lines
end
for _, mode in ipairs({ false, true }) do
hideCollapsed = mode
print("--- collapsed headers hide quests: " .. tostring(mode))
reset()
QuestItemTipDB = nil
assert(loadfile(arg[1]))("QuestItemTip", {})
handler(nil, "ADDON_LOADED", "QuestItemTip")
handler(nil, "PLAYER_ENTERING_WORLD")
local l = tip(1)
check(#l == 2, "item needed by two quests gets two lines")
check(l[1].l == "Quest: [12] Linen Quest" and l[1].r == "7 / 5", "have 7, need 5: " .. tostring(l[1].l) .. " | " .. tostring(l[1].r))
check(l[1].green == true, "met requirement is green")
check(l[2].r == "7 / 10" and l[2].green == false, "alternate objective format, unmet: " .. tostring(l[2].r))
l = tip(2)
check(#l == 1 and l[1].l == "Quest: [18] Collapsed Quest", "quest under a collapsed header is found")
check(l[1] and l[1].r == "2 / 15 (+3 bank)", "bank shown apart: " .. tostring(l[1] and l[1].r))
check(log[5].isCollapsed == true, "collapsed header is restored")
check(toggles == (mode and 2 or 0), "headers toggled only when needed: " .. toggles)
check(#tip(3) == 0, "hidden quest ignored")
check(#tip(4) == 0, "non-quest item adds nothing")
l = tip(5)
check(#l == 1 and l[1].r == "0 / 1", "item name containing a colon")
local before = toggles
handler(nil, "QUEST_LOG_UPDATE")
tip(1); tip(2)
check(toggles == before, "header-toggle QUEST_LOG_UPDATE causes no rescan")
table.insert(log[2].objs, { type = "item", text = "Peacebloom: 0/4", numRequired = 4, numFulfilled = 0 })
handler(nil, "QUEST_ACCEPTED")
l = tip(4)
check(#l == 1 and l[1].r == "9 / 4", "new objective picked up after QUEST_ACCEPTED")
log[3] = { title = "Filler", questID = 40, level = 2, objs = {} }
log[#log + 1] = { title = "Another", questID = 41, level = 2, objs = {} }
handler(nil, "QUEST_LOG_UPDATE")
check(#tip(1) == 1, "quest count change rebuilds on QUEST_LOG_UPDATE")
-- === leftover and provided items ===
reset()
assert(loadfile(arg[1]))("QuestItemTip", {})
handler(nil, "ADDON_LOADED", "QuestItemTip")
handler(nil, "PLAYER_ENTERING_WORLD")
selectedQuest = 77
l = tip(500)
check(#l == 1 and l[1].l == "Quest: [30] Book Quest" and l[1].r == nil, "item a quest handed you names it: " .. tostring(l[1] and l[1].l))
check(selectedQuest == 77, "selected quest is restored")
log[#log + 1] = { title = "Done Soon", questID = 50, level = 9, objs = {
{ type = "item", text = "Old Quest Thing: 1/1", numRequired = 1, numFulfilled = 1 },
} }
log[#log + 1] = { title = "Drop Soon", questID = 51, level = 11, objs = {
{ type = "item", text = "Abandoned Thing: 0/2", numRequired = 2, numFulfilled = 0 },
} }
handler(nil, "QUEST_ACCEPTED")
handler(nil, "QUEST_LOG_UPDATE")
check(QuestItemTipDB["old quest thing"] and QuestItemTipDB["old quest thing"].title == "Done Soon", "quest is recorded without hovering anything")
local n = #log
table.remove(log, n); table.remove(log, n - 1)
completed[50] = true
handler(nil, "QUEST_TURNED_IN")
handler(nil, "QUEST_LOG_UPDATE")
l = tip(501)
check(#l == 1 and l[1].l == "Quest done: [9] Done Soon" and l[1].r == "can delete", "finished quest: " .. tostring(l[1] and l[1].l))
l = tip(504)
check(#l == 1 and l[1].l == "Quest dropped: [11] Drop Soon" and l[1].r == "can delete", "dropped quest: " .. tostring(l[1] and l[1].l))
check(#tip(505) == 0, "not owned: no leftover warning")
l = tip(502)
check(#l == 1 and l[1].l == "Quest item: no quest in your log uses it", "unknown quest item gets the soft note, not can-delete")
lines = {}
postCall(GameTooltip, { id = 503, lines = { { leftText = "Odd Starter" }, { leftText = "This Item Begins a Quest" } } })
check(#lines == 0, "quest-starting item is left alone")
check(#tip(4) == 0 or tip(4)[1].l:find("Quest item", 1, true) == nil, "ordinary item never gets the quest-item note")
-- Delivery quest: no objective, the item is only named in the quest text.
l = tip(507)
check(#l == 1 and l[1].l == "Quest: [18] Collapsed Quest", "quest text under a collapsed header: " .. tostring(l[1] and l[1].l))
check(log[5].isCollapsed == true, "header closed again after reading text")
log[#log + 1] = { title = "Delivery Quest", questID = 52, level = 23, objs = {}, objText = "Bring the Vial of Purest Water to Norric Lochthane in Loch Modan." }
QuestItemTipDB[506] = { questID = 99, title = "Earlier Step", level = 22 }
handler(nil, "QUEST_ACCEPTED")
handler(nil, "QUEST_LOG_UPDATE")
l = tip(506)
check(#l == 1 and l[1].l == "Quest: [23] Delivery Quest" and l[1].r == nil, "delivery item names its quest: " .. tostring(l[1] and l[1].l))
check(QuestItemTipDB[506].questID == 52, "delivery item is remembered, replacing the earlier step")
table.remove(log)
handler(nil, "QUEST_REMOVED")
handler(nil, "QUEST_LOG_UPDATE")
l = tip(506)
check(#l == 1 and l[1].l == "Quest dropped: [23] Delivery Quest" and l[1].r == "can delete", "delivery item after the quest ends: " .. tostring(l[1] and l[1].l))
-- Objective read before the item's name has loaded.
log[#log + 1] = { title = "Waterskin", questID = 53, level = 23, objs = {
{ type = "item", text = " : 0/1", numRequired = 1, numFulfilled = 0 },
} }
handler(nil, "QUEST_ACCEPTED")
handler(nil, "QUEST_LOG_UPDATE")
check(QuestItemTipDB[" "] == nil, "blank objective name is not recorded")
log[#log].objs[1].text = "Peacebloom: 0/1"
handler(nil, "QUEST_LOG_UPDATE")
l = tip(4)
check(#l == 1 and l[1].r == "9 / 1", "objective is read once the name loads: " .. tostring(l[1] and l[1].r))
table.remove(log)
handler(nil, "QUEST_REMOVED")
handler(nil, "QUEST_LOG_UPDATE")
-- Still on the quest, but the objective no longer lists the item.
QuestItemTipDB["peacebloom"] = { questID = 12, title = "Book Quest", level = 30 }
l = tip(4)
check(#l == 1 and l[1].l == "Quest: [30] Book Quest" and l[1].r == nil, "still-active recorded quest is not a delete warning")
QuestItemTipDB["peacebloom"] = nil
-- Mid-abandon: do not disturb Blizzard's popup.
popup = true
selectedQuest = 88
local abandonBefore = abandonQuest
handler(nil, "QUEST_ACCEPTED")
handler(nil, "QUEST_LOG_UPDATE")
check(abandonQuest == abandonBefore and selectedQuest == 88, "abandon popup is left alone")
l = tip(500)
check(#l == 1 and l[1].l == "Quest: [30] Book Quest", "provided items are kept meanwhile")
popup = false
printed = {}
SlashCmdList.QUESTITEMTIP()
check(#printed > 0, "/qit prints the index")
end
print(failures == 0 and "ALL PASSED" or (failures .. " FAILED"))
os.exit(failures == 0 and 0 or 1)

188
tests/test_vf.lua Normal file
View file

@ -0,0 +1,188 @@
-- Runs VendorFlag.lua against a mock of the WoW API.
-- arg[1] = addon file
local now = 1000000
function time() return now end
function hooksecurefunc(t, name, fn)
local orig = t[name]
t[name] = function(...) orig(...); fn(...) end
end
AUCTIONATOR_L_CONFIRM_POST_BELOW_VENDOR = "vendor warning"
AuctionatorSaleItemMixin = { GetConfirmationMessage = function(self) return self.msg end }
AuctionatorGroupsViewItemMixin = { SetItemInfo = function(self, info) self.itemInfo = info end }
local bags = {}
C_Container = { GetContainerItemLink = function(bag, slot) return bags[bag .. ":" .. slot] end }
local function region()
local r = { shown = false }
function r:Show() self.shown = true end
function r:Hide() self.shown = false end
function r:SetAllPoints() end
function r:SetPoint() end
function r:SetColorTexture() end
function r:SetTextColor() end
function r:SetText(t) self.text = t end
return r
end
local function button(bag, slot)
local b = {}
function b:GetBagID() return bag end
function b:GetID() return slot end
function b:CreateTexture() return region() end
function b:CreateFontString() return region() end
return b
end
local function bagFrame(buttons, shown)
local f = { shown = shown }
function f:IsShown() return self.shown end
function f:EnumerateValidItems() return ipairs(buttons) end
function f:UpdateItems() end
return f
end
local b1, b2, b3 = button(0, 1), button(0, 2), button(0, 3)
ContainerFrame1 = bagFrame({ b1, b2 }, true)
ContainerFrameCombinedBags = bagFrame({ b3 }, false)
local LINK_A = "|cffffffff|Hitem:2589::::::::70:::::|h[Linen Cloth]|h|r"
local LINK_BEAR = "|cff1eff00|Hitem:15000::::::-19:123:70:::::|h[Sword of the Bear]|h|r"
local LINK_EAGLE = "|cff1eff00|Hitem:15000::::::-25:456:70:::::|h[Sword of the Eagle]|h|r"
local LINK_OTHER = "|cffffffff|Hitem:4306::::::::70:::::|h[Silk Cloth]|h|r"
GameTooltip = {
AddLine = function(self, l) self.line = l end,
Show = function() end,
GetItem = function(self) return "x", self.link end,
}
ItemRefTooltip = {}
Enum = { TooltipDataType = { Item = 0 } }
local postCall
TooltipDataProcessor = { AddTooltipPostCall = function(_, fn) postCall = fn end }
local tick
C_Timer = { NewTicker = function(_, fn) tick = fn end }
local handler
CreateFrame = function()
return { RegisterEvent = function() end, SetScript = function(_, _, fn) handler = fn end }
end
SlashCmdList = {}
local printed = {}
DEFAULT_CHAT_FRAME = { AddMessage = function(_, m) printed[#printed + 1] = m end }
local failures = 0
local function check(cond, what)
if not cond then failures = failures + 1 end
print((cond and "ok " or "FAIL ") .. what)
end
assert(loadfile(arg[1]))("VendorFlag", {})
local warn = AuctionatorSaleItemMixin.GetConfirmationMessage
handler(nil, "ADDON_LOADED", "Auctionator")
check(VendorFlagDB == nil, "ignores other addons loading")
handler(nil, "ADDON_LOADED", "VendorFlag")
handler(nil, "PLAYER_LOGIN")
bags["0:1"] = LINK_A
bags["0:2"] = LINK_OTHER
bags["0:3"] = LINK_A
check(warn({ msg = "low price", itemInfo = { itemLink = LINK_A } }) == "low price", "other warnings pass through")
check(next(VendorFlagDB) == nil, "other warnings do not flag")
check(warn({ msg = nil, itemInfo = { itemLink = LINK_A } }) == nil, "no warning passes through nil")
check(next(VendorFlagDB) == nil, "no warning does not flag")
check(warn({ msg = "vendor warning", itemInfo = { itemLink = LINK_A } }) == "vendor warning", "vendor warning passes through unchanged")
check(b1.vfTint and b1.vfTint.shown and b1.vfText.text == "10m", "open bag is marked immediately: " .. tostring(b1.vfText and b1.vfText.text))
check(b2.vfTint == nil, "other items stay unmarked")
check(b3.vfTint == nil, "closed bag is not touched yet")
ContainerFrameCombinedBags.shown = true
ContainerFrameCombinedBags:UpdateItems()
check(b3.vfTint and b3.vfTint.shown, "bag gets marked when it opens")
GameTooltip.link = LINK_A
postCall(GameTooltip)
check(GameTooltip.line == "Vendor beats auction (10m left)", "tooltip: " .. tostring(GameTooltip.line))
GameTooltip.line = nil; GameTooltip.link = LINK_OTHER
postCall(GameTooltip)
check(GameTooltip.line == nil, "tooltip silent on unflagged item")
now = now + 245
tick()
check(b1.vfText.text == "6m", "countdown ticks down: " .. tostring(b1.vfText.text))
-- Sold to the vendor.
bags["0:1"] = nil
handler(nil, "BAG_UPDATE_DELAYED")
check(b1.vfTint.shown == false and b1.vfText.shown == false, "sold item loses its mark")
-- Re-flagging restarts the timer.
bags["0:1"] = LINK_A
warn({ msg = "vendor warning", itemInfo = { itemLink = LINK_A } })
check(b1.vfText.text == "10m", "warning again restarts the timer")
now = now + 601
tick()
check(b1.vfTint.shown == false, "mark expires after 10 minutes")
check(next(VendorFlagDB) == nil, "expired flag is cleared")
-- Auctionator's selling list.
local ah, ahOther = button(9, 1), button(9, 2)
function ah:IsVisible() return self.visible end
function ahOther:IsVisible() return true end
ah.visible = true
AuctionatorGroupsViewItemMixin.SetItemInfo(ah, { itemLink = LINK_A })
AuctionatorGroupsViewItemMixin.SetItemInfo(ahOther, { itemLink = LINK_EAGLE })
check(ah.vfTint == nil, "selling list starts unmarked")
warn({ msg = "vendor warning", itemInfo = { itemLink = LINK_A } })
check(ah.vfTint and ah.vfTint.shown and ah.vfText.text == "10m", "selling list is marked as soon as the warning appears")
check(ahOther.vfTint == nil, "other selling list items stay unmarked")
now = now + 245
tick()
check(ah.vfText.text == "6m", "selling list counts down: " .. tostring(ah.vfText.text))
ah.visible = false
now = now + 30
tick()
check(ah.vfText.text == "6m", "hidden selling list is left alone")
ah.visible = true
-- A pooled button is reused for another item, then for an empty slot.
AuctionatorGroupsViewItemMixin.SetItemInfo(ah, { itemLink = LINK_EAGLE })
check(ah.vfTint.shown == false, "reused button drops the mark")
AuctionatorGroupsViewItemMixin.SetItemInfo(ah, { itemLink = LINK_A })
check(ah.vfTint.shown == true, "selling list refresh keeps the mark")
AuctionatorGroupsViewItemMixin.SetItemInfo(ah, nil)
check(ah.vfTint.shown == false, "empty button has no mark")
AuctionatorGroupsViewItemMixin.SetItemInfo(ah, { itemLink = LINK_A })
now = now + 601
tick()
check(ah.vfTint.shown == false, "selling list mark expires")
-- Same item ID, different suffix.
bags["0:1"] = LINK_BEAR
bags["0:2"] = LINK_EAGLE
warn({ msg = "vendor warning", itemInfo = { itemLink = LINK_BEAR } })
check(b1.vfTint.shown == true, "flagged suffix is marked")
check(b2.vfTint == nil or b2.vfTint.shown == false, "other suffix of the same item is not")
-- A reload keeps flags: the file runs again with the saved table.
AuctionatorSaleItemMixin = { GetConfirmationMessage = function(self) return self.msg end }
assert(loadfile(arg[1]))("VendorFlag", {})
handler(nil, "ADDON_LOADED", "VendorFlag")
handler(nil, "PLAYER_LOGIN")
GameTooltip.line = nil; GameTooltip.link = LINK_BEAR
postCall(GameTooltip)
check(GameTooltip.line ~= nil, "flag survives a reload")
SlashCmdList.VENDORFLAG()
check(#printed == 1 and printed[1]:find("15000:-19", 1, true) ~= nil, "/vf lists the flag: " .. tostring(printed[1]))
print(failures == 0 and "ALL PASSED" or (failures .. " FAILED"))
os.exit(failures == 0 and 0 or 1)