188 lines
7.2 KiB
Lua
188 lines
7.2 KiB
Lua
-- 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)
|