Files
Atlas-CFM/tests/tooltip_drop_rate.lua
OEVG d98bde3126 Prepare Atlas-CFM 1.89.1 for Gitea
Load Atlas data on demand, prioritize submitted searches, and show OctoBus dock countdowns on the Blizzard world map. Document installation, fork changes, and upstream credits.

Assisted-by: Codex
2026-11-19 21:26:19 -04:00

108 lines
5.0 KiB
Lua

-- Run from the repository root with Lua 5.0: lua5.0 tests/tooltip_drop_rate.lua
local function front(path) dofile("Atlas-CFM/" .. path) end
local function core(path) dofile("Atlas-CFM_Core/" .. path) end
local function noop() end
function CreateFrame(_, name)
local frame = { scripts = {}, lines = {} }
function frame:SetScript(event, fn) self.scripts[event] = fn end
function frame:GetScript(event) return self.scripts[event] end
function frame:SetOwner() end
function frame:RegisterEvent() end
function frame:UnregisterAllEvents() end
function frame:ClearLines() self.lines = {} end
function frame:SetHyperlink() self.lines = {} end
function frame:AddLine(text) table.insert(self.lines, text) end
function frame:Show() end
function frame:GetName() return name end
return frame
end
GetLocale = function() return "deDE" end -- Addon text remains English.
GetItemInfo = function(id) if id == 900001 then return "Rune Band of Wizardry" end end
getglobal = function(key) return _G[key] end
IsShiftKeyDown = function() return false end
IsControlKeyDown = IsShiftKeyDown
IsAddOnLoaded = IsShiftKeyDown
SetTooltipMoney = noop
SetItemRef = function() ItemRefTooltip:ClearLines() end
GameTooltip = CreateFrame("GameTooltip", "GameTooltip")
ItemRefTooltip = CreateFrame("GameTooltip", "ItemRefTooltip")
AtlasCFM = { Colors = setmetatable({}, {__index = function() return "" end}) }
front("Locales/LocalizationFramework.lua")
front("Locales/enUS/Core.lua")
assert(AtlasCFM.Localization.currentLocale == "enUS")
for _, namespace in pairs(AtlasCFM.Localization.namespaces) do
assert(namespace.enUS == namespace.current, "English tables must share storage")
end
assert(AtlasCFM.Localization.UI["Show Drop Rate on Tooltips"] == "Show Drop Rate on Tooltips")
AtlasCFM.Server = {
GetDataField = function(entry, key) return type(entry) == "table" and entry[key] or nil end,
VANILLA_PLUS = "Vanilla Plus", NOT_VANILLA_PLUS = "!Vanilla Plus",
TURTLE = "Turtle", TURTLE1 = "Turtle1"
}
AtlasCFM.LootUtils = { GetLootTableSource = noop }
AtlasCFMLoot_Data = {}
core("CFMLoot/Core/ItemDB.lua")
core("CFMLoot/Data/Instances/BlackrockSpireUpper.lua")
-- Known, missing, zero, fractional and nested-container rates, plus a second
-- source for the same item: its rate must not overwrite the selected source.
local bosses = AtlasCFM.InstanceData.BlackrockSpireUpper.Bosses
table.insert(bosses, {name = "Test Boss", items = {
{id = 900002, dropRate = 0.05}, {id = 900003}, {id = 900004, dropRate = 0},
{id = 900005, dropRate = 100, container = {900006}}
}})
table.insert(bosses, {name = "Other Boss", items = {{id = 22339, dropRate = 99}}})
AtlasCFMOptions = {LootShowSource = true, TooltipShowDropRate = true, ReagentRows = 0}
local pending = {}
AtlasCFM.Timer = {Start = function(_, fn) table.insert(pending, fn) end}
core("CFMLoot/Core/DataIndex.lua")
core("CFMLoot/Core/Tooltip.lua")
GameTooltip:SetHyperlink("item:22339")
assert(table.getn(GameTooltip.lines) == 0, "Index is still loading")
while table.getn(pending) > 0 do table.remove(pending, 1)() end
local source = "Upper Blackrock Spire - Lord Valthalak"
local function hover(id, expected)
GameTooltip:SetHyperlink("item:" .. id)
assert(GameTooltip.lines[1] == expected,
tostring(GameTooltip.lines[1]) .. " ~= " .. tostring(expected))
end
hover(22339, source .. " (25%)|r")
AtlasCFMOptions.TooltipShowDropRate = false
hover(22339, source .. "|r")
AtlasCFMOptions.TooltipShowDropRate = true
hover(22339, source .. " (25%)|r")
AtlasCFMOptions.LootShowSource = false
hover(22339, nil)
AtlasCFMOptions.LootShowSource = true
hover(900002, "Upper Blackrock Spire - Test Boss (0.05%)|r")
hover(900003, "Upper Blackrock Spire - Test Boss|r")
hover(900004, "Upper Blackrock Spire - Test Boss (0%)|r")
hover(900006, "Upper Blackrock Spire - Test Boss|r")
hover(999999, nil)
AtlasCFM.DataIndex.NameToID["Rune Band of Wizardry"] = 22339
hover(900001, source .. " (25%)|r")
SetItemRef("item:22339", "", "LeftButton")
assert(ItemRefTooltip.lines[1] == source .. " (25%)|r")
-- Also exercise the synchronous index path used by explicit callers.
core("CFMLoot/Core/DataIndex.lua")
AtlasCFM.DataIndex.BuildIndex(false)
assert(AtlasCFM.DataIndex.DropRateCache[22339] == 25)
assert(AtlasCFM.DataIndex.DropRateCache[900006] == nil)
-- Existing saved options gain the default while a saved false stays false.
StaticPopupDialogs = {}
GetAddOnMetadata = function() return "1.89.1" end
front("Stub/Persistence.lua")
core("CFMAtlas/AtlasOptions.lua")
AtlasCFMOptions.TooltipShowDropRate = nil
AtlasCFM.EnsureSavedOptions()
assert(AtlasCFMOptions.TooltipShowDropRate == true)
AtlasCFM.OptionsInit = noop
AtlasCFM.OptionTooltipDropRateOnClick()
assert(AtlasCFMOptions.TooltipShowDropRate == false)
AtlasCFM.SyncOptionsBackup()
AtlasCFM.EnsureSavedOptions()
assert(AtlasCFMOptions.TooltipShowDropRate == false)
AtlasCFM.Quest = {}
core("Locales/enUS/QuestData.lua")
assert(next(AtlasCFM.Quest.DataBase), "English quests must load on every client locale")
print("PASS: source rates, toggle, startup, aliases, chat links, sync/async indexing, English storage")