The bar could change when switching phases: latestCompletionRatio was nil until the selected phase's stats were complete AND the latest list was cached, and the UI then fell back to the selected phase's own completion ratio. Right after login the latest list's items are often not cached yet, so switching phases visibly moved the bar. Always compute a latest-phase ratio inside CompareGear: stats-based when both the latest list and the equipped items are cached, otherwise slot completion against the latest list. Return latestStatsComplete so the UI can mark the estimate with "~" and keep retrying until stats load (capped at 20 attempts). The UI now uses latestCompletionRatio directly instead of falling back to the selected phase. Also refresh on PLAYER_EQUIPMENT_CHANGED so gear swaps update the bar. Tests: phase-independent ratio, slot-based fallback while the latest list is uncached, and equal ratios across selected phases once cached. 106 passing.
422 lines
15 KiB
Lua
422 lines
15 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_DAMAGE_DONE_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_DAMAGE_DONE_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_DAMAGE_DONE_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 upgrades by weighted spec stats", function()
|
|
equip("MainHand", 21869)
|
|
local data = ns.Amibis:CompareGear()
|
|
expect(#data.topUpgrades).toEqual(3)
|
|
-- Shoulder: 45 spell damage (x3) + 20 intellect (x1) = 155
|
|
expect(data.topUpgrades[1].slot).toEqual("Shoulder")
|
|
expect(data.topUpgrades[1].score).toEqual(155)
|
|
expect(data.topUpgrades[1].statDiffs).toEqual({ spellDamage = 45, intellect = 20 })
|
|
-- MainHand: (60 - 35) spell damage (x3) = 75
|
|
expect(data.topUpgrades[2].slot).toEqual("MainHand")
|
|
expect(data.topUpgrades[2].score).toEqual(75)
|
|
-- Head: 20 intellect (x1) + 25 spirit (x1) = 45
|
|
expect(data.topUpgrades[3].slot).toEqual("Head")
|
|
expect(data.topUpgrades[3].score).toEqual(45)
|
|
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_DAMAGE_DONE_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_INTELLECT_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(120)
|
|
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("uses physical stats for melee specs", function()
|
|
local keys = ns.Amibis:GetStatKeysForSpec("WARRIOR", "Arms")
|
|
local seen = {}
|
|
for _, key in ipairs(keys) do seen[key] = true end
|
|
expect(seen.strength).toBeTruthy()
|
|
expect(seen.attackPower).toBeTruthy()
|
|
expect(seen.hit).toBeTruthy()
|
|
expect(seen.crit).toBeTruthy()
|
|
expect(seen.healing).toBeFalsy()
|
|
expect(seen.spellDamage).toBeFalsy()
|
|
expect(seen.spirit).toBeFalsy()
|
|
expect(seen.mp5).toBeFalsy()
|
|
end)
|
|
|
|
it("uses mitigation stats for tanks", function()
|
|
local keys = ns.Amibis:GetStatKeysForSpec("PALADIN", "Protection")
|
|
local seen = {}
|
|
for _, key in ipairs(keys) do seen[key] = true end
|
|
expect(seen.stamina).toBeTruthy()
|
|
expect(seen.defense).toBeTruthy()
|
|
expect(seen.dodge).toBeTruthy()
|
|
expect(seen.parry).toBeTruthy()
|
|
end)
|
|
|
|
it("differs between specs of the same class", function()
|
|
local shadow = table.concat(ns.Amibis:GetStatKeysForSpec("PRIEST", "Shadow"), ",")
|
|
local holy = table.concat(ns.Amibis:GetStatKeysForSpec("PRIEST", "Holy"), ",")
|
|
expect(shadow ~= holy).toBeTruthy()
|
|
end)
|
|
|
|
it("falls back to a default profile for unsupported specs", function()
|
|
local keys = ns.Amibis:GetStatKeysForSpec("DEATHKNIGHT", "Frost")
|
|
expect(#keys > 0).toBeTruthy()
|
|
end)
|
|
|
|
it("keeps every spec profile within the 8-row panel limit", function()
|
|
for _, class in ipairs(ns.Data.BISLists:GetAvailableClasses()) do
|
|
for _, spec in ipairs(ns.Data.BISLists:GetAvailableSpecs(class)) do
|
|
local keys = ns.Amibis:GetStatKeysForSpec(class, spec)
|
|
expect(#keys > 0).toBeTruthy()
|
|
expect(#keys <= 8).toBeTruthy()
|
|
end
|
|
end
|
|
end)
|
|
end)
|
|
|
|
describe("StatRatio weighting", function()
|
|
it("weights primary stats above secondary ones", function()
|
|
local ratios = ns.Amibis
|
|
local bis = { spellDamage = 100, spirit = 100 }
|
|
local primary = ratios:StatRatio({ spellDamage = 100, spirit = 0 }, bis, "PRIEST", "Shadow")
|
|
local secondary = ratios:StatRatio({ spellDamage = 0, spirit = 100 }, bis, "PRIEST", "Shadow")
|
|
expect(primary > secondary).toBeTruthy()
|
|
expect(primary).toBeCloseTo(0.75)
|
|
expect(secondary).toBeCloseTo(0.25)
|
|
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_DAMAGE_DONE_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("reports the latest phase and an estimate while stats load", function()
|
|
local data = ns.Amibis:CompareGear()
|
|
expect(data.latestPhase).toEqual("ZA")
|
|
expect(data.latestStatsComplete).toBeFalsy()
|
|
expect(type(data.latestCompletionRatio)).toEqual("number")
|
|
expect(data.latestCompletionRatio).toEqual(0)
|
|
end)
|
|
|
|
it("measures progress against the latest phase, not the selected one", function()
|
|
local latestList = ns.Data.BISLists:GetBISList("PRIEST", "Shadow", "ZA")
|
|
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_DAMAGE_DONE_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_DAMAGE_DONE_SHORT"] = 90,
|
|
},
|
|
}
|
|
end
|
|
AmibisDB.selectedPhase = "T4"
|
|
local data = ns.Amibis:CompareGear()
|
|
expect(data.phase).toEqual("T4")
|
|
expect(data.latestPhase).toEqual("ZA")
|
|
expect(ns.Amibis:GetCompletionRatio(data)).toBeCloseTo(1.0)
|
|
expect(data.latestCompletionRatio < 1.0).toBeTruthy()
|
|
expect(data.latestCompletionRatio > 0.3).toBeTruthy()
|
|
end)
|
|
|
|
it("ratio matches when the latest phase is also selected", function()
|
|
local list = ns.Data.BISLists:GetBISList("PRIEST", "Shadow", "ZA")
|
|
expect(list).toBeTruthy()
|
|
AmibisDB.selectedPhase = "ZA"
|
|
local data = ns.Amibis:CompareGear()
|
|
expect(data.phase).toEqual("ZA")
|
|
expect(data.latestPhase).toEqual("ZA")
|
|
end)
|
|
end)
|
|
|
|
describe("latest phase progress is independent of the selected phase", function()
|
|
before_each(function()
|
|
MockItems = {}
|
|
MockEquipped = {}
|
|
AmibisCharDB.overrideSpec = "Shadow"
|
|
AmibisDB.selectedPhase = "T4"
|
|
end)
|
|
|
|
it("falls back to latest-phase slot completion when the latest list is not cached", function()
|
|
local t4 = ns.Data.BISLists:GetBISList("PRIEST", "Shadow", "T4")
|
|
local za = ns.Data.BISLists:GetBISList("PRIEST", "Shadow", "ZA")
|
|
|
|
-- Make the selected phase look fully cached, but leave the ZA list uncached.
|
|
for _, entry in pairs(t4) do
|
|
MockItems[entry.itemID] = {
|
|
name = entry.name,
|
|
stats = {
|
|
["ITEM_MOD_INTELLECT_SHORT"] = 100,
|
|
["ITEM_MOD_SPELL_DAMAGE_DONE_SHORT"] = 50,
|
|
},
|
|
}
|
|
end
|
|
|
|
-- Equip two ZA BIS pieces without caching the rest of the list.
|
|
equip("Head", za["Head"].itemID)
|
|
equip("Shoulder", za["Shoulder"].itemID)
|
|
|
|
local total = 0
|
|
for _ in pairs(za) do total = total + 1 end
|
|
|
|
local data = ns.Amibis:CompareGear()
|
|
expect(data.latestPhase).toEqual("ZA")
|
|
expect(data.latestStatsComplete).toBeFalsy()
|
|
expect(data.latestCompletionRatio).toBeCloseTo(2 / total)
|
|
end)
|
|
|
|
it("reports the same ratio for every selected phase once stats are cached", function()
|
|
for _, phase in ipairs({ "T4", "T5", "T6", "ZA" }) do
|
|
for _, entry in pairs(ns.Data.BISLists:GetBISList("PRIEST", "Shadow", phase)) do
|
|
MockItems[entry.itemID] = {
|
|
name = entry.name,
|
|
stats = {
|
|
["ITEM_MOD_INTELLECT_SHORT"] = 100,
|
|
["ITEM_MOD_SPELL_DAMAGE_DONE_SHORT"] = 50,
|
|
},
|
|
}
|
|
end
|
|
end
|
|
|
|
local t6 = ns.Data.BISLists:GetBISList("PRIEST", "Shadow", "T6")
|
|
for slot, entry in pairs(t6) do
|
|
equip(slot, entry.itemID)
|
|
end
|
|
|
|
local results = {}
|
|
for _, phase in ipairs({ "T4", "T5", "T6", "ZA" }) do
|
|
AmibisDB.selectedPhase = phase
|
|
local data = ns.Amibis:CompareGear()
|
|
expect(data.latestStatsComplete).toBeTruthy()
|
|
table.insert(results, data.latestCompletionRatio)
|
|
end
|
|
|
|
for i = 2, #results do
|
|
expect(results[i]).toBeCloseTo(results[1])
|
|
end
|
|
end)
|
|
end)
|