Skip to content

Commit 44219d2

Browse files
committed
test(trade): cover stale result dropdown tooltip guards
1 parent fae1e92 commit 44219d2

1 file changed

Lines changed: 64 additions & 0 deletions

File tree

spec/System/TestTradeQueryCurrency_spec.lua

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,68 @@ describe("TradeQuery Currency Conversion", function()
6262
assert.are.equal(result, "5 chaos, 10 div")
6363
end)
6464
end)
65+
66+
describe("PriceItemRowDisplay tooltip guards", function()
67+
local function makeTooltip()
68+
return new("Tooltip")
69+
end
70+
71+
local function primePriceRow(resultTbl, sortedResultTbl)
72+
mock_tradeQuery.itemsTab = {
73+
activeItemSet = {},
74+
sockets = {},
75+
slots = {},
76+
AddItemTooltip = function() end,
77+
build = { AddStatComparesToTooltip = function() end },
78+
}
79+
mock_tradeQuery.controls = { fullPrice = {}, pbNotice = {} }
80+
mock_tradeQuery.totalPrice = {}
81+
mock_tradeQuery.itemIndexTbl = {}
82+
mock_tradeQuery.onlyWeightedBaseOutput = {}
83+
mock_tradeQuery.resultTbl = resultTbl
84+
mock_tradeQuery.sortedResultTbl = sortedResultTbl
85+
mock_tradeQuery.slotTables = { [1] = { slotName = "Ring 1" } }
86+
87+
mock_tradeQuery:PriceItemRowDisplay(1, nil, 0, 20)
88+
return mock_tradeQuery.controls.resultDropdown1
89+
end
90+
91+
it("returns early when sortedResultTbl row disappears before tooltip evaluation", function()
92+
local dropdown = primePriceRow({}, {})
93+
local tooltip = makeTooltip()
94+
95+
mock_tradeQuery.sortedResultTbl[1] = nil
96+
97+
local ok, err = pcall(function()
98+
dropdown.tooltipFunc(tooltip, "DROP", 1, nil)
99+
end)
100+
101+
assert.is_true(ok, tostring(err))
102+
assert.are.equal(0, #tooltip.lines)
103+
end)
104+
105+
it("returns early when the selected result entry disappears before tooltip evaluation", function()
106+
local dropdown = primePriceRow({
107+
[1] = {
108+
{
109+
currency = "chaos",
110+
amount = 5,
111+
item_string = "Rarity: RARE\nBehemoth Hold\nGold Ring",
112+
}
113+
}
114+
}, {
115+
[1] = { { index = 1 } }
116+
})
117+
local tooltip = makeTooltip()
118+
119+
mock_tradeQuery.resultTbl[1] = {}
120+
121+
local ok, err = pcall(function()
122+
dropdown.tooltipFunc(tooltip, "DROP", 1, dropdown.list[1])
123+
end)
124+
125+
assert.is_true(ok, tostring(err))
126+
assert.are.equal(0, #tooltip.lines)
127+
end)
128+
end)
65129
end)

0 commit comments

Comments
 (0)