Add offline unit test suite for data and core logic

76 tests covering BIS data integrity (all classes/specs/phases, slot
shape, spot checks), ScanItemStats alias aggregation (Frozen
Shadoweave double-count regression), CompareGear upgrade ranking with
spec-specific stat keys, phase resolution, and latest-phase completion.
Runs with any Lua 5.3+ interpreter via mocked WoW API; no client
required. Not referenced in the .toc.
This commit is contained in:
dfj committed 2026-10-11 16:00:24 +02:00
1 parent c59a705d05
commit 7fda3db472
7 files changed
+870

No files matched your search

+58
View File
@@ -0,0 +1,58 @@
# Amibis Tests
Offline unit tests for the Amibis addon's data layer and core logic. No WoW
client required — the WoW API is mocked (`wow_mocks.lua`).
## Running
From the repository root, with any Lua 5.3+ interpreter:
```bash
lua5.4 Amibis/Tests/run.lua
```
Exits 0 on success, 1 on any failure, so it works in CI or a git hook.
No Lua installed? On Debian/Ubuntu you can get one without root:
```bash
apt-get download lua5.4 && dpkg -x lua5.4_*.deb /tmp/lua && /tmp/lua/usr/bin/lua5.4 Amibis/Tests/run.lua
```
## What is covered
| File | Covers |
|---|---|
| `test_data.lua` | `BIS_DATA` registry: 9 classes × 3 specs, well-formed slot entries (valid slots, positive item IDs, non-empty names/sources, optional enchant shape), canonical phase order, `ResolvePhase` fallback, shared-list invariants, T6 spot checks |
| `test_stats.lua` | `ScanItemStats`: MAX aggregation across alias keys (spell damage schools, healing, haste/crit/mp5 ratings), single-mapping pass-through, unmapped key filtering, nil handling |
| `test_compare.lua` | `CompareGear`: BIS counting, upgrade ranking by stat gain, positive-diffs-only scoring, spec-specific stat keys (Shadow counts spell damage, Holy counts healing), phase resolution, `GetStatKeysForSpec`, `GetCompletionRatio` |
## Layout
```
harness.lua # describe/it/expect micro-framework (~150 lines, no deps)
wow_mocks.lua # WoW API stubs + scriptable item/equipment fixtures
run.lua # entry point: wires everything together
test_*.lua # the test suites (receive the addon namespace as vararg)
```
These files are intentionally **not** referenced in `Amibis.toc` — they run on
your dev machine, never in the game client.
## Adding tests
- New suite: create `test_<area>.lua`, start with `local _, ns = ...`, use
`describe` / `before_each` / `it` / `expect(...).toEqual`, and register it in
`run.lua`.
- Item/equipment fixtures: set `MockItems[itemID] = { name = ..., stats = {...} }`
(stats use raw WoW API keys like `ITEM_MOD_INTELLECT_SHORT`; see `STAT_MAP`
in `Amibis.lua`) and `MockEquipped[inventorySlotID] = itemID`.
- Inventory slot IDs: Head=1, Neck=2, Shoulder=3, Back=15, Chest=5, Wrist=9,
Hands=10, Waist=6, Legs=7, Feet=8, Finger0=11, Finger1=12, Trinket0=13,
Trinket1=14, MainHand=16, SecondaryHand=17, Ranged=18.
## Not covered
`UI/ComparisonFrame.lua` — its helpers are file-locals and testing them would
require a full frame API mock. The logic worth testing (stat scanning, scoring,
phase data) lives in the two suites above.
+136
View File
@@ -0,0 +1,136 @@
-- Minimal dependency-free test framework.
-- Provides: describe, it, before_each, expect, TestHarness_report
--
-- expect(value) returns an object with bound matcher methods, so matchers are
-- called with dot syntax: expect(x).toEqual(y).toBeTruthy()
local Harness = {
passed = 0,
failed = 0,
failures = {},
current_describe = "",
before_each_fn = nil,
}
local function deep_equal(a, b)
if a == b then return true end
if type(a) ~= "table" or type(b) ~= "table" then return false end
for k, v in pairs(a) do
if not deep_equal(v, b[k]) then return false end
end
for k in pairs(b) do
if a[k] == nil then return false end
end
return true
end
local function fmt(v)
if type(v) == "table" then
local parts = {}
for k, val in pairs(v) do
table.insert(parts, tostring(k) .. "=" .. tostring(val))
end
return "{" .. table.concat(parts, ", ") .. "}"
end
return tostring(v)
end
local function fail(message)
error(message, 2)
end
function expect(value)
local exp = {}
function exp.toEqual(expected)
if not deep_equal(value, expected) then
fail(string.format("expected %s to equal %s", fmt(value), fmt(expected)))
end
return exp
end
function exp.toBeTruthy()
if not value then
fail("expected truthy, got " .. fmt(value))
end
return exp
end
function exp.toBeFalsy()
if value then
fail("expected falsy, got " .. fmt(value))
end
return exp
end
function exp.toBeNil()
if value ~= nil then
fail("expected nil, got " .. fmt(value))
end
return exp
end
function exp.toBeAtLeast(min)
if not (value >= min) then
fail(string.format("expected %s >= %s", fmt(value), fmt(min)))
end
return exp
end
function exp.toBeAtMost(max)
if not (value <= max) then
fail(string.format("expected %s <= %s", fmt(value), fmt(max)))
end
return exp
end
function exp.toBeCloseTo(expected, tolerance)
tolerance = tolerance or 0.0001
if math.abs(value - expected) > tolerance then
fail(string.format("expected %s close to %s (tolerance %s)", fmt(value), fmt(expected), fmt(tolerance)))
end
return exp
end
function exp.lengthIs(expected)
if #value ~= expected then
fail(string.format("expected length %d, got %d", expected, #value))
end
return exp
end
return exp
end
function describe(name, fn)
Harness.current_describe = name
Harness.before_each_fn = nil
fn()
Harness.before_each_fn = nil
end
function before_each(fn)
Harness.before_each_fn = fn
end
function it(name, fn)
if Harness.before_each_fn then
Harness.before_each_fn()
end
local ok, err = pcall(fn)
if ok then
Harness.passed = Harness.passed + 1
else
Harness.failed = Harness.failed + 1
table.insert(Harness.failures,
Harness.current_describe .. " > " .. name .. ":\n " .. tostring(err))
end
end
function TestHarness_report()
print(string.format("\n%d passed, %d failed", Harness.passed, Harness.failed))
for _, failure in ipairs(Harness.failures) do
print(" FAIL: " .. failure)
end
return Harness.failed == 0
end
+27
View File
@@ -0,0 +1,27 @@
-- Offline test-suite entry point for Amibis.
--
-- Usage, from the repository root:
-- lua5.4 Amibis/Tests/run.lua
--
-- Requires only a Lua 5.3+ interpreter. No external libraries, no WoW client.
-- WoW API calls are mocked by wow_mocks.lua; SavedVariables globals are
-- stubbed below (in-game they are created by InitializeDB on ADDON_LOADED).
local ADDON_NAME = "Amibis"
local ns = {}
dofile("Amibis/Tests/harness.lua")
dofile("Amibis/Tests/wow_mocks.lua")
_G.AmibisDB = { selectedPhase = "T6" }
_G.AmibisCharDB = {}
assert(loadfile("Amibis/Amibis.lua"))(ADDON_NAME, ns)
assert(loadfile("Amibis/Data/BISLists.lua"))(ADDON_NAME, ns)
assert(loadfile("Amibis/Tests/test_data.lua"))(ADDON_NAME, ns)
assert(loadfile("Amibis/Tests/test_stats.lua"))(ADDON_NAME, ns)
assert(loadfile("Amibis/Tests/test_compare.lua"))(ADDON_NAME, ns)
local success = TestHarness_report()
os.exit(success and 0 or 1)
+298
View File
@@ -0,0 +1,298 @@
-- Integration tests for Amibis:CompareGear, upgrade scoring, and stat keys.
-- Mirrors the inventory slot map in Amibis.lua (name -> inventory slotID).
local _, ns = ...
local SLOT_TO_INVENTORY = {
Head = 1, Neck = 2, Shoulder = 3, Back = 15, Chest = 5,
Wrist = 9, Hands = 10, Waist = 6, Legs = 7, Feet = 8,
Finger0 = 11, Finger1 = 12, Trinket0 = 13, Trinket1 = 14,
MainHand = 16, SecondaryHand = 17, Ranged = 18,
}
local function equip(slot, itemID)
MockEquipped[SLOT_TO_INVENTORY[slot]] = itemID
end
local function find_upgrade(data, slot)
for _, upgrade in ipairs(data.topUpgrades) do
if upgrade.slot == slot then return upgrade end
end
return nil
end
describe("CompareGear: upgrade scoring", function()
before_each(function()
MockItems = {
[21869] = {
name = "Old Weapon",
stats = { ["ITEM_MOD_SPELL_POWER_SHORT"] = 35 },
},
[31064] = {
name = "Hood of Absolution",
stats = {
["ITEM_MOD_INTELLECT_SHORT"] = 20,
["ITEM_MOD_SPIRIT_SHORT"] = 25,
},
},
[31070] = {
name = "Shoulderpads of Absolution",
stats = {
["ITEM_MOD_SPELL_POWER_SHORT"] = 45,
["ITEM_MOD_INTELLECT_SHORT"] = 20,
},
},
[30666] = {
name = "Ritssyn's Lost Pendant",
stats = { ["ITEM_MOD_INTELLECT_SHORT"] = 15 },
},
[32374] = {
name = "Zhar'doom, Greatstaff of the Devourer",
stats = { ["ITEM_MOD_SPELL_POWER_SHORT"] = 60 },
},
}
MockEquipped = {}
AmibisDB.selectedPhase = "T6"
AmibisCharDB.overrideSpec = "Shadow"
end)
it("counts BIS slots and total slots", function()
equip("Head", 31064)
equip("MainHand", 21869)
local data = ns.Amibis:CompareGear()
expect(data.hasBISList).toBeTruthy()
expect(data.bisCount).toEqual(1)
expect(data.totalSlots).toEqual(16)
end)
it("ranks empty-slot upgrades by full BIS stat value", function()
equip("MainHand", 21869)
local data = ns.Amibis:CompareGear()
expect(#data.topUpgrades).toEqual(3)
expect(data.topUpgrades[1].slot).toEqual("Shoulder")
expect(data.topUpgrades[1].score).toEqual(65)
expect(data.topUpgrades[1].statDiffs).toEqual({ spellPower = 45, intellect = 20 })
expect(data.topUpgrades[2].slot).toEqual("Head")
expect(data.topUpgrades[2].score).toEqual(45)
expect(data.topUpgrades[3].slot).toEqual("MainHand")
expect(data.topUpgrades[3].score).toEqual(25)
expect(data.topUpgrades[3].statDiffs.spellPower).toEqual(25)
end)
it("includes a partial stat gain when only one stat improves", function()
MockItems[21891] = {
name = "Old Hood",
stats = {
["ITEM_MOD_INTELLECT_SHORT"] = 15,
["ITEM_MOD_SPIRIT_SHORT"] = 10,
["ITEM_MOD_SPELL_POWER_SHORT"] = 8,
},
}
equip("Head", 21891)
equip("MainHand", 21869)
local data = ns.Amibis:CompareGear()
local head = find_upgrade(data, "Head")
expect(head.score).toEqual(20)
expect(head.statDiffs.intellect).toEqual(5)
expect(head.statDiffs.spirit).toEqual(15)
end)
it("scores only positive stat diffs", function()
equip("Head", 31064)
equip("MainHand", 21869)
local data = ns.Amibis:CompareGear()
expect(find_upgrade(data, "Head")).toBeNil()
for _, upgrade in ipairs(data.topUpgrades) do
for _statKey, diff in pairs(upgrade.statDiffs) do
expect(diff > 0).toBeTruthy()
end
end
end)
it("returns empty upgrades when everything is BIS", function()
equip("Head", 31064)
AmibisDB.selectedPhase = nil
AmibisCharDB.overrideSpec = nil
local data = ns.Amibis:CompareGear()
expect(#data.topUpgrades).toBeAtMost(3)
end)
it("reports no BIS list for unsupported spec", function()
AmibisCharDB.overrideSpec = "Nonexistent"
local data = ns.Amibis:CompareGear()
expect(data.hasBISList).toBeFalsy()
expect(#data.topUpgrades).toEqual(0)
end)
it("resolves the phase saved in AmibisDB", function()
AmibisDB.selectedPhase = "T5"
local data = ns.Amibis:CompareGear()
expect(data.phase).toEqual("T5")
end)
end)
describe("CompareGear: spec-specific stat keys", function()
before_each(function()
MockItems = {
[21869] = {
name = "Old Weapon",
stats = { ["ITEM_MOD_SPELL_POWER_SHORT"] = 20 },
},
[32374] = {
name = "Zhar'doom, Greatstaff of the Devourer",
stats = {},
},
[32500] = {
name = "Crystal Spire of Karabor",
stats = {},
},
}
MockEquipped = {}
equip("MainHand", 21869)
AmibisDB.selectedPhase = "T6"
end)
it("counts spell damage for Shadow", function()
AmibisCharDB.overrideSpec = "Shadow"
MockItems[32374].stats = {
["ITEM_MOD_SPELL_DAMAGE_DONE_SHORT"] = 40,
["ITEM_MOD_DAMAGE_DONE_SHORT"] = 40,
}
local data = ns.Amibis:CompareGear()
local mh = find_upgrade(data, "MainHand")
expect(mh).toBeTruthy()
expect(mh.statDiffs.spellDamage).toEqual(40)
expect(mh.score).toEqual(40)
end)
it("ignores spell damage for Holy", function()
AmibisCharDB.overrideSpec = "Holy"
MockItems[32500].stats = {
["ITEM_MOD_SPELL_DAMAGE_DONE_SHORT"] = 40,
["ITEM_MOD_DAMAGE_DONE_SHORT"] = 40,
["ITEM_MOD_HEALING_SHORT"] = 81,
}
local data = ns.Amibis:CompareGear()
local mh = find_upgrade(data, "MainHand")
expect(mh).toBeTruthy()
expect(mh.statDiffs.spellDamage).toBeNil()
expect(mh.statDiffs.healing).toEqual(81)
end)
end)
describe("GetStatKeysForSpec", function()
it("includes spell damage for damage specs", function()
local shadowKeys = ns.Amibis:GetStatKeysForSpec("PRIEST", "Shadow")
local found = false
for _, key in ipairs(shadowKeys) do
if key == "spellDamage" then found = true end
end
expect(found).toBeTruthy()
expect(#shadowKeys).toEqual(7)
end)
it("includes healing for healing specs", function()
local holyKeys = ns.Amibis:GetStatKeysForSpec("PRIEST", "Holy")
local found = false
for _, key in ipairs(holyKeys) do
if key == "healing" then found = true end
end
expect(found).toBeTruthy()
end)
it("falls back to default keys for unsupported specs", function()
local keys = ns.Amibis:GetStatKeysForSpec("WARRIOR", "Arms")
expect(#keys).toEqual(6)
for _, key in ipairs(keys) do
expect(key ~= "healing" and key ~= "spellDamage").toBeTruthy()
end
end)
end)
describe("GetCompletionRatio", function()
before_each(function()
MockItems = {}
MockEquipped = {}
AmibisDB.selectedPhase = "T6"
AmibisCharDB.overrideSpec = "Shadow"
end)
it("falls back to slot completion while stats load", function()
equip("Head", 31064)
local data = ns.Amibis:CompareGear()
expect(data.statsComplete).toBeFalsy()
local ratio = ns.Amibis:GetCompletionRatio(data)
expect(ratio).toBeCloseTo(1 / 16)
end)
it("is 1.0 when fully geared to BIS", function()
local list = ns.Data.BISLists:GetBISList("PRIEST", "Shadow", "T6")
for slot, entry in pairs(list) do
MockItems[entry.itemID] = {
name = entry.name,
stats = {
["ITEM_MOD_INTELLECT_SHORT"] = 100,
["ITEM_MOD_SPELL_POWER_SHORT"] = 50,
},
}
equip(slot, entry.itemID)
end
local data = ns.Amibis:CompareGear()
expect(data.statsComplete).toBeTruthy()
expect(data.bisCount).toEqual(16)
expect(#data.topUpgrades).toEqual(0)
expect(ns.Amibis:GetCompletionRatio(data)).toBeCloseTo(1.0)
end)
end)
describe("latest phase progress", function()
before_each(function()
MockItems = {}
MockEquipped = {}
AmibisDB.selectedPhase = "T6"
AmibisCharDB.overrideSpec = "Shadow"
end)
it("exposes the latest phase and nil ratio while stats load", function()
local data = ns.Amibis:CompareGear()
expect(data.latestPhase).toEqual("T6")
expect(data.latestCompletionRatio).toBeNil()
end)
it("measures progress against the latest phase, not the selected one", function()
local latestList = ns.Data.BISLists:GetBISList("PRIEST", "Shadow", "T6")
local oldList = ns.Data.BISLists:GetBISList("PRIEST", "Shadow", "T4")
for slot, entry in pairs(oldList) do
MockItems[entry.itemID] = {
name = entry.name,
stats = {
["ITEM_MOD_INTELLECT_SHORT"] = 100,
["ITEM_MOD_SPELL_POWER_SHORT"] = 50,
},
}
equip(slot, entry.itemID)
end
for slot, entry in pairs(latestList) do
MockItems[entry.itemID] = {
name = entry.name,
stats = {
["ITEM_MOD_INTELLECT_SHORT"] = 200,
["ITEM_MOD_SPELL_POWER_SHORT"] = 90,
},
}
end
AmibisDB.selectedPhase = "T4"
local data = ns.Amibis:CompareGear()
expect(data.phase).toEqual("T4")
expect(data.latestPhase).toEqual("T6")
expect(ns.Amibis:GetCompletionRatio(data)).toBeCloseTo(1.0)
expect(data.latestCompletionRatio < 1.0).toBeTruthy()
expect(data.latestCompletionRatio > 0.3).toBeTruthy()
end)
it("ratio matches for T6-only lists (latest equals selected)", function()
local list = ns.Data.BISLists:GetBISList("PALADIN", "Protection", "T6")
expect(list).toBeTruthy()
local data = ns.Amibis:CompareGear()
expect(data.latestPhase).toEqual("T6")
end)
end)
+145
View File
@@ -0,0 +1,145 @@
-- Data integrity tests for BISLists.lua — run offline, no WoW client needed.
local _, ns = ...
local BIS = ns.Data.BISLists
local VALID_SLOTS = {
Head = true, Neck = true, Shoulder = true, Back = true, Chest = true,
Wrist = true, Hands = true, Waist = true, Legs = true, Feet = true,
Finger0 = true, Finger1 = true, Trinket0 = true, Trinket1 = true,
MainHand = true, SecondaryHand = true, Ranged = true,
}
local function validate_entry(slot, entry)
expect(VALID_SLOTS[slot]).toBeTruthy()
expect(type(entry.itemID)).toEqual("number")
expect(entry.itemID > 0).toBeTruthy()
expect(type(entry.name)).toEqual("string")
expect(#entry.name > 0).toBeTruthy()
expect(type(entry.source)).toEqual("string")
expect(#entry.source > 0).toBeTruthy()
if entry.enchant then
expect(type(entry.enchant.id)).toEqual("number")
expect(type(entry.enchant.name)).toEqual("string")
expect(#entry.enchant.name > 0).toBeTruthy()
end
end
describe("BIS data registry", function()
local classes = BIS:GetAvailableClasses()
it("covers all 9 classes", function()
expect(#classes).toEqual(9)
end)
for _, class in ipairs(classes) do
local specs = BIS:GetAvailableSpecs(class)
table.sort(specs)
it(class .. " has all 3 specs", function()
expect(#specs).toEqual(3)
end)
for _, spec in ipairs(specs) do
it(class .. "/" .. spec .. " lists are well-formed", function()
local phases = BIS:GetAvailablePhases(class, spec)
expect(#phases > 0).toBeTruthy()
for _, phase in ipairs(phases) do
local list = BIS:GetBISList(class, spec, phase)
expect(list).toBeTruthy()
local count = 0
for slot, entry in pairs(list) do
count = count + 1
validate_entry(slot, entry)
end
expect(count >= 8).toBeTruthy()
end
end)
end
end
end)
describe("phase ordering and resolution", function()
it("returns phases in canonical order", function()
local phases = BIS:GetAvailablePhases("PRIEST", "Shadow")
expect(phases[1]).toEqual("T4")
expect(phases[2]).toEqual("T5")
expect(phases[3]).toEqual("T6")
end)
it("reports the latest phase for every spec", function()
for _, class in ipairs(BIS:GetAvailableClasses()) do
for _, spec in ipairs(BIS:GetAvailableSpecs(class)) do
expect(BIS:GetLatestPhase(class, spec)).toEqual("T6")
end
end
end)
it("keeps the saved phase when it exists", function()
expect(BIS:ResolvePhase("PRIEST", "Shadow", "T6")).toEqual("T6")
expect(BIS:ResolvePhase("PRIEST", "Shadow", "T5")).toEqual("T5")
end)
it("falls back to the first available phase", function()
expect(BIS:ResolvePhase("PALADIN", "Protection", "T5")).toEqual("T4")
expect(BIS:ResolvePhase("DRUID", "Feral Combat", "T5")).toEqual("T4")
expect(BIS:ResolvePhase("DRUID", "Balance", "T6")).toEqual("T6")
end)
it("returns preferred phase for unknown class", function()
expect(BIS:ResolvePhase("DEATHKNIGHT", "Frost", "T5")).toEqual("T5")
end)
it("returns nil lookup for unknown spec", function()
expect(BIS:GetBISList("PRIEST", "Nonexistent", "T6")).toBeNil()
end)
end)
describe("known T6 spot checks", function()
it("shadow priest T6 head is the Hyjal token", function()
local list = BIS:GetBISList("PRIEST", "Shadow", "T6")
expect(list["Head"].itemID).toEqual(31064)
expect(list["Head"].name).toEqual("Hood of Absolution")
end)
it("discipline priest shares the holy T6 list", function()
expect(BIS:GetBISList("PRIEST", "Discipline", "T6"))
.toEqual(BIS:GetBISList("PRIEST", "Holy", "T6"))
end)
it("hunter BM and MM share the T6 list", function()
expect(BIS:GetBISList("HUNTER", "Beast Mastery", "T6"))
.toEqual(BIS:GetBISList("HUNTER", "Marksmanship", "T6"))
end)
it("all three warlock specs share the T6 list", function()
local affliction = BIS:GetBISList("WARLOCK", "Affliction", "T6")
expect(BIS:GetBISList("WARLOCK", "Demonology", "T6")).toEqual(affliction)
expect(BIS:GetBISList("WARLOCK", "Destruction", "T6")).toEqual(affliction)
end)
end)
describe("T4 (Phase 1) data", function()
it("covers every spec", function()
for _, class in ipairs(BIS:GetAvailableClasses()) do
for _, spec in ipairs(BIS:GetAvailableSpecs(class)) do
local list = BIS:GetBISList(class, spec, "T4")
expect(list).toBeTruthy()
end
end
end)
it("uses Karazhan/Gruul/Magtheridon gear", function()
local list = BIS:GetBISList("PRIEST", "Shadow", "T4")
expect(list["Head"].itemID).toEqual(24266)
expect(list["MainHand"].name).toEqual("Nathrezim Mindblade")
expect(list["MainHand"].source).toEqual("Karazhan - Prince Malchezaar")
end)
it("paladin protection prot has no T5 entry", function()
local phases = BIS:GetAvailablePhases("PALADIN", "Protection")
expect(phases[1]).toEqual("T4")
expect(phases[2]).toEqual("T6")
expect(BIS:GetBISList("PALADIN", "Protection", "T5")).toBeNil()
end)
end)
+118
View File
@@ -0,0 +1,118 @@
-- Unit tests for Amibis:ScanItemStats — alias aggregation behavior.
local _, ns = ...
describe("ScanItemStats", function()
before_each(function()
MockItems = {}
end)
it("takes MAX across aliased spell damage keys", function()
MockItems[1] = {
name = "Aliased Item",
stats = {
["ITEM_MOD_SPELL_DAMAGE_DONE_SHORT"] = 28,
["ITEM_MOD_DAMAGE_DONE_SHORT"] = 28,
["ITEM_MOD_SPELL_DMG_SHORT"] = 40,
},
}
local stats = ns.Amibis:ScanItemStats(1)
expect(stats.spellDamage).toEqual(40)
end)
it("does not double count school spell damage", function()
MockItems[21870] = {
name = "Frozen Shadoweave Boots",
stats = {
["ITEM_MOD_SPELL_DAMAGE_DONE_SHORT"] = 28,
["ITEM_MOD_DAMAGE_DONE_SHORT"] = 28,
},
}
local stats = ns.Amibis:ScanItemStats(21870)
expect(stats.spellDamage).toEqual(28)
end)
it("takes MAX across aliased healing keys", function()
MockItems[2] = {
name = "Healing Item",
stats = {
["ITEM_MOD_HEALING_DONE_SHORT"] = 40,
["ITEM_MOD_SPELL_HEALING_DONE_SHORT"] = 40,
["ITEM_MOD_HEALING_SHORT"] = 55,
},
}
expect(ns.Amibis:ScanItemStats(2).healing).toEqual(55)
end)
it("takes MAX across aliased rating keys", function()
MockItems[3] = {
name = "Rating Item",
stats = {
["ITEM_MOD_HASTE_RATING_SHORT"] = 21,
["ITEM_MOD_SPELL_HASTE_RATING_SHORT"] = 21,
["ITEM_MOD_CRIT_RATING_SHORT"] = 14,
["ITEM_MOD_SPELL_CRIT_RATING_SHORT"] = 14,
["ITEM_MOD_MANA_REGENERATION_SHORT"] = 10,
["ITEM_MOD_POWER_REGEN0_SHORT"] = 10,
},
}
local stats = ns.Amibis:ScanItemStats(3)
expect(stats.haste).toEqual(21)
expect(stats.crit).toEqual(14)
expect(stats.mp5).toEqual(10)
end)
it("keeps the highest school value", function()
MockItems[4] = {
name = "Mixed School Item",
stats = {
["ITEM_MOD_SPELL_DAMAGE_DONE_SHORT"] = 28,
["ITEM_MOD_DAMAGE_DONE_SHORT"] = 31,
},
}
expect(ns.Amibis:ScanItemStats(4).spellDamage).toEqual(31)
end)
it("passes through single-mapping stats", function()
MockItems[5] = {
name = "Plain Item",
stats = {
["ITEM_MOD_INTELLECT_SHORT"] = 30,
["ITEM_MOD_SPIRIT_SHORT"] = 12,
["ITEM_MOD_STAMINA_SHORT"] = 21,
["ITEM_MOD_SPELL_POWER_SHORT"] = 33,
},
}
local stats = ns.Amibis:ScanItemStats(5)
expect(stats.intellect).toEqual(30)
expect(stats.spirit).toEqual(12)
expect(stats.stamina).toEqual(21)
expect(stats.spellPower).toEqual(33)
end)
it("ignores unmapped stat keys", function()
MockItems[6] = {
name = "Resist Item",
stats = {
["ITEM_MOD_FIRE_RESISTANCE_SHORT"] = 15,
["ITEM_MOD_STRENGTH_SHORT"] = 8,
["ITEM_MOD_INTELLECT_SHORT"] = 4,
},
}
local stats = ns.Amibis:ScanItemStats(6)
expect(stats.intellect).toEqual(4)
local keyCount = 0
for _ in pairs(stats) do keyCount = keyCount + 1 end
expect(keyCount).toEqual(1)
end)
it("returns nil for unknown items", function()
expect(ns.Amibis:ScanItemStats(999999)).toBeNil()
end)
it("returns an empty table for items with no mapped stats", function()
MockItems[7] = { name = "Empty Item", stats = {} }
local stats = ns.Amibis:ScanItemStats(7)
expect(stats).toBeTruthy()
expect(next(stats)).toBeNil()
end)
end)
+88
View File
@@ -0,0 +1,88 @@
-- Minimal WoW API mocks for offline testing.
-- Fixtures are scriptable: set MockItems / MockEquipped before calling addon code.
_G.UIParent = {}
_G.CopyTable = function(t)
if type(t) ~= "table" then return t end
local out = {}
for k, v in pairs(t) do
out[k] = v
end
return out
end
_G.MockItems = {} -- itemID -> { name = string, stats = table (WoW API keys) }
_G.MockEquipped = {} -- inventory slotID -> itemID
local function itemLink(itemID)
local name = _G.MockItems[itemID] and _G.MockItems[itemID].name or ("item" .. itemID)
return "|Hitem:" .. itemID .. ":0:0:0:0:0:0:0:0|h[" .. name .. "]|h"
end
_G.MockItemLink = itemLink
function GetItemInfo(itemID)
local it = _G.MockItems[itemID]
if not it then return nil end
return it.name, itemLink(itemID), 4, 100, 70
end
function GetItemStats(link)
local itemID = tonumber(string.match(link, "item:(%d+)"))
local it = _G.MockItems[itemID]
return it and it.stats or nil
end
function GetInventoryItemLink(_, slotID)
local itemID = _G.MockEquipped[slotID]
if not itemID then return nil end
return itemLink(itemID)
end
function UnitClass() return "Priest", "PRIEST" end
function GetTalentTabInfo() return 0, 0, 0, 0 end
function ChatEdit_InsertLink() end
function DressUpItemLink() end
function IsShiftKeyDown() return false end
function IsControlKeyDown() return false end
local function makeChild()
return setmetatable({}, {
__index = function(_, key)
return function(_, ...) return nil end
end
})
end
local function makeFrame()
local frame = { fonts = {}, textures = {} }
return setmetatable(frame, {
__index = function(self, key)
if key == "CreateFontString" then
return function()
local fs = makeChild()
table.insert(self.fonts, fs)
return fs
end
elseif key == "CreateTexture" then
return function()
local tx = makeChild()
table.insert(self.textures, tx)
return tx
end
end
return function(_, ...) return self end
end
})
end
_G.MockFrames = {}
function CreateFrame()
local f = makeFrame()
table.insert(_G.MockFrames, f)
return f
end
_G.GameTooltip = makeFrame()
_G.SlashCmdList = {}