Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions spec/System/TestTradeQueryGenerator_spec.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,58 @@
local dkjson = require "dkjson"

describe("TradeQueryGenerator", function()
local mock_queryGen = new("TradeQueryGenerator", { itemsTab = {} })

local function findStatFilter(queryTable, id)
for _, group in ipairs(queryTable.query.stats) do
for _, filter in ipairs(group.filters or {}) do
if filter.id == id then
return filter
end
end
end
end

local function finishQueryWithAttributeShortfall(shortfall, includeAttrReqs)
local queryGen = new("TradeQueryGenerator", { itemsTab = {} })
local queryTable
local errMsg
queryGen.modWeights = {
{ tradeModId = "explicit.stat_3299347043", weight = 1, meanStatDiff = 1 },
}
queryGen.tradeTypeIndex = 1
queryGen.requesterContext = {}
queryGen.requesterCallback = function(_, queryJson, queryErrMsg)
queryTable = dkjson.decode(queryJson)
errMsg = queryErrMsg
end
queryGen.calcContext = {
itemCategoryQueryStr = "ring",
special = {},
testItem = {
BuildAndParseRaw = function() end,
},
baseOutput = { TotalDPS = 100 },
baseStatValue = 0,
options = {
statWeights = { { stat = "TotalDPS", weightMult = 1 } },
includeAllWEMods = false,
includeAttrReqs = includeAttrReqs,
includeMirrored = true,
influence1 = 1,
influence2 = 1,
},
attrReqShortfall = shortfall,
}

local previousClosePopup = main.ClosePopup
main.ClosePopup = function() end
queryGen:FinishQuery()
main.ClosePopup = previousClosePopup

return queryTable, errMsg
end

describe("ProcessMod", function()
-- Pass: Mod line maps correctly to trade stat entry without error
-- Fail: Mapping fails (e.g., no match found), indicating incomplete stat parsing for curse mods, potentially missing curse-enabling items in queries
Expand Down Expand Up @@ -57,4 +109,25 @@ describe("TradeQueryGenerator", function()
_G.MAX_FILTERS = orig_max
end)
end)

describe("attribute requirement filters", function()
it("adds needed attribute pseudo filters to the generated query", function()
local queryTable, errMsg = finishQueryWithAttributeShortfall({ Str = 12, Dex = 34, Int = 56 }, true)
assert.is_nil(errMsg)
assert.are.equal(12, findStatFilter(queryTable, "pseudo.pseudo_total_strength").value.min)
assert.are.equal(34, findStatFilter(queryTable, "pseudo.pseudo_total_dexterity").value.min)
assert.are.equal(56, findStatFilter(queryTable, "pseudo.pseudo_total_intelligence").value.min)
end)

it("omits attribute pseudo filters when disabled or no shortfall exists", function()
local disabledQuery = finishQueryWithAttributeShortfall({ Str = 12, Dex = 34, Int = 56 }, false)
local zeroQuery = finishQueryWithAttributeShortfall({ Str = 0, Dex = 0, Int = 0 }, true)
assert.is_nil(findStatFilter(disabledQuery, "pseudo.pseudo_total_strength"))
assert.is_nil(findStatFilter(disabledQuery, "pseudo.pseudo_total_dexterity"))
assert.is_nil(findStatFilter(disabledQuery, "pseudo.pseudo_total_intelligence"))
assert.is_nil(findStatFilter(zeroQuery, "pseudo.pseudo_total_strength"))
assert.is_nil(findStatFilter(zeroQuery, "pseudo.pseudo_total_dexterity"))
assert.is_nil(findStatFilter(zeroQuery, "pseudo.pseudo_total_intelligence"))
end)
end)
end)
85 changes: 85 additions & 0 deletions spec/System/TestTradeQuery_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,90 @@ describe("TradeQuery", function()
end)
assert.are.equal(0, #tooltip.lines)
end)

it("returns early from action button tooltips when filtering clears the selected result", function()
local tq = newTradeQuery({
resultTbl = { [1] = { [1] = { item_string = "Rarity: RARE\nBehemoth Hold\nGold Ring", amount = 1, currency = "chaos" } } },
sortedResultTbl = { [1] = {} },
})
buildRow1Dropdown(tq)
local tooltip = new("Tooltip")

assert.has_no.errors(function()
tq.controls.importButton1.tooltipFunc(tooltip)
tq.controls.whisperButton1.tooltipFunc(tooltip)
end)
assert.are.equal(0, #tooltip.lines)
end)
end)

describe("attribute requirement result filtering", function()
local function newTradeQueryWithOutput(output, slotTbl)
local calcCalls = 0
local tq = new("TradeQuery", { itemsTab = {} })
tq.slotTables[1] = slotTbl or { slotName = "Ring 1" }
tq.resultTbl = {
[1] = {
[1] = { item_string = "Rarity: RARE\nBehemoth Hold\nGold Ring", amount = 1, currency = "chaos" },
},
}
tq.sortModes = {
Weight = "(Highest) Weighted Sum",
}
tq.itemsTab.build = {
calcsTab = {
GetMiscCalculator = function()
return function()
calcCalls = calcCalls + 1
return output
end, {}
end,
},
}
tq.itemsTab.slots = {
["Ring 1"] = {},
}
return tq, function()
return calcCalls
end
end

it("filters fetched results that do not meet attribute requirements", function()
local tq = newTradeQueryWithOutput({ ReqStr = 50, Str = 40, ReqDex = 0, Dex = 0, ReqInt = 0, Int = 0 })
tq.hideResultsFailingAttributeRequirements = true
local sortedItems = tq:SortFetchResults(1, tq.sortModes.Weight)
assert.are.equal(0, #sortedItems)
end)

it("keeps fetched results that meet attribute requirements", function()
local tq = newTradeQueryWithOutput({ ReqStr = 50, Str = 60, ReqDex = 30, Dex = 30, ReqInt = 20, Int = 25 })
tq.hideResultsFailingAttributeRequirements = true
local sortedItems = tq:SortFetchResults(1, tq.sortModes.Weight)
assert.are.equal(1, #sortedItems)
assert.are.equal(1, sortedItems[1].index)
end)

it("filters fetched results that do not meet Omniscience requirements", function()
local tq = newTradeQueryWithOutput({ ReqOmni = 100, Omni = 80 })
tq.hideResultsFailingAttributeRequirements = true
local sortedItems = tq:SortFetchResults(1, tq.sortModes.Weight)
assert.are.equal(0, #sortedItems)
end)

it("keeps fetched results without recalculating by default", function()
local tq, calcCalls = newTradeQueryWithOutput({ ReqStr = 50, Str = 40, ReqDex = 0, Dex = 0, ReqInt = 0, Int = 0 })
local sortedItems = tq:SortFetchResults(1, tq.sortModes.Weight)
assert.are.equal(1, #sortedItems)
assert.are.equal(1, sortedItems[1].index)
assert.are.equal(0, calcCalls())
end)

it("does not apply equipment attribute filtering to rows without a replacement slot", function()
local tq, calcCalls = newTradeQueryWithOutput({ ReqStr = 50, Str = 40, ReqDex = 0, Dex = 0, ReqInt = 0, Int = 0 }, { slotName = "Megalomaniac", unique = true })
local sortedItems = tq:SortFetchResults(1, tq.sortModes.Weight)
assert.are.equal(1, #sortedItems)
assert.are.equal(1, sortedItems[1].index)
assert.are.equal(0, calcCalls())
end)
end)
end)
Loading
Loading