-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Expand file tree
/
Copy pathTestLoadouts_spec.lua
More file actions
392 lines (338 loc) · 16.9 KB
/
Copy pathTestLoadouts_spec.lua
File metadata and controls
392 lines (338 loc) · 16.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
local t_insert = table.insert
describe("TestLoadouts", function()
before_each(function()
newBuild()
build.itemsTab:CreateDisplayItemFromRaw([[Dialla's Malefaction
Sage's Robe
Energy Shield: 95
EnergyShieldBasePercentile: 0
Variant: Pre 3.19.0
Variant: Current
Selected Variant: 2
Sage's Robe
Quality: 20
Sockets: R-G-B-B-B-B
LevelReq: 37
Implicits: 0
Gems can be Socketed in this Item ignoring Socket Colour
{variant:1}Gems Socketed in Red Sockets have +1 to Level
{variant:2}Gems Socketed in Red Sockets have +2 to Level
{variant:1}Gems Socketed in Green Sockets have +10% to Quality
{variant:2}Gems Socketed in Green Sockets have +30% to Quality
{variant:1}Gems Socketed in Blue Sockets gain 25% increased Experience
{variant:2}Gems Socketed in Blue Sockets gain 100% increased Experience
Has no Attribute Requirements]])
build.itemsTab:AddDisplayItem()
runCallback("OnFrame")
end)
teardown(function()
-- newBuild() takes care of resetting everything in setup()
end)
describe("Build", function()
describe("NewLoadout", function()
it("Creates a new loadout with the correct name", function()
local loadoutName = "Loadout Name"
build:NewLoadout(loadoutName, function() end)
build:SyncLoadouts()
-- There are 5 static items in the list
assert.are.equals(7, #build.controls.buildLoadouts.list)
assert.are.equals(loadoutName, build.controls.buildLoadouts.list[3])
assert.is_true(build.modFlag)
end)
it("calls the callback function", function()
local callbackCalled = false
build:NewLoadout("Loadout Name", function() callbackCalled = true end)
build:SyncLoadouts()
-- There are 5 static items in the list
assert.are.equals(7, #build.controls.buildLoadouts.list)
assert.are.equals(true, callbackCalled)
assert.is_true(build.modFlag)
end)
end)
describe("CopyLoadout", function()
it("Copies a loadout with a new name", function()
local loadoutName = "Loadout Name"
local newSpec, newItemSet, newSkillSet, newConfigSet = build:CopyLoadout(1, 1, 1, 1, loadoutName)
build:SyncLoadouts()
-- There are 5 static items in the list
assert.are.equals(7, #build.controls.buildLoadouts.list)
-- First index is the "Loadout: " header, second index is the start of the loadouts
assert.is_not.same(build.controls.buildLoadouts.list[2], build.controls.buildLoadouts.list[3])
assert.are.equals(loadoutName, build.controls.buildLoadouts.list[3])
assert.is_not.same(newSpec, build.spec)
assert.is_not.same(newItemSet, build.itemsTab.itemSets[1])
assert.is_not.same(newSkillSet, build.skillsTab.skillSets[1])
assert.is_not.same(newConfigSet, build.configTab.configSets[1])
assert.is_same(loadoutName, newSpec.title)
assert.is_same(loadoutName, newItemSet.title)
assert.is_same(loadoutName, newSkillSet.title)
assert.is_same(loadoutName, newConfigSet.title)
assert.is_true(build.modFlag)
end)
end)
describe("DeleteLoadout", function()
it("Deletes a loadout and sets the next to the requested loadout by name", function()
local loadoutNameToDelete = "Delete Me"
build:NewLoadout(loadoutNameToDelete, function() end)
build:SyncLoadouts()
-- There are 5 static items in the list
assert.are.equals(7, #build.controls.buildLoadouts.list)
local loadoutToDelete = build:GetLoadoutByName(loadoutNameToDelete)
local nextLoadout = build.controls.buildLoadouts.list[2] -- Default loadout
build:DeleteLoadout(loadoutNameToDelete, nextLoadout)
build:SyncLoadouts()
assert.is_nil(build.treeTab.specList[loadoutToDelete.specId])
assert.is_nil(build.skillsTab.skillSets[loadoutToDelete.skillSetId])
assert.is_nil(build.itemsTab.itemSets[loadoutToDelete.itemSetId])
assert.is_nil(build.configTab.configSets[loadoutToDelete.configSetId])
assert.is_nil(build.itemsTab.itemSetOrderList[loadoutToDelete.itemSetId])
assert.is_nil(build.skillsTab.skillSetOrderList[loadoutToDelete.skillSetId])
assert.is_nil(build.configTab.configSetOrderList[loadoutToDelete.configSetId])
assert.is_same(nextLoadout.specId, build.treeTab.displaySpecId)
assert.is_same(nextLoadout.itemSetId, build.itemsTab.displayItemSetId)
assert.is_same(nextLoadout.skillSetId, build.skillsTab.displaySkillSetId)
assert.is_same(nextLoadout.configSetId, build.configTab.displayConfigSetId)
assert.is_true(build.modFlag)
end)
it("Deleting the first loadout with one other loadout decrements the index for the remaining sets",
function()
local loadoutNameToDelete = "Default"
local nextLoadout = "Do not delete"
build:NewLoadout(nextLoadout, function() end)
build:SyncLoadouts()
-- There are 5 static items in the list
assert.are.equals(7, #build.controls.buildLoadouts.list)
local loadoutToDelete = build:GetLoadoutByName(loadoutNameToDelete)
build:DeleteLoadout(loadoutNameToDelete, nextLoadout)
build:SyncLoadouts()
assert.are.equals(1, #build.treeTab.specList)
assert.are.equals(1, #build.skillsTab.skillSets)
assert.are.equals(1, #build.itemsTab.itemSets)
assert.are.equals(1, #build.configTab.configSets)
assert.are.equals(nextLoadout, build.treeTab.specList[1].title)
assert.are.equals(nextLoadout, build.skillsTab.skillSets[1].title)
assert.are.equals(nextLoadout, build.itemsTab.itemSets[1].title)
assert.are.equals(nextLoadout, build.configTab.configSets[1].title)
assert.are.equals(1, #build.itemsTab.itemSetOrderList)
assert.are.equals(1, #build.skillsTab.skillSetOrderList)
assert.are.equals(1, #build.configTab.configSetOrderList)
assert.are.equals(1, build.itemsTab.itemSetOrderList[1])
assert.are.equals(1, build.skillsTab.skillSetOrderList[1])
assert.are.equals(1, build.configTab.configSetOrderList[1])
assert.is_same(nextLoadout.specId, build.treeTab.displaySpecId)
assert.is_same(nextLoadout.itemSetId, build.itemsTab.displayItemSetId)
assert.is_same(nextLoadout.skillSetId, build.skillsTab.displaySkillSetId)
assert.is_same(nextLoadout.configSetId, build.configTab.displayConfigSetId)
assert.is_true(build.modFlag)
end)
it(
"Deleting the first loadout with multiple other loadouts does not change the index for the remaining sets",
function()
local loadoutNameToDelete = "Default"
local nextLoadout1 = "Do not delete 1"
local nextLoadout2 = "Do not delete 2"
build:NewLoadout(nextLoadout1, function() end)
build:NewLoadout(nextLoadout2, function() end)
build:SyncLoadouts()
-- There are 5 static items in the list
assert.are.equals(8, #build.controls.buildLoadouts.list)
local loadoutToDelete = build:GetLoadoutByName(loadoutNameToDelete)
build:DeleteLoadout(loadoutNameToDelete, nextLoadout1)
build:SyncLoadouts()
assert.are.equals(2, #build.treeTab.specList)
assert.are.equals(3, #build.skillsTab.skillSets)
assert.are.equals(3, #build.itemsTab.itemSets)
assert.are.equals(3, #build.configTab.configSets)
assert.are.equals(nextLoadout1, build.treeTab.specList[1].title)
assert.are.equals(nextLoadout1, build.skillsTab.skillSets[2].title)
assert.are.equals(nextLoadout1, build.itemsTab.itemSets[2].title)
assert.are.equals(nextLoadout1, build.configTab.configSets[2].title)
assert.are.equals(nextLoadout2, build.treeTab.specList[2].title)
assert.are.equals(nextLoadout2, build.skillsTab.skillSets[3].title)
assert.are.equals(nextLoadout2, build.itemsTab.itemSets[3].title)
assert.are.equals(nextLoadout2, build.configTab.configSets[3].title)
assert.is_same(nextLoadout1.specId, build.treeTab.displaySpecId)
assert.is_same(nextLoadout1.itemSetId, build.itemsTab.displayItemSetId)
assert.is_same(nextLoadout1.skillSetId, build.skillsTab.displaySkillSetId)
assert.is_same(nextLoadout1.configSetId, build.configTab.displayConfigSetId)
assert.is_true(build.modFlag)
end)
end)
describe("RenameLoadout", function()
it("renames a loadout and calls the callback", function()
local oldName = "Old Loadout"
local newName = "New Loadout"
local callbackCalled = false
build:NewLoadout(oldName, function() end)
build:SyncLoadouts()
build:RenameLoadout(oldName, newName, function() callbackCalled = true end)
build:SyncLoadouts()
-- Verify the new name appears in the loadout list
assert.is_same(newName, build.controls.buildLoadouts.list[3])
-- Verify titles updated on spec, itemSet, skillSet, and configSet
local loadout = build:GetLoadoutByName(newName)
assert.is_same(newName, build.treeTab.specList[loadout.specId].title)
assert.is_same(newName, build.itemsTab.itemSets[loadout.itemSetId].title)
assert.is_same(newName, build.skillsTab.skillSets[loadout.skillSetId].title)
assert.is_same(newName, build.configTab.configSets[loadout.configSetId].title)
-- Ensure callback was called
assert.is_true(callbackCalled)
-- Old name should no longer exist
assert.is_nil(build:GetLoadoutByName(oldName))
assert.is_true(build.modFlag)
end)
end)
end)
describe("BuildSetService", function()
local buildSetService
before_each(function()
buildSetService = new("BuildSetService", build)
end)
describe("NewLoadout", function()
it("creates a new loadout", function()
local loadoutName = "Loadout Name"
buildSetService:NewLoadout(loadoutName)
assert.are.equals(7, #build.controls.buildLoadouts.list)
assert.are.equals(loadoutName, build.controls.buildLoadouts.list[3])
assert.is_true(build.modFlag)
end)
end)
describe("CopyLoadout", function()
it("copies an existing loadout and selects it", function()
local loadoutName = "Loadout Name"
local loadoutToCopy = build:GetLoadoutByName("Default")
buildSetService:CopyLoadout(loadoutToCopy.specId, loadoutToCopy.itemSetId, loadoutToCopy.skillSetId,
loadoutToCopy.configSetId, loadoutName)
assert.are.equals(7, #build.controls.buildLoadouts.list)
assert.are.equals(loadoutName, build.controls.buildLoadouts.list[3])
assert.are.equals(3, build.controls.buildLoadouts.selIndex)
assert.is_true(build.modFlag)
end)
end)
describe("RenameLoadout", function()
it("renames an existing loadout", function()
local oldname = "New Loadout"
local newName = "Renamed Loadout"
buildSetService:NewLoadout(oldname)
buildSetService:RenameLoadout(oldname, newName)
assert.are.equals(7, #build.controls.buildLoadouts.list)
assert.is_same({ "Default", newName },
{ build.controls.buildLoadouts.list[2], build.controls.buildLoadouts.list[3] })
assert.is_true(build.modFlag)
end)
end)
describe("DeleteLoadout", function()
it("deletes the current loadout", function()
local loadoutNameToDelete = "Delete Me"
buildSetService:NewLoadout(loadoutNameToDelete)
build:SetActiveLoadout(build:GetLoadoutByName(loadoutNameToDelete))
local specIdToDelete = build:GetLoadoutByName(loadoutNameToDelete).specId
buildSetService:DeleteLoadout(2, build.treeTab.specList, build.treeTab.specList[specIdToDelete])
assert.are.equals(6, #build.controls.buildLoadouts.list)
-- Default loadout return when only one loadout remains
assert.is_same({ itemSetId = 1, skillSetId = 1, configSetId = 1 },
build:GetLoadoutByName(loadoutNameToDelete))
end)
it("deletes the loadout before the current", function()
local loadoutNameToDelete = "Default"
local currentLoadout = "Do not delete"
buildSetService:NewLoadout(currentLoadout)
build:SetActiveLoadout(build:GetLoadoutByName(currentLoadout))
local specIdToDelete = build:GetLoadoutByName(loadoutNameToDelete).specId
buildSetService:DeleteLoadout(1, build.treeTab.specList, build.treeTab.specList[specIdToDelete])
assert.are.equals(6, #build.controls.buildLoadouts.list)
-- Default loadout return when only one loadout remains
assert.is_same({ itemSetId = 1, skillSetId = 1, configSetId = 1 },
build:GetLoadoutByName(loadoutNameToDelete))
assert.are.equals(2, build.controls.buildLoadouts.selIndex)
assert.are.equals("Do not delete", build.controls.buildLoadouts:GetSelValue())
end)
it("deletes the loadout after the current", function()
local loadoutNameToDelete = "Delete Me"
local currentLoadout = "Do not delete"
buildSetService:NewLoadout(currentLoadout)
buildSetService:NewLoadout(loadoutNameToDelete)
build:SetActiveLoadout(build:GetLoadoutByName(currentLoadout))
local specIdToDelete = build:GetLoadoutByName(loadoutNameToDelete).specId
buildSetService:DeleteLoadout(3, build.treeTab.specList, build.treeTab.specList[specIdToDelete])
assert.are.equals(7, #build.controls.buildLoadouts.list)
assert.is_nil(build:GetLoadoutByName(loadoutNameToDelete))
assert.are.equals(3, build.controls.buildLoadouts.selIndex)
assert.are.equals(currentLoadout, build.controls.buildLoadouts:GetSelValue())
end)
end)
describe("Integration", function()
it("completes a loadout lifecycle", function()
-- 2 New Loadouts, Copy 2, Delete one of each
local newLoadout1 = "New Loadout 1"
local newLoadout2 = "New Loadout 2"
local copyLoadout1 = "Copy Loadout 1"
local copyLoadout2 = "Copy Loadout 2"
local deleteLoadout1 = newLoadout1
local deleteLoadout2 = copyLoadout2
local currentLoadout = newLoadout2
buildSetService:NewLoadout(newLoadout1)
assert.are.equals(7, #build.controls.buildLoadouts.list)
assert.are.equals(newLoadout1, build.controls.buildLoadouts.list[3])
buildSetService:NewLoadout(newLoadout2)
assert.are.equals(8, #build.controls.buildLoadouts.list)
assert.are.equals(newLoadout2, build.controls.buildLoadouts.list[4])
build:SetActiveLoadout(build:GetLoadoutByName(currentLoadout))
assert.are.equals(4, build.controls.buildLoadouts.selIndex)
local loadoutToCopy = build:GetLoadoutByName(newLoadout1)
buildSetService:CopyLoadout(loadoutToCopy.specId, loadoutToCopy.itemSetId, loadoutToCopy.skillSetId,
loadoutToCopy.configSetId, copyLoadout1)
assert.are.equals(9, #build.controls.buildLoadouts.list)
assert.are.equals(copyLoadout1, build.controls.buildLoadouts.list[5])
assert.are.equals(5, build.controls.buildLoadouts.selIndex)
assert.is_true(build.modFlag)
local loadoutToCopy = build:GetLoadoutByName(newLoadout2)
buildSetService:CopyLoadout(loadoutToCopy.specId, loadoutToCopy.itemSetId, loadoutToCopy.skillSetId,
loadoutToCopy.configSetId, copyLoadout2)
assert.are.equals(10, #build.controls.buildLoadouts.list)
assert.are.equals(copyLoadout2, build.controls.buildLoadouts.list[6])
assert.are.equals(6, build.controls.buildLoadouts.selIndex)
assert.is_true(build.modFlag)
build:SetActiveLoadout(build:GetLoadoutByName(currentLoadout))
assert.are.equals(4, build.controls.buildLoadouts.selIndex)
local specIdToDelete = build:GetLoadoutByName(deleteLoadout1).specId
buildSetService:DeleteLoadout(2, build.treeTab.specList, build.treeTab.specList[specIdToDelete])
assert.are.equals(9, #build.controls.buildLoadouts.list)
assert.is_nil(build:GetLoadoutByName(deleteLoadout1))
assert.are.equals(3, build.controls.buildLoadouts.selIndex)
assert.are.equals(currentLoadout, build.controls.buildLoadouts:GetSelValue())
local specIdToDelete = build:GetLoadoutByName(deleteLoadout2).specId
buildSetService:DeleteLoadout(4, build.treeTab.specList, build.treeTab.specList[specIdToDelete])
assert.are.equals(8, #build.controls.buildLoadouts.list)
assert.is_nil(build:GetLoadoutByName(deleteLoadout2))
assert.are.equals(3, build.controls.buildLoadouts.selIndex)
assert.are.equals(currentLoadout, build.controls.buildLoadouts:GetSelValue())
end)
it("deletes all but the last loadout then copies it", function()
local loadoutNames = { "Loadout 1", "Loadout 2", "Loadout 3", "Loadout 4" }
for _, name in ipairs(loadoutNames) do
buildSetService:NewLoadout(name)
end
assert.are.equals(10, #build.controls.buildLoadouts.list)
build:SetActiveLoadout(build:GetLoadoutByName(loadoutNames[3]))
for i = 1, 4 do
local loadoutToDelete = build:GetLoadoutByName(build.controls.buildLoadouts.list[2])
local specIdToDelete = loadoutToDelete.specId
buildSetService:DeleteLoadout(1, build.treeTab.specList, build.treeTab.specList[specIdToDelete])
assert.are.equals(10 - i, #build.controls.buildLoadouts.list)
end
assert.is_not_nil(build:GetLoadoutByName(loadoutNames[4]))
assert.are.equals(2, build.controls.buildLoadouts.selIndex)
assert.are.equals(loadoutNames[4], build.controls.buildLoadouts:GetSelValue())
for i = 1, 3 do
local copyLoadoutName = loadoutNames[i] .. " Copy"
local loadoutToCopy = build:GetLoadoutByName(loadoutNames[4])
buildSetService:CopyLoadout(loadoutToCopy.specId, loadoutToCopy.itemSetId, loadoutToCopy.skillSetId,
loadoutToCopy.configSetId, copyLoadoutName)
assert.are.equals(6 + i, #build.controls.buildLoadouts.list)
assert.are.equals(copyLoadoutName, build.controls.buildLoadouts.list[2 + i])
end
end)
end)
end)
end)