|
1 | 1 | local t_insert = table.insert |
| 2 | +local t_remove = table.remove |
2 | 3 |
|
3 | 4 | describe("TestLoadouts", function() |
4 | 5 | before_each(function() |
@@ -195,6 +196,156 @@ describe("TestLoadouts", function() |
195 | 196 | assert.is_true(build.modFlag) |
196 | 197 | end) |
197 | 198 | end) |
| 199 | + |
| 200 | + describe("ReorderLoadout", function() |
| 201 | + local function assertActiveLoadoutByName(expectedName) |
| 202 | + local activeSpec = build.treeTab.specList[build.treeTab.activeSpec] |
| 203 | + local activeItemSet = build.itemsTab.itemSets[build.itemsTab.activeItemSetId] |
| 204 | + local activeSkillSet = build.skillsTab.skillSets[build.skillsTab.activeSkillSetId] |
| 205 | + local activeConfigSet = build.configTab.configSets[build.configTab.activeConfigSetId] |
| 206 | + assert.is_not_nil(activeSpec) |
| 207 | + assert.is_same(expectedName, activeSpec.title) |
| 208 | + assert.is_not_nil(activeItemSet) |
| 209 | + assert.is_same(expectedName, activeItemSet.title) |
| 210 | + assert.is_not_nil(activeSkillSet) |
| 211 | + assert.is_same(expectedName, activeSkillSet.title) |
| 212 | + assert.is_not_nil(activeConfigSet) |
| 213 | + assert.is_same(expectedName, activeConfigSet.title) |
| 214 | + end |
| 215 | + |
| 216 | + it("does not reorder loadouts when oldIndex is the same as newIndex", function() |
| 217 | + build:NewLoadout("Loadout A") |
| 218 | + build:NewLoadout("Loadout B") |
| 219 | + build:NewLoadout("Loadout C") |
| 220 | + build.modFlag = false |
| 221 | + |
| 222 | + build:SetActiveLoadout(build:GetLoadoutByName("Loadout A")) |
| 223 | + |
| 224 | + local spec = build.treeTab.specList[2] |
| 225 | + t_remove(build.treeTab.specList, 2) |
| 226 | + t_insert(build.treeTab.specList, 2, spec) |
| 227 | + build:ReorderLoadout(2, 2) |
| 228 | + |
| 229 | + assert.is_same(4, #build.treeTab.specList) |
| 230 | + assert.is_same("Loadout A", build.treeTab.specList[2].title) |
| 231 | + assertActiveLoadoutByName("Loadout A") |
| 232 | + assert.is_false(build.modFlag) |
| 233 | + end) |
| 234 | + |
| 235 | + it("reorders loadouts when oldIndex is less than newIndex and activeSpec is at oldIndex", function() |
| 236 | + build:NewLoadout("Loadout A") |
| 237 | + build:NewLoadout("Loadout B") |
| 238 | + build:NewLoadout("Loadout C") |
| 239 | + build.modFlag = false |
| 240 | + |
| 241 | + build:SetActiveLoadout(build:GetLoadoutByName("Loadout A")) |
| 242 | + |
| 243 | + local spec = build.treeTab.specList[2] |
| 244 | + t_remove(build.treeTab.specList, 2) |
| 245 | + t_insert(build.treeTab.specList, 4, spec) |
| 246 | + build:ReorderLoadout(2, 4) |
| 247 | + |
| 248 | + assert.is_same(4, #build.treeTab.specList) |
| 249 | + assert.is_same("Loadout A", build.treeTab.specList[4].title) |
| 250 | + assertActiveLoadoutByName("Loadout A") |
| 251 | + assert.is_true(build.modFlag) |
| 252 | + end) |
| 253 | + |
| 254 | + it("reorders loadouts when oldIndex is less than newIndex and activeSpec is before oldIndex", function() |
| 255 | + build:NewLoadout("Loadout A") |
| 256 | + build:NewLoadout("Loadout B") |
| 257 | + build:NewLoadout("Loadout C") |
| 258 | + build.modFlag = false |
| 259 | + |
| 260 | + build:SetActiveLoadout(build:GetLoadoutByName("Loadout C")) |
| 261 | + |
| 262 | + local spec = build.treeTab.specList[2] |
| 263 | + t_remove(build.treeTab.specList, 2) |
| 264 | + t_insert(build.treeTab.specList, 3, spec) |
| 265 | + build:ReorderLoadout(2, 3) |
| 266 | + |
| 267 | + assert.is_same(4, #build.treeTab.specList) |
| 268 | + assert.is_same("Loadout A", build.treeTab.specList[3].title) |
| 269 | + assertActiveLoadoutByName("Loadout C") |
| 270 | + assert.is_true(build.modFlag) |
| 271 | + end) |
| 272 | + |
| 273 | + it("reorders loadouts when oldIndex is less than newIndex and activeSpec is after oldIndex", function() |
| 274 | + build:NewLoadout("Loadout A") |
| 275 | + build:NewLoadout("Loadout B") |
| 276 | + build:NewLoadout("Loadout C") |
| 277 | + build.modFlag = false |
| 278 | + |
| 279 | + build:SetActiveLoadout(build:GetLoadoutByName("Loadout B")) |
| 280 | + |
| 281 | + local spec = build.treeTab.specList[2] |
| 282 | + t_remove(build.treeTab.specList, 2) |
| 283 | + t_insert(build.treeTab.specList, 4, spec) |
| 284 | + build:ReorderLoadout(2, 4) |
| 285 | + |
| 286 | + assert.is_same(4, #build.treeTab.specList) |
| 287 | + assert.is_same("Loadout A", build.treeTab.specList[4].title) |
| 288 | + assertActiveLoadoutByName("Loadout B") |
| 289 | + assert.is_true(build.modFlag) |
| 290 | + end) |
| 291 | + |
| 292 | + it("reorders loadouts when oldIndex is greater than newIndex and activeSpec is at oldIndex", function() |
| 293 | + build:NewLoadout("Loadout A") |
| 294 | + build:NewLoadout("Loadout B") |
| 295 | + build:NewLoadout("Loadout C") |
| 296 | + build.modFlag = false |
| 297 | + |
| 298 | + build:SetActiveLoadout(build:GetLoadoutByName("Loadout C")) |
| 299 | + |
| 300 | + local spec = build.treeTab.specList[4] |
| 301 | + t_remove(build.treeTab.specList, 4) |
| 302 | + t_insert(build.treeTab.specList, 2, spec) |
| 303 | + build:ReorderLoadout(4, 2) |
| 304 | + |
| 305 | + assert.is_same(4, #build.treeTab.specList) |
| 306 | + assert.is_same("Loadout C", build.treeTab.specList[2].title) |
| 307 | + assertActiveLoadoutByName("Loadout C") |
| 308 | + assert.is_true(build.modFlag) |
| 309 | + end) |
| 310 | + |
| 311 | + it("reorders loadouts when oldIndex is greater than newIndex and activeSpec is before newIndex", function() |
| 312 | + build:NewLoadout("Loadout A") |
| 313 | + build:NewLoadout("Loadout B") |
| 314 | + build:NewLoadout("Loadout C") |
| 315 | + build.modFlag = false |
| 316 | + |
| 317 | + build:SetActiveLoadout(build:GetLoadoutByName("Loadout B")) |
| 318 | + |
| 319 | + local spec = build.treeTab.specList[4] |
| 320 | + t_remove(build.treeTab.specList, 4) |
| 321 | + t_insert(build.treeTab.specList, 2, spec) |
| 322 | + build:ReorderLoadout(4, 2) |
| 323 | + |
| 324 | + assert.is_same(4, #build.treeTab.specList) |
| 325 | + assert.is_same("Loadout C", build.treeTab.specList[2].title) |
| 326 | + assertActiveLoadoutByName("Loadout B") |
| 327 | + assert.is_true(build.modFlag) |
| 328 | + end) |
| 329 | + |
| 330 | + it("reorders loadouts when oldIndex is greater than newIndex and activeSpec is after newIndex", function() |
| 331 | + build:NewLoadout("Loadout A") |
| 332 | + build:NewLoadout("Loadout B") |
| 333 | + build:NewLoadout("Loadout C") |
| 334 | + build.modFlag = false |
| 335 | + |
| 336 | + build:SetActiveLoadout(build:GetLoadoutByName("Loadout A")) |
| 337 | + |
| 338 | + local spec = build.treeTab.specList[4] |
| 339 | + t_remove(build.treeTab.specList, 4) |
| 340 | + t_insert(build.treeTab.specList, 3, spec) |
| 341 | + build:ReorderLoadout(4, 3) |
| 342 | + |
| 343 | + assert.is_same(4, #build.treeTab.specList) |
| 344 | + assert.is_same("Loadout C", build.treeTab.specList[3].title) |
| 345 | + assertActiveLoadoutByName("Loadout A") |
| 346 | + assert.is_true(build.modFlag) |
| 347 | + end) |
| 348 | + end) |
198 | 349 | end) |
199 | 350 |
|
200 | 351 | describe("BuildSetService", function() |
|
0 commit comments