Files
WoW-Hybrid-gateway/tests/turtle_talent_points_test.lua

95 lines
4.1 KiB
Lua

-- The active self-talent frame displays provider:AvailablePoints() as its currency.
local root = assert(arg[1], 'gateway directory required')
dofile(root .. '/client_addons/GatewayDiagnostics/TurtleData.lua')
dofile(root .. '/client_addons/GatewayDiagnostics/TurtleTalentProvider.lua')
local p = GatewayTurtleTalentProvider.New(GatewayTurtleData)
local function snapshot(seq, points, spells)
p:Receive(('GWTURTLE1 BEGIN %d 1 1 60 %d %d'):format(seq, points, #spells))
if #spells > 0 then
p:Receive(('GWTURTLE1 SPELLS %d %s'):format(seq, table.concat(spells, ',')))
end
assert(p:Receive(('GWTURTLE1 END %d'):format(seq)))
end
-- Warrior talent 56 is Improved Heroic Strike; 12282 is its first rank.
snapshot(1, 2, {})
assert(p:Stage(56) and p:Rank(56, false) == 0 and p:AvailablePoints() == 1)
snapshot(2, 1, {12295})
assert(p:Rank(56, true) == 1 and p:AvailablePoints() == 0)
snapshot(3, 0, {12295,12300})
assert(p:Rank(56, true) == 0 and p:Rank(56, false) == 0)
assert(next(p.staged) == nil and p:AvailablePoints() == 0 and #p:Purchases() == 0)
-- A point-only snapshot cannot acknowledge the rank or discard an active Apply.
snapshot(4, 1, {})
assert(p:Stage(56))
local expected = assert(p:PurchaseExpectation(56, 1))
p.pending = {expected=expected}
snapshot(5, 0, {})
assert(p.pending.expected == expected and p:Rank(56, true) == 1)
assert(p:Rank(56, false) == 0 and p:AvailablePoints() == 0 and not p:PurchaseAcknowledged(expected))
snapshot(6, 0, {12282})
assert(p:Rank(56, false) == 1 and next(p.staged) == nil)
assert(p:AvailablePoints() == 0 and p:PurchaseAcknowledged(expected))
p = GatewayTurtleTalentProvider.New(GatewayTurtleData)
-- A trainer reset can remove the learned ranks underneath an unsent selection.
-- The player selected only rank 3 of Improved Heroic Strike.
snapshot(7, 49, {12663})
assert(p:Stage(56) and #p:Purchases() == 1)
snapshot(8, 51, {})
assert(p:Rank(56, true) == 0 and p:AvailablePoints() == 51 and #p:Purchases() == 0)
-- Both specs have ten Arms points. Replacing Improved Rend with Improved
-- Charge removes the two-rank prerequisite for Deep Wounds. Keep the separate
-- legal Deflection choice without charging for or submitting the obsolete one.
snapshot(9, 41, {12679, 12664, 12658})
assert(p:Stage(64) and p:Stage(60) and #p:Purchases() == 2)
snapshot(10, 41, {12679, 12664, 12697})
local queue = assert(p:Purchases())
assert(p:Rank(64, true) == 0 and p:Rank(60, true) == 1)
assert(p:AvailablePoints() == 40 and #queue == 1 and queue[1].id == 60)
p:Undo()
-- Losing tier points can invalidate a selection even with no arrow prerequisite.
snapshot(11, 46, {12679})
assert(p:Stage(59) and p:Stage(56))
snapshot(12, 51, {})
assert(p:Rank(59, true) == 0 and p:Rank(56, true) == 1 and p:AvailablePoints() == 50)
p:Undo()
-- A normal training upgrade removes the previous spell ID in the same
-- snapshot. A valid unsent selection keeps its cost and its rank.
snapshot(13, 50, {12295})
assert(p:Stage(56))
snapshot(14, 49, {12676})
assert(p:Rank(56, true) == 1 and #p:Purchases() == 1 and p:AvailablePoints() == 48)
-- The in-flight acknowledgement remains independent. If a source spec change
-- happens while it waits, the first resync preserves only legal unsent choices.
p:Undo()
snapshot(15, 41, {12679, 12664, 12658})
assert(p:Stage(64) and p:Stage(60))
local pending = {expected=assert(p:PurchaseExpectation(64, 1))}
p.pending = pending
snapshot(16, 41, {12679, 12664, 12697})
assert(p.pending == pending and not p:PurchaseAcknowledged(pending.expected))
p.pending = nil
p.resyncSeq = 16
snapshot(17, 41, {12679, 12664, 12697})
assert(p:Rank(64, true) == 0 and p:Rank(60, true) == 1 and #p:Purchases() == 1)
p:Undo()
snapshot(18, 49, {12663})
assert(p:Stage(56))
pending = {expected=assert(p:PurchaseExpectation(56, 3))}
p.pending = pending
snapshot(19, 51, {})
assert(p.pending == pending and not p:PurchaseAcknowledged(pending.expected))
p.pending = nil
p.resyncSeq = 19
snapshot(20, 51, {})
assert(#p:Purchases() == 0 and p:AvailablePoints() == 51)
print('PASS self-talent previews across balance updates, refunds, specialization changes, and normal rank acknowledgements')