wow-addons/tests/test_ff.lua
rope 0a810dc451 Add Flight Finder
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 14:47:59 +00:00

205 lines
7.6 KiB
Lua

-- Runs FlightFinder against a mock of the WoW map and taxi API.
-- arg[1] = addon folder (FlightFinder)
local dir = arg[1] or "FlightFinder"
local failures = 0
local function check(cond, msg)
if not cond then
failures = failures + 1
io.write("FAIL: ", msg, "\n")
end
end
-- Map rects: top/bottom are world X, left/right world Y.
local RECTS = {
[1415] = { inst = 0, top = 7467, bottom = -16000, left = 16000, right = -19200, type = 2, parent = 947 },
[1414] = { inst = 1, top = 12800, bottom = -11733, left = 17067, right = -19733, type = 2, parent = 947 },
[1437] = { inst = 0, top = -1500, bottom = -4800, left = 200, right = -4800, type = 3, parent = 1415 }, -- Wetlands
[1432] = { inst = 0, top = -4500, bottom = -6300, left = -1700, right = -4500, type = 3, parent = 1415 }, -- Loch Modan
[1426] = { inst = 0, top = -3400, bottom = -6600, left = 1500, right = -2500, type = 3, parent = 1415 }, -- Dun Morogh
[1455] = { inst = 0, top = -4500, bottom = -5200, left = -700, right = -1500, type = 3, parent = 1426 }, -- Ironforge
[1434] = { inst = 0, top = -11000, bottom = -15000, left = 2000, right = -2000, type = 3, parent = 1415 }, -- Stranglethorn
}
-- which zone the client puts a world point in: first matching rect among these, smallest first
local ZONES = { 1455, 1437, 1432, 1426, 1434 }
Enum = { UIMapType = { Cosmic = 0, World = 1, Continent = 2, Zone = 3, Dungeon = 4, Micro = 5 } }
function CreateVector2D(x, y)
return { x = x, y = y, GetXY = function(self) return self.x, self.y end }
end
local waypoint
UiMapPoint = { CreateFromCoordinates = function(m, u, v) return { m = m, u = u, v = v } end }
C_Map = {
GetMapInfo = function(id)
if id == 947 then return { mapID = 947, mapType = 1, parentMapID = 0 } end
local r = RECTS[id]
return r and { mapID = id, mapType = r.type, parentMapID = r.parent }
end,
GetWorldPosFromMapPos = function(id, v)
local r = RECTS[id]
if not r then return nil end
return r.inst, CreateVector2D(r.top + (r.bottom - r.top) * v.y, r.left + (r.right - r.left) * v.x)
end,
GetMapPosFromWorldPos = function(inst, pos)
for _, id in ipairs(ZONES) do
local r = RECTS[id]
if r.inst == inst and pos.x <= r.top and pos.x >= r.bottom and pos.y <= r.left and pos.y >= r.right then
return id, CreateVector2D(0, 0)
end
end
return inst == 0 and 1415 or 1414, CreateVector2D(0, 0)
end,
CanSetUserWaypointOnMap = function(id) return RECTS[id].type == 3 end,
SetUserWaypoint = function(p) waypoint = p end,
}
C_SuperTrack = { SetSuperTrackedUserWaypoint = function() end }
local apiKnown = {} -- nodeIDs GetTaxiNodesForMap reports as discovered, by zone
C_TaxiMap = {
GetTaxiNodesForMap = function(id)
local out = {}
for _, nodeID in ipairs(apiKnown[id] or {}) do
out[#out + 1] = { nodeID = nodeID, isUndiscovered = false }
end
return out
end,
}
local taxi = {}
function NumTaxiNodes() return #taxi end
function TaxiNodeName(i) return taxi[i][1] end
function TaxiNodeGetType(i) return taxi[i][2] end
local faction = "Alliance"
function UnitFactionGroup() return faction end
function CreateFromMixins(...)
local t = {}
for i = 1, select("#", ...) do
for k, v in pairs((select(i, ...))) do t[k] = v end
end
return t
end
MapCanvasDataProviderMixin = {
OnAdded = function(self, map) self.owningMap = map end,
GetMap = function(self) return self.owningMap end,
RegisterEvent = function() end,
UnregisterEvent = function() end,
}
MapCanvasPinMixin = {
UseFrameLevelType = function() end,
SetScalingLimits = function() end,
CheckMouseButtonPassthrough = function() end,
GetMap = function() return WorldMapFrame end,
}
local function texture()
return { SetVertexColor = function() end, SetTexture = function() end }
end
local eventFrame
function CreateFrame()
local f = { scripts = {} }
function f:RegisterEvent() end
function f:SetScript(name, fn) self.scripts[name] = fn end
eventFrame = f
return f
end
local pins = {}
local mapID = 1437
WorldMapFrame = {
AddDataProvider = function(self, p) p:OnAdded(self) end,
GetMapID = function() return mapID end,
RemoveAllPinsByTemplate = function() pins = {} end,
AcquirePin = function(self, template, id)
local pin = CreateFromMixins(FlightFinderPinMixin)
pin.Disc, pin.Ring, pin.Glyph = texture(), texture(), texture()
pin:OnLoad()
pin:OnAcquired(id)
function pin:SetPosition(u, v) self.u, self.v = u, v end
pins[#pins + 1] = pin
return pin
end,
}
local printed
function print(s) printed = s end
SlashCmdList = {}
local ns = {}
for _, file in ipairs({ "Data.lua", "FlightFinder.lua" }) do
assert(loadfile(dir .. "/" .. file))("FlightFinder", ns)
end
eventFrame.scripts.OnEvent(eventFrame, "ADDON_LOADED", "FlightFinder")
local function show(id)
mapID = id
ns.provider:RefreshAllData()
local ids = {}
for _, p in ipairs(pins) do
ids[p.nodeID] = p
end
return ids
end
-- Wetlands: Menethil (7) is undiscovered and sits inside the map
local p = show(1437)[7]
check(p, "Menethil marked on Wetlands")
check(p and p.u > 0 and p.u < 1 and p.v > 0 and p.v < 1, "Menethil inside the Wetlands map")
-- Thelsamar (8) is in Loch Modan, not on the Wetlands map
check(not show(1437)[8], "Loch Modan's flight point stays off Wetlands")
check(show(1432)[8], "Thelsamar on Loch Modan")
-- Horde flight points never show for Alliance
check(not show(1434)[18], "Horde Booty Bay hidden for Alliance")
check(show(1434)[19], "Alliance Booty Bay shown")
-- the map API knows Menethil: no marker, and it's remembered for the continent map
apiKnown[1437] = { 7 }
check(not show(1437)[7], "known Menethil not marked")
apiKnown[1437] = nil
check(not show(1415)[7], "Menethil stays known on the continent map")
check(show(1415)[8], "Thelsamar still marked on the continent map")
-- city node shows on its zone (Ironforge sits in Dun Morogh)
check(show(1426)[6], "Ironforge marked on Dun Morogh")
-- taxi map: Thelsamar reachable, Ironforge not yet discovered
taxi = { { "Thelsamar, Loch Modan", "REACHABLE" }, { "Ironforge, Dun Morogh", "NONE" } }
eventFrame.scripts.OnEvent(eventFrame, "TAXIMAP_OPENED")
check(not show(1432)[8], "taxi map taught Thelsamar")
check(show(1426)[6], "NONE taxi node stays undiscovered")
-- same-named flight masters next to each other: one marker, known if either is
faction = "Horde"
local grp = ns.groups[3274]
check(grp and #grp == 2, "Powderfuse Port's two nodes form one place")
FlightFinderCharDB.known[3275] = true
local function powderfuse()
local ids, n = show(1415), 0
if ids[3274] then n = n + 1 end
if ids[3275] then n = n + 1 end
return n
end
check(powderfuse() == 0, "Powderfuse known through its twin")
FlightFinderCharDB.known[3275] = nil
check(powderfuse() == 1, "one Powderfuse marker")
-- clicking a continent marker sets the waypoint on its zone map
faction = "Alliance"
FlightFinderCharDB.known[8] = nil
local loch = show(1415)[8]
check(loch, "Thelsamar back after forgetting")
waypoint = nil
loch:OnMouseClickAction("LeftButton")
check(waypoint and waypoint.m == 1432, "waypoint set on Loch Modan, got " .. tostring(waypoint and waypoint.m))
-- slash toggles and counts
SlashCmdList.FLIGHTFINDER("")
check(printed and printed:find("hidden") and printed:find("%d+ / %d+"), "slash prints hidden + count: " .. tostring(printed))
check(next(show(1437)) == nil, "hidden shows nothing")
SlashCmdList.FLIGHTFINDER("")
check(show(1432)[8], "shown again")
if failures == 0 then
print = io.write
io.write("ok\n")
else
os.exit(1)
end