Skip to content

Commit f853db1

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

2 files changed

Lines changed: 88 additions & 0 deletions

File tree

spec/System/TestTradeQueryCurrency_spec.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,5 @@ describe("TradeQuery Currency Conversion", function()
6262
assert.are.equal(result, "5 chaos, 10 div")
6363
end)
6464
end)
65+
6566
end)
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
describe("TradeQuery", function()
2+
local mock_tradeQuery = new("TradeQuery", { itemsTab = {} })
3+
4+
local function makeTooltip()
5+
return new("Tooltip")
6+
end
7+
8+
local function makeTradeResult(overrides)
9+
local result = {
10+
index = 1,
11+
currency = "chaos",
12+
amount = 5,
13+
item_string = "Rarity: RARE\nBehemoth Hold\nGold Ring",
14+
}
15+
for key, value in pairs(overrides or {}) do
16+
result[key] = value
17+
end
18+
return result
19+
end
20+
21+
local function makeResultState(result)
22+
result = result or makeTradeResult()
23+
return {
24+
resultTbl = {
25+
[1] = {
26+
[result.index] = {
27+
currency = result.currency,
28+
amount = result.amount,
29+
item_string = result.item_string,
30+
}
31+
}
32+
},
33+
sortedResultTbl = {
34+
[1] = {
35+
{ index = result.index }
36+
}
37+
}
38+
}
39+
end
40+
41+
local function makeTraderTooltipFixture(opts)
42+
opts = opts or {}
43+
mock_tradeQuery.itemsTab = {
44+
activeItemSet = {},
45+
sockets = {},
46+
slots = {},
47+
AddItemTooltip = function() end,
48+
build = { AddStatComparesToTooltip = function() end },
49+
}
50+
mock_tradeQuery.controls = { fullPrice = {}, pbNotice = {} }
51+
mock_tradeQuery.totalPrice = {}
52+
mock_tradeQuery.itemIndexTbl = {}
53+
mock_tradeQuery.onlyWeightedBaseOutput = {}
54+
mock_tradeQuery.resultTbl = opts.resultTbl or {}
55+
mock_tradeQuery.sortedResultTbl = opts.sortedResultTbl or {}
56+
mock_tradeQuery.slotTables = { [1] = { slotName = "Ring 1" } }
57+
58+
mock_tradeQuery:PriceItemRowDisplay(1, nil, 0, 20)
59+
return {
60+
tooltip = makeTooltip(),
61+
dropdown = mock_tradeQuery.controls.resultDropdown1,
62+
tradeQuery = mock_tradeQuery,
63+
}
64+
end
65+
66+
describe("result dropdown tooltip", function()
67+
it("returns early when the sorted row is stale", function()
68+
local fx = makeTraderTooltipFixture()
69+
fx.tradeQuery.sortedResultTbl[1] = nil
70+
local ok, err = pcall(function()
71+
fx.dropdown.tooltipFunc(fx.tooltip, "DROP", 1, nil)
72+
end)
73+
assert.is_true(ok, tostring(err))
74+
assert.are.equal(0, #fx.tooltip.lines)
75+
end)
76+
77+
it("returns early when the selected result entry is gone", function()
78+
local fx = makeTraderTooltipFixture(makeResultState())
79+
fx.tradeQuery.resultTbl[1] = {}
80+
local ok, err = pcall(function()
81+
fx.dropdown.tooltipFunc(fx.tooltip, "DROP", 1, fx.dropdown.list[1])
82+
end)
83+
assert.is_true(ok, tostring(err))
84+
assert.are.equal(0, #fx.tooltip.lines)
85+
end)
86+
end)
87+
end)

0 commit comments

Comments
 (0)