Repository navigation
Expand file tree
/
Copy pathactions_spec.lua
More file actions
330 lines (306 loc) · 10.3 KB
/
Copy pathactions_spec.lua
File metadata and controls
330 lines (306 loc) · 10.3 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
describe('Actions', function()
local function init(wow, actions)
wow.addon.ClassActionSpecs[2] = { actions }
wow.state.player.class = 2
wow.state.player.name = 'Moo'
wow.state.realm = 'Cow'
wow.state:SendEvent('PLAYER_LOGIN')
wow.state:SendEvent('PLAYER_ENTERING_WORLD')
end
local everything = {
{ action = 3 },
{ bandage = true },
{ buff = true },
{ drink = true },
{ eat = true },
{ healset = { spells = { 'Greater Heal' }, ranks = { 1 } }, rank = 1 },
{ invslot = 13 },
{ macro = '/lol' },
{ mount = true },
{ noncombat = 2 },
{ page = {} },
{ petaction = 7 },
{ spell = 'Cooking' },
{ stopcasting = true },
}
it('makes a button', function()
wow.state.knownSpells = { 23456 }
init(wow, {
[1] = {
mouseover = true,
rank = 5,
spell = 'Greater Heal',
},
})
wow.env.mooActionButton1:Click()
local macro = ('/dismount [noflying]\n' .. '/cast [@mouseover,help,nodead][] Greater Heal(Rank 5)')
assert.same({ { macro = macro } }, wow.state.commands)
end)
it('drinks', function()
init(wow, {
[46] = { drink = true },
})
local button = wow.env.mooActionButton46
assert.same('', button:GetAttribute('macrotext'))
assert.same(0.0, button:GetAlpha())
wow.state.inventory[5350] = 1
wow.state:SendEvent('BAG_UPDATE_DELAYED')
assert.same('/run FollowUnit("player")\n/use item:5350', button:GetAttribute('macrotext'))
assert.same(1.0, button:GetAlpha())
end)
it('makes the right amount of buttons', function()
init(wow, {})
assert.Not.Nil(wow.env.mooActionButton1)
assert.Not.Nil(wow.env.mooActionButton48)
assert.Nil(wow.env.mooActionButton49)
end)
it('invokes macros on click', function()
init(wow, {
[34] = { buff = true },
})
wow.env.mooActionButton34:Click()
local macro = '/click PallyPowerAuto RightButton\n/click mooBuffButton'
assert.same({ { macro = macro } }, wow.state.commands)
end)
it('does not crash on events', function()
init(wow, everything)
wow.state:SendEvent('PLAYER_LOGIN')
wow.state:SendEvent('PLAYER_ENTERING_WORLD')
wow.state:SendEvent('BAG_UPDATE_DELAYED')
wow.state:SendEvent('UPDATE_BINDINGS')
wow.state:SendEvent('SPELL_UPDATE_COOLDOWN')
wow.state:SendEvent('PLAYER_EQUIPMENT_CHANGED', 4)
wow.state:EnterCombat()
wow.state:SendEvent('BAG_UPDATE_DELAYED')
wow.state:LeaveCombat()
wow.state:SendEvent('BAG_UPDATE_DELAYED')
end)
it('obeys stopcasting', function()
wow.state.knownSpells = { 23456 }
init(wow, {
[41] = {
mouseover = true,
stopcasting = true,
spell = 'Lay on Hands',
},
})
wow.env.mooActionButton41:Click()
local macro = ('/dismount [noflying]\n/stopcasting\n' .. '/cast [@mouseover,help,nodead][] Lay on Hands')
assert.same({ { macro = macro } }, wow.state.commands)
end)
it('can initialize all class specs', function()
for classid in pairs(wow.addon.ClassActionSpecs) do
wow.state.player.name = 'Notarealname'
wow.state.realm = 'Notarealrealm'
wow.state.player.class = classid
wow.state:SendEvent('PLAYER_LOGIN')
wow.state:SendEvent('PLAYER_ENTERING_WORLD')
assert.same('fraction1', wow.env.mooActionButtonHeader:GetAttribute('fractionpage'), classid)
end
end)
it('has non-combat macrotexts that are not too long', function()
init(wow, everything)
for i = 1, 48 do
local t = wow.env['mooActionButton' .. i]:GetAttribute('macrotext')
assert.True(not t or t:len() < 1024, i)
end
end)
it('has combat macrotexts that are not too long', function()
init(wow, everything)
wow.state:EnterCombat()
for i = 1, 48 do
local t = wow.env['mooActionButton' .. i]:GetAttribute('macrotext')
assert.True(not t or t:len() < 1024, i)
end
end)
it('hides buttons with no actions', function()
init(wow, {
[43] = { mount = true },
})
assert.False(wow.env.mooActionButton43:IsShown())
assert.False(wow.env.mooActionButton44:IsShown())
end)
it('shows mount button when a mount is available', function()
wow.state.inventory[5663] = 1
init(wow, {
[43] = { mount = true },
})
assert.True(wow.env.mooActionButton43:IsShown())
assert.False(wow.env.mooActionButton44:IsShown())
end)
it('does not crash OnUpdate', function()
init(wow, everything)
wow.state:TickUpdate(1)
end)
it('manages button state machine for spells', function()
init(wow, {
[1] = { spell = 'Greater Heal' },
})
assert.False(wow.env.mooActionButton1:IsShown())
wow.state:EnterCombat()
assert.False(wow.env.mooActionButton1:IsShown())
wow.state.knownSpells = { 23456 }
wow.state:SendEvent('SPELLS_CHANGED')
assert.False(wow.env.mooActionButton1:IsShown())
wow.state:LeaveCombat()
assert.True(wow.env.mooActionButton1:IsShown())
end)
it('changes pages', function()
init(wow, {
[1] = {
page = {
[2] = { macro = '/lol' },
},
},
})
assert.True(wow.env.mooActionButton1:IsShown())
assert.False(wow.env.mooActionButton2:IsShown())
wow.env.mooActionButton1:Click()
assert.False(wow.env.mooActionButton1:IsShown())
assert.True(wow.env.mooActionButton2:IsShown())
wow.env.mooActionButton2:Click()
assert.True(wow.env.mooActionButton1:IsShown())
assert.False(wow.env.mooActionButton2:IsShown())
assert.same({
{ macro = '#page:fraction1x1x' },
{ macro = '/lol' },
}, wow.state.commands)
end)
it('sets correct attributes on actions', function()
wow.state.actions[42] = true
init(wow, { { action = 42 } })
local button = wow.env.mooActionButton1
assert.same('action', button:GetAttribute('type'))
assert.same(42, button:GetAttribute('action'))
end)
it('sets correct attributes on petactions', function()
wow.state.petactions[2] = { nil, 'texture', false }
init(wow, { { petaction = 2 } })
local button = wow.env.mooActionButton1
assert.same('pet', button:GetAttribute('type'))
assert.same(2, button:GetAttribute('action'))
end)
it('sets button text', function()
init(wow, { { macro = '/lol', actionText = 'Laugh' } })
assert.same('Laugh', wow.env.mooActionButton1.Name:GetText())
end)
it('sets button text through paging', function()
init(wow, { {
actionText = 'Parent',
page = { { actionText = 'Child', macro = '/lol' } },
} })
local button = wow.env.mooActionButton1
assert.same('Parent', button.Name:GetText())
button:Click()
assert.same('Child', button.Name:GetText())
button:Click()
assert.same('Parent', button.Name:GetText())
end)
it('changes inventory counts', function()
init(wow, { { buff = true, reagent = 12345 } })
local button = wow.env.mooActionButton1
wow.state.inventory[12345] = 7
wow.state:SendEvent('BAG_UPDATE_DELAYED')
assert.same('7', button.Count:GetText())
wow.state.inventory[12345] = 5
wow.state:SendEvent('BAG_UPDATE_DELAYED')
assert.same('5', button.Count:GetText())
end)
it('does not overwrite button count if action page is not current', function()
init(wow, {
[1] = { buff = true, reagent = 12345 },
[2] = {
page = {
[1] = { buff = true },
},
},
})
local buffButton = wow.env.mooActionButton1
local pageButton = wow.env.mooActionButton2
wow.state.inventory[12345] = 7
wow.state:SendEvent('BAG_UPDATE_DELAYED')
assert.same('7', buffButton.Count:GetText())
pageButton:Click()
assert.same('', buffButton.Count:GetText())
wow.state.inventory[12345] = 5
wow.state:SendEvent('BAG_UPDATE_DELAYED')
assert.same('', buffButton.Count:GetText())
buffButton:Click()
assert.same('5', buffButton.Count:GetText())
end)
it('creates switcher buttons', function()
init(wow, everything)
assert.Not.Nil(wow.env.mooActionButtonAction1Switcher)
assert.Not.Nil(wow.env.mooActionButtonAction2Switcher)
assert.Not.Nil(wow.env.mooActionButtonFraction1Switcher)
assert.Not.Nil(wow.env.mooActionButtonFraction1x11xSwitcher)
assert.Not.Nil(wow.env.mooActionButtonPetSwitcher)
assert.Not.Nil(wow.env.mooActionButtonProfessionSwitcher)
end)
it('honors class action specs', function()
wow.state.player.class = 2
wow.addon.ClassActionSpecs[2] = { { [37] = { buff = true } } }
wow.state:SendEvent('PLAYER_LOGIN')
wow.state:SendEvent('PLAYER_ENTERING_WORLD')
assert.True(wow.env.mooActionButton37:IsShown())
end)
describe('healset type', function()
local slowHeals = {
ranks = { 1.0, 0.7, 0.4 },
spells = { 'Greater Heal', 'Heal', 'Lesser Heal' },
}
local fastHeals = {
ranks = { 1.0, 0.3, 0 },
spells = { 'Flash Heal' },
}
local actionSpec = {
{ healset = slowHeals, rank = 3 },
{ healset = slowHeals, rank = 2 },
{ healset = slowHeals, rank = 1 },
{ healset = fastHeals, rank = 3 },
{ healset = fastHeals, rank = 2 },
{ healset = fastHeals, rank = 1 },
}
it('defaults to empty', function()
init(wow, actionSpec)
for i = 1, 6 do
assert.False(wow.env['mooActionButton' .. i]:IsShown())
end
end)
it('only sets top rank when one spell is known', function()
wow.state.knownSpells = { 2052, 9474 }
init(wow, actionSpec)
local buttonNames = { [1] = 'LH2', [4] = 'FH4' }
for i = 1, 6 do
local button = wow.env['mooActionButton' .. i]
local buttonName = buttonNames[i]
if buttonName then
assert.True(button:IsShown(), buttonName)
assert.same(buttonName, button.Name:GetText(), buttonName)
else
assert.False(button:IsShown(), i)
end
end
end)
it('finds stable marriage when more spells are known than needed', function()
wow.state.knownSpells = {
10965,
10964,
10963,
2060,
6064, -- Greater Heal / Heal
10915,
9474,
9473,
9472,
2061, -- Flash Heal
}
init(wow, actionSpec)
for i, rank in ipairs({ 4, 3, 2, 5, 2, 1 }) do
local button = wow.env['mooActionButton' .. i]
assert.True(button:IsShown())
assert.same(('(Rank %d)'):format(rank), button:GetAttribute('macrotext'):sub(-8), i)
end
end)
end)
end)