Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions spec/System/TestItemCorruption_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
describe("Item corruption source transitions", function()
local initialPopupCount

local function assertImplicitSelectionsCleared(controls)
for i = 1, 5 do
assert.are.equal(1, controls["implicit" .. i].selIndex)
end
end

before_each(function()
newBuild()
main:SelectControl()
initialPopupCount = #main.popups
build.itemsTab.displayItem = new("Item"):Item(main.uniqueDB.byTitle["glimpse of chaos"].raw)
build.itemsTab:CorruptDisplayItem()
end)

after_each(function()
main:SelectControl()
while #main.popups > initialPopupCount do
main:ClosePopup()
end
end)

it("switches from Glimpse of Chaos to Scourge with the fifth implicit selected", function()
local controls = main.popups[1].controls
controls.implicit5:SetSel(2)
assert.are.equal(2, controls.implicit5.selIndex)

assert.has_no.errors(function()
controls.source:SetSel(3)
end)
assert.are.equal("Scourge", controls.source:GetSelValue())
assertImplicitSelectionsCleared(controls)
assert.is_false(controls.implicit5:IsShown())
end)

it("clears implicit selections across adjacent source transitions", function()
local controls = main.popups[1].controls
local transitions = {
{ fromSourceIndex = 1, implicitIndex = 5, toSourceIndex = 2 },
{ fromSourceIndex = 2, implicitIndex = 5, toSourceIndex = 1 },
{ fromSourceIndex = 2, implicitIndex = 4, toSourceIndex = 3 },
{ fromSourceIndex = 3, implicitIndex = 4, toSourceIndex = 2 },
}

for _, transition in ipairs(transitions) do
controls.source:SetSel(transition.fromSourceIndex)
controls["implicit" .. transition.implicitIndex]:SetSel(2)
assert.are.equal(2, controls["implicit" .. transition.implicitIndex].selIndex)
controls.source:SetSel(transition.toSourceIndex)
assert.are.equal(transition.toSourceIndex, controls.source.selIndex)
assertImplicitSelectionsCleared(controls)
end
end)
end)
7 changes: 4 additions & 3 deletions src/Classes/ItemsTab.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3425,6 +3425,10 @@ function ItemsTabClass:CorruptDisplayItem()
"^7Source:")
controls.source = new("DropDownControl"):DropDownControl({ "TOPLEFT", nil, "TOPLEFT" }, { 100, 30, 150, 18 },
sourceList, function(index, value)
-- Clear selections without callbacks before the source changes; Implicit #5 has no Scourge pair.
for i = 1, maxImplicitNum do
controls[string.format("implicit%d", i)]:SetSel(1, true)
end
if value == "Scourge" then
currentModType = "ScourgeUpside"
buildImplicitList("ScourgeUpside")
Expand All @@ -3445,9 +3449,6 @@ function ItemsTabClass:CorruptDisplayItem()
else
buildCorruptLists(currentModType)
end
for i = 1, maxImplicitNum do
controls[string.format("implicit%d", i)]:SetSel(1)
end
end)
controls.source.enabled = #sourceList > 1
controls.sortLabel = new("LabelControl"):LabelControl({"TOPRIGHT",nil,"TOPLEFT"}, {350, 20, 0, 16}, "^7Sort by:")
Expand Down
Loading