Compare commits
2
Commits
5ff421bd09
...
7fda3db472
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7fda3db472 | ||
|
|
c59a705d05 |
No files matched your search
@@ -10,23 +10,30 @@ Amibis/
|
|||||||
├── Amibis.lua # Core: DB init, item scanning, stat aggregation, gear comparison, slash commands
|
├── Amibis.lua # Core: DB init, item scanning, stat aggregation, gear comparison, slash commands
|
||||||
├── Data/
|
├── Data/
|
||||||
│ └── BISLists.lua # BIS data store (class → spec → phase → slot)
|
│ └── BISLists.lua # BIS data store (class → spec → phase → slot)
|
||||||
└── UI/
|
├── UI/
|
||||||
└── ComparisonFrame.lua # Main UI frame, slot rows, stats panel
|
│ └── ComparisonFrame.lua # Main UI frame, slot rows, stats panel, phase selector bar
|
||||||
|
└── Tests/ # Offline test suite (NOT in .toc — dev machine only)
|
||||||
|
├── run.lua # Entry point: lua5.4 Amibis/Tests/run.lua
|
||||||
|
├── harness.lua # describe/it/expect micro-framework
|
||||||
|
├── wow_mocks.lua # WoW API stubs + scriptable item fixtures
|
||||||
|
├── test_*.lua # Suites: data integrity, stat scanning, gear comparison
|
||||||
|
└── README.md # Coverage, layout, how to add tests
|
||||||
```
|
```
|
||||||
|
|
||||||
## Key facts
|
## Key facts
|
||||||
- **Load order** is defined in `Amibis.toc`: `Amibis.lua` → `Data/BISLists.lua` → `UI/ComparisonFrame.lua`
|
- **Load order** is defined in `Amibis.toc`: `Amibis.lua` → `Data/BISLists.lua` → `UI/ComparisonFrame.lua`
|
||||||
- **Slash command**: `/amibis` toggles the UI; `/amibis spec <SpecName>` overrides auto-detected spec; `/amibis spec clear` resets override
|
- **Slash command**: `/amibis` toggles the UI; `/amibis spec <SpecName>` overrides auto-detected spec; `/amibis spec clear` resets override. Phase is selected by clicking phase segments in the phase bar (T4 | T5 | T6).
|
||||||
- **SavedVariables**: `AmibisDB` (account-wide, stores selected phase), `AmibisCharDB` (per-character, stores frame position + spec override)
|
- **SavedVariables**: `AmibisDB` (account-wide, stores selected phase), `AmibisCharDB` (per-character, stores frame position + spec override)
|
||||||
- **Namespace pattern**: `local addonName, ns = ...` — all modules attach to `ns`
|
- **Namespace pattern**: `local addonName, ns = ...` — all modules attach to `ns`
|
||||||
- **No build/test/lint tooling** — tested in-game via WoW client
|
- **Tests**: offline suite in `Tests/` (mocked WoW API, no client needed) — run `lua5.4 Amibis/Tests/run.lua` from the repo root; see `Tests/README.md`. UI still verified in-game.
|
||||||
- **Currently**: Only T5 data populated
|
- **Currently**: T4 (Phase 1) and T6 (Phase 3) populated for all 9 classes; T5 (Phase 2) populated for the original specs (Druid Feral Combat + Paladin Protection/Retribution have T4/T6 only). Default phase is T6. Phase-progress bar measures completion against the **latest** available phase regardless of which phase is selected.
|
||||||
|
|
||||||
## Adding new BIS data
|
## Adding new BIS data
|
||||||
1. Add a `local CLASS_T5 = { ... }` table in `Data/BISLists.lua` following the existing `PRIEST_T5` structure
|
1. Add a `local CLASS_T4 = { ... }` table in `Data/BISLists.lua` following the existing `PRIEST_T4` structure
|
||||||
2. Register it in `BIS_DATA` under the appropriate class/spec/phase key
|
2. Register it in `BIS_DATA` under the appropriate class/spec/phase key
|
||||||
3. Each slot entry: `{ itemID, name, source, enchant? }`
|
3. Each slot entry: `{ itemID, name, source, enchant? }`
|
||||||
4. Ensure class name matches WoW's English class constant (e.g. `"WARRIOR"`, not `"Warrior"`)
|
4. Ensure class name matches WoW's English class constant (e.g. `"WARRIOR"`, not `"Warrior"`)
|
||||||
|
5. Phases are ordered via `PHASE_ORDER = { "T4", "T5", "T6" }` — T4 = Phase 1 (Karazhan/Gruul/Magtheridon), T5 = Phase 2 (SSC/TK), T6 = Phase 3 (Black Temple/Hyjal). T4/T6 data is sourced from wowtbc.gg `page-data` JSON (the per-phase `bis` variants, group/raid-flagged).
|
||||||
|
|
||||||
## UI conventions
|
## UI conventions
|
||||||
- ElvUI-style dark backdrop (`{0.07, 0.07, 0.07}`, alpha 0.95)
|
- ElvUI-style dark backdrop (`{0.07, 0.07, 0.07}`, alpha 0.95)
|
||||||
|
|||||||
+66
-4
@@ -5,7 +5,7 @@ ns.Amibis = Amibis
|
|||||||
Amibis.version = "1.0.0"
|
Amibis.version = "1.0.0"
|
||||||
|
|
||||||
local DEFAULT_AMIBIS_DB = {
|
local DEFAULT_AMIBIS_DB = {
|
||||||
selectedPhase = "T5",
|
selectedPhase = "T6",
|
||||||
}
|
}
|
||||||
|
|
||||||
local DEFAULT_AMIBIS_CHAR_DB = {
|
local DEFAULT_AMIBIS_CHAR_DB = {
|
||||||
@@ -60,6 +60,34 @@ function Amibis:GetStatKeysForSpec(class, spec)
|
|||||||
return GetUpgradeStatKeys(class, spec)
|
return GetUpgradeStatKeys(class, spec)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Amibis:StatRatio(equippedStats, bisStats, class, spec)
|
||||||
|
if not equippedStats or not bisStats then return 0 end
|
||||||
|
|
||||||
|
local statKeys = GetUpgradeStatKeys(class, spec)
|
||||||
|
local count, sum = 0, 0
|
||||||
|
for _, statKey in ipairs(statKeys) do
|
||||||
|
local bis = bisStats[statKey] or 0
|
||||||
|
if bis > 0 then
|
||||||
|
local current = equippedStats[statKey] or 0
|
||||||
|
local ratio = current / bis
|
||||||
|
if ratio > 1 then ratio = 1 end
|
||||||
|
sum = sum + ratio
|
||||||
|
count = count + 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if count == 0 then return 0 end
|
||||||
|
return sum / count
|
||||||
|
end
|
||||||
|
|
||||||
|
function Amibis:GetCompletionRatio(data)
|
||||||
|
if not data then return 0 end
|
||||||
|
if data.statsComplete and data.bisStats then
|
||||||
|
return self:StatRatio(data.equippedStats, data.bisStats, data.class, data.spec)
|
||||||
|
end
|
||||||
|
return (data.bisCount or 0) / math.max(1, data.totalSlots or 1)
|
||||||
|
end
|
||||||
|
|
||||||
local function InitializeDB()
|
local function InitializeDB()
|
||||||
if not AmibisDB then
|
if not AmibisDB then
|
||||||
AmibisDB = CopyTable(DEFAULT_AMIBIS_DB)
|
AmibisDB = CopyTable(DEFAULT_AMIBIS_DB)
|
||||||
@@ -183,9 +211,14 @@ local STAT_MAP = {
|
|||||||
["ITEM_MOD_HEALING_SHORT"] = "healing",
|
["ITEM_MOD_HEALING_SHORT"] = "healing",
|
||||||
}
|
}
|
||||||
|
|
||||||
local MAX_AGGREGATE_STATS = {
|
-- Stats that multiple WoW API keys map to (school-specific spell damage, haste
|
||||||
|
-- rating, etc.): only one alias is ever active, so take MAX instead of SUM.
|
||||||
|
local ALIAS_STATS = {
|
||||||
healing = true,
|
healing = true,
|
||||||
spellDamage = true,
|
spellDamage = true,
|
||||||
|
mp5 = true,
|
||||||
|
haste = true,
|
||||||
|
crit = true,
|
||||||
}
|
}
|
||||||
|
|
||||||
function Amibis:ScanItemStats(itemID)
|
function Amibis:ScanItemStats(itemID)
|
||||||
@@ -203,7 +236,7 @@ function Amibis:ScanItemStats(itemID)
|
|||||||
for wowKey, ourKey in pairs(STAT_MAP) do
|
for wowKey, ourKey in pairs(STAT_MAP) do
|
||||||
local value = stats[wowKey]
|
local value = stats[wowKey]
|
||||||
if value then
|
if value then
|
||||||
if MAX_AGGREGATE_STATS[ourKey] then
|
if ALIAS_STATS[ourKey] then
|
||||||
local current = result[ourKey]
|
local current = result[ourKey]
|
||||||
if not current or value > current then
|
if not current or value > current then
|
||||||
result[ourKey] = value
|
result[ourKey] = value
|
||||||
@@ -247,7 +280,7 @@ end
|
|||||||
function Amibis:CompareGear()
|
function Amibis:CompareGear()
|
||||||
local class = self:GetPlayerClass()
|
local class = self:GetPlayerClass()
|
||||||
local spec = AmibisCharDB.overrideSpec or self:GetPlayerSpec()
|
local spec = AmibisCharDB.overrideSpec or self:GetPlayerSpec()
|
||||||
local phase = AmibisDB.selectedPhase or "T5"
|
local phase = ns.Data.BISLists:ResolvePhase(class, spec, AmibisDB.selectedPhase or "T5")
|
||||||
|
|
||||||
local bisList = ns.Data.BISLists:GetBISList(class, spec, phase)
|
local bisList = ns.Data.BISLists:GetBISList(class, spec, phase)
|
||||||
if not bisList then
|
if not bisList then
|
||||||
@@ -357,6 +390,33 @@ function Amibis:CompareGear()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local latestPhase = ns.Data.BISLists:GetLatestPhase(class, spec)
|
||||||
|
local latestCompletionRatio = nil
|
||||||
|
if latestPhase and statsComplete then
|
||||||
|
local latestList = ns.Data.BISLists:GetBISList(class, spec, latestPhase)
|
||||||
|
if latestList then
|
||||||
|
local latestStatsComplete = true
|
||||||
|
for slotName, bisItem in pairs(latestList) do
|
||||||
|
if not GetItemInfo(bisItem.itemID) then
|
||||||
|
latestStatsComplete = false
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if latestStatsComplete then
|
||||||
|
if latestPhase == phase then
|
||||||
|
latestCompletionRatio = self:StatRatio(equippedStats, bisStats, class, spec)
|
||||||
|
else
|
||||||
|
local latestItems = {}
|
||||||
|
for slotName, bisItem in pairs(latestList) do
|
||||||
|
latestItems[slotName] = { itemID = bisItem.itemID }
|
||||||
|
end
|
||||||
|
local latestStats = self:AggregateStats(latestItems)
|
||||||
|
latestCompletionRatio = self:StatRatio(equippedStats, latestStats, class, spec)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
class = class,
|
class = class,
|
||||||
spec = spec,
|
spec = spec,
|
||||||
@@ -369,6 +429,8 @@ function Amibis:CompareGear()
|
|||||||
equippedStats = equippedStats,
|
equippedStats = equippedStats,
|
||||||
bisStats = bisStats,
|
bisStats = bisStats,
|
||||||
statsComplete = statsComplete,
|
statsComplete = statsComplete,
|
||||||
|
latestPhase = latestPhase,
|
||||||
|
latestCompletionRatio = latestCompletionRatio,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
+956
-26
File diff suppressed because it is too large.
Load diff
@@ -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.
|
||||||
@@ -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
|
||||||
@@ -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)
|
||||||
@@ -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)
|
||||||
@@ -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)
|
||||||
@@ -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)
|
||||||
@@ -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 = {}
|
||||||
@@ -238,6 +238,10 @@ local StatsPanelTitle = nil
|
|||||||
local StatLabels = {}
|
local StatLabels = {}
|
||||||
local StatValues = {}
|
local StatValues = {}
|
||||||
local UpgradeLabels = {}
|
local UpgradeLabels = {}
|
||||||
|
local PhaseBar = nil
|
||||||
|
local PhaseProgressFill = nil
|
||||||
|
local PhaseProgressText = nil
|
||||||
|
local PhaseButtons = {}
|
||||||
|
|
||||||
local STAT_LABELS = {
|
local STAT_LABELS = {
|
||||||
healing = "+Healing",
|
healing = "+Healing",
|
||||||
@@ -424,6 +428,85 @@ local function StatKeysEqual(a, b)
|
|||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function CreatePhaseBar(parent, anchor)
|
||||||
|
local bar = CreateFrame("Frame", nil, parent, "BackdropTemplate")
|
||||||
|
bar:SetPoint("TOPLEFT", anchor, "BOTTOMLEFT", 0, -4)
|
||||||
|
bar:SetPoint("TOPRIGHT", anchor, "BOTTOMRIGHT", 0, -4)
|
||||||
|
bar:SetHeight(24)
|
||||||
|
|
||||||
|
bar:SetBackdrop({
|
||||||
|
bgFile = "Interface\\Buttons\\WHITE8x8",
|
||||||
|
edgeFile = "Interface\\Buttons\\WHITE8x8",
|
||||||
|
tile = false,
|
||||||
|
tileSize = 0,
|
||||||
|
edgeSize = 1,
|
||||||
|
insets = { left = 0, right = 0, top = 0, bottom = 0 }
|
||||||
|
})
|
||||||
|
bar:SetBackdropColor(ELVUI_TITLE_BG[1], ELVUI_TITLE_BG[2], ELVUI_TITLE_BG[3], 0.9)
|
||||||
|
bar:SetBackdropBorderColor(ELVUI_BORDER_COLOR[1], ELVUI_BORDER_COLOR[2], ELVUI_BORDER_COLOR[3], ELVUI_BORDER_ALPHA)
|
||||||
|
|
||||||
|
local fill = bar:CreateTexture(nil, "BACKGROUND")
|
||||||
|
fill:SetTexture("Interface\\Buttons\\WHITE8x8")
|
||||||
|
fill:SetVertexColor(0, 0.68, 0.3, 0.28)
|
||||||
|
fill:SetPoint("TOPLEFT", bar, "TOPLEFT", 1, -1)
|
||||||
|
fill:SetPoint("BOTTOMLEFT", bar, "BOTTOMLEFT", 1, 1)
|
||||||
|
fill:SetWidth(1)
|
||||||
|
|
||||||
|
local progressText = bar:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
|
||||||
|
progressText:SetPoint("RIGHT", bar, "RIGHT", -6, 0)
|
||||||
|
progressText:SetText("")
|
||||||
|
progressText:SetTextColor(0.75, 0.95, 0.75, 1)
|
||||||
|
|
||||||
|
PhaseBar = bar
|
||||||
|
PhaseProgressFill = fill
|
||||||
|
PhaseProgressText = progressText
|
||||||
|
return bar
|
||||||
|
end
|
||||||
|
|
||||||
|
local function ClearPhaseButtons()
|
||||||
|
for _, btn in ipairs(PhaseButtons) do
|
||||||
|
btn:Hide()
|
||||||
|
btn:SetParent(nil)
|
||||||
|
end
|
||||||
|
PhaseButtons = {}
|
||||||
|
end
|
||||||
|
|
||||||
|
local function RebuildPhaseButtons(class, spec, activePhase)
|
||||||
|
ClearPhaseButtons()
|
||||||
|
local phases = ns.Data.BISLists:GetAvailablePhases(class, spec)
|
||||||
|
local barWidth = PhaseBar:GetWidth()
|
||||||
|
local count = #phases
|
||||||
|
if count == 0 or barWidth <= 0 then return end
|
||||||
|
local segWidth = barWidth / count
|
||||||
|
|
||||||
|
for i, phase in ipairs(phases) do
|
||||||
|
local btn = CreateFrame("Button", nil, PhaseBar)
|
||||||
|
btn:SetPoint("TOPLEFT", PhaseBar, "TOPLEFT", (i - 1) * segWidth, 0)
|
||||||
|
btn:SetSize(segWidth, 24)
|
||||||
|
|
||||||
|
local text = btn:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
|
||||||
|
text:SetPoint("CENTER", btn, "CENTER", 0, 0)
|
||||||
|
text:SetText(phase)
|
||||||
|
if phase == activePhase then
|
||||||
|
text:SetTextColor(1, 0.82, 0, 1)
|
||||||
|
else
|
||||||
|
text:SetTextColor(0.45, 0.45, 0.45, 1)
|
||||||
|
end
|
||||||
|
|
||||||
|
if phase ~= activePhase then
|
||||||
|
btn:SetScript("OnClick", function()
|
||||||
|
AmibisDB.selectedPhase = phase
|
||||||
|
ns.UI.RefreshUI()
|
||||||
|
end)
|
||||||
|
btn:EnableMouse(true)
|
||||||
|
else
|
||||||
|
btn:EnableMouse(false)
|
||||||
|
end
|
||||||
|
|
||||||
|
PhaseButtons[i] = btn
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local function InitializeUI()
|
local function InitializeUI()
|
||||||
if MainFrame then return end
|
if MainFrame then return end
|
||||||
|
|
||||||
@@ -431,7 +514,9 @@ local function InitializeUI()
|
|||||||
local titleBar, title = CreateTitleBar(MainFrame)
|
local titleBar, title = CreateTitleBar(MainFrame)
|
||||||
TitleText = title
|
TitleText = title
|
||||||
|
|
||||||
local summaryBar, summary = CreateSummaryBar(MainFrame, titleBar)
|
local phaseBar = CreatePhaseBar(MainFrame, titleBar)
|
||||||
|
|
||||||
|
local summaryBar, summary = CreateSummaryBar(MainFrame, phaseBar)
|
||||||
SummaryText = summary
|
SummaryText = summary
|
||||||
|
|
||||||
local header = CreateColumnHeaders(MainFrame, summaryBar)
|
local header = CreateColumnHeaders(MainFrame, summaryBar)
|
||||||
@@ -483,6 +568,13 @@ function ns.UI.RefreshUI()
|
|||||||
UpgradeLabels[i]:SetText("")
|
UpgradeLabels[i]:SetText("")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
ClearPhaseButtons()
|
||||||
|
if PhaseProgressFill then
|
||||||
|
PhaseProgressFill:SetWidth(1)
|
||||||
|
end
|
||||||
|
if PhaseProgressText then
|
||||||
|
PhaseProgressText:SetText("")
|
||||||
|
end
|
||||||
for i = 1, MAX_VISIBLE_ROWS do
|
for i = 1, MAX_VISIBLE_ROWS do
|
||||||
SlotRows[i].slotText:SetText("")
|
SlotRows[i].slotText:SetText("")
|
||||||
SlotRows[i].equippedText:SetText("")
|
SlotRows[i].equippedText:SetText("")
|
||||||
@@ -496,6 +588,18 @@ function ns.UI.RefreshUI()
|
|||||||
|
|
||||||
SummaryText:SetText(string.format("BIS: %d/%d slots", data.bisCount, data.totalSlots))
|
SummaryText:SetText(string.format("BIS: %d/%d slots", data.bisCount, data.totalSlots))
|
||||||
|
|
||||||
|
if PhaseBar then
|
||||||
|
RebuildPhaseButtons(data.class, data.spec, data.phase)
|
||||||
|
local ratio = data.latestCompletionRatio or Amibis:GetCompletionRatio(data)
|
||||||
|
local targetPhase = data.latestPhase or data.phase
|
||||||
|
if PhaseProgressFill then
|
||||||
|
PhaseProgressFill:SetWidth(math.max(1, PhaseBar:GetWidth() * ratio))
|
||||||
|
end
|
||||||
|
if PhaseProgressText then
|
||||||
|
PhaseProgressText:SetText(string.format("%d%% to %s", math.floor(ratio * 100 + 0.5), targetPhase))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
for i = 1, MAX_VISIBLE_ROWS do
|
for i = 1, MAX_VISIBLE_ROWS do
|
||||||
local row = SlotRows[i]
|
local row = SlotRows[i]
|
||||||
local slotData = data.slots[i]
|
local slotData = data.slots[i]
|
||||||
|
|||||||
Reference in new issue
Block a user