|
| 1 | +describe("TestImportReimport", function() |
| 2 | + local dkjson = require "dkjson" |
| 3 | + local DEFAULT_CHARACTER_LEVEL = 12 |
| 4 | + local DEFAULT_ITEM_LEVEL = 10 |
| 5 | + local TEST_IMPORT_ITEM_ID = "test-import-item-1" |
| 6 | + local DEFAULT_SOCKET_COLOR = "R" |
| 7 | + |
| 8 | + before_each(function() |
| 9 | + newBuild() |
| 10 | + end) |
| 11 | + |
| 12 | + local function makeGemProperties(level) |
| 13 | + return { |
| 14 | + { name = "Level", values = { { tostring(level), 0 } } }, |
| 15 | + { name = "Quality", values = { { "+0%", 0 } } }, |
| 16 | + } |
| 17 | + end |
| 18 | + |
| 19 | + local function makeSocketedGemEntry(socket, support, typeLine, level) |
| 20 | + return { |
| 21 | + socket = socket, |
| 22 | + support = support, |
| 23 | + typeLine = typeLine, |
| 24 | + properties = makeGemProperties(level), |
| 25 | + } |
| 26 | + end |
| 27 | + |
| 28 | + -- Build a minimal import item so the tests stay focused on state, not fixture noise. |
| 29 | + local function makeImportItem(itemTypeLine, inventoryId, socketedItems, itemId) |
| 30 | + local maxSocketIndex = 0 |
| 31 | + for _, socketedItem in ipairs(socketedItems) do |
| 32 | + maxSocketIndex = math.max(maxSocketIndex, socketedItem.socket + 1) |
| 33 | + end |
| 34 | + local sockets = {} |
| 35 | + for index = 1, maxSocketIndex do |
| 36 | + sockets[index] = { group = 0, sColour = DEFAULT_SOCKET_COLOR } |
| 37 | + end |
| 38 | + return { |
| 39 | + id = itemId or TEST_IMPORT_ITEM_ID, |
| 40 | + frameType = 0, |
| 41 | + name = "", |
| 42 | + typeLine = itemTypeLine, |
| 43 | + inventoryId = inventoryId, |
| 44 | + ilvl = DEFAULT_ITEM_LEVEL, |
| 45 | + properties = {}, |
| 46 | + sockets = sockets, |
| 47 | + socketedItems = socketedItems, |
| 48 | + } |
| 49 | + end |
| 50 | + |
| 51 | + -- Build a minimal import payload so the tests stay focused on state, not fixture noise. |
| 52 | + local function buildImportPayload(items) |
| 53 | + return dkjson.encode({ |
| 54 | + character = { level = DEFAULT_CHARACTER_LEVEL }, |
| 55 | + items = items, |
| 56 | + }) |
| 57 | + end |
| 58 | + |
| 59 | + local function reimportSocketedItemsWithOptions(itemTypeLine, inventoryId, socketedItems, clearItems) |
| 60 | + build.importTab.controls.charImportItemsClearSkills.state = true |
| 61 | + build.importTab.controls.charImportItemsClearItems.state = clearItems |
| 62 | + build.importTab:ImportItemsAndSkills(buildImportPayload({ |
| 63 | + makeImportItem(itemTypeLine, inventoryId, socketedItems), |
| 64 | + })) |
| 65 | + runCallback("OnFrame") |
| 66 | + end |
| 67 | + |
| 68 | + local function reimportSingleSocketedGemWithOptions(itemTypeLine, inventoryId, gemName, clearItems) |
| 69 | + reimportSocketedItemsWithOptions(itemTypeLine, inventoryId, { |
| 70 | + makeSocketedGemEntry(0, false, gemName, 20), |
| 71 | + }, clearItems) |
| 72 | + end |
| 73 | + |
| 74 | + local function reimportSingleSocketedGem(itemTypeLine, inventoryId, gemName) |
| 75 | + reimportSingleSocketedGemWithOptions(itemTypeLine, inventoryId, gemName, false) |
| 76 | + end |
| 77 | + |
| 78 | + local function assertReimportPreservesSkillSubstate(slotName, itemTypeLine, inventoryId, gemName, fieldName, fieldValue) |
| 79 | + build.skillsTab:PasteSocketGroup(string.format([[ |
| 80 | +Slot: %s |
| 81 | +%s 20/0 1 |
| 82 | +]], slotName, gemName)) |
| 83 | + runCallback("OnFrame") |
| 84 | + |
| 85 | + local socketGroup = build.skillsTab.socketGroupList[1] |
| 86 | + local srcInstance = socketGroup.displaySkillList[1].activeEffect.srcInstance |
| 87 | + srcInstance[fieldName] = fieldValue |
| 88 | + srcInstance[fieldName.."Calcs"] = fieldValue |
| 89 | + build.modFlag = true |
| 90 | + build.buildFlag = true |
| 91 | + runCallback("OnFrame") |
| 92 | + |
| 93 | + reimportSingleSocketedGem(itemTypeLine, inventoryId, gemName) |
| 94 | + |
| 95 | + socketGroup = build.skillsTab.socketGroupList[1] |
| 96 | + srcInstance = socketGroup.displaySkillList[1].activeEffect.srcInstance |
| 97 | + assert.are.equal(fieldValue, srcInstance[fieldName]) |
| 98 | + assert.are.equal(fieldValue, srcInstance[fieldName.."Calcs"]) |
| 99 | + end |
| 100 | + |
| 101 | + it("preserves full DPS state and manually disabled gems when reimporting items and skills", function() |
| 102 | + build.skillsTab:PasteSocketGroup([[ |
| 103 | +Slot: Helmet |
| 104 | +Cleave 1/0 1 |
| 105 | +Heavy Strike 1/0 1 |
| 106 | +Added Fire Damage 1/0 DISABLED 1 |
| 107 | +]]) |
| 108 | + runCallback("OnFrame") |
| 109 | + |
| 110 | + local socketGroup = build.skillsTab.socketGroupList[1] |
| 111 | + socketGroup.includeInFullDPS = true |
| 112 | + socketGroup.mainActiveSkill = 2 |
| 113 | + runCallback("OnFrame") |
| 114 | + |
| 115 | + build.importTab.controls.charImportItemsClearSkills.state = true |
| 116 | + build.importTab.controls.charImportItemsClearItems.state = false |
| 117 | + build.importTab:ImportItemsAndSkills(buildImportPayload({ |
| 118 | + makeImportItem("Iron Hat", "Helm", { |
| 119 | + makeSocketedGemEntry(0, false, "Cleave", 1), |
| 120 | + makeSocketedGemEntry(1, false, "Heavy Strike", 1), |
| 121 | + makeSocketedGemEntry(2, true, "Added Fire Damage Support", 2), |
| 122 | + }), |
| 123 | + })) |
| 124 | + runCallback("OnFrame") |
| 125 | + |
| 126 | + socketGroup = build.skillsTab.socketGroupList[1] |
| 127 | + assert.are.equal("Helmet", socketGroup.slot) |
| 128 | + assert.is_true(socketGroup.includeInFullDPS) |
| 129 | + assert.are.equal(2, socketGroup.mainActiveSkill) |
| 130 | + assert.are.equal(2, socketGroup.gemList[3].level) |
| 131 | + assert.is_false(socketGroup.gemList[3].enabled) |
| 132 | + end) |
| 133 | + |
| 134 | + it("preserves full DPS state and disabled gems when reimporting with deleted equipment", function() |
| 135 | + build.skillsTab:PasteSocketGroup([[ |
| 136 | +Slot: Helmet |
| 137 | +Cleave 1/0 1 |
| 138 | +Heavy Strike 1/0 1 |
| 139 | +Added Fire Damage 1/0 DISABLED 1 |
| 140 | +]]) |
| 141 | + runCallback("OnFrame") |
| 142 | + |
| 143 | + local socketGroup = build.skillsTab.socketGroupList[1] |
| 144 | + socketGroup.includeInFullDPS = true |
| 145 | + socketGroup.mainActiveSkill = 2 |
| 146 | + runCallback("OnFrame") |
| 147 | + |
| 148 | + reimportSocketedItemsWithOptions("Iron Hat", "Helm", { |
| 149 | + makeSocketedGemEntry(0, false, "Cleave", 1), |
| 150 | + makeSocketedGemEntry(1, false, "Heavy Strike", 1), |
| 151 | + makeSocketedGemEntry(2, true, "Added Fire Damage Support", 2), |
| 152 | + }, true) |
| 153 | + |
| 154 | + socketGroup = build.skillsTab.socketGroupList[1] |
| 155 | + assert.are.equal("Helmet", socketGroup.slot) |
| 156 | + assert.is_true(socketGroup.includeInFullDPS) |
| 157 | + assert.are.equal(2, socketGroup.mainActiveSkill) |
| 158 | + assert.are.equal(2, socketGroup.gemList[3].level) |
| 159 | + assert.is_false(socketGroup.gemList[3].enabled) |
| 160 | + end) |
| 161 | + |
| 162 | + it("preserves two socket groups when reimporting items and skills", function() |
| 163 | + build.skillsTab:PasteSocketGroup([[ |
| 164 | +Slot: Helmet |
| 165 | +Cleave 1/0 1 |
| 166 | +Heavy Strike 1/0 1 |
| 167 | +Added Fire Damage 1/0 DISABLED 1 |
| 168 | +]]) |
| 169 | + runCallback("OnFrame") |
| 170 | + |
| 171 | + build.skillsTab:PasteSocketGroup([[ |
| 172 | +Slot: Gloves |
| 173 | +Blight 20/0 1 |
| 174 | +]]) |
| 175 | + runCallback("OnFrame") |
| 176 | + |
| 177 | + local helmetGroup = build.skillsTab.socketGroupList[1] |
| 178 | + helmetGroup.includeInFullDPS = true |
| 179 | + helmetGroup.mainActiveSkill = 2 |
| 180 | + local glovesGroup = build.skillsTab.socketGroupList[2] |
| 181 | + glovesGroup.enabled = false |
| 182 | + runCallback("OnFrame") |
| 183 | + |
| 184 | + build.importTab.controls.charImportItemsClearSkills.state = true |
| 185 | + build.importTab.controls.charImportItemsClearItems.state = false |
| 186 | + build.importTab:ImportItemsAndSkills(buildImportPayload({ |
| 187 | + makeImportItem("Iron Hat", "Helm", { |
| 188 | + makeSocketedGemEntry(0, false, "Cleave", 1), |
| 189 | + makeSocketedGemEntry(1, false, "Heavy Strike", 1), |
| 190 | + makeSocketedGemEntry(2, true, "Added Fire Damage Support", 2), |
| 191 | + }, "test-import-item-helmet"), |
| 192 | + makeImportItem("Rawhide Gloves", "Gloves", { |
| 193 | + makeSocketedGemEntry(0, false, "Blight", 20), |
| 194 | + }, "test-import-item-gloves"), |
| 195 | + })) |
| 196 | + runCallback("OnFrame") |
| 197 | + |
| 198 | + local groupsBySlot = {} |
| 199 | + for _, socketGroup in ipairs(build.skillsTab.socketGroupList) do |
| 200 | + groupsBySlot[socketGroup.slot] = socketGroup |
| 201 | + end |
| 202 | + |
| 203 | + assert.are.equal(2, #build.skillsTab.socketGroupList) |
| 204 | + assert.is_not_nil(groupsBySlot.Helmet) |
| 205 | + assert.is_not_nil(groupsBySlot.Gloves) |
| 206 | + assert.is_true(groupsBySlot.Helmet.includeInFullDPS) |
| 207 | + assert.are.equal(2, groupsBySlot.Helmet.mainActiveSkill) |
| 208 | + assert.is_false(groupsBySlot.Gloves.enabled) |
| 209 | + end) |
| 210 | + |
| 211 | + it("preserves skill part selection when reimporting items and skills", function() |
| 212 | + assertReimportPreservesSkillSubstate("Helmet", "Iron Hat", "Helm", "Blight", "skillPart", 2) |
| 213 | + end) |
| 214 | + |
| 215 | + it("preserves stage count when reimporting items and skills", function() |
| 216 | + assertReimportPreservesSkillSubstate("Weapon 1", "Driftwood Wand", "Weapon", "Scorching Ray", "skillStageCount", 8) |
| 217 | + end) |
| 218 | + |
| 219 | + it("preserves mine count when reimporting items and skills", function() |
| 220 | + assertReimportPreservesSkillSubstate("Gloves", "Rawhide Gloves", "Gloves", "Pyroclast Mine", "skillMineCount", 12) |
| 221 | + end) |
| 222 | + |
| 223 | + it("preserves minion skill when reimporting items and skills", function() |
| 224 | + assertReimportPreservesSkillSubstate("Gloves", "Rawhide Gloves", "Gloves", "Summon Chaos Golem", "skillMinionSkill", 3) |
| 225 | + end) |
| 226 | +end) |
0 commit comments