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.
299 lines
10 KiB
Lua
299 lines
10 KiB
Lua
-- 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)
|