Skip to content
Merged
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
203 changes: 196 additions & 7 deletions spec/System/TestItemListControl_spec.lua
Original file line number Diff line number Diff line change
@@ -1,40 +1,229 @@
describe("ItemListControl", function()
local originalGetCursorPos
local originalOpenConfirmPopup

local function newItemListControl()
local activeItemSet = {
id = 1,
title = "Boss",
["Body Armour"] = { selItemId = 1 },
[1000] = { selItemId = 5 },
}
local otherItemSet = {
id = 2,
title = "Mapping",
["Body Armour"] = { selItemId = 2 },
[2000] = { selItemId = 6 },
}
local treeTab = {
activeSpec = 1,
specList = {
{
title = "Boss",
jewels = { [100] = 3 },
nodes = { [100] = { alloc = true } },
BuildClusterJewelGraphs = function() end,
},
{
title = "Mapping",
jewels = { [200] = 4 },
nodes = { [200] = { alloc = true } },
BuildClusterJewelGraphs = function() end,
},
},
}
local itemsTab = {
itemOrderList = { 1, 2 },
itemOrderList = { 1, 2, 3, 4, 5, 6, 7 },
items = {
[1] = { id = 1, type = "Body Armour", base = { subType = "" } },
[2] = { id = 2, type = "Jewel", base = { subType = "" } },
[2] = { id = 2, type = "Body Armour", base = { subType = "" } },
[3] = { id = 3, type = "Jewel", base = { subType = "" } },
[4] = { id = 4, type = "Jewel", base = { subType = "" } },
[5] = { id = 5, type = "Jewel", base = { subType = "" } },
[6] = { id = 6, type = "Jewel", base = { subType = "" } },
[7] = { id = 7, type = "Jewel", base = { subType = "" } },
},
itemSets = { activeItemSet },
itemSetOrderList = { 1, 2 },
itemSets = { activeItemSet, otherItemSet },
activeItemSetId = 1,
activeItemSet = activeItemSet,
slots = { },
build = {
treeTab = {
activeSpec = 1,
specList = { { title = "Boss", jewels = { }, nodes = { } } },
itemListSpecialLinks = { },
treeListSpecialLinks = { },
controls = {
buildLoadouts = { list = { "Boss", "Mapping" } },
},
treeTab = treeTab,
},
PopulateSlots = function() end,
AddUndoState = function() end,
}
itemsTab.GetEquippedSlotForItem = function(_, item)
for _, itemSetId in ipairs(itemsTab.itemSetOrderList) do
local itemSet = itemsTab.itemSets[itemSetId]
if itemSet["Body Armour"].selItemId == item.id then
return { label = "Body Armour" }, itemSetId ~= itemsTab.activeItemSetId and itemSet or nil
end
end
end
itemsTab.DeleteItem = function(_, item)
itemsTab.items[item.id] = nil
local index = isValueInArray(itemsTab.itemOrderList, item.id)
if index then
table.remove(itemsTab.itemOrderList, index)
end
end
local control = new("ItemListControl"):ItemListControl(nil, { 0, 0, 360, 308 }, itemsTab, true)
return control, itemsTab
return control, itemsTab, treeTab
end

before_each(function()
originalGetCursorPos = GetCursorPos
originalOpenConfirmPopup = main.OpenConfirmPopup
end)

after_each(function()
GetCursorPos = originalGetCursorPos
main.OpenConfirmPopup = originalOpenConfirmPopup
end)

it("only shows items from the active item set and passive tree", function()
local control = newItemListControl()
control:UpdateLoadoutList()
control.controls.loadoutFilter.selIndex = 2

control:UpdateList()

assert.are.same({ 1, 3, 5 }, control.list)
end)

it("uses the selected item set and passive tree for named loadouts", function()
local control = newItemListControl()
control:UpdateLoadoutList()
control.controls.loadoutFilter.selIndex = isValueInArray(control.controls.loadoutFilter.list, "Mapping")

control:UpdateList()

assert.are.same({ 2, 4, 6 }, control.list)
end)

it("matches linked sets and old passive tree display names", function()
local control, itemsTab, treeTab = newItemListControl()
itemsTab.itemSets[2].title = "Gear {mapping}"
treeTab.specList[2].title = "Tree {mapping}"
itemsTab.build.itemListSpecialLinks.mapping = { setId = 2 }
itemsTab.build.treeListSpecialLinks.mapping = { setId = 2 }
itemsTab.build.controls.buildLoadouts.list = { "Tree {mapping}", "[0.4] Boss" }
control:UpdateLoadoutList()
control.controls.loadoutFilter.selIndex = isValueInArray(control.controls.loadoutFilter.list, "Tree {mapping}")

control:UpdateList()

assert.are.same({ 2, 4, 6 }, control.list)

control.controls.loadoutFilter.selIndex = isValueInArray(control.controls.loadoutFilter.list, "[0.4] Boss")
control:UpdateList()

assert.are.same({ 1, 3, 5 }, control.list)
end)

it("clears hidden selections and preserves visible selections by item ID", function()
local control = newItemListControl()
control:UpdateLoadoutList()
control.selIndex = 2
control.selValue = 2
control.controls.loadoutFilter.selIndex = 2

control:UpdateList()

assert.is_nil(control.selIndex)
assert.is_nil(control.selValue)

control.selIndex = 3
control.selValue = 3
control:UpdateList()

assert.are.equal(2, control.selIndex)
assert.are.equal(3, control.selValue)
end)

it("only allows internal reordering in the unfiltered item list", function()
local control = newItemListControl()
control:UpdateLoadoutList()
control:UpdateList()

assert.is_true(control.isMutable)

control.controls.loadoutFilter.selIndex = 2
control:UpdateList()

assert.is_false(control.isMutable)

control.controls.loadoutFilter.selIndex = 1
control:UpdateList()

assert.is_true(control.isMutable)
end)

it("refreshes filter options when loadouts are renamed without a new output revision", function()
local control, itemsTab, treeTab = newItemListControl()
itemsTab.build.outputRevision = 1
control.lastOutputRevision = 1
control:UpdateLoadoutList()
itemsTab.itemSets[2].title = "Renamed"
treeTab.specList[2].title = "Renamed"
itemsTab.build.controls.buildLoadouts.list = { "Boss", "Renamed" }
wipeTable(itemsTab.itemOrderList)
wipeTable(itemsTab.items)

control:Draw({ x = 0, y = 0, width = 1920, height = 1080 })

assert.is_nil(isValueInArray(control.controls.loadoutFilter.list, "Mapping"))
assert.is_not_nil(isValueInArray(control.controls.loadoutFilter.list, "Renamed"))
end)

it("clears the canonical item order when deleting all from a filtered list", function()
local control, itemsTab = newItemListControl()
control:UpdateLoadoutList()
control.controls.loadoutFilter.selIndex = isValueInArray(control.controls.loadoutFilter.list, "Mapping")
control:UpdateList()
main.OpenConfirmPopup = function(_, _, _, _, onConfirm)
onConfirm()
end

control.controls.deleteAll.onClick()

assert.are.same({ }, itemsTab.itemOrderList)
assert.are.same({ }, itemsTab.items)
end)

it("deletes unused items across the entire build while filtered", function()
local control, itemsTab = newItemListControl()
control:UpdateLoadoutList()
control.controls.loadoutFilter.selIndex = isValueInArray(control.controls.loadoutFilter.list, "Mapping")
control:UpdateList()

control.controls.deleteUnused.onClick()

assert.is_nil(itemsTab.items[7])
assert.is_nil(isValueInArray(itemsTab.itemOrderList, 7))
assert.are.same({ 2, 4, 6 }, control.list)
end)

it("keeps bulk actions enabled when the filtered list is empty", function()
local control, itemsTab, treeTab = newItemListControl()
itemsTab.activeItemSet["Body Armour"].selItemId = 0
itemsTab.activeItemSet[1000].selItemId = 0
treeTab.specList[1].jewels = { }
control:UpdateLoadoutList()
control.controls.loadoutFilter.selIndex = 2

control:UpdateList()

assert.are.same({ }, control.list)
assert.is_true(control.controls.deleteUnused.enabled())
assert.is_true(control.controls.deleteAll.enabled())
end)

it("releases focus after opening an item with a double click", function()
Expand Down
Loading
Loading