|
| 1 | +describe("Buy similar mod stat matching", function() |
| 2 | + local bs = LoadModule("Classes/CompareBuySimilar") |
| 3 | + local dkjson = require "dkjson" |
| 4 | + |
| 5 | + describe("addModEntries mod matching", function() |
| 6 | + it("matches impossible escape mods as options", function() |
| 7 | + local fromNothing = new("Item", [[ |
| 8 | +Impossible Escape |
| 9 | +Viridian Jewel |
| 10 | +LevelReq: 0 |
| 11 | +Radius: Small |
| 12 | +Limited to: 1 |
| 13 | +Implicits: 0 |
| 14 | +Passive skills in radius of Elemental Overload can be Allocated without being connected to your tree |
| 15 | +Corrupted]]) |
| 16 | + |
| 17 | + local modSources = { |
| 18 | + { list = fromNothing.explicitModLines, type = "explicit" } |
| 19 | + } |
| 20 | + local modEntries = bs.addModEntries(fromNothing, modSources) |
| 21 | + assert.equal(1, #modEntries) |
| 22 | + assert.same( |
| 23 | + { |
| 24 | + formattedLines = { colorCodes.MAGIC .. "Passive skills in radius of Elemental Overload can be Allocated without being connected to your tree" }, |
| 25 | + type = "explicit", |
| 26 | + isOption = true, |
| 27 | + invert = false, |
| 28 | + tradeIds = { "explicit.stat_2422708892" }, |
| 29 | + value = 22088 |
| 30 | + }, |
| 31 | + modEntries[1]) |
| 32 | + end) |
| 33 | + |
| 34 | + it("matches thread of hope radius as an option", function() |
| 35 | + local thread = new("Item", [[ |
| 36 | +Rarity: UNIQUE |
| 37 | +Thread of Hope |
| 38 | +Crimson Jewel |
| 39 | +Radius: Variable |
| 40 | +Implicits: 0 |
| 41 | +Only affects Passives in Massive Ring |
| 42 | +-15% to all Elemental Resistances |
| 43 | +Passive Skills in Radius can be Allocated without being connected to your tree |
| 44 | +Passage]]) |
| 45 | + local modSources = { |
| 46 | + { list = thread.explicitModLines, type = "explicit" } |
| 47 | + } |
| 48 | + local modEntries = bs.addModEntries(thread, modSources) |
| 49 | + assert.equal(4, #modEntries) |
| 50 | + assert.equal("explicit.stat_3642528642", modEntries[1].tradeIds[1]) |
| 51 | + assert.equal(5, modEntries[1].value) |
| 52 | + end) |
| 53 | + |
| 54 | + it("combines mods that are the same stat", function() |
| 55 | + local lifeDiamond = new("Item", [[ |
| 56 | +Test Subject |
| 57 | +Diamond |
| 58 | +Implicits: 0 |
| 59 | ++100 to Maximum Life |
| 60 | ++50 to Maximum Life |
| 61 | ++50% to Fire Resistance]]) |
| 62 | + |
| 63 | + local entries = bs.addModEntries(lifeDiamond, { { list = lifeDiamond.explicitModLines, type = "explicit" } }) |
| 64 | + assert.equal(2, #entries) |
| 65 | + assert.equal(2, #entries[1].formattedLines) |
| 66 | + assert.equal("+100 to Maximum Life", StripEscapes(entries[1].formattedLines[1])) |
| 67 | + assert.equal("+50 to Maximum Life", StripEscapes(entries[1].formattedLines[2])) |
| 68 | + assert.equal(150, entries[1].value) |
| 69 | + |
| 70 | + local lifelessDiamond = new("Item", [[ |
| 71 | +Test Subject |
| 72 | +Diamond |
| 73 | +Implicits: 0 |
| 74 | +-100 to Maximum Life |
| 75 | ++50 to Maximum Life |
| 76 | ++50% to Fire Resistance]]) |
| 77 | + local entries = bs.addModEntries(lifelessDiamond, |
| 78 | + { { list = lifelessDiamond.explicitModLines, type = "explicit" } }) |
| 79 | + assert.equal(2, #entries) |
| 80 | + assert.equal(2, #entries[1].formattedLines) |
| 81 | + assert.equal(-50, entries[1].value) |
| 82 | + end) |
| 83 | + |
| 84 | + it("is not case-sensitive", function () |
| 85 | + local funnyItem = new("Item", [[ |
| 86 | +Test Subject |
| 87 | +Diamond |
| 88 | +Implicits: 1 |
| 89 | ++50 tO MaxIMum lifE]]) |
| 90 | + |
| 91 | + local entries = bs.addModEntries(funnyItem, {{list = funnyItem.implicitModLines, type = "implicit"}}) |
| 92 | + assert.equal(1, #entries) |
| 93 | + end) |
| 94 | + |
| 95 | + it("does not combine implicit and explicit mods", function() |
| 96 | + local lifelessDiamond = new("Item", [[ |
| 97 | +Test Subject |
| 98 | +Diamond |
| 99 | +Implicits: 1 |
| 100 | +-100 to Maximum Life |
| 101 | ++50 to Maximum Life]]) |
| 102 | + local entries = bs.addModEntries(lifelessDiamond, |
| 103 | + { { list = lifelessDiamond.implicitModLines, type = "implicit" }, { list = lifelessDiamond.explicitModLines, type = "explicit" } }) |
| 104 | + assert.equal(2, #entries) |
| 105 | + assert.equal(-100, entries[1].value) |
| 106 | + assert.equal(50, entries[2].value) |
| 107 | + end) |
| 108 | + end) |
| 109 | + describe("popup URL controls", function() |
| 110 | + local originalCopy |
| 111 | + local originalOpenURL |
| 112 | + local originalFetchLeagues |
| 113 | + local copiedUrl |
| 114 | + local leaguesByRealm = { |
| 115 | + pc = { "PC League", "PC Event", "Standard" }, |
| 116 | + sony = { "PS4 League", "Standard" }, |
| 117 | + xbox = { "Xbox League", "Standard" }, |
| 118 | + } |
| 119 | + |
| 120 | + before_each(function() |
| 121 | + newBuild() |
| 122 | + originalCopy = _G.Copy |
| 123 | + originalOpenURL = _G.OpenURL |
| 124 | + copiedUrl = nil |
| 125 | + local requests = build.itemsTab.tradeQuery.tradeQueryRequests |
| 126 | + originalFetchLeagues = requests.FetchLeagues |
| 127 | + requests.FetchLeagues = function(_, realm, callback) |
| 128 | + callback(leaguesByRealm[realm]) |
| 129 | + end |
| 130 | + end) |
| 131 | + |
| 132 | + after_each(function() |
| 133 | + build.itemsTab.tradeQuery.tradeQueryRequests.FetchLeagues = originalFetchLeagues |
| 134 | + _G.Copy = originalCopy |
| 135 | + _G.OpenURL = originalOpenURL |
| 136 | + bs.lastRealmIdx = nil |
| 137 | + bs.lastLeagueByRealm = nil |
| 138 | + bs.lastListedIndex = nil |
| 139 | + main:ClosePopup() |
| 140 | + end) |
| 141 | + |
| 142 | + local function openPopup(item, slotName) |
| 143 | + item = item or new("Item", "Rarity: Rare\nTest Ring\nRuby Ring\nImplicits: 0\n+50 to maximum Life") |
| 144 | + bs.openPopup(item, slotName or "Ring", build) |
| 145 | + local controls = main.popups[1].controls |
| 146 | + _G.Copy = function(url) copiedUrl = url end |
| 147 | + _G.OpenURL = function() end |
| 148 | + return controls |
| 149 | + end |
| 150 | + |
| 151 | + local function getQuery(controls) |
| 152 | + controls.search.onClick() |
| 153 | + local queryJson = urlDecode(assert(copiedUrl:match("[?&]q=(.+)$"))) |
| 154 | + return dkjson.decode(queryJson) |
| 155 | + end |
| 156 | + |
| 157 | + it("rebuilds the URL when league and listed status change", function() |
| 158 | + local controls = openPopup() |
| 159 | + getQuery(controls) |
| 160 | + local initialUrl = copiedUrl |
| 161 | + |
| 162 | + controls.leagueDrop:SetSel(isValueInArray(controls.leagueDrop.list, "Standard")) |
| 163 | + getQuery(controls) |
| 164 | + assert.not_equal(initialUrl, copiedUrl) |
| 165 | + assert.is_truthy(copiedUrl:find("/Standard?", 1, true)) |
| 166 | + local standardUrl = copiedUrl |
| 167 | + |
| 168 | + controls.listedDrop:SetSel(4) |
| 169 | + local query = getQuery(controls) |
| 170 | + assert.not_equal(standardUrl, copiedUrl) |
| 171 | + assert.equal("any", query.query.status.option) |
| 172 | + end) |
| 173 | + |
| 174 | + it("persists league choices by name for each realm", function() |
| 175 | + local controls = openPopup() |
| 176 | + assert.equal("PC Event", controls.leagueDrop:GetSelValue()) |
| 177 | + controls.leagueDrop:SetSel(2) |
| 178 | + controls.leagueDrop:SetSel(1) |
| 179 | + controls.realmDrop:SetSel(3) |
| 180 | + assert.equal("Xbox League", controls.leagueDrop:GetSelValue()) |
| 181 | + controls.leagueDrop:SetSel(2) |
| 182 | + controls.realmDrop:SetSel(1) |
| 183 | + assert.equal("PC Event", controls.leagueDrop:GetSelValue()) |
| 184 | + controls.leagueDrop:SetSel(2) |
| 185 | + controls.realmDrop:SetSel(3) |
| 186 | + assert.equal("Standard", controls.leagueDrop:GetSelValue()) |
| 187 | + controls.listedDrop:SetSel(4) |
| 188 | + main:ClosePopup() |
| 189 | + |
| 190 | + controls = openPopup() |
| 191 | + assert.equal(3, bs.lastRealmIdx) |
| 192 | + assert.equal("Standard", controls.leagueDrop:GetSelValue()) |
| 193 | + assert.equal("Any", controls.listedDrop:GetSelValue()) |
| 194 | + end) |
| 195 | + |
| 196 | + it("encodes option values in the generated query", function() |
| 197 | + local item = new("Item", [[ |
| 198 | +Rarity: UNIQUE |
| 199 | +Impossible Escape |
| 200 | +Viridian Jewel |
| 201 | +LevelReq: 0 |
| 202 | +Radius: Small |
| 203 | +Limited to: 1 |
| 204 | +Implicits: 0 |
| 205 | +Passive skills in radius of Elemental Overload can be Allocated without being connected to your tree |
| 206 | +Corrupted]]) |
| 207 | + local controls = openPopup(item, "Jewel") |
| 208 | + controls.mod1Check.state = true |
| 209 | + controls.mod1Check.changeFunc() |
| 210 | + |
| 211 | + local filter = getQuery(controls).query.stats[1].filters[1] |
| 212 | + assert.equal("explicit.stat_2422708892", filter.id) |
| 213 | + assert.equal(22088, filter.value.option) |
| 214 | + end) |
| 215 | + |
| 216 | + it("inverts reduced stat bounds in the generated query", function() |
| 217 | + local item = new("Item", [[ |
| 218 | +Rarity: Rare |
| 219 | +Test Ring |
| 220 | +Ruby Ring |
| 221 | +Implicits: 0 |
| 222 | +67% reduced maximum Life]]) |
| 223 | + local controls = openPopup(item) |
| 224 | + controls.mod1Check.state = true |
| 225 | + controls.mod1Check.changeFunc() |
| 226 | + |
| 227 | + local value = getQuery(controls).query.stats[1].filters[1].value |
| 228 | + assert.is_nil(value.min) |
| 229 | + assert.equal(-67, value.max) |
| 230 | + end) |
| 231 | + |
| 232 | + it("uses a count group for ambiguous trade stats", function() |
| 233 | + local item = new("Item", [[ |
| 234 | +Rarity: Rare |
| 235 | +Test Ring |
| 236 | +Ruby Ring |
| 237 | +Implicits: 0 |
| 238 | +Adds 5 to 15 Fire Damage]]) |
| 239 | + local modEntries = bs.addModEntries(item, { { list = item.explicitModLines, type = "explicit" } }) |
| 240 | + local ambiguousIndex |
| 241 | + for index, entry in ipairs(modEntries) do |
| 242 | + if #entry.tradeIds > 1 then |
| 243 | + ambiguousIndex = index |
| 244 | + break |
| 245 | + end |
| 246 | + end |
| 247 | + assert.is_truthy(ambiguousIndex) |
| 248 | + |
| 249 | + local controls = openPopup(item) |
| 250 | + local check = controls["mod" .. ambiguousIndex .. "Check"] |
| 251 | + check.state = true |
| 252 | + check.changeFunc() |
| 253 | + |
| 254 | + local countFilter = getQuery(controls).query.stats[2] |
| 255 | + assert.equal("count", countFilter.type) |
| 256 | + assert.equal(1, countFilter.value.min) |
| 257 | + assert.equal(#modEntries[ambiguousIndex].tradeIds, #countFilter.filters) |
| 258 | + end) |
| 259 | + end) |
| 260 | +end) |
0 commit comments