-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Expand file tree
/
Copy pathTestRadiusJewelStatDiff_spec.lua
More file actions
803 lines (689 loc) · 27.6 KB
/
Copy pathTestRadiusJewelStatDiff_spec.lua
File metadata and controls
803 lines (689 loc) · 27.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
-- Helper: BFS from class start to find and allocate path to nearest jewel socket
local function allocatePathToSocket(spec)
local classStart
for _, node in pairs(spec.allocNodes) do
if node.type == "ClassStart" then
classStart = node
break
end
end
if not classStart then return nil end
local queue = { classStart }
local visited = { [classStart.id] = true }
local parent = { }
local targetSocket
local head = 1
while head <= #queue do
local current = queue[head]
head = head + 1
if current.isJewelSocket then
targetSocket = current
break
end
for _, linked in ipairs(current.linked) do
if not visited[linked.id] and linked.type ~= "Mastery" and linked.type ~= "AscendClassStart" then
visited[linked.id] = true
parent[linked.id] = current
queue[#queue + 1] = linked
end
end
end
if not targetSocket then return nil end
-- Trace path back and allocate all nodes
local current = targetSocket
while current do
current.alloc = true
spec.allocNodes[current.id] = current
current = parent[current.id]
end
return targetSocket
end
local function allocatePathToNode(spec, targetNode)
local classStart
for _, node in pairs(spec.allocNodes) do
if node.type == "ClassStart" then
classStart = node
break
end
end
if not classStart then return false end
local queue = { classStart }
local visited = { [classStart.id] = true }
local parent = { }
local head = 1
while head <= #queue do
local current = queue[head]
head = head + 1
if current.id == targetNode.id then
break
end
for _, linked in ipairs(current.linked) do
if not visited[linked.id] and linked.type ~= "Mastery" and linked.type ~= "AscendClassStart" then
visited[linked.id] = true
parent[linked.id] = current
queue[#queue + 1] = linked
end
end
end
if not visited[targetNode.id] then return false end
local current = targetNode
while current do
current.alloc = true
spec.allocNodes[current.id] = current
current = parent[current.id]
end
return true
end
-- Helper: find allocated non-socket non-keystone nodes in a socket's radius
local function findAllocatedNodesInRadius(spec, socketNode, radiusIndex)
local result = { }
local inRadius = socketNode.nodesInRadius and socketNode.nodesInRadius[radiusIndex]
for nodeId in pairs(inRadius or { }) do
local node = spec.nodes[nodeId]
if node and node.alloc and node.type ~= "Socket" and node.type ~= "Keystone"
and node.type ~= "ClassStart" and node.type ~= "AscendClassStart" then
result[#result + 1] = node
end
end
return result
end
-- Helper: index in nodesInRadius for a named jewel radius (e.g. "Large").
-- Reads data.jewelRadius rather than hardcoding the index, so the tests stay
-- correct if the radius table is ever reordered.
local function radiusIndexFor(label)
for index, info in ipairs(data.jewelRadius) do
if info.label == label then
return index
end
end
end
-- Helper: standard test prelude — allocate a path to the nearest jewel socket,
-- run the build pipeline once, and return the spec + socket.
local function setupAllocatedSocket()
local spec = build.spec
local socketNode = allocatePathToSocket(spec)
spec:BuildAllDependsAndPaths()
runCallback("OnFrame")
assert.is_truthy(socketNode, "Should find a jewel socket")
return spec, socketNode
end
local function setupAllocatedSockets(count)
local spec = build.spec
local sockets = { }
local sortedSockets = { }
for _, node in pairs(spec.nodes) do
if node.isJewelSocket then
sortedSockets[#sortedSockets + 1] = node
end
end
table.sort(sortedSockets, function(a, b)
return a.id < b.id
end)
for _, socketNode in ipairs(sortedSockets) do
if allocatePathToNode(spec, socketNode) then
sockets[#sockets + 1] = socketNode
if #sockets >= count then
break
end
end
end
if #sockets < count then
pending("Could not allocate the requested number of jewel sockets for this tree layout")
return spec, sockets
end
spec:BuildAllDependsAndPaths()
runCallback("OnFrame")
return spec, sockets
end
local function rebuildBuild()
build.buildFlag = true
runCallback("OnFrame")
end
-- Helper: install an existing item into a jewel socket, bypassing
-- BuildClusterJewelGraphs. Returns the slot.
local function equipJewelInSocket(item, socketNode)
build.itemsTab:AddItem(item, true)
build.spec.jewels[socketNode.id] = item.id
local slot = build.itemsTab.sockets[socketNode.id]
if slot then
slot.selItemId = item.id
end
return slot
end
-- Helper: minimal Thread of Hope item. Uses "Radius: Variable" + a single
-- variant with "Only affects Passives in Large Ring", which is the real in-game
-- parsing path: the mod sets jewelData.radiusIndex (an annular ring index, not
-- the same as the full-circle index 3 that "Radius: Large" would produce).
local function newThreadOfHope()
return new("Item", "Rarity: UNIQUE\n" ..
"Thread of Hope\n" ..
"Crimson Jewel\n" ..
"Variant: Large Ring\n" ..
"Selected Variant: 1\n" ..
"Radius: Variable\n" ..
"Implicits: 0\n" ..
"Only affects Passives in Large Ring\n" ..
"Passives in Radius can be Allocated without being connected to your Tree\n")
end
local function newCustomLeapJewel(name)
return new("Item", "Rarity: RARE\n" ..
name .. "\n" ..
"Crimson Jewel\n" ..
"Radius: Variable\n" ..
"Implicits: 0\n" ..
"Only affects Passives in Large Ring\n" ..
"Passives in Radius can be Allocated without being connected to your Tree\n")
end
local function newPlainJewel()
return new("Item", "Rarity: RARE\n" ..
"Plain Spark\n" ..
"Crimson Jewel\n" ..
"Implicits: 0\n")
end
local function newSplitPersonality()
return new("Item", "Rarity: UNIQUE\n" ..
"Split Personality\n" ..
"Crimson Jewel\n" ..
"Implicits: 0\n" ..
"+5 to Strength\n" ..
"This Jewel's Socket has 25% increased effect per Allocated Passive Skill between it and your Class' starting location\n")
end
-- Helper: minimal Impossible Escape item. Uses "Radius: Small" and targets
-- a specific keystone. The parser populates both impossibleEscapeKeystone
-- and impossibleEscapeKeystones from the "in Radius of X" mod.
local function newImpossibleEscape(keystoneName)
return new("Item", "Rarity: UNIQUE\n" ..
"Impossible Escape\n" ..
"Viridian Jewel\n" ..
"Radius: Small\n" ..
"Implicits: 0\n" ..
"Passive Skills in Radius of " .. keystoneName .. " can be Allocated without being connected to your Tree\n")
end
-- Helper: equip a Thread of Hope in a socket and return the item.
local function equipThreadOfHope(socketNode)
local item = newThreadOfHope()
equipJewelInSocket(item, socketNode)
return item
end
-- Helper: minimal Lethal Pride item — only the lines the parser needs to
-- populate jewelData.conqueredBy and jewelRadiusIndex. Variants and flavour
-- text are intentionally omitted; the tests exercise behavior, not the parser
-- against the full serialized form.
local function newLethalPride()
return new("Item", "Rarity: UNIQUE\n" ..
"Lethal Pride\n" ..
"Timeless Jewel\n" ..
"Radius: Large\n" ..
"Implicits: 0\n" ..
"Commanded leadership over 10000 warriors under Kaom\n")
end
-- Helper: simulate a Karui Timeless conquest on an allocated node by replacing
-- its modList with a known +100 Life mod. The LUT binary files do not load in
-- the headless test environment, so the real BuildAllDependsAndPaths conquest
-- path cannot run. This must be called *after* runCallback("OnFrame"), or BADP
-- will reset the modList back to the original tree node modList.
local function simulateKaruiConquest(node)
node.conqueredBy = { id = 10000, conqueror = { id = 1, type = "karui" } }
node.modList = new("ModList")
node.modList:NewMod("Life", "BASE", 100, "Timeless Jewel")
end
local function overrideNodeWithLife(spec, node, life)
local override = copyTable(spec.tree.nodes[node.id], true)
override.id = node.id
override.dn = node.dn
override.sd = { "+" .. life .. " to maximum Life" }
override.modList = new("ModList")
override.modList:NewMod("Life", "BASE", life, "Test")
spec.hashOverrides[node.id] = override
end
-- Helper: find the first unallocated, non-Mastery, non-Keystone node in a
-- socket's radius that is reachable through an intuitiveLeapLike jewel.
local function findIntuitiveLeapTarget(spec, socketNode, radiusIndex)
local inRadius = socketNode.nodesInRadius and socketNode.nodesInRadius[radiusIndex]
for nodeId in pairs(inRadius or { }) do
local node = spec.nodes[nodeId]
if node and not node.alloc and #node.intuitiveLeapLikesAffecting > 0
and node.type ~= "Mastery" and node.type ~= "Keystone" then
return node
end
end
return nil
end
-- Helper: true iff any tooltip line contains the given needle (literal match).
local function tooltipContains(tooltip, needle)
for _, line in ipairs(tooltip.lines) do
if (line.text or ""):find(needle, 1, true) then
return true
end
end
return false
end
local function tooltipText(tooltip)
local lines = { }
for _, line in ipairs(tooltip.lines) do
if line.text then
lines[#lines + 1] = line.text
end
end
return table.concat(lines, "\n")
end
local function tooltipContainsNegativeStat(tooltip, label)
for _, line in ipairs(tooltip.lines) do
local text = line.text or ""
if text:find(colorCodes.NEGATIVE, 1, true) and text:find(label, 1, true) then
return true
end
end
return false
end
local function sortedNodeIds(nodeMap)
local nodeIds = { }
for nodeId in pairs(nodeMap or { }) do
nodeIds[#nodeIds + 1] = nodeId
end
table.sort(nodeIds)
return nodeIds
end
local function findLeapOverlapCandidates(spec, radiusIndex)
local socketList = { }
for _, node in pairs(spec.nodes) do
if node.isJewelSocket and node.nodesInRadius and node.nodesInRadius[radiusIndex] then
socketList[#socketList + 1] = node
end
end
table.sort(socketList, function(a, b)
return a.id < b.id
end)
local candidates = { }
for i = 1, #socketList - 1 do
for j = i + 1, #socketList do
for _, nodeId in ipairs(sortedNodeIds(socketList[i].nodesInRadius[radiusIndex])) do
if socketList[j].nodesInRadius[radiusIndex][nodeId] then
local node = spec.nodes[nodeId]
if node and node.type ~= "Mastery" and node.type ~= "Keystone" and node.type ~= "Socket"
and node.type ~= "ClassStart" and node.type ~= "AscendClassStart" then
candidates[#candidates + 1] = {
socketAId = socketList[i].id,
socketBId = socketList[j].id,
targetNodeId = nodeId,
}
end
end
end
end
end
return candidates
end
describe("TestRadiusJewelStatDiff", function()
before_each(function()
newBuild()
end)
teardown(function() end)
it("Lethal Pride item parses conqueredBy correctly", function()
local item = newLethalPride()
build.itemsTab:AddItem(item, true)
assert.is_truthy(item.jewelData, "Item should have jewelData")
assert.is_truthy(item.jewelData.conqueredBy, "Item should have conqueredBy")
assert.are.equals(10000, item.jewelData.conqueredBy.id)
assert.are.equals("karui", item.jewelData.conqueredBy.conqueror.type)
assert.is_truthy(item.jewelRadiusIndex, "Item should have jewelRadiusIndex")
end)
it("Thread of Hope item parses intuitiveLeapLike correctly", function()
local item = newThreadOfHope()
build.itemsTab:AddItem(item, true)
assert.is_truthy(item.jewelData, "Item should have jewelData")
assert.is_truthy(item.jewelData.intuitiveLeapLike, "Item should have intuitiveLeapLike")
assert.is_truthy(item.jewelRadiusIndex, "Item should have jewelRadiusIndex")
end)
it("calcFunc removeNodes/addNodes changes output for allocated nodes", function()
local spec, socketNode = setupAllocatedSocket()
local nodesInRadius = findAllocatedNodesInRadius(spec, spec.nodes[socketNode.id], radiusIndexFor("Large"))
assert.is_true(#nodesInRadius > 0, "Should have allocated nodes in radius")
local calcFunc = build.calcsTab:GetMiscCalculator(build)
local testNode = nodesInRadius[1]
local origNode = spec.tree.nodes[testNode.id]
assert.is_truthy(calcFunc({ removeNodes = { [testNode] = true } }),
"calcFunc with removeNodes should return output")
assert.is_truthy(calcFunc({ removeNodes = { [testNode] = true }, addNodes = { [origNode] = true } }),
"calcFunc with removeNodes+addNodes should return output")
end)
it("timeless jewel comparison: removeNodes/addNodes on conquered nodes changes output", function()
local spec, socketNode = setupAllocatedSocket()
local nodesInRadius = findAllocatedNodesInRadius(spec, spec.nodes[socketNode.id], radiusIndexFor("Large"))
assert.is_true(#nodesInRadius > 0, "Should have allocated nodes in radius")
local conqueredNode = nodesInRadius[1]
local origNode = spec.tree.nodes[conqueredNode.id]
simulateKaruiConquest(conqueredNode)
-- Snapshot the state including the simulated conquest, then revert
-- the conquered node back to the original tree node via override.
local calcFunc, calcBase = build.calcsTab:GetMiscCalculator(build)
local output = calcFunc({
removeNodes = { [conqueredNode] = true },
addNodes = { [origNode] = true },
})
assert.are_not.equals(calcBase.Life, output.Life,
"Reverting conquered node should change Life output")
end)
it("Thread of Hope enables allocation of unconnected nodes", function()
local spec, socketNode = setupAllocatedSocket()
local item = equipThreadOfHope(socketNode)
spec:BuildAllDependsAndPaths()
runCallback("OnFrame")
local targetNode = findIntuitiveLeapTarget(spec, spec.nodes[socketNode.id], item.jewelRadiusIndex)
assert.is_truthy(targetNode, "Should find an unallocated node affected by Thread of Hope")
spec:AllocNode(targetNode)
spec:BuildAllDependsAndPaths()
runCallback("OnFrame")
assert.is_true(targetNode.alloc, "Node should be allocated")
assert.is_false(targetNode.connectedToStart, "Node should not be connected to start")
local nodesInLeapRadius = spec:NodesInIntuitiveLeapLikeRadius(spec.nodes[socketNode.id])
local found = false
for _, node in ipairs(nodesInLeapRadius) do
if node.id == targetNode.id then
found = true
break
end
end
assert.is_true(found, "NodesInIntuitiveLeapLikeRadius should include the allocated node")
end)
it("Thread of Hope removal comparison removes dependent nodes via override", function()
local spec, socketNode = setupAllocatedSocket()
local item = equipThreadOfHope(socketNode)
spec:BuildAllDependsAndPaths()
runCallback("OnFrame")
local targetNode = findIntuitiveLeapTarget(spec, spec.nodes[socketNode.id], item.jewelRadiusIndex)
assert.is_truthy(targetNode, "Should find a node to allocate through Thread of Hope")
spec:AllocNode(targetNode)
spec:BuildAllDependsAndPaths()
runCallback("OnFrame")
-- Build override like ItemsTab does: remove nodes only reachable through the jewel
local override = { removeNodes = { } }
for _, node in ipairs(spec:NodesInIntuitiveLeapLikeRadius(spec.nodes[socketNode.id])) do
if not node.connectedToStart then
override.removeNodes[node] = true
end
end
assert.is_truthy(override.removeNodes[spec.nodes[targetNode.id]],
"Node allocated through Thread of Hope should be in removeNodes")
local calcFunc = build.calcsTab:GetMiscCalculator(build)
assert.is_truthy(calcFunc(override), "calcFunc with removeNodes should return output")
end)
it("intuitiveLeapLike replacement comparison removes nodes unsupported by the new jewel", function()
local spec, socketNode = setupAllocatedSocket()
local leapItem = newCustomLeapJewel("Leap Spark")
local slot = equipJewelInSocket(leapItem, socketNode)
spec:BuildAllDependsAndPaths()
runCallback("OnFrame")
local targetNode = findIntuitiveLeapTarget(spec, spec.nodes[socketNode.id], leapItem.jewelRadiusIndex)
assert.is_truthy(targetNode, "Should find a node to allocate through the radius jewel")
overrideNodeWithLife(spec, targetNode, 100)
spec:BuildAllDependsAndPaths()
runCallback("OnFrame")
targetNode = spec.nodes[targetNode.id]
spec:AllocNode(targetNode)
spec:BuildAllDependsAndPaths()
rebuildBuild()
assert.is_true(targetNode.alloc, "Node should be allocated")
assert.is_false(targetNode.connectedToStart, "Node should be supported only by the radius jewel")
local plainJewel = newPlainJewel()
build.itemsTab:AddItem(plainJewel, true)
local tooltip = new("Tooltip")
build.itemsTab:AddItemTooltip(tooltip, plainJewel, slot)
assert.is_true(tooltipContains(tooltip, "Equipping this item in"),
"Replacing the radius jewel should show the stat loss from unsupported nodes")
assert.is_true(tooltipContainsNegativeStat(tooltip, "Total Life"),
"Replacing the radius jewel should remove the life node only supported by that jewel:\n" .. tooltipText(tooltip))
end)
it("intuitiveLeapLike removal comparison keeps nodes supported by another radius jewel", function()
local probeItem = newCustomLeapJewel("Probe Spark")
build.itemsTab:AddItem(probeItem, true)
local radiusIndex = probeItem.jewelRadiusIndex
local candidates = findLeapOverlapCandidates(build.spec, radiusIndex)
assert.is_true(#candidates > 0, "Should find jewel sockets with overlapping radius")
local spec, socketA, socketB, targetNodeId
for _, candidate in ipairs(candidates) do
newBuild()
spec = build.spec
socketA = spec.nodes[candidate.socketAId]
socketB = spec.nodes[candidate.socketBId]
assert.is_truthy(socketA, "First overlap socket should exist")
assert.is_truthy(socketB, "Second overlap socket should exist")
assert.is_true(allocatePathToNode(spec, socketA), "Should allocate path to first socket")
assert.is_true(allocatePathToNode(spec, socketB), "Should allocate path to second socket")
spec:BuildAllDependsAndPaths()
runCallback("OnFrame")
if not spec.nodes[candidate.targetNodeId].alloc then
targetNodeId = candidate.targetNodeId
break
end
end
assert.is_truthy(targetNodeId, "Should find an overlap target not already allocated by the socket paths")
local itemA = newCustomLeapJewel("First Leap")
local slotA = equipJewelInSocket(itemA, socketA)
local itemB = newCustomLeapJewel("Second Leap")
equipJewelInSocket(itemB, socketB)
spec:BuildAllDependsAndPaths()
runCallback("OnFrame")
local targetNode = spec.nodes[targetNodeId]
assert.are.equals(2, #targetNode.intuitiveLeapLikesAffecting,
"Target node should be supported by both radius jewels")
overrideNodeWithLife(spec, targetNode, 100)
spec:BuildAllDependsAndPaths()
runCallback("OnFrame")
targetNode = spec.nodes[targetNodeId]
spec:AllocNode(targetNode)
spec:BuildAllDependsAndPaths()
rebuildBuild()
assert.is_true(targetNode.alloc, "Overlap node should be allocated")
assert.is_false(targetNode.connectedToStart, "Overlap node should be supported only by radius jewels")
assert.are.equals(2, #targetNode.intuitiveLeapLikesAffecting,
"Allocated overlap node should still be supported by both radius jewels")
local tooltip = new("Tooltip")
build.itemsTab:AddItemTooltip(tooltip, itemA, slotA)
assert.is_false(tooltipContainsNegativeStat(tooltip, "Total Life"),
"Removing one overlapping radius jewel should not remove the life node still supported by the other:\n" .. tooltipText(tooltip))
end)
it("Impossible Escape parses and targets a keystone correctly", function()
local item = newImpossibleEscape("Iron Reflexes")
build.itemsTab:AddItem(item, true)
assert.is_truthy(item.jewelData, "IE should have jewelData")
assert.is_truthy(item.jewelData.impossibleEscapeKeystone, "IE should have impossibleEscapeKeystone")
assert.are.equals("iron reflexes", item.jewelData.impossibleEscapeKeystone)
assert.is_truthy(item.jewelData.impossibleEscapeKeystones, "IE should have impossibleEscapeKeystones")
assert.is_truthy(item.jewelData.impossibleEscapeKeystones["iron reflexes"],
"IE should target Iron Reflexes")
end)
it("Impossible Escape removal comparison removes dependent nodes via override", function()
local spec, socketNode = setupAllocatedSocket()
-- IE works via a keystone's radius, not the socket's radius.
-- Find a keystone that has unallocated nodes in its radius for the IE's radius index.
local item = newImpossibleEscape("Iron Reflexes")
equipJewelInSocket(item, socketNode)
spec:BuildAllDependsAndPaths()
runCallback("OnFrame")
-- IE populates intuitiveLeapLikesAffecting on nodes in the keystone's radius,
-- not the socket's radius. Search all spec nodes for an affected target.
local targetNode
for _, node in pairs(spec.nodes) do
if not node.alloc and #node.intuitiveLeapLikesAffecting > 0
and node.type ~= "Mastery" and node.type ~= "Keystone" then
targetNode = node
break
end
end
if not targetNode then
pending("No allocatable node in Impossible Escape radius for this tree layout")
return
end
spec:AllocNode(targetNode)
spec:BuildAllDependsAndPaths()
runCallback("OnFrame")
-- Build override like ItemsTab does
local override = { removeNodes = { } }
local nodesToRemove = spec:NodesInIntuitiveLeapLikeRadius(spec.nodes[socketNode.id])
for _, node in ipairs(nodesToRemove) do
if not node.connectedToStart then
override.removeNodes[node] = true
end
end
assert.is_truthy(override.removeNodes[spec.nodes[targetNode.id]],
"Node allocated through Impossible Escape should be in removeNodes")
local calcFunc = build.calcsTab:GetMiscCalculator(build)
assert.is_truthy(calcFunc(override), "calcFunc with removeNodes should return output")
end)
it("AddItemTooltip emits a remove-comparison block for an equipped Timeless jewel", function()
local spec, socketNode = setupAllocatedSocket()
local item = newLethalPride()
local slot = equipJewelInSocket(item, socketNode)
assert.is_truthy(slot, "Should find a slot for the jewel socket")
local nodesInRadius = findAllocatedNodesInRadius(spec, spec.nodes[socketNode.id], item.jewelRadiusIndex)
assert.is_true(#nodesInRadius > 0, "Should have allocated nodes in jewel radius")
simulateKaruiConquest(nodesInRadius[1])
local tooltip = new("Tooltip")
build.itemsTab:AddItemTooltip(tooltip, item, slot)
assert.is_true(tooltipContains(tooltip, "Removing this item"),
"tooltip should contain a 'Removing this item' comparison header")
end)
it("AddItemTooltip avoids rebuilding unused limited-unique socket comparisons without a target slot", function()
local spec, sockets = setupAllocatedSockets(2)
local item = newThreadOfHope()
item.limit = 1
equipJewelInSocket(item, sockets[1])
spec:BuildAllDependsAndPaths()
runCallback("OnFrame")
local specClass = getmetatable(spec)
local originalBuildAllDependsAndPaths = specClass.BuildAllDependsAndPaths
local rebuilds = 0
specClass.BuildAllDependsAndPaths = function(self, ...)
rebuilds = rebuilds + 1
return originalBuildAllDependsAndPaths(self, ...)
end
local ok, err = pcall(function()
local tooltip = new("Tooltip")
build.itemsTab:AddItemTooltip(tooltip, item)
end)
specClass.BuildAllDependsAndPaths = originalBuildAllDependsAndPaths
if not ok then
error(err)
end
assert.are.equals(1, rebuilds,
"limited unique radius jewels should rebuild only the same-unique slot that will be displayed")
end)
it("AddItemTooltip reuses targeted radius jewel comparison specs until output changes", function()
local spec, sockets = setupAllocatedSockets(2)
local item = newCustomLeapJewel("Cached Leap")
local slot = equipJewelInSocket(item, sockets[1])
spec:BuildAllDependsAndPaths()
runCallback("OnFrame")
local originalSlotOnlyTooltips = main.slotOnlyTooltips
main.slotOnlyTooltips = true
local specClass = getmetatable(spec)
local originalBuildAllDependsAndPaths = specClass.BuildAllDependsAndPaths
local rebuilds = 0
specClass.BuildAllDependsAndPaths = function(self, ...)
rebuilds = rebuilds + 1
return originalBuildAllDependsAndPaths(self, ...)
end
local ok, err = pcall(function()
local tooltip = new("Tooltip")
build.itemsTab:AddItemTooltip(tooltip, item, slot)
tooltip = new("Tooltip")
build.itemsTab:AddItemTooltip(tooltip, item, slot)
assert.are.equals(1, rebuilds,
"targeted radius jewel hover should reuse its cached comparison spec")
build.outputRevision = build.outputRevision + 1
tooltip = new("Tooltip")
build.itemsTab:AddItemTooltip(tooltip, item, slot)
assert.are.equals(2, rebuilds,
"targeted radius jewel comparison spec cache should reset when output changes")
end)
specClass.BuildAllDependsAndPaths = originalBuildAllDependsAndPaths
main.slotOnlyTooltips = originalSlotOnlyTooltips
if not ok then
error(err)
end
end)
it("AddItemTooltip skips UI path rebuilds for temporary radius jewel specs", function()
local spec, sockets = setupAllocatedSockets(2)
local radiusItem = newThreadOfHope()
local radiusSlot = equipJewelInSocket(radiusItem, sockets[1])
local splitItem = newSplitPersonality()
equipJewelInSocket(splitItem, sockets[2])
spec:BuildAllDependsAndPaths()
runCallback("OnFrame")
assert.is_true((spec.nodes[sockets[2].id].distanceToClassStart or 0) > 0,
"Split Personality socket should have a class-start distance in the base spec")
local originalSlotOnlyTooltips = main.slotOnlyTooltips
main.slotOnlyTooltips = true
local specClass = getmetatable(spec)
local originalBuildPathFromNode = specClass.BuildPathFromNode
local originalSetNodeDistanceToClassStart = specClass.SetNodeDistanceToClassStart
local buildPathCalls = 0
local distanceCalls = 0
specClass.BuildPathFromNode = function(self, ...)
buildPathCalls = buildPathCalls + 1
return originalBuildPathFromNode(self, ...)
end
specClass.SetNodeDistanceToClassStart = function(self, ...)
distanceCalls = distanceCalls + 1
return originalSetNodeDistanceToClassStart(self, ...)
end
local ok, err = pcall(function()
local tooltip = new("Tooltip")
build.itemsTab:AddItemTooltip(tooltip, radiusItem, radiusSlot)
end)
specClass.BuildPathFromNode = originalBuildPathFromNode
specClass.SetNodeDistanceToClassStart = originalSetNodeDistanceToClassStart
main.slotOnlyTooltips = originalSlotOnlyTooltips
if not ok then
error(err)
end
assert.are.equals(0, buildPathCalls,
"temporary tooltip specs should not rebuild UI node paths")
assert.is_true(distanceCalls > 0,
"temporary tooltip specs should still refresh jewel socket distances used by calc")
end)
it("AddItemTooltip reuses full radius jewel comparison outputs until output changes", function()
local spec, sockets = setupAllocatedSockets(2)
local item = newCustomLeapJewel("Cached Full Leap")
local slot = equipJewelInSocket(item, sockets[1])
spec:BuildAllDependsAndPaths()
runCallback("OnFrame")
local originalSlotOnlyTooltips = main.slotOnlyTooltips
main.slotOnlyTooltips = false
build.itemsTab.jewelComparisonOutputCache = nil
build.itemsTab.targetedJewelComparisonSpecCache = nil
local originalGetMiscCalculator = build.calcsTab.GetMiscCalculator
local calcCalls = 0
build.calcsTab.GetMiscCalculator = function(self, ...)
local calcFunc, calcBase = originalGetMiscCalculator(self, ...)
return function(...)
calcCalls = calcCalls + 1
return calcFunc(...)
end, calcBase
end
local ok, err = pcall(function()
local tooltip = new("Tooltip")
build.itemsTab:AddItemTooltip(tooltip, item, slot)
local firstPassCalcCalls = calcCalls
assert.is_true(firstPassCalcCalls > 0,
"full radius jewel tooltip should calculate outputs on first pass")
tooltip = new("Tooltip")
build.itemsTab:AddItemTooltip(tooltip, item, slot)
local secondPassCalcCalls = calcCalls - firstPassCalcCalls
assert.is_true(secondPassCalcCalls < firstPassCalcCalls,
"full radius jewel tooltip should reuse cached radius outputs on second pass")
build.outputRevision = build.outputRevision + 1
local beforeInvalidationCalcCalls = calcCalls
tooltip = new("Tooltip")
build.itemsTab:AddItemTooltip(tooltip, item, slot)
assert.is_true(calcCalls - beforeInvalidationCalcCalls > secondPassCalcCalls,
"full radius jewel output cache should reset when output changes")
end)
build.calcsTab.GetMiscCalculator = originalGetMiscCalculator
main.slotOnlyTooltips = originalSlotOnlyTooltips
if not ok then
error(err)
end
end)
end)