-- 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(a, b, c) if c then local original = a[b] a[b] = function(...) original(...); c(...) end else hooks[a] = b end end GossipAvailableQuestButtonMixin = { Setup = function(self, info) self.text = info.title; self.setups = (self.setups or 0) + 1 end } local function listButton(id, isActive) local b = { id = id, isActive = isActive, heightSets = 0, resizes = 0, Icon = { GetHeight = function() return 16 end } } function b:GetID() return self.id end function b:GetText() return self.text end function b:SetText(t) self.text = t end function b:GetTextHeight() return 12 end function b:SetHeight() self.heightSets = self.heightSets + 1 end function b:Resize() self.resizes = self.resizes + 1 end return b end local greetingRows = {} local greetingShow QuestFrameGreetingPanel = { titleButtonPool = { EnumerateActive = function() local i = 0 return function() i = i + 1; return greetingRows[i] end end }, HookScript = function(_, _, fn) greetingShow = fn end, } local availableByIndex = {} function GetAvailableQuestInfo(i) return false, 0, false, false, availableByIndex[i] 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") -- NPC quest lists. local MARK = "|cff8a2be2[D]|r " local gossip = listButton() GossipAvailableQuestButtonMixin.Setup(gossip, { questID = 65, title = "Pre Quest" }) check(gossip.text == MARK .. "Pre Quest", "gossip row is marked: " .. tostring(gossip.text)) check(gossip.resizes == 1, "gossip row is resized for the longer text") GossipAvailableQuestButtonMixin.Setup(gossip, { questID = 99, title = "Other" }) check(gossip.text == "Other", "reused gossip row has no mark") GossipAvailableQuestButtonMixin.Setup(gossip, { questID = 65, title = "Pre Quest" }) check(gossip.resizes == 2 and gossip.text == MARK .. "Pre Quest", "setup again marks once") local avail, plain, turnin = listButton(1, 0), listButton(2, 0), listButton(1, 1) avail.text, plain.text, turnin.text = "Offer", "Plain", "Turn in" availableByIndex = { 65, 99 } greetingRows = { avail, plain, turnin } greetingShow() check(avail.text == MARK .. "Offer" and avail.heightSets == 1, "greeting offer is marked and resized") check(plain.text == "Plain", "other greeting offer is not") check(turnin.text == "Turn in", "quests already in progress are not marked") hooks.QuestFrameGreetingPanel_OnShow() check(avail.text == MARK .. "Offer" and avail.heightSets == 1, "both greeting hooks mark only once") classID = 2 availableByIndex = { 72 } avail.text = "Druid only" greetingRows = { avail } greetingShow() check(avail.text == "Druid only", "list respects class") classID = 1 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)