|
| 1 | +describe("TradeQuery", function() |
| 2 | + describe("result dropdown tooltipFunc", function() |
| 3 | + -- Builds a TradeQuery with the strict minimum needed for |
| 4 | + -- PriceItemRowDisplay to construct row 1 without exploding. Only the |
| 5 | + -- two itemsTab subtables read by the slot lookup at the top of |
| 6 | + -- PriceItemRowDisplay need to be created here; everything else either |
| 7 | + -- lives behind a callback we never trigger, or is already initialized |
| 8 | + -- by the TradeQuery constructor. |
| 9 | + local function newTradeQuery(state) |
| 10 | + local tq = new("TradeQuery", { itemsTab = {} }) |
| 11 | + tq.itemsTab.activeItemSet = {} |
| 12 | + tq.itemsTab.slots = {} |
| 13 | + tq.slotTables[1] = { slotName = "Ring 1" } |
| 14 | + if state.resultTbl then tq.resultTbl = state.resultTbl end |
| 15 | + if state.sortedResultTbl then tq.sortedResultTbl = state.sortedResultTbl end |
| 16 | + return tq |
| 17 | + end |
| 18 | + |
| 19 | + -- Builds row 1 of the trader UI and returns the dropdown that owns the |
| 20 | + -- tooltipFunc we want to exercise. |
| 21 | + local function buildRow1Dropdown(tq) |
| 22 | + tq:PriceItemRowDisplay(1, nil, 0, 20) |
| 23 | + return tq.controls.resultDropdown1 |
| 24 | + end |
| 25 | + |
| 26 | + it("returns early when sortedResultTbl[row_idx] is missing", function() |
| 27 | + -- No sorted results at all -> first guard must short-circuit. |
| 28 | + local tq = newTradeQuery({}) |
| 29 | + local dropdown = buildRow1Dropdown(tq) |
| 30 | + local tooltip = new("Tooltip") |
| 31 | + |
| 32 | + assert.has_no.errors(function() |
| 33 | + dropdown.tooltipFunc(tooltip, "DROP", 1, nil) |
| 34 | + end) |
| 35 | + assert.are.equal(0, #tooltip.lines) |
| 36 | + end) |
| 37 | + |
| 38 | + it("returns early when the backing result entry has been cleared", function() |
| 39 | + -- The dropdown must be built against a valid result so that |
| 40 | + -- PriceItemRowDisplay's construction loop succeeds; we wipe |
| 41 | + -- resultTbl[1] only afterwards, to simulate a stale tooltip |
| 42 | + -- callback firing after the results were invalidated. |
| 43 | + local tq = newTradeQuery({ |
| 44 | + resultTbl = { [1] = { [1] = { item_string = "Rarity: RARE\nBehemoth Hold\nGold Ring" } } }, |
| 45 | + sortedResultTbl = { [1] = { { index = 1 } } }, |
| 46 | + }) |
| 47 | + local dropdown = buildRow1Dropdown(tq) |
| 48 | + tq.resultTbl[1] = {} |
| 49 | + local tooltip = new("Tooltip") |
| 50 | + |
| 51 | + assert.has_no.errors(function() |
| 52 | + dropdown.tooltipFunc(tooltip, "DROP", 1, nil) |
| 53 | + end) |
| 54 | + assert.are.equal(0, #tooltip.lines) |
| 55 | + end) |
| 56 | + end) |
| 57 | +end) |
0 commit comments