wow-addons/tests/test_mw.lua
rope 3a26e31458 Maelstrom Alert: 5-stack Maelstrom Weapon alert
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-24 20:18:17 +00:00

209 lines
7.9 KiB
Lua

-- Runs MaelstromAlert.lua against a mock of the WoW API.
-- arg[1] = addon file
local clock = 100
function GetTime() return clock end
STANDARD_TEXT_FONT = "Fonts\\FRIZQT__.TTF"
SOUNDKIT = { ALARM_CLOCK_WARNING_3 = 12889 }
local sounds = 0
function PlaySound(id, channel) assert(id == 12889 and channel == "Master"); sounds = sounds + 1 end
local secrets = {}
function issecretvalue(v) return secrets[v] == true end
local function newSecret() local s = {}; secrets[s] = true; return s end
local printed = {}
function print(s) printed[#printed + 1] = s end
SlashCmdList = {}
local class, dead, combat = "SHAMAN", false, false
local aura -- nil = no buff; table = buff
local aurasSecret = false
local ctText -- what C_CombatText.GetCurrentEventInfo returns
function UnitClass() return "Shaman", class end
function UnitIsDeadOrGhost() return dead end
function InCombatLockdown() return combat end
local names = { [403] = "Lightning Bolt", [421] = "Chain Lightning", [8004] = "Lesser Healing Wave",
[408505] = "Maelstrom Weapon", [17364] = "Stormstrike", [16246] = "Clearcasting" }
C_Spell = { GetSpellName = function(id) return names[id] end }
C_UnitAuras = { GetAuraDataBySpellName = function(unit, name, filter)
assert(unit == "player" and name == "Maelstrom Weapon" and filter == "HELPFUL")
if aurasSecret then return nil end -- RequiresNonSecretAura: no values
return aura
end }
C_Secrets = {
ShouldAurasBeSecret = function() return aurasSecret end,
ShouldSpellAuraBeSecret = function(id) assert(id == 408505); return aurasSecret end,
GetSpellAuraSecrecy = function() return 2 end,
}
C_CombatText = { GetCurrentEventInfo = function() return ctText end }
local frames = {}
local function region()
local r = { shown = true, alpha = 1, scale = 1 }
function r:Show() self.shown = true end
function r:Hide() self.shown = false end
function r:IsShown() return self.shown end
function r:SetText(t) self.text = t end
function r:SetTexture(t) self.texture = t end
function r:SetScale(s) assert(s > 0); self.scale = s end
function r:SetAlpha(a) assert(a >= -1e-9 and a <= 1 + 1e-9); self.alpha = a end
function r:EnableMouse(m) self.mouse = m end
function r:GetPoint() return "CENTER", UIParent, "CENTER", 0, 50 end
local noop = function() end
for _, k in ipairs({ "SetPoint", "ClearAllPoints", "SetAllPoints", "SetSize", "SetBlendMode", "SetVertexColor",
"SetFont", "SetTextColor", "SetFrameStrata", "SetMovable", "SetClampedToScreen", "RegisterForDrag",
"SetTexCoord", "StartMoving", "StopMovingOrSizing" }) do
r[k] = r[k] or noop
end
return r
end
local fontStrings = {}
function CreateFrame(_, name)
local fr = region()
fr.scripts, fr.events = {}, {}
function fr:SetScript(k, fn) self.scripts[k] = fn end
function fr:RegisterEvent(e) self.events[e] = true end
function fr:RegisterUnitEvent(e) self.events[e] = true end
function fr:UnregisterEvent(e) self.events[e] = nil end
function fr:CreateTexture() return region() end
function fr:CreateFontString() local s = region(); fontStrings[#fontStrings + 1] = s; return s end
frames[#frames + 1] = fr
if name then _G[name] = fr end
return fr
end
UIParent = region()
dofile(arg[1])
local frame = MaelstromAlertFrame
local ev
for _, fr in ipairs(frames) do if fr.events.ADDON_LOADED then ev = fr end end
local label = fontStrings[1]
local function fire(...) ev.scripts.OnEvent(ev, ...) end
local function tick(sec)
for _ = 1, math.floor(sec / 0.1 + 0.5) do
clock = clock + 0.1
ev.scripts.OnUpdate(ev, 0.1)
if frame.shown then frame.scripts.OnUpdate(frame, 0.1) end
end
end
local function stacks(n) aura = n and { applications = n, spellId = 408505, icon = 136048 } or nil end
fire("ADDON_LOADED", "Other")
assert(MaelstromAlertDB == nil)
fire("ADDON_LOADED", "MaelstromAlert")
assert(ev.events.COMBAT_TEXT_UPDATE and ev.events.UNIT_SPELLCAST_SUCCEEDED)
fire("PLAYER_ENTERING_WORLD")
tick(0.2)
assert(not frame.shown)
-- Readable stacks: nothing at 4, alert + one chime at 5, gone when spent.
for n = 1, 4 do stacks(n); tick(0.1) end
assert(not frame.shown and sounds == 0)
stacks(5); tick(0.1)
assert(frame.shown and sounds == 1 and label.text == "MAELSTROM 5", tostring(label.text))
assert(frame.texture == nil and MaelstromAlertDB.spellID == 408505)
tick(2)
assert(sounds == 1, "chime once")
stacks(nil); tick(0.1)
assert(not frame.shown)
-- Secret in combat: "Maelstrom Ready" combat text with a secret text.
combat, aurasSecret = true, true
fire("COMBAT_TEXT_UPDATE", "DAMAGE")
ctText = newSecret()
tick(0.1)
assert(not frame.shown)
fire("COMBAT_TEXT_UPDATE", "SPELL_ACTIVE")
assert(frame.shown and sounds == 2 and label.text == "MAELSTROM")
assert(MaelstromAlertDB.log.text.secret == 1)
-- Other casts don't spend it; Lightning Bolt does.
fire("UNIT_SPELLCAST_SUCCEEDED", "player", "guid", 17364)
assert(frame.shown)
fire("UNIT_SPELLCAST_SUCCEEDED", "player", "guid", 403)
assert(not frame.shown)
-- Unspent, it runs out after the buff's 30s.
fire("COMBAT_TEXT_UPDATE", "SPELL_ACTIVE")
tick(29)
assert(frame.shown)
tick(1.2)
assert(not frame.shown)
-- A secret event type is ignored without touching it.
fire("COMBAT_TEXT_UPDATE", newSecret())
assert(not frame.shown)
-- Readable reactive text that isn't Maelstrom is ignored and logged.
ctText = "Overpower"
fire("COMBAT_TEXT_UPDATE", "SPELL_ACTIVE")
assert(not frame.shown and MaelstromAlertDB.log.text.Overpower == 1)
ctText = "Maelstrom Ready"
fire("COMBAT_TEXT_UPDATE", "SPELL_ACTIVE")
assert(frame.shown)
fire("UNIT_SPELLCAST_SUCCEEDED", "player", "guid", 421)
assert(not frame.shown)
-- Spell glow on a spender while secret.
fire("SPELL_ACTIVATION_OVERLAY_GLOW_SHOW", 8004)
assert(frame.shown)
fire("SPELL_ACTIVATION_OVERLAY_GLOW_HIDE", 8004)
assert(not frame.shown)
-- Glow on something else doesn't count, but is logged.
fire("SPELL_ACTIVATION_OVERLAY_GLOW_SHOW", 17364)
assert(not frame.shown and MaelstromAlertDB.log.glows["17364 Stormstrike"] == 1)
-- A secret glow ID is skipped.
fire("SPELL_ACTIVATION_OVERLAY_GLOW_SHOW", newSecret())
assert(not frame.shown and MaelstromAlertDB.log.glows.secret == 1)
-- Proc overlay for Maelstrom Weapon; a bare hide clears every overlay.
fire("SPELL_ACTIVATION_OVERLAY_SHOW", 16246)
assert(not frame.shown)
fire("SPELL_ACTIVATION_OVERLAY_SHOW", 408505)
assert(frame.shown)
fire("SPELL_ACTIVATION_OVERLAY_HIDE", nil)
assert(not frame.shown)
-- Back to readable: the aura wins over stale signals.
fire("COMBAT_TEXT_UPDATE", "SPELL_ACTIVE")
assert(frame.shown)
combat, aurasSecret = false, false
stacks(nil); tick(0.1)
assert(not frame.shown, "readable no-buff clears the combat text signal")
aurasSecret = true; tick(0.1)
assert(not frame.shown, "cleared, not just masked")
aurasSecret = false
-- Combat reads are counted for diagnosis.
assert(MaelstromAlertDB.log.reads.secret > 0)
-- Death and other classes.
stacks(5); tick(0.1); assert(frame.shown)
dead = true; tick(0.1); assert(not frame.shown); dead = false
class = "WARRIOR"; fire("PLAYER_ENTERING_WORLD"); assert(not frame.shown)
class = "SHAMAN"; fire("PLAYER_ENTERING_WORLD"); assert(frame.shown)
stacks(nil); tick(0.1)
-- Slash commands.
local before = sounds
SlashCmdList.MAELSTROMALERT("")
assert(frame.shown and sounds == before + 1 and printed[#printed]:find("on, sound on"))
tick(3.2)
assert(not frame.shown, "preview ends")
SlashCmdList.MAELSTROMALERT("off")
stacks(5); tick(0.1)
assert(not frame.shown)
SlashCmdList.MAELSTROMALERT("on")
assert(frame.shown)
stacks(nil); tick(0.1)
SlashCmdList.MAELSTROMALERT("sound off")
before = sounds
stacks(5); tick(0.1)
assert(frame.shown and sounds == before)
stacks(nil); tick(0.1)
SlashCmdList.MAELSTROMALERT("move")
assert(frame.shown and frame.mouse)
frame.scripts.OnDragStop(frame)
assert(MaelstromAlertDB.point[4] == 50)
SlashCmdList.MAELSTROMALERT("move")
assert(not frame.shown and not frame.mouse)
SlashCmdList.MAELSTROMALERT("reset")
assert(MaelstromAlertDB.point == nil)
io.write("ok\n")